-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
121 lines (103 loc) · 2.6 KB
/
index.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var instance_skel = require('../../instance_skel');
require('isomorphic-unfetch')
var debug;
var log;
const stacksQueryGQL = `query stacks {
stacks {
id
label
}
}`
const executeStackMutationGQL = `mutation executeStack($id: String) {
executeStack(id: $id)
}`
function instance(system, id, config) {
var self = this;
// super-constructor
instance_skel.apply(this, arguments);
self.actions(); // export actions
return self;
}
instance.prototype.updateConfig = function(config) {
var self = this;
self.config = config;
self.actions();
}
instance.prototype.init = function() {
var self = this;
self.status(self.STATE_OK);
debug = self.debug;
log = self.log;
}
// Return config fields for web config
instance.prototype.config_fields = function () {
var self = this;
return [
{
type: 'text',
id: 'info',
width: 12,
label: 'Information',
value: 'This module provides the ability to execute Stacks on <a href="https://boreal.systems">Boreal Systems Director</>'
},
{
type: 'textinput',
id: 'core',
label: 'Director Core URI',
width: 12
}
]
}
// When module gets deleted
instance.prototype.destroy = function() {
var self = this;
debug("destroy");
}
instance.prototype.actions = function(system) {
var self = this;
fetch(`${self.config.core}/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: stacksQueryGQL
})
})
.then(r => r.json())
.then(data => self.stacks = data.data.stacks)
.then(() =>
self.setActions({
'stack': {
label: 'Execute Stack',
options: [
{
label: 'Stack',
type: 'dropdown',
id: 'stack',
choices: self.stacks,
default: 'false'
},
]
}
})
)
}
instance.prototype.action = function(action) {
var self = this;
console.log(action)
fetch(`${self.config.core}/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: executeStackMutationGQL,
variables: { id: action.options.stack }
})
})
}
instance_skel.extendedBy(instance);
exports = module.exports = instance;