diff --git a/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-edit.js b/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-edit.js index 5c1ecb503fb..71df6c93240 100644 --- a/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-edit.js +++ b/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-edit.js @@ -9,6 +9,7 @@ import I18n from "discourse-i18n"; export default class AutomationEdit extends Controller { @service dialog; + @service router; error = null; isUpdatingAutomation = false; isTriggeringAutomation = false; @@ -26,7 +27,7 @@ export default class AutomationEdit extends Controller { } @action - saveAutomation() { + saveAutomation(routeToIndex = false) { this.setProperties({ error: null, isUpdatingAutomation: true }); return ajax( @@ -40,6 +41,9 @@ export default class AutomationEdit extends Controller { ) .then(() => { this.send("refreshRoute"); + if (routeToIndex) { + this.router.transitionTo("adminPlugins.discourse-automation.index"); + } }) .catch((e) => this._showError(e)) .finally(() => { diff --git a/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-new.js b/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-new.js index 298007c854b..f082e38e33c 100644 --- a/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-new.js +++ b/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-new.js @@ -1,38 +1,46 @@ +import { tracked } from "@glimmer/tracking"; import Controller from "@ember/controller"; -import EmberObject, { action } from "@ember/object"; -import { service } from "@ember/service"; -import { extractError } from "discourse/lib/ajax-error"; +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; export default class AutomationNew extends Controller { @service router; + @tracked filterText = ""; - form = null; - error = null; - - init() { - super.init(...arguments); - this._resetForm(); + @action + updateFilterText(event) { + this.filterText = event.target.value; } @action - saveAutomation() { - this.set("error", null); - - this.model.automation - .save(this.form.getProperties("name", "script")) - .then(() => { - this._resetForm(); - this.router.transitionTo( - "adminPlugins.discourse-automation.edit", - this.model.automation.id - ); - }) - .catch((e) => { - this.set("error", extractError(e)); - }); + resetFilterText() { + this.filterText = ""; } - _resetForm() { - this.set("form", EmberObject.create({ name: null, script: null })); + get scriptableContent() { + let scripts = this.model.scriptables.content; + let filter = this.filterText.toLowerCase(); + + if (!filter) { + return scripts; + } + + return scripts.filter((script) => { + const name = script.name ? script.name.toLowerCase() : ""; + const description = script.description + ? script.description.toLowerCase() + : ""; + return name.includes(filter) || description.includes(filter); + }); + } + + @action + selectScriptToEdit(newScript) { + this.model.automation.save({ script: newScript.id }).then(() => { + this.router.transitionTo( + "adminPlugins.discourse-automation.edit", + this.model.automation.id + ); + }); } } diff --git a/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-index.js b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-index.js index da2410c18fc..586341b2027 100644 --- a/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-index.js +++ b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-index.js @@ -1,13 +1,22 @@ import { action } from "@ember/object"; +import { service } from "@ember/service"; import DiscourseRoute from "discourse/routes/discourse"; export default class AutomationIndex extends DiscourseRoute { + @service router; + controllerName = "admin-plugins-discourse-automation-index"; model() { return this.store.findAll("discourse-automation-automation"); } + afterModel(model) { + if (!model.length) { + this.router.transitionTo("adminPlugins.discourse-automation.new"); + } + } + @action triggerRefresh() { this.refresh(); diff --git a/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-new.js b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-new.js index 77c1145674b..9fe8164815e 100644 --- a/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-new.js +++ b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-new.js @@ -6,6 +6,7 @@ export default class AutomationNew extends DiscourseRoute { model() { return hash({ + scripts: this.store.findAll("discourse-automation-automation"), scriptables: this.store.findAll("discourse-automation-scriptable"), automation: this.store.createRecord("discourse-automation-automation"), }); diff --git a/plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-edit.hbs b/plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-edit.hbs index 9036e062855..d43749415d6 100644 --- a/plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-edit.hbs +++ b/plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-edit.hbs @@ -10,11 +10,12 @@
{{model.automation.trigger.doc}}
+{{this.model.automation.trigger.doc}}
{{model.automation.script.with_trigger_doc}}
+{{this.model.automation.script.with_trigger_doc}}
{{i18n "discourse_automation.no_automation_yet"}}
-