Merge branch 'main' into feature-active-targets

This commit is contained in:
Randall Morey committed 2021-02-08 16:33:14 -05:00
commit 7fa1d759f2
7 files changed
+88 -13

No files matched your search

+21 -1
View File
@@ -1,9 +1,10 @@
import Component from '@glimmer/component';
import ClipboardJS from 'clipboard';
import { action } from '@ember/object';
import { getOwner } from '@ember/application';
import { generateComponentID } from 'rose/utilities/component-auto-id';
import { task, timeout } from 'ember-concurrency';
import { tracked } from '@glimmer/tracking';
import ClipboardJS from 'clipboard';
export default class CopyableComponent extends Component {
@@ -46,6 +47,18 @@ export default class CopyableComponent extends Component {
return ClipboardJS.isSupported();
}
// =methods
/**
* Returns the first element with the specified class name if exists,
* otherwise undefined.
* @return {?HTMLElement}
*/
getFirstElementByClassName(className) {
const document = getOwner(this).lookup('service:-document').documentElement;
return document.getElementsByClassName(className)[0];
}
// =actions
/**
@@ -57,6 +70,13 @@ export default class CopyableComponent extends Component {
/* istanbul ignore next */
this.clipboard = new ClipboardJS(`#${this.copyableButtonId}`, {
text: () => this.args.text,
// ClipboardJS depends on inserting a hidden textarea that receives
// focus in order to copy text to the clipboard. However, our modal
// has a focus trap that prevents this focus. Thus we try to set the
// container to a modal (if exists), since this is the only container
// a user would be able to interact with. If a modal doesn't exist,
// container is set to `undefined` and thus uses the default body element.
container: this.getFirstElementByClassName('rose-dialog')
});
/* istanbul ignore next */
this.clipboard.on('success', (clipboardEvent) => {
+13 -5
View File
@@ -57,11 +57,19 @@
@dismiss={{accept}}
as |dialog|>
<dialog.body>
{{t 'states.connection.success.description'
port=confirmation.text.port
address=confirmation.text.address
protocol=confirmation.text.protocol
}}
<Copyable
@text={{concat confirmation.text.address ":" confirmation.text.port}}
@buttonText={{t "actions.copy-to-clipboard"}}
@acknowledgeText={{t "states.copied"}}
>
{{t 'states.connection.success.description'
port=confirmation.text.port
address=confirmation.text.address
protocol=confirmation.text.protocol
}}
</Copyable>
</dialog.body>
<dialog.footer>
<Rose::Button @style="primary" {{on "click" accept}}>
@@ -27,7 +27,13 @@
class={{concat "session-status-" sessionAggregate.session.status}}
@name="app-icons/action-session"
@size="medium" />
<code>{{sessionAggregate.session.id}}</code>
<Copyable
@text={{sessionAggregate.session.id}}
@buttonText={{t "actions.copy-to-clipboard"}}
@acknowledgeText={{t "states.copied"}}
>
<code>{{sessionAggregate.session.id}}</code>
</Copyable>
</row.headerCell>
<row.cell>{{sessionAggregate.target.displayName}}</row.cell>
<row.cell>
@@ -30,16 +30,34 @@
<p>{{model.target.description}}</p>
</row.cell>
<row.cell>
{{model.target.id}}
<Copyable
@text={{model.target.id}}
@buttonText={{t "actions.copy-to-clipboard"}}
@acknowledgeText={{t "states.copied"}}
>
<code>{{model.target.id}}</code>
</Copyable>
</row.cell>
<row.cell>
{{model.target.type}}
{{#if model.target.type}}
<Rose::Badge>
{{t (concat "resources.target.types." model.target.type)}}
</Rose::Badge>
{{/if}}
</row.cell>
<row.cell>
<div>
<Copyable
@text={{model.project.id}}
@buttonText={{t "actions.copy-to-clipboard"}}
@acknowledgeText={{t "states.copied"}}
>
<code>{{model.project.id}}</code>
</Copyable>
</div>
<Rose::Badge @style='informational'>
{{model.project.name}}
</Rose::Badge>
<p>{{model.project.id}}</p>
</row.cell>
<row.cell>
<Rose::Button @style="secondary" {{on "click" (route-action "connect" model)}}>
@@ -1,4 +1,13 @@
<h2>
{{@model.target.displayName}}
</h2>
<p>{{@model.target.description}}</p>
<p>{{@model.target.description}}</p>
<p>
<Copyable
@text={{@model.target.id}}
@buttonText={{t "actions.copy-to-clipboard"}}
@acknowledgeText={{t "states.copied"}}
>
<code>{{@model.target.id}}</code>
</Copyable>
</p>
@@ -8,7 +8,15 @@
{{host.displayName}}
<p>{{host.description}}</p>
</row.cell>
<row.cell>{{host.id}}</row.cell>
<row.cell>
<Copyable
@text={{host.id}}
@buttonText={{t "actions.copy-to-clipboard"}}
@acknowledgeText={{t "states.copied"}}
>
<code>{{host.id}}</code>
</Copyable>
</row.cell>
<row.cell>{{host.attributes.address}}</row.cell>
<row.cell>
<Rose::Badge>{{t (concat 'resources.host.types.' host.type)}}</Rose::Badge>
@@ -7,7 +7,13 @@
class={{concat "session-status-" session.status}}
@name="app-icons/action-session"
@size="medium" />
{{session.id}}
<Copyable
@text={{session.id}}
@buttonText={{t "actions.copy-to-clipboard"}}
@acknowledgeText={{t "states.copied"}}
>
<code>{{session.id}}</code>
</Copyable>
</row.cell>
<row.cell>
<time datetime={{format-date-iso session.created_time}}>