ui and settings ready

This commit is contained in:
Senad Uka
2016-10-15 15:58:41 +02:00
parent a85be6c2b6
commit 31b355f381
15 changed files with 269 additions and 16 deletions

6
android/FarmAlarm/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

View File

@@ -28,3 +28,4 @@ fortawesome:fontawesome
mfpierre:chartist-js
standard-minifier-css
standard-minifier-js
iron:router

View File

@@ -39,6 +39,14 @@ http@1.1.4
huttonr:bootstrap3@3.3.6_10
huttonr:bootstrap3-assets@3.3.6_3
id-map@1.0.6
iron:controller@1.0.12
iron:core@1.0.11
iron:dynamic-template@1.0.12
iron:layout@1.0.12
iron:location@1.0.11
iron:middleware-stack@1.1.0
iron:router@1.0.13
iron:url@1.0.11
jquery@1.11.7
launch-screen@1.0.10
less@2.5.7

View File

@@ -0,0 +1,14 @@
<template name="alarm">
<div class="hello">
<h1> Temperatura </h1>
<div class="jumbotron text-center center-block" >
{{#with last_reading}}
<div class="huge_text"> {{temperatureValue}}°C</div>
<div>{{pretty_time created_at}}</div>
{{/with}}
<button id="run_alarm_settings" class="btn btn-default"> <i class="fa fa-wrench"></i> Podešavanje </button>
</div>
</div>
</template>

41
app/client/alarm/alarm.js Normal file
View File

@@ -0,0 +1,41 @@
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")
}
});
Template.alarm.events({
'click #run_alarm_settings': function() {
Modal.show('alarm_settings');
}
});
Template.alarm.helpers({
});

View File

@@ -0,0 +1,84 @@
<template name="alarm_settings">
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Podešavanje Alarma</h4>
</div>
<div class="modal-body">
<div class="form-group">
<h3>Alarmiraj:</h3>
<table class="table">
<tr>
<td>ako je temperatura niža od
</td>
<td>
<input name="min_temperature" type="number" min="-20" max="50" />°C</td>
</tr>
<tr>
<td>ako je temperatura viša od
</td>
<td>
<input name="max_temperature" type="number" min="-20" max="50" />°C</td>
</tr>
<tr>
<td>ako se Zoblak Alarm Kutija ne javi
</td>
<td>
<input name="timeout_box" type="number" min="1" max="90" /> minuta </td>
</tr>
<tr>
<td>ako se bar jedan mobitel ne javi
</td>
<td>
<input name="timeout_phone" type="number" min="1" max="90" /> minuta </td>
</tr>
</table>
</div>
<div class="form-group">
<h3>U slučaju kritične situacije - javi SMS-om na telefone: </h3>
<table class="table">
<td>1.
</td>
<td>
<input name="sms_1" type="text" placeholder="06xxxxxxxx" />
</td>
<tr>
<td>2.
</td>
<td>
<input name="sms_2" type="text" placeholder="06xxxxxxxx" />
</td>
</tr>
<tr>
<td>3.
</td>
<td>
<input name="sms_3" type="text" placeholder="06xxxxxxxx" />
</td>
</tr>
<tr>
<td>4.
</td>
<td>
<input name="sms_4" type="text" placeholder="06xxxxxxxx" />
</td>
</tr>
</table>
</div>
</div>
<div class="modal-footer">
<button id="save_settings" class="btn btn-default" name="save_settings" data-dismiss="modal">Zapamti</button>
</div>
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,43 @@
Template.settings.helpers({
timeSelected: function(time) {
var config = controller_state().config;
return config.automaticTimeOfDay == time;
},
dayChecked: function(day) {
var config = controller_state().config;
var days = config.automaticDaysOfWeek || [];
return days.includes(day)
},
manualInflowChecked: function(day) {
var config = controller_state().config;
return config.manualInflow;
}
});
Template.settings.events({
'click #save_settings': function() {
var instance = Template.instance();
selectedTime = instance.$('#time_of_day').val();
selectedDays = [];
instance.$('.day_checkbox').each(function() {
if (this.checked) {
selectedDays.push(instance.$(this).val());
}
});
var manualInflow = instance.$('#manual_inflow').is(':checked');
console.log("MI ", manualInflow);
var controller_id = Session.get('controller_id');
Meteor.call('saveControllerConfig', controller_id, selectedTime, selectedDays, manualInflow);
}
});
Template.sensorData.helpers({
created_at_formatted: function() {
return moment(this.created_at).format("DD.MM.YYYY, HH:mm")
}
});

View File

@@ -12,7 +12,7 @@
{{> tabs}}
<div class="container-fluid">
{{> Template.dynamic template=template_name }}
{{> Template.dynamic template=template_name }}
</div>

View File

@@ -6,3 +6,27 @@ Template.body.helpers({
return Session.get("templateName");
}
});
controller_state = function() {
var controller = Session.get('controller_id');
var result = {}
if (controller) {
result = ControllerState.findOne({
controller_id: controller
});
}
if (!result) {
result = {}
};
return result;
};
accessible = function(feature) {
var controller = controller_state();
console.log('cotnroller ', controller);
if (!controller.features) return false;
return controller.features[feature] === true;
}

View File

@@ -6,6 +6,10 @@
padding-top: 10px;
}
.huge_text {
font-size: 3em;
}
@media all and (orientation: portrait) {
#bucket_image {
width: 90%;

View File

@@ -1,17 +1,3 @@
function controller_state() {
var controller = Session.get('controller_id');
var result = {}
if (controller) {
result = ControllerState.findOne({
controller_id: controller
});
}
if (!result) {
result = {}
};
return result;
};
Template.settings.helpers({
timeSelected: function(time) {

View File

@@ -1,4 +1,4 @@
Tracker.autorun(function () {
Tracker.autorun(function() {
var id = Session.get('controller_id');
if (id) {
Meteor.subscribe("sensor_data", id);
@@ -6,3 +6,15 @@ Tracker.autorun(function () {
Meteor.subscribe('pictures', id);
}
});
Router.route('/', function() {
if (accessible('start')) {
Session.set('templateName', 'start');
} else {
Session.set('templateName', 'no_access')
}
});
Router.route('/farmalarm', function() {
});

View File

@@ -1,10 +1,26 @@
<template name="tabs">
<div></div>
<ul class="nav nav-tabs">
{{#if accessible 'start'}}
<li role="presentation" class="{{ class_for 'start' }}"><a href="#">Stanje</a></li>
{{/if}}
{{#if accessible 'weather'}}
<li role="presentation" class="{{ class_for 'weather' }}"><a href="#">Vrijeme</a></li>
{{/if}}
{{#if accessible 'log'}}
<li role="presentation" class="{{ class_for 'log' }}"><a href="#">Novosti</a></li>
{{/if}}
{{#if accessible 'surveillance'}}
<li role="presentation" class="{{ class_for 'surveillance' }}"><a href="#">Videonadzor</a></li>
{{/if}}
{{#if accessible 'alarm'}}
<li role="presentation" class="{{ class_for 'alarm' }}"><a href="#">Alarm</a></li>
{{/if}}
<li role="presentation" class="controller_selection"> <input type="number" id="controller" name="controller" value="{{ selected_controller }}" min="1" max="99999"> <button id="switch" name="switch">Prebaci</button>
</li>
</ul>

View File

@@ -14,6 +14,8 @@ Template.tabs.helpers({
selected_controller: function() {
return Session.get('controller_id');
},
accessible: accessible
});
Template.tabs.events({
@@ -32,6 +34,11 @@ Template.tabs.events({
'click .settings': function() {
Session.set('templateName', 'settings');
},
'click .alarm': function() {
Session.set('templateName', 'alarm');
},
'click #switch': function() {
var instance = Template.instance();
controller_id = instance.$('#controller').val();

View File

@@ -162,6 +162,13 @@ function stateOrDefault(id) {
draining_period_unit: 'minutes',
manualInflow: true
},
features: {
start: true,
weather: true,
surveillance: true,
log: true,
alarm: true
},
set_by: 'server'
});
};