Skip to content

Commit c4c0a32

Browse files
committed
Merge branch 'mqtt-lib' of https://github.com/bcmi-labs/node-red-contrib-arduino-cloud into mqtt-lib
2 parents 78a81a5 + 3cbd012 commit c4c0a32

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

arduino-cloud.html

Lines changed: 34 additions & 9 deletions
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 },
@@ -43,27 +47,35 @@
4347
initThings(this.connection, this.thing);
4448
initProperties(this.connection, this.thing, this.property, outs);
4549
}
46-
$("select#node-input-connection").change(() => {
50+
$("select#node-input-connection").change((e) => {
4751
const connection = $("#node-input-connection").val();
52+
const thing_id = $("#node-input-thing").val();
4853
$("select#node-input-thing").empty();
4954
$("select#node-input-property").empty();
50-
if(this.defaultname && connection === "_ADD_") {
51-
$("#node-input-name").val("");
55+
if(connection === "_ADD_") {
56+
$("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-thing");
57+
if(this.defaultname){
58+
$("#node-input-name").val("");
59+
}
5260
}
53-
if (this.connection !== connection && connection !== "_ADD_") {
61+
if ((this.connection !== connection || thing_id === "") && connection !== "_ADD_") {
5462
initThings(connection);
5563
}
5664
$("#node-input-thing").trigger("change");
5765
});
5866
$("#node-input-thing").change(() => {
59-
6067
const thing_id = $("#node-input-thing").val();
68+
const connection = $("#node-input-connection").val();
69+
const thing_text = $("#node-input-thing").find('option:selected').text()
6170
if (thing_id && thing_id !== "") {
62-
const connection = $("#node-input-connection").val();
6371
initProperties(connection, thing_id, undefined, outs);
72+
} else if (connection === "_ADD_") {
73+
$("select#node-input-property").empty();
74+
$("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-property");
6475
} else {
6576
$("select#node-input-property").empty();
66-
}
77+
$("<option value='" + "" + "'> " + "No thing selected" + "</option>").appendTo("#node-input-property");
78+
}
6779
$("#node-input-property").trigger("change");
6880
});
6981
$("#node-input-property").change(() => {
@@ -117,7 +129,10 @@
117129
$.getJSON(`things?${queryString}`, things => {
118130
$("select#node-input-thing").empty();
119131
if (things && typeof (things) == "object" && things.error) {
132+
$("select#node-input-thing").empty();
120133
$("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-thing");
134+
$("select#node-input-property").empty();
135+
$("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-property");
121136
} else if (things && Array.isArray(things) && things.length !== 0) {
122137
$("<option value='" + "" + "'> " + "Select a thing" + "</option>").appendTo("#node-input-thing");
123138
for (const t of things) {
@@ -127,6 +142,11 @@
127142
$("#node-input-thing").val(thing_id);
128143
}
129144
$("#node-input-property").trigger("change");
145+
} else if (things && Array.isArray(things) && things.length === 0) {
146+
$("select#node-input-thing").empty();
147+
$("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-thing");
148+
$("select#node-input-property").empty();
149+
$("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-property");
130150
}
131151
});
132152
}
@@ -141,7 +161,10 @@
141161
$.getJSON(`properties?${queryString}`, properties => {
142162
$("select#node-input-property").empty();
143163
if (properties && typeof (properties) == "object" && properties.error) {
164+
$("select#node-input-thing").empty();
144165
$("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-thing");
166+
$("select#node-input-property").empty();
167+
$("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-property");
145168
} else if ((properties && Array.isArray(properties) && properties.length !== 0)) {
146169
$("<option value='" + "" + "'> " + "Select a property" + "</option>").appendTo("#node-input-property");
147170
for (const p of properties) {
@@ -152,6 +175,8 @@
152175
$("#node-input-property").val(property_id);
153176
}
154177
$("#node-input-name").trigger("change");
178+
} else if (properties && Array.isArray(properties) && properties.length === 0) {
179+
$("<option value='" + "" + "'> " + "No properties available" + "</option>").appendTo("#node-input-property");
155180
}
156181
});
157182
}

0 commit comments

Comments
 (0)