diff --git a/assets/javascripts/discourse/components/share-report.hbs b/assets/javascripts/discourse/components/share-report.hbs new file mode 100644 index 0000000..e000148 --- /dev/null +++ b/assets/javascripts/discourse/components/share-report.hbs @@ -0,0 +1,25 @@ +
+ + {{d-icon "link"}} + {{@group}} + + + {{#if this.visible}} + + {{/if}} +
diff --git a/assets/javascripts/discourse/components/share-report.js b/assets/javascripts/discourse/components/share-report.js index 121275c..fbd42ae 100644 --- a/assets/javascripts/discourse/components/share-report.js +++ b/assets/javascripts/discourse/components/share-report.js @@ -1,76 +1,63 @@ -import Component from "@ember/component"; -import discourseComputed, { on } from "discourse-common/utils/decorators"; +import Component from "@glimmer/component"; import getURL from "discourse-common/lib/get-url"; -import { bind } from "@ember/runloop"; +import { bind } from "discourse-common/utils/decorators"; +import { action } from "@ember/object"; +import { tracked } from "@glimmer/tracking"; -export default Component.extend({ - classNames: ["share-report"], +export default class ShareReport extends Component { + @tracked visible = false; + element; - group: null, - query: null, - visible: false, + get link() { + return getURL(`/g/${this.args.group}/reports/${this.args.query.id}`); + } - @discourseComputed("group", "query") - link() { - return getURL(`/g/${this.group}/reports/${this.query.id}`); - }, - - _mouseDownHandler(event) { - if (!this.element || this.isDestroying || this.isDestroyed) { - return; + @bind + mouseDownHandler(e) { + if (!this.element.contains(e.target)) { + this.close(); } - if ($(this.element).has(event.target).length !== 0) { + } + + @bind + keyDownHandler(e) { + if (e.keyCode === 27) { + this.close(); + } + } + + @action + registerListeners(element) { + if (!element || this.isDestroying || this.isDestroyed) { return; } - this.send("close"); + this.element = element; + document.addEventListener("mousedown", this.mouseDownHandler); + element.addEventListener("keydown", this.keyDownHandler); + } - return true; - }, + @action + unregisterListeners(element) { + this.element = element; + document.removeEventListener("mousedown", this.mouseDownHandler); + element.removeEventListener("keydown", this.keyDownHandler); + } - _keydownHandler(event) { - if (!this.element || this.isDestroying || this.isDestroyed) { - return; - } + @action + focusInput(e) { + e.select(); + e.focus(); + } - if (event.keyCode === 27) { - this.send("close"); - } - }, + @action + open(e) { + e.preventDefault(); + this.visible = true; + } - @on("init") - _setupHandlers() { - this._boundMouseDownHandler = bind(this, this._mouseDownHandler); - this._boundKeydownHandler = bind(this, this._keydownHandler); - }, - - didInsertElement() { - this._super(...arguments); - - $("html") - .on("mousedown.outside-share-link", this._boundMouseDownHandler) - .on("keydown.share-view", this._boundKeydownHandler); - }, - - willDestroyElement() { - this._super(...arguments); - - $("html") - .off("mousedown.outside-share-link", this._boundMouseDownHandler) - .off("keydown.share-view", this._boundKeydownHandler); - }, - - actions: { - open() { - this.set("visible", true); - window.setTimeout( - () => $(this.element).find("input").select().focus(), - 160 - ); - }, - - close() { - this.set("visible", false); - }, - }, -}); + @action + close() { + this.visible = false; + } +} diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index afc8090..503a527 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -45,7 +45,7 @@ {{#if model.length}} {{#unless selectedItem.fake}} -
+
{{#if selectedItem}} {{#if editing}}
@@ -108,10 +108,14 @@ {{! the SQL editor will show the first time you }} {{#if everEditing}} -
+
- {{ace-editor content=selectedItem.sql mode="sql" disabled=selectedItem.destroyed}} + {{ace-editor + content=selectedItem.sql + mode="sql" + disabled=selectedItem.destroyed + }}
@@ -252,7 +256,7 @@ -
+
{{/unless}} {{conditional-loading-spinner condition=loading}} @@ -347,7 +351,7 @@ {{#each query.group_names as |group|}} - {{share-report group=group query=query}} + {{/each}} @@ -363,7 +367,7 @@ {{else}} -
+
{{i18n "explorer.no_search_results"}} diff --git a/assets/javascripts/discourse/templates/components/share-report.hbs b/assets/javascripts/discourse/templates/components/share-report.hbs deleted file mode 100644 index 3c03002..0000000 --- a/assets/javascripts/discourse/templates/components/share-report.hbs +++ /dev/null @@ -1,19 +0,0 @@ -
- {{d-icon "link"}} - {{group}} -
- -{{#if visible}} - -{{/if}}