1
0
Fork 0

WIP: Edit Columns modal functionality

Currently modal and edit columns works but removes only field and not corresponding submission.
Dieser Commit ist enthalten in:
Keegan George 2021-08-30 16:33:48 -07:00
Ursprung d74d3d25be
Commit 0bc151fc7b
5 geänderte Dateien mit 87 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,16 @@
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, {
actions: {
save() {
this.send("closeModal");
},
resetToDefault() {
this.get('model.fields').forEach(field => {
field.set("enabled", true);
});
}
}
});

Datei anzeigen

@ -2,6 +2,9 @@ import Controller from "@ember/controller";
import { fmt } from "discourse/lib/computed"; import { fmt } from "discourse/lib/computed";
import { empty } from "@ember/object/computed"; import { empty } from "@ember/object/computed";
import CustomWizard from "../models/custom-wizard"; import CustomWizard from "../models/custom-wizard";
import showModal from "discourse/lib/show-modal";
import discourseComputed from "discourse-common/utils/decorators";
export default Controller.extend({ export default Controller.extend({
downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"), downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"),
@ -31,8 +34,11 @@ export default Controller.extend({
return submissions.map(submission => { return submissions.map(submission => {
let field = fields.find(f => Object.keys(submission).includes(f.id)); let field = fields.find(f => Object.keys(submission).includes(f.id));
if (!field.enabled) { if (!field.enabled) {
submission.delete(field.id); // insert field / submission deletion code here:
}; console.log(field, "is not enabled for ", submission);
} else if (field.enabled) {
console.log(field, "is enabled for ", submission);
}
return submission; return submission;
}); });
}, },
@ -44,5 +50,14 @@ export default Controller.extend({
this.loadMoreSubmissions(); this.loadMoreSubmissions();
} }
}, },
showEditColumnsModal() {
const controller = showModal("admin-wizards-submissions-columns", {
model: {
fields: this.get('fields'),
submissions: this.get('submissions')
}
});
},
}, },
}); });

Datei anzeigen

@ -224,31 +224,33 @@ CustomWizard.reopenClass({
}) })
.then((result) => { .then((result) => {
if (result.wizard) { if (result.wizard) {
let fields = ["username"]; console.log(result);
let fields = [{ id: "username", label: "User"}];
let submissions = []; let submissions = [];
let wizard = result.wizard; let wizard = result.wizard;
let total = result.total; let total = result.total;
result.submissions.forEach((s) => { result.submissions.forEach((s) => {
let submission = { let submission = {
username: s.username, username: s.user,
}; };
Object.keys(s.fields).forEach((f) => { Object.keys(s.fields).forEach((fieldId) => {
if (fields.indexOf(f) < 0) { if (!fields.some(field => field.id === fieldId)) {
fields.push(f); fields.push({ id: fieldId, label: s.fields[fieldId].label });
}
if (fields.includes(f)) {
submission[f] = s.fields[f];
} }
submission[fieldId] = s.fields[fieldId];
}); });
submission["submitted_at"] = s.submitted_at; submission["submitted_at"] = s.submitted_at;
submissions.push(submission); submissions.push(submission);
}); });
fields.push("submitted_at"); let submittedAt = {
id: "submitted_at",
label: "Submitted At"
}
fields.push(submittedAt);
return { return {
wizard, wizard,

Datei anzeigen

@ -1,6 +1,7 @@
import CustomWizard from "../models/custom-wizard";
import DiscourseRoute from "discourse/routes/discourse";
import { A } from "@ember/array"; import { A } from "@ember/array";
import EmberObject from "@ember/object";
import DiscourseRoute from "discourse/routes/discourse";
import CustomWizard from "../models/custom-wizard";
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
model(params) { model(params) {
@ -8,9 +9,14 @@ export default DiscourseRoute.extend({
}, },
setupController(controller, model) { setupController(controller, model) {
const fields = model.fields.map((f) => {
const fieldsObject = EmberObject.create(f);
fieldsObject.enabled = true;
return fieldsObject;
});
controller.setProperties({ controller.setProperties({
wizard: model.wizard, wizard: model.wizard,
fields: model.fields, fields: A(fields),
submissions: A(model.submissions), submissions: A(model.submissions),
total: model.total, total: model.total,
}); });

Datei anzeigen

@ -0,0 +1,32 @@
{{#d-modal-body title="directory.edit_columns.title"}}
{{#if loading}}
{{loading-spinner size="large"}}
{{else}}
<div class="edit-directory-columns-container">
{{#each model.fields as |field|}}
<div class="edit-directory-column">
<div class="left-content">
<label class="column-name">
{{input type="checkbox" checked=field.enabled}}
{{directory-table-header-title field=field.label translated=true}}
</label>
</div>
</div>
{{/each}}
</div>
{{/if}}
{{/d-modal-body}}
<div class="modal-footer">
{{d-button
class="btn-primary"
label="directory.edit_columns.save"
action=(action "save")
}}
{{d-button
class="btn-secondary reset-to-default"
label="directory.edit_columns.reset_to_default"
action=(action "resetToDefault")
}}
</div>