This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
integration.js
101 lines (80 loc) · 3 KB
/
integration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Controller from '@ember/controller';
import {alias} from '@ember/object/computed';
import {computed} from '@ember/object';
import {task, timeout} from 'ember-concurrency';
export default Controller.extend({
integration: alias('model'),
allWebhooks: computed(function () {
return this.store.peekAll('webhook');
}),
filteredWebhooks: computed('allWebhooks.@each.{isNew,isDeleted}', function () {
return this.allWebhooks.filter((webhook) => {
let matchesIntegration = webhook.belongsTo('integration').id() === this.integration.id;
return matchesIntegration
&& !webhook.isNew
&& !webhook.isDeleted;
});
}),
actions: {
save() {
return this.save.perform();
},
toggleUnsavedChangesModal(transition) {
let leaveTransition = this.leaveScreenTransition;
if (!transition && this.showUnsavedChangesModal) {
this.set('leaveScreenTransition', null);
this.set('showUnsavedChangesModal', false);
return;
}
if (!leaveTransition || transition.targetName === leaveTransition.targetName) {
this.set('leaveScreenTransition', transition);
// if a save is running, wait for it to finish then transition
if (this.save.isRunning) {
return this.save.last.then(() => {
transition.retry();
});
}
// we genuinely have unsaved data, show the modal
this.set('showUnsavedChangesModal', true);
}
},
leaveScreen() {
let transition = this.leaveScreenTransition;
if (!transition) {
this.notifications.showAlert('Sorry, there was an error in the application. Please let the Ghost team know what happened.', {type: 'error'});
return;
}
// roll back changes on model props
this.integration.rollbackAttributes();
return transition.retry();
},
confirmWebhookDeletion(webhook) {
this.set('webhookToDelete', webhook);
},
cancelWebhookDeletion() {
this.set('webhookToDelete', null);
},
deleteWebhook() {
return this.webhookToDelete.destroyRecord();
}
},
save: task(function* () {
return yield this.integration.save();
}),
copyContentKey: task(function* () {
this._copyInputTextToClipboard('input#content_key');
yield timeout(3000);
}),
copyAdminKey: task(function* () {
this._copyInputTextToClipboard('input#admin_key');
yield timeout(3000);
}),
_copyInputTextToClipboard(selector) {
let input = document.querySelector(selector);
input.disabled = false;
input.focus();
input.select();
document.execCommand('copy');
input.disabled = true;
}
});