Skip to content

Field checking improved #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions arduino-cloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,56 @@
},
paletteLabel: labelName,
oneditprepare: function () {
debugger;
if (this.connection && this.connection !== "_ADD_") {
initThings(this.connection, this.thing);
initProperties(this.connection, this.thing, this.property, outs);
}
$("select#node-input-connection").change((e) => {
debugger;
const connection = $("#node-input-connection").val();
const thing_id = $("#node-input-thing").val();
$("select#node-input-thing").empty();
$("select#node-input-property").empty();
if (connection === "_ADD_") {
$("select#node-input-thing").empty();
$("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-thing");
if (this.defaultname) {
$("#node-input-name").val("");
}
$("#node-input-thing").trigger("change");
} else {
if (thing_id !== "updating") {
$("select#node-input-thing").empty();
$("select#node-input-property").empty();
initThings(connection);
}
}
if ((this.connection !== connection || thing_id === "") && connection !== "_ADD_") {
initThings(connection);
}
$("#node-input-thing").trigger("change");
});
$("#node-input-thing").change(() => {
const thing_id = $("#node-input-thing").val();
const property_id = $("#node-input-property").val();
const connection = $("#node-input-connection").val();
const thing_text = $("#node-input-thing").find('option:selected').text()
if (thing_id && thing_id !== "") {
initProperties(connection, thing_id, undefined, outs);
} else if (connection === "_ADD_") {
debugger;
if (connection === "_ADD_") {
$("select#node-input-property").empty();
$("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-property");
} else {
$("select#node-input-property").empty();
$("<option value='" + "" + "'> " + "No thing selected" + "</option>").appendTo("#node-input-property");
}
$("#node-input-property").trigger("change");
$("#node-input-property").trigger("change");
} else if (property_id !== "updating") {
if (thing_id === undefined || thing_id === null || thing_id === "") {
$("select#node-input-property").empty();
$("<option value='" + "" + "'> " + "No thing selected" + "</option>").appendTo("#node-input-property");
$("#node-input-property").trigger("change");
} else {
$("select#node-input-property").empty();
initProperties(connection, thing_id, undefined, outs);
}
}
});
$("#node-input-property").change(() => {
const property_name = $("#node-input-property").find('option:selected').text();
const property_value = $("#node-input-property").find('option:selected').val();
if (property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) {
debugger;
if (property_name !== " " && property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) {
this.propname = property_name;
$("#node-input-name").val(property_name);
}
Expand Down Expand Up @@ -127,9 +138,15 @@
}
}
function initThings(connection, thing_id) {
debugger;
const queryString = prepareQueryString(connection);
if (!queryString || queryString === "")
return;

$("select#node-input-thing").empty();
$("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-thing");
$("select#node-input-thing").val("updating");

$.getJSON(`things?${queryString}`, things => {
$("select#node-input-thing").empty();
if (things && typeof (things) == "object" && things.error) {
Expand All @@ -145,7 +162,7 @@
if (thing_id !== undefined) {
$("#node-input-thing").val(thing_id);
}
$("#node-input-property").trigger("change");
$("#node-input-thing").trigger("change");
} else if (things && Array.isArray(things) && things.length === 0) {
$("select#node-input-thing").empty();
$("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-thing");
Expand All @@ -155,13 +172,18 @@
});
}
function initProperties(connection, thing_id, property_id, outs) {
debugger;
let queryString = prepareQueryString(connection);
if (!queryString || queryString === "")
return;
if (!thing_id || thing_id === "" || thing_id === "0")
return;
queryString = `${queryString}&thing_id=${thing_id}`;
$("#node-input-property").html("");

$("select#node-input-property").empty();
$("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-property");
$("select#node-input-property").val("updating");

$.getJSON(`properties?${queryString}`, properties => {
$("select#node-input-property").empty();
if (properties && typeof (properties) == "object" && properties.error) {
Expand All @@ -178,7 +200,7 @@
if (property_id !== undefined) {
$("#node-input-property").val(property_id);
}
$("#node-input-name").trigger("change");
$("#node-input-property").trigger("change");
} else if (properties && Array.isArray(properties) && properties.length === 0) {
$("<option value='" + "" + "'> " + "No properties available" + "</option>").appendTo("#node-input-property");
}
Expand Down