forked from 74Labs/node-red-contrib-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google.html
179 lines (166 loc) · 6.09 KB
/
google.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<script type="text/javascript">
RED.nodes.registerType('google-conn', {
category: 'config',
defaults: {
name: {
value: "Google",
required: true
},
subject: {
value: "",
required: false
},
key: {
value: "{}",
required: true
},
scopes: {
value: "",
required: true
}
},
inputs: 0,
outputs: 0,
label: function () {
return this.name || "Google API";
}
});
</script>
<script type="text/x-red" data-template-name="google-conn">
<div class="form-row">
<label for="node-config-input-name">
<i class="icon-bookmark"></i>
Name</label>
<input type="text" id="node-config-input-name"/>
</div>
<div class="form-row">
<label for="node-config-input-name">
<i class="fa fa-envelope"></i>
Subject</label>
<input type="text" id="node-config-input-subject"/>
</div>
<div class="form-row">
<label for="node-config-input-key">
<i class="fa fa-fw fa-key"></i>
JSON Key</label>
<textarea id="node-config-input-key" rows="20" style="width: 100%"></textarea>
</div>
<div class="form-row">
<label for="node-config-input-scopes">
<i class="fa fa-fw fa-list"></i>
Scopes</label>
<textarea id="node-config-input-scopes" rows="10" style="width: 100%"></textarea>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('google', {
category: 'function',
color: '#FFCC66',
icon: 'google.png',
defaults: {
name: {
value: ""
},
google: {
type: "google-conn"
},
api: {
type: ""
},
operation: {
type: ""
}
},
inputs: 1,
outputs: 1,
label: function () {
return this.name || "google";
},
oneditprepare: function oneditprepare() {
var node = this;
var selectAPI = $('#node-input-api');
var selectOperation = $('#node-input-operation');
var scopesInfo = $('#node-scopes-info');
selectAPI.change(function () {
scopesInfo.empty();
selectOperation.children().not('#node-input-dynamic-operation').remove();
var api = selectAPI.val();
if (api) {
$.getJSON("google/apis/" + api + "/info", function (data) {
selectOperation.children().last().after(data.operations.map(function (d) {
return $('<option></option>').attr('value', d).attr('selected', node.operation === d).text(d).wrap('<p/>').parent().html();
}).join(""));
if (data.operations.indexOf(node.operation) < 0) {
$('#node-input-dynamic-operation').attr('selected', true);
}
$.each(data.scopes, function (i, v) {
scopesInfo.append($('<li></li>').text(v));
});
});
} else {
$('#node-input-dynamic-operation').attr('selected', true);
}
selectOperation.change();
});
$.getJSON("google/apis", function (data) {
selectAPI.children().last().after(data.map(function (d) {
return $('<option></option>').attr('value', d).attr('selected', node.api === d).text(d).wrap('<p/>').parent().html();
}).join(""));
if (data.indexOf(node.api) < 0) {
$('#node-input-dynamic-api').attr('selected', true);
}
selectAPI.change();
});
}
});
</script>
<script type="text/x-red" data-template-name="google">
<div class="form-row">
<label for="node-input-name">
<i class="icon-tag"></i>
Name</label>
<input type="text" id="node-input-name" placeholder="Name"/>
</div>
<div class="form-row">
<label for="node-input-google">
<i class="fa fa-google"></i>
Connection</label>
<input type="text" id="node-input-google"/>
</div>
<div class="form-row">
<label for="node-input-api">
<i class="fa fa-wrench"></i>
API</label>
<select type="text" id="node-input-api" style="display: inline-block;">
<option value="" id="node-input-dynamic-api" style="font-style: italic;">Dynamic (msg.api)</option>
</select>
</div>
<div class="form-row">
<label for="node-input-operation">
<i class="fa fa-wrench"></i>
Operation</label>
<select type="text" id="node-input-operation" style="display: inline-block; vertical-align: top;">
<option value="" id="node-input-dynamic-operation" style="font-style: italic;">Dynamic (msg.operation)</option>
</select>
</div>
<div class="form-row">
<label for="node-scopes-info">API Scopes</label>
<ul id="node-scopes-info"></ul>
</div>
</script>
<script type="text/x-red" data-help-name="google">
<p>A node that calls method of Google API.</p>
<p>API and operation selection can be made via node configuration or values passed in
<b>msg.google.api</b>
and/or
<b>msg.google.operation</b>.</p>
<p>Params for call are passed via
<b>msg.payload</b>.</p>
<p>The result is returned in
<b>msg.payload</b>.</p>
<p>See the
<a href="https://github.com/google/google-api-nodejs-client" target="_blank">
<i>google-api-nodejs-client</i>
</a> and <a href="https://developers.google.com/discovery/" target="_blank"><i>Google API Discovery Service</i></a>
for available APIs and operations.</p>
</script>