Skip to content

Commit

Permalink
Fix bug in actuactor selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ktg committed Oct 24, 2016
1 parent e8cddb1 commit 7a327e6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
33 changes: 18 additions & 15 deletions src/www/install.pug
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ html
$.get("/databox-directory/api/sensor"),
$.get("/databox-directory/api/sensor_type"),
$.get("/databox-directory/api/actuator"),
$.get("/databox-directory/api/actuator_type")
).done(function (datastores, sensorList, sensorTypes, actuatorList, actuatorTypes) {
$.get("/databox-directory/api/actuator_type"),
$.get("/databox-directory/api/controller")
).done(function (datastores, sensorList, sensorTypes, actuatorList, actuatorTypes, controllers) {
var combined = [];
var index = 0;
for (var sensor of sensorList[0]) {
for (var datastore of datastores[0]) {
if (sensor.datastore_id === datastore.id) {
Expand All @@ -57,12 +59,14 @@ html
sensor.type = sensorType.description;
}
}
sensor.index = index;
combined.push(sensor);
index ++;
}
for(var actuator of actuatorList[0]) {
for (var datastore of datastores[0]) {
if (actuator.datastore_id === datastore.id) {
actuator.endpoint = datastore.hostname + datastore.api_url;
for (var controller of controllers[0]) {
if (actuator.controller_id === controller.id) {
actuator.endpoint = controller.hostname + controller.api_url;
}
}

Expand All @@ -72,7 +76,9 @@ html
actuator.type = actuatorType.description;
}
}
actuator.index = index;
combined.push(actuator);
index ++;
}
sensors = combined;
console.log(JSON.stringify(combined));
Expand All @@ -89,18 +95,15 @@ html
}
}

function selectSensor(datasource_id, sensor_id) {
function selectSensor(datasource_id, sensor_index) {
for (var datasource of manifest.datasources) {
if (datasource.clientid === datasource_id) {
for (var sensor of sensors) {
if (sensor.id === sensor_id) {
datasource.endpoint = sensor.endpoint;
datasource.sensor_id = sensor.id;
datasource.sensor = sensor.description + ", " + sensor.location;
update();
return true;
}
}
var sensors = sensors[sensor_index];
datasource.endpoint = sensor.endpoint;
datasource.sensor_id = sensor.id;
datasource.sensor = sensor.description + ", " + sensor.location;
update();
return true;
}
}
return true;
Expand Down
8 changes: 4 additions & 4 deletions src/www/templates/app-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ else {
if ('number' == typeof $$obj.length) {
for (var pug_index4 = 0, $$l = $$obj.length; pug_index4 < $$l; pug_index4++) {
var sensor = $$obj[pug_index4];
pug_html = pug_html + "\u003Cli" + (" class=\"mdl-menu__item\""+pug_attr("onclick", 'selectSensor("' + datasource.clientid + '",' + sensor.id + ')', true, false)) + "\u003E" + (pug_escape(null == (pug_interp = sensor.type + ', ' + sensor.location) ? "" : pug_interp)) + "\u003C\u002Fli\u003E";
pug_html = pug_html + "\u003Cli" + (" class=\"mdl-menu__item\""+pug_attr("onclick", 'selectSensor("' + datasource.clientid + '",' + sensor.index + ')', true, false)) + "\u003E" + (pug_escape(null == (pug_interp = sensor.type + ', ' + sensor.location) ? "" : pug_interp)) + "\u003C\u002Fli\u003E";
}
} else {
var $$l = 0;
for (var pug_index4 in $$obj) {
$$l++;
var sensor = $$obj[pug_index4];
pug_html = pug_html + "\u003Cli" + (" class=\"mdl-menu__item\""+pug_attr("onclick", 'selectSensor("' + datasource.clientid + '",' + sensor.id + ')', true, false)) + "\u003E" + (pug_escape(null == (pug_interp = sensor.type + ', ' + sensor.location) ? "" : pug_interp)) + "\u003C\u002Fli\u003E";
pug_html = pug_html + "\u003Cli" + (" class=\"mdl-menu__item\""+pug_attr("onclick", 'selectSensor("' + datasource.clientid + '",' + sensor.index + ')', true, false)) + "\u003E" + (pug_escape(null == (pug_interp = sensor.type + ', ' + sensor.location) ? "" : pug_interp)) + "\u003C\u002Fli\u003E";
}
}
}).call(this);
Expand Down Expand Up @@ -183,14 +183,14 @@ else {
if ('number' == typeof $$obj.length) {
for (var pug_index5 = 0, $$l = $$obj.length; pug_index5 < $$l; pug_index5++) {
var sensor = $$obj[pug_index5];
pug_html = pug_html + "\u003Cli" + (" class=\"mdl-menu__item\""+pug_attr("onclick", 'selectSensor("' + datasource.clientid + '",' + sensor.id + ')', true, false)) + "\u003E" + (pug_escape(null == (pug_interp = sensor.type + ', ' + sensor.location) ? "" : pug_interp)) + "\u003C\u002Fli\u003E";
pug_html = pug_html + "\u003Cli" + (" class=\"mdl-menu__item\""+pug_attr("onclick", 'selectSensor("' + datasource.clientid + '",' + sensor.index + ')', true, false)) + "\u003E" + (pug_escape(null == (pug_interp = sensor.type + ', ' + sensor.location) ? "" : pug_interp)) + "\u003C\u002Fli\u003E";
}
} else {
var $$l = 0;
for (var pug_index5 in $$obj) {
$$l++;
var sensor = $$obj[pug_index5];
pug_html = pug_html + "\u003Cli" + (" class=\"mdl-menu__item\""+pug_attr("onclick", 'selectSensor("' + datasource.clientid + '",' + sensor.id + ')', true, false)) + "\u003E" + (pug_escape(null == (pug_interp = sensor.type + ', ' + sensor.location) ? "" : pug_interp)) + "\u003C\u002Fli\u003E";
pug_html = pug_html + "\u003Cli" + (" class=\"mdl-menu__item\""+pug_attr("onclick", 'selectSensor("' + datasource.clientid + '",' + sensor.index + ')', true, false)) + "\u003E" + (pug_escape(null == (pug_interp = sensor.type + ', ' + sensor.location) ? "" : pug_interp)) + "\u003C\u002Fli\u003E";
}
}
}).call(this);
Expand Down
2 changes: 1 addition & 1 deletion src/www/templates/app-manifest.pug
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ div
| No sensors found
else
each sensor in getSensors(datasource.type)
li.mdl-menu__item(onclick='selectSensor("' + datasource.clientid + '",' + sensor.id + ')')
li.mdl-menu__item(onclick='selectSensor("' + datasource.clientid + '",' + sensor.index + ')')
= sensor.type + ', ' + sensor.location

button.mdl-button.mdl-button--colored.mdl-button--raised(style="float: right", onclick="installApp()", disabled=!isValid())
Expand Down

0 comments on commit 7a327e6

Please sign in to comment.