From 6572b32706961bf45bdfe343dba2318704c2da06 Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 14 Sep 2023 19:14:44 +0100 Subject: [PATCH] move modals to glimmer components --- .../modal/admin-wizards-columns.hbs | 35 +++++++++++++++++++ .../components/modal/admin-wizards-columns.js | 14 ++++++++ .../modal/next-session-scheduled.hbs | 20 +++++++++++ .../modal/next-session-scheduled.js | 29 +++++++++++++++ .../controllers/admin-wizards-columns.js.es6 | 14 -------- .../admin-wizards-submissions-show.js.es6 | 6 ++-- .../admin-wizards-wizard-show.js.es6 | 8 +++-- .../controllers/next-session-scheduled.js.es6 | 30 ---------------- .../templates/modal/admin-wizards-columns.hbs | 35 ------------------- .../modal/next-session-scheduled.hbs | 17 --------- 10 files changed, 107 insertions(+), 101 deletions(-) create mode 100644 assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs create mode 100644 assets/javascripts/discourse/components/modal/admin-wizards-columns.js create mode 100644 assets/javascripts/discourse/components/modal/next-session-scheduled.hbs create mode 100644 assets/javascripts/discourse/components/modal/next-session-scheduled.js delete mode 100644 assets/javascripts/discourse/controllers/admin-wizards-columns.js.es6 delete mode 100644 assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 delete mode 100644 assets/javascripts/discourse/templates/modal/admin-wizards-columns.hbs delete mode 100644 assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs diff --git a/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs b/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs new file mode 100644 index 00000000..f83a92a0 --- /dev/null +++ b/assets/javascripts/discourse/components/modal/admin-wizards-columns.hbs @@ -0,0 +1,35 @@ + + {{#if loading}} + + {{else}} +
+ {{#each this.args.model.columns as |column|}} +
+
+ +
+
+ {{/each}} +
+ {{/if}} + +
+ diff --git a/assets/javascripts/discourse/components/modal/admin-wizards-columns.js b/assets/javascripts/discourse/components/modal/admin-wizards-columns.js new file mode 100644 index 00000000..87c6673f --- /dev/null +++ b/assets/javascripts/discourse/components/modal/admin-wizards-columns.js @@ -0,0 +1,14 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; + +export default class AdminWizardsColumnComponent extends Component { + title = I18n.t("admin.wizard.edit_columns"); + + @action save() { + this.args.closeModal(); + } + + @action resetToDefault() { + this.args.model.reset(); + } +} diff --git a/assets/javascripts/discourse/components/modal/next-session-scheduled.hbs b/assets/javascripts/discourse/components/modal/next-session-scheduled.hbs new file mode 100644 index 00000000..62d291f2 --- /dev/null +++ b/assets/javascripts/discourse/components/modal/next-session-scheduled.hbs @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/assets/javascripts/discourse/components/modal/next-session-scheduled.js b/assets/javascripts/discourse/components/modal/next-session-scheduled.js new file mode 100644 index 00000000..890ecc73 --- /dev/null +++ b/assets/javascripts/discourse/components/modal/next-session-scheduled.js @@ -0,0 +1,29 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { action } from "@ember/object"; + +export default class NextSessionScheduledComponent extends Component { + @tracked bufferedDateTime; + title = I18n.t("admin.wizard.after_time_modal.title"); + + constructor() { + super(...arguments); + this.bufferedDateTime = this.args.model.dateTime + ? moment(this.args.model.dateTime) + : moment(Date.now()); + } + + get submitDisabled() { + return moment().isAfter(this.bufferedDateTime); + } + + @action submit() { + const dateTime = this.bufferedDateTime; + this.args.model.update(moment(dateTime).utc().toISOString()); + this.args.closeModal(); + } + + @action dateTimeChanged(dateTime) { + this.bufferedDateTime = dateTime; + } +} diff --git a/assets/javascripts/discourse/controllers/admin-wizards-columns.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-columns.js.es6 deleted file mode 100644 index 4754c577..00000000 --- a/assets/javascripts/discourse/controllers/admin-wizards-columns.js.es6 +++ /dev/null @@ -1,14 +0,0 @@ -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.reset")(); - }, - }, -}); diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 index 41dabbb4..dfcf3b7e 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -2,11 +2,13 @@ import Controller from "@ember/controller"; import { empty } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators"; import { fmt } from "discourse/lib/computed"; -import showModal from "discourse/lib/show-modal"; +import { inject as service } from "@ember/service"; +import AdminWizardsColumnsModal from "../components/modal/admin-wizards-columns"; import CustomWizardAdmin from "../models/custom-wizard-admin"; import { formatModel } from "../lib/wizard-submission"; export default Controller.extend({ + modal: service(), downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"), noResults: empty("submissions"), page: 0, @@ -57,7 +59,7 @@ export default Controller.extend({ }, showEditColumnsModal() { - return showModal("admin-wizards-columns", { + return this.modal.show(AdminWizardsColumnsModal, { model: { columns: this.get("fields"), reset: () => { diff --git a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 index 75ea0ff7..6fa38b0b 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 @@ -3,7 +3,8 @@ import { observes, } from "discourse-common/utils/decorators"; import { notEmpty } from "@ember/object/computed"; -import showModal from "discourse/lib/show-modal"; +import { inject as service } from "@ember/service"; +import NextSessionScheduledModal from "../components/modal/next-session-scheduled"; import { generateId, wizardFieldList } from "../lib/wizard"; import { dasherize } from "@ember/string"; import { later, scheduleOnce } from "@ember/runloop"; @@ -13,6 +14,7 @@ import I18n from "I18n"; import { filterValues } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; export default Controller.extend({ + modal: service(), hasName: notEmpty("wizard.name"), @observes("currentStep") @@ -126,7 +128,7 @@ export default Controller.extend({ }, setNextSessionScheduled() { - let controller = showModal("next-session-scheduled", { + this.modal.show(NextSessionScheduledModal, { model: { dateTime: this.wizard.after_time_scheduled, update: (dateTime) => @@ -134,7 +136,7 @@ export default Controller.extend({ }, }); - controller.setup(); + // controller.setup(); }, copyUrl() { diff --git a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 b/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 deleted file mode 100644 index b8f51d1f..00000000 --- a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 +++ /dev/null @@ -1,30 +0,0 @@ -import { default as discourseComputed } from "discourse-common/utils/decorators"; -import Controller from "@ember/controller"; - -export default Controller.extend({ - title: "admin.wizard.after_time_modal.title", - - setup() { - this.set( - "bufferedDateTime", - this.model.dateTime ? moment(this.model.dateTime) : moment(Date.now()) - ); - }, - - @discourseComputed("bufferedDateTime") - submitDisabled(dateTime) { - return moment().isAfter(dateTime); - }, - - actions: { - submit() { - const dateTime = this.get("bufferedDateTime"); - this.get("model.update")(moment(dateTime).utc().toISOString()); - this.send("closeModal"); - }, - - dateTimeChanged(dateTime) { - this.set("bufferedDateTime", dateTime); - }, - }, -}); diff --git a/assets/javascripts/discourse/templates/modal/admin-wizards-columns.hbs b/assets/javascripts/discourse/templates/modal/admin-wizards-columns.hbs deleted file mode 100644 index b37a92bf..00000000 --- a/assets/javascripts/discourse/templates/modal/admin-wizards-columns.hbs +++ /dev/null @@ -1,35 +0,0 @@ -{{#d-modal-body title="admin.wizard.edit_columns"}} - {{#if loading}} - {{loading-spinner size="large"}} - {{else}} -
- {{#each model.columns as |column|}} -
-
- -
-
- {{/each}} -
- {{/if}} -{{/d-modal-body}} - - \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs b/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs deleted file mode 100644 index c7e52a56..00000000 --- a/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs +++ /dev/null @@ -1,17 +0,0 @@ -{{#d-modal-body class="next-session-time-modal" title=title}} - {{date-time-input - date=bufferedDateTime - onChange=(action "dateTimeChanged") - showTime=true - clearable=true - }} -{{/d-modal-body}} - - \ No newline at end of file