From 446e6bf29c4daa3ec3851604cfc280f54791fe18 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Mon, 28 Oct 2019 14:32:09 -0500 Subject: [PATCH] FEATURE: Popup to copy shareable links to reports (#41) * FEATURE: Popup to copy shareable links to reports * Only show created_at if it is non-empty * remove unneeded dependencies in share-report * Use Discourse.BaseUrl and i18n some text --- .../discourse/components/share-report.js.es6 | 86 +++++++++++++++++++ .../routes/admin-plugins-explorer.js.es6 | 2 - .../templates/admin/plugins-explorer.hbs | 8 +- .../templates/components/share-report.hbs | 13 +++ assets/stylesheets/explorer.scss | 24 +++++- config/locales/client.en.yml | 1 + 6 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 assets/javascripts/discourse/components/share-report.js.es6 create mode 100644 assets/javascripts/discourse/templates/components/share-report.hbs diff --git a/assets/javascripts/discourse/components/share-report.js.es6 b/assets/javascripts/discourse/components/share-report.js.es6 new file mode 100644 index 0000000..6dfbc25 --- /dev/null +++ b/assets/javascripts/discourse/components/share-report.js.es6 @@ -0,0 +1,86 @@ +import { + default as computed, + on +} from "ember-addons/ember-computed-decorators"; + +export default Ember.Component.extend({ + classNames: ["share-report"], + + group: null, + query: null, + visible: false, + + @computed("group", "query") + link() { + return ( + Discourse.BaseUrl + + "/g/" + + this.group + + "/reports/" + + this.query.id + ); + }, + + _mouseDownHandler(event) { + if (!this.element || this.isDestroying || this.isDestroyed) { + return; + } + if ($(this.element).has(event.target).length !== 0) { + return; + } + + this.send("close"); + + return true; + }, + + _keydownHandler(event) { + if (!this.element || this.isDestroying || this.isDestroyed) { + return; + } + + if (event.keyCode === 27) { + this.send("close"); + } + }, + + @on("init") + _setupHandlers() { + this._boundMouseDownHandler = Ember.run.bind(this, this._mouseDownHandler); + this._boundKeydownHandler = Ember.run.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(e) { + this.set("visible", true); + window.setTimeout( + () => + $(this.element) + .find("input") + .select() + .focus(), + 160 + ); + }, + + close(e) { + this.set("visible", false); + } + } +}); diff --git a/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 index 39d1213..02b4a87 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-explorer.js.es6 @@ -24,8 +24,6 @@ export default Discourse.Route.extend({ "group_names", (query.group_ids || []) .map(id => groupNames[id]) - .filter(n => n) - .join(", ") ); }); return { model, schema, groups }; diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index d5c7aa3..c14ff34 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -206,16 +206,16 @@ {{/if}} - {{#if query.group_names}} - {{query.group_names}} - {{/if}} + {{#each query.group_names as |group|}} + {{share-report group=group query=query}} + {{/each}} {{#if query.last_run_at}} {{bound-date query.last_run_at}} - {{else}} + {{else if query.created_at}} {{bound-date query.created_at}} diff --git a/assets/javascripts/discourse/templates/components/share-report.hbs b/assets/javascripts/discourse/templates/components/share-report.hbs new file mode 100644 index 0000000..4493742 --- /dev/null +++ b/assets/javascripts/discourse/templates/components/share-report.hbs @@ -0,0 +1,13 @@ +
+ {{d-icon "link"}} + {{group}} +
+{{#if visible}} + +{{/if}} diff --git a/assets/stylesheets/explorer.scss b/assets/stylesheets/explorer.scss index 5b412c9..f8c6406 100644 --- a/assets/stylesheets/explorer.scss +++ b/assets/stylesheets/explorer.scss @@ -360,7 +360,10 @@ table.group-reports { color: $primary-high; } .query-group-names { - color: $primary-high; + color: $tertiary; + a { + display: inline; + } } .query-created-at { color: $primary-medium; @@ -398,3 +401,22 @@ table.group-reports { .explorer-pad-bottom { margin-bottom: 200px; } + +.share-report { + cursor: pointer; + + label { + color: $primary-high; + } + input { + margin-right: 4px; + } + .popup { + background: white; + position: absolute; + box-shadow: shadow("card"); + padding: 12px; + z-index: 1; + } +} + diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ae4a7bf..5ea10e3 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -60,6 +60,7 @@ en: other: "Showing top %{count} results." query_name: "Query" query_groups: "Groups" + link: "Link for" report_name: "Report" query_description: "Description" query_time: "Last run"