Skip to content

Commit

Permalink
feat(measurements): Deleting measurements
Browse files Browse the repository at this point in the history
Added functionality for deleting all measurements or selecting a timeframe and delete all
measurements between the timestamps.

#85
  • Loading branch information
mpfeil committed Jun 26, 2018
1 parent bd345b0 commit 93f1f3a
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 243 deletions.
199 changes: 36 additions & 163 deletions app/scripts/controllers/account.box.edit.sensors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
var vm = this;
vm.sensors = [];
vm.icons = [];
vm.timestamps = [{ name: '2018-03-19T18:53:18.005Z'}];
vm.deleteStamps = [];
//vm.sensor.chart.data = [];
vm.deleteOptions = {
fromDate: undefined,
toDate: undefined,
method: 'timeframe',
params: {}
}

vm.addSensor = addSensor;
vm.deleteSensor = deleteSensor;
Expand All @@ -26,49 +29,9 @@
vm.undo = undo;
vm.editMeasurements = editMeasurements;
vm.deleteMeasurements = deleteMeasurements;
vm.getSensorData = getSensorData;
vm.addTimestamp = addTimestamp;
vm.openCalendar = openCalendar;

vm.setDeleteMethod = setDeleteMethod;
vm.save = save;


vm.settings = {
deletePickerStart: {
date: moment().subtract(5, 'm').toDate(),
open: false,
buttonBar: {
show: false
},
timepickerOptions: {
readonlyInput: false,
showMeridian: false,
max: null,
min: null
},
datepickerOptions: {
minDate: null
}
},
deletePickerEnd: {
date: moment().toDate(),
open: false,
buttonBar: {
show: false
},
timepickerOptions: {
readonlyInput: false,
showMeridian: false,
max: null,
min: null
},
datepickerOptions: {
maxDate: null
}
}
};


activate();

////
Expand Down Expand Up @@ -128,22 +91,6 @@
setSensorsEditMode();
}



/*function getLatestSensorData (boxId, sensorId) {
return $http.get(getUrl() + '/boxes/' + boxId + '/data/' + sensorId)
.then(success)
.then(function (measurements) {
// attach an id to each measurement
for (var i = 0; i < measurements.length; i++) {
measurements[i].id = i;
}
return measurements;
})
.catch(failed);
}*/

function deleteSensor (sensor) {
if(sensor.new){
var index = vm.sensors.indexOf(sensor);
Expand Down Expand Up @@ -242,119 +189,45 @@
delete sensor.deleted;
}

function setDeleteMethod (method) {
delete vm.deleteOptions.params;
switch (method) {
case 'timeframe':
vm.deleteOptions.method = 'timeframe'
if (angular.isDefined(vm.deleteOptions.fromDate) && angular.isDefined(vm.deleteOptions.toDate)) {
vm.deleteOptions.params = {
'from-date': vm.deleteOptions.fromDate.toISOString(),
'to-date': vm.deleteOptions.toDate.toISOString()
}
}
break;
case 'all':
vm.deleteOptions.method = 'all';
vm.deleteOptions.params = {
deleteAllMeasurements: true
}
break;
}
}

function editMeasurements (sensor) {
sensor.restore = angular.copy(sensor);
sensor.measurementsediting = true;
console.log(sensor);
getSensorData(sensor, {});
//sensor.editing = true;

setSensorsEditMode();
}

/*return getLatestSensorData(boxData._id, sensor._id)
function deleteMeasurements (sensor){
setDeleteMethod(vm.deleteOptions.method);
return AccountService.deleteMeasurement(boxData._id, sensor._id, vm.deleteOptions.params)
.then(function (response) {
angular.copy(response.data, sensor.chart.data);
angular.copy(sensor.chart.data, vm.sensor.chart.data);
notifications.addAlert('info', 'NOTIFICATION_BOX_UPDATE_SUCCESS');
console.log('success', response);
setSensorsEditMode();
})
.catch(function (error) {
console.log('ERROR RESPONSE');
console.log(error);
notifications.addAlert('danger', 'NOTIFICATION_BOX_UPDATE_FAILED');
});*/

setSensorsEditMode();
}

function deleteMeasurements (sensor){
console.log(vm.deleteOptions);
if(vm.deleteOptions === 'deleteAll'){
console.log('I am Delete All');
return AccountService.deleteMeasurement(boxData._id, sensor._id,
{
deleteAllMeasurements: true
});
}

if(vm.deleteOptions === 'timestamps'){
console.log('I am timestamps');
var timestampsArr = vm.deleteStamps;
return AccountService.deleteMeasurement(boxData._id, sensor._id,
{
timestamps: timestampsArr
});
}
if(vm.deleteOptions === 'fromToDate'){
console.log('I am fromToDate');
var fromDate = vm.settings.deletePickerStart.date;
var toDate = vm.settings.deletePickerEnd.date;
return AccountService.deleteMeasurement(boxData._id, sensor._id,
{
'from-date': fromDate,
'to-date': toDate
console.log('error', error);
});
}

setSensorsEditMode();
}

function getSensorData (sensor, data) {
return OpenSenseMapAPI.getSensorData(boxData._id, sensor._id, data)
.then(function (response) {
sensor.chart = [];
sensor.chart.data = [];
for (var j = 0; j < response.length; j++) {
sensor.chart.data.push({
id: response[j].id,
value: parseFloat(response[j].value),
date: new Date(response[j].createdAt),
unit: sensor.unit,
});
}
sensor.chart.done = true;
return response;
})
.then(function (measurements) {
return measurements;
})
.catch(function (error) {
sensor.chart.error = true;
});
}



function addTimestamp () {
console.log('hello');
if (vm.timestampName) {
vm.timestamps.push({ name: vm.timestampName });
vm.deleteStamps.push(vm.timestampName);
console.log(vm.deleteStamps);
vm.timestampName = '';
}
}

function openCalendar (e, picker) {
e.preventDefault();
e.stopPropagation();
switch(picker) {
case 'deletePickerStart':
vm.settings.deletePickerStart.open = true;
break;
case 'deletePickerEnd':
vm.settings.deletePickerEnd.open = true;
vm.settings.deletePickerEnd.datepickerOptions.maxDate = moment().toDate();
vm.settings.deletePickerEnd.datepickerOptions.minDate = vm.settings.deletePickerStart.date;
vm.settings.deletePickerEnd.timepickerOptions.max = moment().toDate();
vm.settings.deletePickerEnd.timepickerOptions.min = vm.settings.deletePickerStart.timepickerOptions.max;
/*$timeout(function () {
//TODO check jqLite
// angular.element('#deletePickerEnd').parent()[0].children[1].style.right = "0px";
// angular.element('#deletePickerEnd').parent()[0].children[1].style.left = "auto";
});*/
break;
}
}


}
})();
143 changes: 63 additions & 80 deletions app/views/account.box.edit.sensors.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,87 +49,70 @@ <h2 style="margin-top: 0px; margin-bottom: 0px">{{'EDIT_CHANGESENSORS'|translate
</span>
<div style="padding-right: 15px;" ng-show="sensor.measurementsediting">
<div class="row">
<strong>{{'CONFIG_PHENOMENON'|translate}}:</strong> <code style="border-right: 1px solid #e1e4e8;">{{ sensor.title }}</code>
<strong>ID: </strong><code style="border-right: 1px solid #e1e4e8;">{{sensor._id}}</code>
<strong style="border-right: 1px solid #e1e4e8";>{{'CONFIG_UNIT'|translate}}: </strong><code style="border-right: 1px solid #e1e4e8;"> {{sensor.unit}} </code>
<strong>{{'CONFIG_TYPE'|translate}}: </strong> <code style="border-right: 1px solid #e1e4e8;"> {{sensor.sensorType}} </code>
<hr>
<form>
<strong>{{'CONFIG_PHENOMENON'|translate}}:</strong> <code style="border-right: 1px solid #e1e4e8;">{{ sensor.title }}</code>
<strong>ID: </strong><code style="border-right: 1px solid #e1e4e8;">{{sensor._id}}</code>
<strong style="border-right: 1px solid #e1e4e8";>{{'CONFIG_UNIT'|translate}}: </strong><code style="border-right: 1px solid #e1e4e8;"> {{sensor.unit}} </code>
<strong>{{'CONFIG_TYPE'|translate}}: </strong> <code style="border-right: 1px solid #e1e4e8;"> {{sensor.sensorType}} </code>
<hr>

<p>Select your deleting options:</p>

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4" style="border-right: 1px solid #e1e4e8;border-bottom: 1px solid #e1e4e8;">
<input type="radio" ng-model="sensors.deleteOptions" value="fromToDate"> Select two dates and delete all measuerements between these dates.
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4" style="border-right: 1px solid #e1e4e8;border-bottom: 1px solid #e1e4e8;">
<input type="radio" ng-model="sensors.deleteOptions" value="timestamps"> Select several time- stamps of measurements you want to delete.
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4" style="border-bottom: 1px solid #e1e4e8;">
<input type="radio" ng-model="sensors.deleteOptions" value="deleteAll"> Select to enable deletion off all measurements from this sensor.
</div>
</form>
</div>

<div class="row">
<div ng-switch="sensors.deleteOptions">

<div ng-switch-when="fromToDate">

<label for="deletePickerStart">{{'INTERP_TIMESTAMPBEGIN'|translate}}</label>
<div class="input-group">
<input id="deletePickerStart" type="text" class="form-control" datetime-picker="dd/MM/yyyy HH:mm" ng-model="sensors.settings.deletePickerStart.date" is-open="sensors.settings.deletePickerStart.open" button-bar="sensors.settings.deletePickerStart.buttonBar" timepicker-options="sensors.settings.deletePickerStart.timepickerOptions" datepicker-options="sensors.settings.deletePickerStart.datepickerOptions" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="sensors.openCalendar($event, 'deletePickerStart')"><i class="fa fa-calendar"></i></button>
</span>
<p>Select your deleting options:</p>
<uib-tabset active="active">
<uib-tab index="0" select="sensors.setDeleteMethod('timeframe')">
<uib-tab-heading>
<i class="glyphicon glyphicon-calendar"></i> Zeitraum
</uib-tab-heading>
<div class="row">
<div class="col-lg-11 col-md-11" style="margin-top: 25px;">
<div uib-alert class="alert-warning">
Select two dates and delete all measuerements between these dates.
</div>
</div>

<label for="deletePickerEnd">{{'INTERP_TIMESTAMPEND'|translate}}</label>
<div class="input-group">
<input id="deletePickerEnd" type="text" class="form-control" datetime-picker="dd/MM/yyyy HH:mm" ng-model="sensors.settings.deletePickerEnd.date" is-open="sensors.settings.deletePickerEnd.open" button-bar="sensors.settings.deletePickerEnd.buttonBar" timepicker-options="sensors.settings.deletePickerEnd.timepickerOptions" datepicker-options="sensors.settings.deletePickerEnd.datepickerOptions" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="sensors.openCalendar($event, 'deletePickerEnd')"><i class="fa fa-calendar"></i></button>
</span>
</div>
<div class="row">
<div class="col-lg-6 col-md-11">
<osem-calendar
osem-placeholder-text-start-date="{{ 'DATEPICKER_STARTINGDATE' | translate}}"
osem-placeholder-text-end-date="{{ 'DATEPICKER_ENDINGDATE' | translate}}"
osem-current-text="{{ 'DATEPICKER_CURRENTTEXT' | translate }}"
osem-clear-text="{{ 'DATEPICKER_CLEARTEXT' | translate }}"
osem-close-text="{{ 'DATEPICKER_CLOSETEXT' | translate }}"
osem-start-date="sensors.deleteOptions.fromDate"
osem-end-date="sensors.deleteOptions.toDate">
</osem-calendar>
</div>
<div class="col-lg-5 col-md-11" ng-if="sensors.deleteOptions.fromDate !== undefinded && sensors.deleteOptions.toDate !== undefinded">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Möchtest du für den gewählten Zeitraum wirklich alle Messungen löschen?</h3>
</div>
<div class="panel-body">
Diese Aktion kann nicht rückgängig gemacht werden!
<button ng-click="sensors.deleteMeasurements(sensor)" class="btn btn-default pull-right" style="color: #d9534f;">Delete</button>
</div>
</div>


</div>
<div ng-switch-when="timestamps">
<!-- <osem-calendar
ng-if="sensor.chart.done"
osem-placeholder-text-start-date="{{ 'DATEPICKER_STARTINGDATE' | translate}}"
osem-placeholder-text-end-date="{{ 'DATEPICKER_ENDINGDATE' | translate}}"
osem-current-text="{{ 'DATEPICKER_CURRENTTEXT' | translate }}"
osem-clear-text="{{ 'DATEPICKER_CLEARTEXT' | translate }}"
osem-close-text="{{ 'DATEPICKER_CLOSETEXT' | translate }}"
osem-start-date="sensor.chart.fromDate"
osem-end-date="sensor.chart.toDate"
osem-on-clear="details.resetFilter(sensor)"
osem-on-range-set="details.performFilter(sensor)">
</osem-calendar>
-->
<osem-charts
ng-if="sensor.chart.done"
chart-data="sensor.chart.data"
selected-measurement="sensor.chart.selectedMeasurement"
y-axis-title="sensor.chart.yAxisTitle"
tooltip-placeholder="{{ 'CHART_TOOLTIP_PLACEHOLDER' | translate }}">
</osem-charts>
Select timestamps of measurements you want to delete:
<form ng-submit="sensors.addTimestamp()">
<input type="text" placeholder="YYYY-MM-DDTHH:MM:SS.IIIZ" ng-model="sensors.timestampName">
<button class="btn btn-primary" type="submit">Add</button>
<ul>
<li ng-repeat="timestamp in sensors.timestamps">
{{ timestamp.name }}
</li>
</ul>
</form>
</div>
<div ng-switch-when="deleteAll">
<div uib-alert class="alert-warning"> Attention! If you choose this option you're going to delete ALL MEASUREMENTS from this sensor!</div>
</div>
</div>
</div>
</div>
</div>
</uib-tab>
<uib-tab index="2" select="sensors.setDeleteMethod('all')">
<uib-tab-heading>
<i class="glyphicon glyphicon-folder-close"></i> Alle Messungen
</uib-tab-heading>
<div class="row">
<div class="col-lg-11 col-md-11" style="margin-top: 25px;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Möchtest du wirklich alle Messungen für diesen Sensor löschen?</h3>
</div>
<div class="panel-body">
Diese Aktion kann nicht rückgängig gemacht werden!
<button ng-click="sensors.deleteMeasurements(sensor)" class="btn btn-default pull-right" style="color: #d9534f;">Delete</button>
</div>
</div>
</div>
</div>
</uib-tab>
</uib-tabset>
</div>
</div>
<div style="padding-right: 15px;" ng-show="sensor.editing">
<form>
Expand Down Expand Up @@ -182,9 +165,9 @@ <h2 style="margin-top: 0px; margin-bottom: 0px">{{'EDIT_CHANGESENSORS'|translate
</span>

<span class="sensor-details" style="height: 222px;" ng-show="sensor.measurementsediting">
<button type="button" class="btn btn-xs btn-danger" style="display: block;" ng-click="sensors.deleteMeasurements(sensor)">
<!-- <button type="button" class="btn btn-xs btn-danger" style="display: block;" ng-click="sensors.deleteMeasurements(sensor)">
<span class="glyphicon glyphicon-trash"></span> Delete Measurements
</button>
</button> -->
<button type="button" class="btn btn-xs btn-warning" style="display: block;" ng-click="sensors.cancelSensor(sensor)">
<span class="fa fa-undo"></span> Return
</button>
Expand Down

0 comments on commit 93f1f3a

Please sign in to comment.