Skip to content

Commit a5f3061

Browse files
committed
Configuration ux improved
1 parent b9820df commit a5f3061

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

arduino-cloud.html

+32-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
window.connectionManager = [];
33

44
function validator(v) {
5-
return (v !== null && v !== "" && v !== undefined);
5+
return (v !== null && v !== undefined && v !== "");
6+
}
7+
8+
function validateConnection(v) {
9+
return (v !== null && v !== undefined && v !== "" && v !== "_ADD_");
610
}
711

812
function validateTime(v) {
913
return (v !== null && v !== "" && v !== undefined && Number.isInteger(parseInt(v)) && parseInt(v) !== 0);
1014
}
1115

1216
function getDefaults(nodeName){
13-
var ret={connection: { type: "arduino-connection", validate: validator },
17+
var ret={connection: { type: "arduino-connection", validate: validateConnection },
1418
thing: { value: "", validate: validator },
1519
property: { value: "", validate: validator },
1620
name: { value: "", validate: validator },
@@ -47,26 +51,34 @@
4751
const connection = $("#node-input-connection").val();
4852
$("select#node-input-thing").empty();
4953
$("select#node-input-property").empty();
50-
if(this.defaultname && connection === "_ADD_") {
51-
$("#node-input-name").val("");
54+
if(connection === "_ADD_") {
55+
$("<option value='" + "" + "'> " + "Select a connection" + "</option>").appendTo("#node-input-thing");
56+
if(this.defaultname){
57+
$("#node-input-name").val("");
58+
}
5259
}
5360
if (this.connection !== connection && connection !== "_ADD_") {
5461
initThings(connection);
5562
}
5663
$("#node-input-thing").trigger("change");
5764
});
5865
$("#node-input-thing").change(() => {
59-
6066
const thing_id = $("#node-input-thing").val();
67+
const connection = $("#node-input-connection").val();
68+
const thing_text = $("#node-input-thing").find('option:selected').text()
6169
if (thing_id && thing_id !== "") {
62-
const connection = $("#node-input-connection").val();
6370
initProperties(connection, thing_id, undefined, outs);
71+
} else if (connection === "_ADD_") {
72+
$("select#node-input-property").empty();
73+
$("<option value='" + "" + "'> " + "Select a connection" + "</option>").appendTo("#node-input-property");
6474
} else {
6575
$("select#node-input-property").empty();
66-
}
76+
$("<option value='" + "" + "'> " + "Select a thing" + "</option>").appendTo("#node-input-property");
77+
}
6778
$("#node-input-property").trigger("change");
6879
});
6980
$("#node-input-property").change(() => {
81+
debugger;
7082
const property_name = $("#node-input-property").find('option:selected').text();
7183
const property_value = $("#node-input-property").find('option:selected').val();
7284
if (property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) {
@@ -166,7 +178,10 @@
166178
$.getJSON(`things?${queryString}`, things => {
167179
$("select#node-input-thing").empty();
168180
if (things && typeof (things) == "object" && things.error) {
181+
$("select#node-input-thing").empty();
169182
$("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-thing");
183+
$("select#node-input-property").empty();
184+
$("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-property");
170185
} else if (things && Array.isArray(things) && things.length !== 0) {
171186
$("<option value='" + "" + "'> " + "Select a thing" + "</option>").appendTo("#node-input-thing");
172187
for (const t of things) {
@@ -176,6 +191,11 @@
176191
$("#node-input-thing").val(thing_id);
177192
}
178193
$("#node-input-property").trigger("change");
194+
} else if (things && Array.isArray(things) && things.length === 0) {
195+
$("select#node-input-thing").empty();
196+
$("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-thing");
197+
$("select#node-input-property").empty();
198+
$("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-property");
179199
}
180200
});
181201
}
@@ -190,7 +210,10 @@
190210
$.getJSON(`properties?${queryString}`, properties => {
191211
$("select#node-input-property").empty();
192212
if (properties && typeof (properties) == "object" && properties.error) {
213+
$("select#node-input-thing").empty();
193214
$("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-thing");
215+
$("select#node-input-property").empty();
216+
$("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-property");
194217
} else if ((properties && Array.isArray(properties) && properties.length !== 0)) {
195218
$("<option value='" + "" + "'> " + "Select a property" + "</option>").appendTo("#node-input-property");
196219
for (const p of properties) {
@@ -201,6 +224,8 @@
201224
$("#node-input-property").val(property_id);
202225
}
203226
$("#node-input-name").trigger("change");
227+
} else if (properties && Array.isArray(properties) && properties.length === 0) {
228+
$("<option value='" + "" + "'> " + "No properties available" + "</option>").appendTo("#node-input-property");
204229
}
205230
});
206231
}

0 commit comments

Comments
 (0)