-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatagate_create.html
229 lines (210 loc) · 6.7 KB
/
datagate_create.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!--
Copyright 2013, 2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/javascript">
var color = "#f2f2f2";
RED.nodes.registerType('datagate create', {
color: color,
category: 'S4CBigData',
defaults: {
auth: {
type: "datagate-credentials",
required: true
},
name: {
value: ""
},
description: {
value: ""
},
packageId: {
value: "",
required: true
},
timeseries: {
value: false,
required: false
},
fields: {
value: [{
type: "text",
id: "field_name"
}],
required: true
}
},
inputs: 0,
outputs: 0,
icon: "ckan_logo.png",
label: function () {
return this.name || "datagate create";
},
oneditprepare: function () {
var node = this;
var text = {
value: "text",
label: "text:"
};
var int = {
value: "int",
label: "int:"
};
var float = {
value: "float",
label: "float:"
};
var bool = {
value: "bool",
label: "bool:"
};
var date = {
value: "date",
label: "date:"
};
var json = {
value: "json",
label: "json:"
};
var time = {
value: "time",
label: "time:"
};
var timez = {
value: "time with time zone",
label: "timez:"
};
var timestamp = {
value: "timestamp",
label: "timestamp:"
};
var timestampz = {
value: "timestamp with time zone",
label: "timestampz:"
};
var supportedTypes = [text, int, float, bool, json, date, time, timez, timestamp, timestampz];
$("#node-input-field-container").css('min-height', '250px').css('min-width', '450px').editableList({
addItem: function (container, i, opt) {
var field = opt;
if (!field.hasOwnProperty('type')) {
field.type = 'text';
}
var row = $('<div/>').appendTo(container);
var valueField = $('<input/>', {
class: "node-input-field-value",
type: "text",
style: "margin-left: 5px;padding-left: 10px;"
}).appendTo(row).typedInput({
default: 'text',
types: supportedTypes
});
var finalspan = $('<span/>', {
style: "float: right;margin-top: 6px;"
}).appendTo(row);
finalspan.append(' → <span class="node-input-field-index">' + (i + 1) + '</span> ');
if (typeof field.id != "undefined") {
valueField.typedInput('value', field.id);
valueField.typedInput('type', field.type || 'text');
}
valueField.change()
},
removeItem: function (opt) {
var fields = $("#node-input-field-container").editableList('items');
fields.each(function (i) {
$(this).find(".node-input-field-index").html(i + 1);
});
},
removable: true
});
console.log(this.fields)
for (var i = 0; i < this.fields.length; i++) {
var field = this.fields[i];
$("#node-input-field-container").editableList('addItem', field);
}
},
oneditsave: function () {
var fields = $("#node-input-field-container").editableList('items');
var fieldset;
var node = this;
node.fields = [];
fields.each(function (i) {
var field = $(this);
var r = {};
r.id = field.find(".node-input-field-value").typedInput('value');
r.type = field.find(".node-input-field-value").typedInput('type');
if (r.id && r.type) {
node.fields.push(r);
}
});
},
button: {
onclick: function () {
console.log('querying')
var node = this;
$.ajax({
url: "datagate_create/" + this.id,
type: "POST",
success: function (resp) {
RED.notify("Node triggered", "success");
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 404) {
RED.notify("Node not deployed", "error");
} else {
RED.notify('Status: ' + jqXHR.status + ', ' + textStatus, "error");
}
}
});
}
}
});
</script>
<script type="text/x-red" data-template-name="datagate create">
<div class="form-row">
<label for="node-input-auth">
<i class="fa"></i> DATAGATE Auth:</label>
<input type="text" autocomplete="off" id="node-input-auth">
</div>
<div class="form-row">
<label for="node-input-name">
<i class="fa"></i> Resource Name:</label>
<input type="text" autocomplete="off" id="node-input-name">
</div>
<!-- <div class="form-row">
<label for="node-input-description"><i class="fa"></i> Description</label>
<input type="text" autocomplete="off" id="node-input-description">
</div> -->
<div class="form-row">
<label for="node-input-packageId">
<i class="fa"></i> Dataset Id:</label>
<input type="text" autocomplete="off" id="node-input-packageId">
</div>
<div class="form-row">
<label>Timeseries?</label>
<input type="checkbox" id="node-input-timeseries" style="display: inline-block; width: auto; vertical-align: top;">
</div>
<div class="form-row node-input-field-container-row">
<label for="node-input-field-container" style="width: 100%;">
<i class="fa"></i> Fields: choose the field type and specify its name.</label>
<ol id="node-input-field-container"></ol>
</div>
</script>
<script type="text/x-red" data-help-name="datagate create">
<p>This node creates a new DATAGATE Datastore resource. It allows to specify the resource schema to be stored (i.e the fields
of the data, like latitude, longitude of coordinate data).</p>
<p>It also supports creating timeseries resources using DATAGATE Timeseries API, a new extension that allows DATAGATE to work
with timeseries data. More at
<a href="https://github.com/namgk/ckan-timeseries">DATAGATE Timeseries Github</a>
</p>
<p>
<b>Note: Timeseries API will not be able to work with resources created by original Datastore API</b>
</p>
</script>