forked from 74Labs/node-red-contrib-google
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle.html
More file actions
123 lines (113 loc) · 4.6 KB
/
Copy pathgoogle.html
File metadata and controls
123 lines (113 loc) · 4.6 KB
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
<script type="text/javascript">
RED.nodes.registerType("google", {
category: "function",
color: "#ffcc66",
icon: "google.png",
defaults: {
name: {
value: ""
},
google: {
type: "google-credentials",
required: true
},
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 className="form-row">
<label htmlFor="node-input-name">
<i className="icon-tag"></i>
Name</label>
<input type="text" id="node-input-name" placeholder="Name"/>
</div>
<div className="form-row">
<label htmlFor="node-input-google">
<i className="fa fa-google"></i>
Connection</label>
<input type="text" id="node-input-google"/>
</div>
<div className="form-row">
<label htmlFor="node-input-api">
<i className="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 className="form-row">
<label htmlFor="node-input-operation">
<i className="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 className="form-row">
<label htmlFor="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>