2020-04-12 01:27:16 +02:00
|
|
|
import Controller from "@ember/controller";
|
2021-07-14 08:05:13 +02:00
|
|
|
import { empty } from "@ember/object/computed";
|
2024-11-22 17:11:51 +01:00
|
|
|
import { service } from "@ember/service";
|
2021-09-03 00:38:30 +02:00
|
|
|
import { fmt } from "discourse/lib/computed";
|
2024-11-22 17:11:51 +01:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2023-09-14 20:14:44 +02:00
|
|
|
import AdminWizardsColumnsModal from "../components/modal/admin-wizards-columns";
|
2022-10-05 17:14:43 +02:00
|
|
|
import { formatModel } from "../lib/wizard-submission";
|
2024-11-22 17:11:51 +01:00
|
|
|
import CustomWizardAdmin from "../models/custom-wizard-admin";
|
2020-04-12 01:27:16 +02:00
|
|
|
|
|
|
|
export default Controller.extend({
|
2023-09-14 20:14:44 +02:00
|
|
|
modal: service(),
|
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);
|
2022-10-05 17:14:43 +02:00
|
|
|
CustomWizardAdmin.submissions(wizardId, page)
|
2021-07-14 08:05:13 +02:00
|
|
|
.then((result) => {
|
|
|
|
if (result.submissions) {
|
2022-10-05 17:20:25 +02:00
|
|
|
const { submissions } = formatModel(result);
|
2022-10-05 17:14:43 +02:00
|
|
|
|
|
|
|
this.get("submissions").pushObjects(submissions);
|
2021-07-14 08:05:13 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.set("loadingMore", false);
|
|
|
|
});
|
2021-07-14 08:04:19 +02:00
|
|
|
},
|
2021-09-01 21:46:39 +02:00
|
|
|
|
2022-10-05 17:14:43 +02:00
|
|
|
@discourseComputed("submissions.[]", "fields.@each.enabled")
|
2021-08-25 03:59:24 +02:00
|
|
|
displaySubmissions(submissions, fields) {
|
2021-08-31 22:29:30 +02:00
|
|
|
let result = [];
|
|
|
|
|
2021-09-03 00:38:30 +02:00
|
|
|
submissions.forEach((submission) => {
|
2021-08-31 22:29:30 +02:00
|
|
|
let sub = {};
|
|
|
|
|
2021-09-03 00:38:30 +02:00
|
|
|
Object.keys(submission).forEach((fieldId) => {
|
|
|
|
if (fields.some((f) => f.id === fieldId && f.enabled)) {
|
2021-08-31 22:29:30 +02:00
|
|
|
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() {
|
2023-09-14 20:14:44 +02:00
|
|
|
return this.modal.show(AdminWizardsColumnsModal, {
|
2021-08-31 01:33:48 +02:00
|
|
|
model: {
|
2021-09-09 08:07:12 +02:00
|
|
|
columns: this.get("fields"),
|
|
|
|
reset: () => {
|
|
|
|
this.get("fields").forEach((field) => {
|
|
|
|
field.set("enabled", true);
|
|
|
|
});
|
|
|
|
},
|
2021-09-03 00:38:30 +02:00
|
|
|
},
|
2021-08-31 01:33:48 +02:00
|
|
|
});
|
|
|
|
},
|
2021-07-14 08:05:13 +02:00
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
});
|