Upgrade share-report to Octane (#195)
* Upgrade share-report to Octane * add requested changes
This commit is contained in:
parent
467b6c8a91
commit
fea231f200
|
@ -0,0 +1,25 @@
|
||||||
|
<div class="share-report">
|
||||||
|
<a href="#" {{on "click" this.open}} class="share-report-button">
|
||||||
|
{{d-icon "link"}}
|
||||||
|
{{@group}}
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{{#if this.visible}}
|
||||||
|
<div
|
||||||
|
class="popup"
|
||||||
|
{{did-insert this.registerListeners}}
|
||||||
|
{{will-destroy this.unregisterListeners}}
|
||||||
|
>
|
||||||
|
<label>{{i18n "explorer.link"}} {{@group}}</label>
|
||||||
|
<input type="text" value={{this.link}} {{did-insert this.focusInput}} />
|
||||||
|
|
||||||
|
<DButton
|
||||||
|
@action={{this.close}}
|
||||||
|
@class="btn-flat close"
|
||||||
|
@icon="times"
|
||||||
|
@aria-label="share.close"
|
||||||
|
@title="share.close"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
|
@ -1,76 +1,63 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@glimmer/component";
|
||||||
import discourseComputed, { on } from "discourse-common/utils/decorators";
|
|
||||||
import getURL from "discourse-common/lib/get-url";
|
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({
|
export default class ShareReport extends Component {
|
||||||
classNames: ["share-report"],
|
@tracked visible = false;
|
||||||
|
element;
|
||||||
|
|
||||||
group: null,
|
get link() {
|
||||||
query: null,
|
return getURL(`/g/${this.args.group}/reports/${this.args.query.id}`);
|
||||||
visible: false,
|
}
|
||||||
|
|
||||||
@discourseComputed("group", "query")
|
@bind
|
||||||
link() {
|
mouseDownHandler(e) {
|
||||||
return getURL(`/g/${this.group}/reports/${this.query.id}`);
|
if (!this.element.contains(e.target)) {
|
||||||
},
|
this.close();
|
||||||
|
|
||||||
_mouseDownHandler(event) {
|
|
||||||
if (!this.element || this.isDestroying || this.isDestroyed) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
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;
|
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) {
|
@action
|
||||||
if (!this.element || this.isDestroying || this.isDestroyed) {
|
focusInput(e) {
|
||||||
return;
|
e.select();
|
||||||
}
|
e.focus();
|
||||||
|
}
|
||||||
|
|
||||||
if (event.keyCode === 27) {
|
@action
|
||||||
this.send("close");
|
open(e) {
|
||||||
}
|
e.preventDefault();
|
||||||
},
|
this.visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
@on("init")
|
@action
|
||||||
_setupHandlers() {
|
close() {
|
||||||
this._boundMouseDownHandler = bind(this, this._mouseDownHandler);
|
this.visible = false;
|
||||||
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);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
{{#if model.length}}
|
{{#if model.length}}
|
||||||
{{#unless selectedItem.fake}}
|
{{#unless selectedItem.fake}}
|
||||||
<div class="query-edit {{if editName "editing"}}">
|
<div class="query-edit {{if editName 'editing'}}">
|
||||||
{{#if selectedItem}}
|
{{#if selectedItem}}
|
||||||
{{#if editing}}
|
{{#if editing}}
|
||||||
<div class="name">
|
<div class="name">
|
||||||
|
@ -108,10 +108,14 @@
|
||||||
|
|
||||||
{{! the SQL editor will show the first time you }}
|
{{! the SQL editor will show the first time you }}
|
||||||
{{#if everEditing}}
|
{{#if everEditing}}
|
||||||
<div class="query-editor {{if hideSchema "no-schema"}}">
|
<div class="query-editor {{if hideSchema 'no-schema'}}">
|
||||||
<div class="panels-flex">
|
<div class="panels-flex">
|
||||||
<div class="editor-panel">
|
<div class="editor-panel">
|
||||||
{{ace-editor content=selectedItem.sql mode="sql" disabled=selectedItem.destroyed}}
|
{{ace-editor
|
||||||
|
content=selectedItem.sql
|
||||||
|
mode="sql"
|
||||||
|
disabled=selectedItem.destroyed
|
||||||
|
}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="right-panel">
|
<div class="right-panel">
|
||||||
|
@ -252,7 +256,7 @@
|
||||||
</label>
|
</label>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<hr>
|
<hr />
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
{{conditional-loading-spinner condition=loading}}
|
{{conditional-loading-spinner condition=loading}}
|
||||||
|
@ -347,7 +351,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td class="query-group-names">
|
<td class="query-group-names">
|
||||||
{{#each query.group_names as |group|}}
|
{{#each query.group_names as |group|}}
|
||||||
{{share-report group=group query=query}}
|
<ShareReport @group={{group}} @query={{query}} />
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</td>
|
</td>
|
||||||
<td class="query-created-at">
|
<td class="query-created-at">
|
||||||
|
@ -363,7 +367,7 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{else}}
|
{{else}}
|
||||||
<br>
|
<br />
|
||||||
<em class="no-search-results">
|
<em class="no-search-results">
|
||||||
{{i18n "explorer.no_search_results"}}
|
{{i18n "explorer.no_search_results"}}
|
||||||
</em>
|
</em>
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
<div role="button" onclick={{action "open"}}>
|
|
||||||
{{d-icon "link"}}
|
|
||||||
{{group}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{#if visible}}
|
|
||||||
<div class="popup">
|
|
||||||
<label>{{i18n "explorer.link"}} {{group}}</label>
|
|
||||||
<input type="text" value={{link}}>
|
|
||||||
|
|
||||||
{{d-button
|
|
||||||
action="close"
|
|
||||||
class="btn-flat close"
|
|
||||||
icon="times"
|
|
||||||
aria-label="share.close"
|
|
||||||
title="share.close"
|
|
||||||
}}
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
Loading…
Reference in New Issue