saving and temperature works
This commit is contained in:
50
app/client/alarm.js
Normal file
50
app/client/alarm.js
Normal file
@@ -0,0 +1,50 @@
|
||||
function sensor_data_collection() {
|
||||
var controllerId = Session.get('controller_id');
|
||||
return SensorData.find({
|
||||
controllerId: controllerId
|
||||
}, {
|
||||
sort: {
|
||||
created_at: -1
|
||||
},
|
||||
limit: 3
|
||||
});
|
||||
}
|
||||
|
||||
function last_sensor_reading() {
|
||||
var controller = Session.get('controller_id');
|
||||
var result = null;
|
||||
if (controller) {
|
||||
result = sensor_data_collection();
|
||||
}
|
||||
if (result && result.count() > 0) {
|
||||
return result.fetch()[0];
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
Template.alarm.helpers({
|
||||
last_reading: last_sensor_reading,
|
||||
pretty_time: function(time) {
|
||||
return moment(time).format("DD.MM.YYYY, HH:mm")
|
||||
},
|
||||
all_temperatures: function() {
|
||||
var result="";
|
||||
var temperatures = last_sensor_reading().temperatures;
|
||||
|
||||
for(var i in temperatures) {
|
||||
result += '' + parseFloat(temperatures[i]).toFixed(1) + ' °C ';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
Template.alarm.events({
|
||||
'click #run_alarm_settings': function() {
|
||||
Modal.show('alarm_settings');
|
||||
}
|
||||
});
|
||||
|
||||
Template.alarm.helpers({
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user