2020-04-12 01:27:16 +02:00
|
|
|
import Controller from "@ember/controller";
|
|
|
|
import { fmt } from "discourse/lib/computed";
|
2021-07-14 08:05:13 +02:00
|
|
|
import { empty } from "@ember/object/computed";
|
2021-07-14 08:04:19 +02:00
|
|
|
import CustomWizard from "../models/custom-wizard";
|
2021-08-31 01:33:48 +02:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
|
|
|
2020-04-12 01:27:16 +02:00
|
|
|
|
|
|
|
export default Controller.extend({
|
2021-03-28 11:06:49 +02:00
|
|
|
downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"),
|
2021-07-14 08:05:13 +02:00
|
|
|
noResults: empty("submissions"),
|
2021-07-14 08:04:19 +02:00
|
|
|
page: 0,
|
|
|
|
total: 0,
|
|
|
|
|
|
|
|
loadMoreSubmissions() {
|
2021-07-14 08:05:13 +02:00
|
|
|
const page = this.get("page");
|
|
|
|
const wizardId = this.get("wizard.id");
|
2021-07-14 08:04:19 +02:00
|
|
|
|
2021-07-14 08:05:13 +02:00
|
|
|
this.set("loadingMore", true);
|
|
|
|
CustomWizard.submissions(wizardId, page)
|
|
|
|
.then((result) => {
|
|
|
|
if (result.submissions) {
|
|
|
|
this.get("submissions").pushObjects(result.submissions);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.set("loadingMore", false);
|
|
|
|
});
|
2021-07-14 08:04:19 +02:00
|
|
|
},
|
2021-08-25 03:59:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
@discourseComputed('submissions', 'fields.@each.enabled')
|
|
|
|
displaySubmissions(submissions, fields) {
|
2021-08-31 22:29:30 +02:00
|
|
|
let result = [];
|
|
|
|
|
|
|
|
submissions.forEach(submission => {
|
|
|
|
let sub = {};
|
|
|
|
|
|
|
|
Object.keys(submission).forEach(fieldId => {
|
|
|
|
if (fields.some(f => f.id === fieldId && f.enabled)) {
|
|
|
|
sub[fieldId] = submission[fieldId];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
result.push(sub);
|
2021-08-25 03:59:24 +02:00
|
|
|
});
|
2021-08-31 22:29:30 +02:00
|
|
|
|
|
|
|
return result;
|
2021-08-25 03:59:24 +02:00
|
|
|
},
|
2021-07-14 08:04:19 +02:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
loadMore() {
|
2021-07-14 08:05:13 +02:00
|
|
|
if (!this.loadingMore && this.submissions.length < this.total) {
|
|
|
|
this.set("page", this.get("page") + 1);
|
2021-07-14 08:04:19 +02:00
|
|
|
this.loadMoreSubmissions();
|
|
|
|
}
|
2021-07-14 08:05:13 +02:00
|
|
|
},
|
2021-08-31 01:33:48 +02:00
|
|
|
|
|
|
|
showEditColumnsModal() {
|
|
|
|
const controller = showModal("admin-wizards-submissions-columns", {
|
|
|
|
model: {
|
|
|
|
fields: this.get('fields'),
|
|
|
|
submissions: this.get('submissions')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2021-07-14 08:05:13 +02:00
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
});
|