From a8771d2ad57083a91b7130df807fa54c26205d11 Mon Sep 17 00:00:00 2001 From: Ricky Chon Date: Tue, 14 Jul 2020 11:24:24 -0400 Subject: [PATCH] FEATURE: Add hide button (toggleable) for all queries (frontend only) * Switches between hide/unhide on click * Works almost like the delete button, but toggles between the query's hidden attribute instead * So far this is only a frontend feature, the backend implementation still needs work --- .../controllers/admin-plugins-explorer.js.es6 | 26 +++++++++++++++++++ .../templates/admin/plugins-explorer.hbs | 11 +++++--- config/locales/client.en.yml | 2 ++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 index 45abb25..3107950 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 @@ -236,6 +236,32 @@ export default Ember.Controller.extend({ }); }, + hide() { + const query = this.selectedItem; + this.setProperties({ loading: true, showResults: false }); + + query.set("isNew", true); + + this.store + .destroyRecord("query", query) + .then(() => query.set("hidden", true)) + .catch(popupAjaxError) + .finally(() => { + query.set("isNew", false); + this.set("loading", false); + }); + }, + + unhide() { + const query = this.selectedItem; + this.setProperties({ loading: true, showResults: true }); + query + .save() + .then(() => query.set("hidden", false)) + .catch(popupAjaxError) + .finally(() => this.set("loading", false)); + }, + run() { if (this.get("selectedItem.dirty")) { return; diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index 91b3487..306ba02 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -118,9 +118,14 @@ {{#if everEditing}} {{d-button action=(action "discard") icon="undo" label="explorer.undo" disabled=saveDisabled}} {{/if}} - {{#unless editDisabled}} - {{d-button action=(action "destroy") class="btn-danger" icon="trash-alt" label="explorer.delete"}} - {{/unless}} + {{#if selectedItem.hidden}} + {{d-button action=(action "unhide") icon="undo" label="explorer.unhide"}} + {{else}} + {{d-button action=(action "hide") icon="far-eye-slash" label="explorer.hide"}} + {{#unless editDisabled}} + {{d-button action=(action "destroy") class="btn-danger" icon="trash-alt" label="explorer.delete"}} + {{/unless}} + {{/if}} {{/if}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index c234e28..4edd290 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -49,6 +49,8 @@ en: edit: "Edit" delete: "Delete" recover: "Undelete Query" + hide: "Hide" + unhide: "Unhide Query" download_json: "JSON" download_csv: "CSV" others_dirty: "A query has unsaved changes that will be lost if you navigate away."