From 2398d73e241f86616d74cc94e7cf9f453c1ea46c Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Sat, 23 Feb 2019 16:48:18 +0700 Subject: [PATCH] Added copyable API Url to custom integration screen --- .../app/controllers/settings/integration.js | 32 +++-- .../app/templates/settings/integration.hbs | 128 +++++++++--------- 2 files changed, 88 insertions(+), 72 deletions(-) diff --git a/ghost/admin/app/controllers/settings/integration.js b/ghost/admin/app/controllers/settings/integration.js index 3a7e889e2f..216960ab01 100644 --- a/ghost/admin/app/controllers/settings/integration.js +++ b/ghost/admin/app/controllers/settings/integration.js @@ -11,12 +11,20 @@ import {task, timeout} from 'ember-concurrency'; export default Controller.extend({ config: service(), + ghostPaths: service(), imageExtensions: IMAGE_EXTENSIONS, imageMimeTypes: IMAGE_MIME_TYPES, integration: alias('model'), + apiUrl: computed(function () { + let origin = window.location.origin; + let subdir = this.ghostPaths.subdir; + + return this.ghostPaths.url.join(origin, subdir); + }), + allWebhooks: computed(function () { return this.store.peekAll('webhook'); }), @@ -127,21 +135,29 @@ export default Controller.extend({ }), copyContentKey: task(function* () { - this._copyInputTextToClipboard('input#content_key'); + this._copyTextToClipboard(this.integration.contentKey.secret); yield timeout(3000); }), copyAdminKey: task(function* () { - this._copyInputTextToClipboard('input#admin_key'); + this._copyTextToClipboard(this.integration.adminKey.secret); yield timeout(3000); }), - _copyInputTextToClipboard(selector) { - let input = document.querySelector(selector); - input.disabled = false; - input.focus(); - input.select(); + copyApiUrl: task(function* () { + this._copyTextToClipboard(this.apiUrl); + yield timeout(3000); + }), + + _copyTextToClipboard(text) { + let textarea = document.createElement('textarea'); + textarea.value = text; + textarea.setAttribute('readonly', ''); + textarea.style.position = 'absolute'; + textarea.style.left = '-9999px'; + document.body.appendChild(textarea); + textarea.select(); document.execCommand('copy'); - input.disabled = true; + document.body.removeChild(textarea); } }); diff --git a/ghost/admin/app/templates/settings/integration.hbs b/ghost/admin/app/templates/settings/integration.hbs index f1171324ee..496069d906 100644 --- a/ghost/admin/app/templates/settings/integration.hbs +++ b/ghost/admin/app/templates/settings/integration.hbs @@ -1,5 +1,5 @@
-
+

{{#link-to "settings.integrations" data-test-link="integrations-back"}}Integrations{{/link-to}} @@ -92,70 +92,70 @@ -

API Keys

-
- {{#with integration.contentKey as |contentKey|}} - {{#gh-validation-status-container class="flex flex-column w-100 mr5"}} -
- - - {{#if copyContentKey.isRunning}} - Copied to clipboard - {{else}} - {{contentKey.lastSeenAtUTC}} - {{/if}} - -
-
- - -
-
- -
-
-
- {{/gh-validation-status-container}} - {{/with}} - {{#if config.enableDeveloperExperiments}} - {{#with integration.adminKey as |adminKey|}} - {{#gh-validation-status-container class="flex flex-column w-100 ml3"}} -
- - - {{#if copyAdminKey.isRunning}} - Copied to clipboard - {{else}} - {{adminKey.lastSeenAtUTC}} - {{/if}} - -
-
- - -
-
- +
+ + + + + + + {{#if config.enableDeveloperExperiments}} + + + + + {{/if}} + + + + + +
Content API Key +
+ {{this.integration.contentKey.secret}} +
+
+ +
- - {{/gh-validation-status-container}} - {{/with}} - {{/if}} +
Admin API Key +
+ {{this.integration.adminKey.secret}} +
+
+ +
+
+
+
API URL +
+ {{this.apiUrl}} +
+
+ +
+
+
+

Webhooks

@@ -214,7 +214,7 @@ {{#link-to "settings.integration.webhooks.new" integration classNames="flex items-center" data-test-link="add-webhook"}}
- {{svg-jar "add" class="w3 h3 fill-blue-d1"}} + {{svg-jar "add" class="w3 h3 fill-blue-d1"}} Add webhook
{{/link-to}}