Skip to content
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

fix(registration): Fix sensor deletion #307

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
42 changes: 16 additions & 26 deletions app/scripts/controllers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
};
vm.privacy = false;
vm.completed = false;
vm.sensorIncomplete = true;

//new sensebox object
vm.newSenseBox = {
Expand Down Expand Up @@ -128,9 +129,7 @@
vm.markers = {};
vm.sensors = [];
vm.editMarkerInput = {};
vm.sensorSetup = '';
vm.editing = {};
vm.isCustom = {};
vm.events = {
autolocation: true,
};
Expand Down Expand Up @@ -182,7 +181,7 @@
function randomFixedInteger (length) {
return Math.floor(
Math.pow(10, length - 1) +
Math.random() * (Math.pow(10, length) - Math.pow(10, length - 1) - 1)
Math.random() * (Math.pow(10, length) - Math.pow(10, length - 1) - 1)
);
}

Expand All @@ -208,7 +207,7 @@
.then(function (response) {
vm.boxScript = response;
})
.catch(function () {});
.catch(function () { });
}

function compile () {
Expand All @@ -218,8 +217,8 @@
board: 'sensebox-mcu',
sketch: vm.boxScript,
})
.then(function () {})
.catch(function () {})
.then(function () { })
.catch(function () { })
.finally(function () {
vm.compiling = false;
});
Expand Down Expand Up @@ -326,15 +325,14 @@

function add (icon, title, unit, sensorType) {
var sensor = {
id: vm.sensors.length,
id: randomFixedInteger(4),
index: vm.sensors.length,
icon: icon,
title: title,
unit: unit,
sensorType: sensorType,
};
vm.sensors.push(sensor);
vm.sensorSetup = JSON.stringify(vm.sensors);
edit(sensor.id);
vm.sensorIncomplete = false;

if (vm.ttn.profile === 'cayenne-lpp') {
Expand All @@ -344,27 +342,18 @@

function remove (index) {
vm.sensors.splice(index, 1);
vm.isCustom[index] = false;
vm.editing[index] = false;
for (var i = 0; i < vm.sensors.length; i++) {
vm.sensors[i].id = i;
vm.sensors[i].index = i;
}
if (vm.sensors.length === 0) {
vm.sensorSetup = '';
vm.sensorIncomplete = true;
} else {
vm.sensorSetup = JSON.stringify($scope.sensors);
}

if (vm.ttn.profile === 'cayenne-lpp') {
updateCayenneDecoding();
}
}

function edit (index) {
vm.editing[index] = true;
}

function setSensorIcon (sensor, newIcon) {
sensor.icon = newIcon.name;
}
Expand All @@ -381,7 +370,7 @@
.then(function (data) {
vm.boxScript = data;
})
.catch(function () {});
.catch(function () { });
}

function completeRegistration () {
Expand Down Expand Up @@ -515,6 +504,7 @@
function senseBoxSetupValid () {
var validTTN = true;
var validMQTT = true;
var validSensorSetup = false;

if (vm.ttnEnabled) {
validTTN = vm.validTTNconfig;
Expand All @@ -524,7 +514,11 @@
validMQTT = vm.validMQTTURL;
}

return validTTN && validMQTT;
if (vm.modelSelected.id === 'custom' || vm.modelSelected.id === 'edu') {
validSensorSetup = vm.sensorIncomplete;
}

return validTTN && validMQTT && !validSensorSetup;
}

function generateSensorTemplate (templateName) {
Expand Down Expand Up @@ -804,15 +798,14 @@
map.setView([vm.markers.box.lat, vm.markers.box.lng], 16);
}
})
.catch(function () {});
.catch(function () { });
}, 200);
}
});

$scope.$watch('register.modelSelected.id', function (newValue) {
if (newValue.indexOf('home') === 0) {
vm.modelSelected.name = 'senseBox Home ' + newValue.substring(4);
vm.sensorSetup = vm.modelSelected.id;

vm.newModel.connection = null;
vm.extensions.feinstaub.id = '';
Expand All @@ -823,7 +816,6 @@
}

if (newValue.indexOf('luftdaten') === 0) {
vm.sensorSetup = vm.modelSelected.id;
vm.extensions.feinstaub.id = '';
vm.newModel.connection = null;

Expand All @@ -845,13 +837,11 @@
}

if (newValue.indexOf('hackair') === 0) {
vm.sensorSetup = vm.modelSelected.id;
vm.extensions.feinstaub.id = '';
vm.newModel.connection = null;
}

if (newValue === 'custom') {
vm.sensorSetup = '';
vm.extensions.feinstaub.id = '';
vm.newModel.connection = null;
vm.newModel.sensors = {
Expand Down
24 changes: 15 additions & 9 deletions app/views/account.box.register.html
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,7 @@ <h4>CO<sub>2</sub></h4>
<input type="text" name="icon{{sensor.id}}" ng-hide="true" ng-model="sensor.icon" required>
<div class="form-group has-feedback"
ng-class="{ 'has-error' : senseboxForm.icon{{sensor.id}}.$invalid, 'has-success' : senseboxForm.icon{{sensor.id}}.$valid && sensor.icon!='' }">
<div class="btn-group xxxl" uib-dropdown
ng-show="register.editing[sensor.id] && !register.isCustom[sensor.id]">
<div class="btn-group xxxl" uib-dropdown>
<button id="btn-append-to-body" type="button" class="form-control btn btn-default xxxl"
uib-dropdown-toggle>
<span class="icon osem-icon" ng-class="sensor.icon"></span><span
Expand All @@ -921,7 +920,8 @@ <h4>CO<sub>2</sub></h4>
</td>
<td>
<div class="form-group has-feedback"
ng-class="{ 'has-error' : senseboxForm.phenomenom{{sensor.id}}.$invalid, 'has-success' : senseboxForm.phenomenom{{sensor.id}}.$invalid && sensor.title!='' }">
ng-class="{ 'has-error' : senseboxForm.phenomenom{{sensor.id}}.$invalid, 'has-success' : senseboxForm.phenomenom{{sensor.id}}.$valid && sensor.title!='' }">
<!-- ng-class="{ 'has-error' : senseboxForm.phenomenom{{sensor.id}}.$invalid, 'has-success' : senseboxForm.phenomenom{{sensor.id}}.$invalid && sensor.title!='' }"> -->
<input name="phenomenom{{sensor.id}}" class="form-control" type="text"
ng-model="sensor.title" required>
<span ng-show="senseboxForm.phenomenom{{sensor.id}}.$valid && sensor.title!=''"
Expand Down Expand Up @@ -953,8 +953,9 @@ <h4>CO<sub>2</sub></h4>
</div>
</td>
<td style="white-space: nowrap">
<button type="button" class="btn btn-danger" ng-show="register.editing[sensor.id]"
ng-click="register.remove(sensor.id);">
<button type="button" class="btn btn-danger" ng-click="register.remove(sensor.index);">
<!-- <button type="button" class="btn btn-danger" ng-show="register.editing[sensor.id]"
ng-click="register.remove(sensor.id);"> -->
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
Expand Down Expand Up @@ -1122,8 +1123,7 @@ <h4>CO<sub>2</sub></h4>
<input type="text" name="icon{{sensor.id}}" ng-hide="true" ng-model="sensor.icon" required>
<div class="form-group has-feedback"
ng-class="{ 'has-error' : senseboxForm.icon{{sensor.id}}.$invalid, 'has-success' : senseboxForm.icon{{sensor.id}}.$valid && sensor.icon!='' }">
<div class="btn-group xxxl" uib-dropdown
ng-show="register.editing[sensor.id] && !register.isCustom[sensor.id]">
<div class="btn-group xxxl" uib-dropdown>
<button id="btn-append-to-body" type="button" class="form-control btn btn-default xxxl"
uib-dropdown-toggle>
<span class="icon osem-icon" ng-class="sensor.icon"></span><span
Expand Down Expand Up @@ -1176,8 +1176,9 @@ <h4>CO<sub>2</sub></h4>
</div>
</td>
<td style="white-space: nowrap">
<button type="button" class="btn btn-danger" ng-show="register.editing[sensor.id]"
ng-click="register.remove(sensor.id);">
<button type="button" class="btn btn-danger" ng-click="register.remove(sensor.index);">
<!-- <button type="button" class="btn btn-danger" ng-show="register.editing[sensor.id]"
ng-click="register.remove(sensor.id);"> -->
<span class="glyphicon glyphicon-trash"></span>
</button>
</td>
Expand Down Expand Up @@ -1319,6 +1320,11 @@ <h1><small>{{ 'STEP2_SUB4' | translate }}</small></h1>
<label class="control-label">{{ 'TTN_DECODEOPTIONS' | translate }}</label>
<input type="text" name="ttn_decodeoptions" class="form-control monospace"
ng-model="register.ttn.decodeOptions" ng-disabled="register.ttn.profile === 'sensebox/home'"
ng-required="register.ttn.profile !== 'sensebox/home'">
</div>
<!-- TTN Port -->
<div class="form-group">
<label class="control-label">{{ 'TTN_PORT' | translate }}</label>
ng-required="register.ttn.profile !== 'sensebox/home'"
ng-show="register.ttn.profile != 'cayenne-lpp'">
<table class="table table-striped table-bordered" ng-show="register.ttn.profile == 'cayenne-lpp'">
Expand Down