created and tested server side water control
This commit is contained in:
@@ -1,25 +1,20 @@
|
||||
|
||||
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>TFM</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Amir Smajevic, Adnan Strojil, Senad Uka">
|
||||
</head>
|
||||
<meta charset="utf-8">
|
||||
<title>TFM</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Amir Smajevic, Adnan Strojil, Senad Uka">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body>
|
||||
|
||||
<ul class="nav nav-tabs">
|
||||
<li role="presentation" class="active"><a href="#">Početak</a></li>
|
||||
<li role="presentation"><a href="#">Novosti</a></li>
|
||||
</ul>
|
||||
{{> tabs}}
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="hello">
|
||||
{{> display}}
|
||||
</div>
|
||||
</div> <!-- /container -->
|
||||
<div class="container-fluid">
|
||||
{{> Template.dynamic template=template_name }}
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<!-- /container -->
|
||||
|
||||
</body>
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
if (Meteor.isClient) {
|
||||
// at the beginning
|
||||
Session.set("templateName", "start");
|
||||
|
||||
Template.display.helpers({
|
||||
sensorDataCollection: function () {
|
||||
return SensorData.find({}, {sort: {created_at: -1}})
|
||||
}
|
||||
});
|
||||
|
||||
Template.display.events({
|
||||
});
|
||||
|
||||
Template.sensorData.helpers({
|
||||
created_at_formatted: function() {
|
||||
return moment(this.created_at).format("DD.MM.YYYY, HH:mm")
|
||||
}
|
||||
});
|
||||
}
|
||||
Template.body.helpers({
|
||||
template_name: function() {
|
||||
return Session.get("templateName");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,3 +2,7 @@
|
||||
padding: 40px 15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.controller_selection {
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<template name="display">
|
||||
<ul>
|
||||
{{#each sensorDataCollection}}
|
||||
{{> sensorData}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
</template>
|
||||
13
app/client/log.html
Normal file
13
app/client/log.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<template name="log">
|
||||
|
||||
<div class="hello">
|
||||
<h1> Podaci sa senzora: </h1>
|
||||
<button id="clear_log">Očisti</button>
|
||||
<ul>
|
||||
{{#each sensorDataCollection}}
|
||||
{{> sensorData}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
21
app/client/log.js
Normal file
21
app/client/log.js
Normal file
@@ -0,0 +1,21 @@
|
||||
Template.log.helpers({
|
||||
sensorDataCollection: function() {
|
||||
return SensorData.find({}, {
|
||||
sort: {
|
||||
created_at: -1
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Template.log.events({
|
||||
'click clear_log': function() {
|
||||
Meteor.call('clearLog');
|
||||
}
|
||||
});
|
||||
|
||||
Template.sensorData.helpers({
|
||||
created_at_formatted: function() {
|
||||
return moment(this.created_at).format("DD.MM.YYYY, HH:mm")
|
||||
}
|
||||
});
|
||||
5
app/client/start.html
Normal file
5
app/client/start.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<template name="start">
|
||||
<div class="col-lg-12 text-center">
|
||||
{{>state}}
|
||||
</div>
|
||||
</template>
|
||||
17
app/client/start.js
Normal file
17
app/client/start.js
Normal file
@@ -0,0 +1,17 @@
|
||||
var options = {
|
||||
location: 40.7127+','+ 74.0059, // New York
|
||||
unit: 'c',
|
||||
success: function(weather) {
|
||||
html = '<h2><i class="sw icon-'+weather.code+'"></i> '
|
||||
html += weather.temp+'°'+weather.units.temp+'</h2>';
|
||||
html += '<ul><li>'+weather.city+', '+weather.region +'</li>';
|
||||
html += '<li class="currently">'+weather.currently+'</li>';
|
||||
|
||||
$("#weather").html(html);
|
||||
},
|
||||
error: function(error) {
|
||||
$("#weather").html('<p>'+error+'</p>');
|
||||
}
|
||||
}
|
||||
|
||||
Weather.options = options
|
||||
18
app/client/state.html
Normal file
18
app/client/state.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<template name="state">
|
||||
|
||||
<h1> Controller state</h1>
|
||||
<div>
|
||||
{{#with controller_state}}
|
||||
<div>Controller broj: {{controller_id}}</div>
|
||||
<div>Otpusni ventil: {{pretty_valve state.out_valve }}</div>
|
||||
<div>Stanje postavio: {{ set_by }}</div>
|
||||
<div>Zadnja komunikacija: {{time}}</div>
|
||||
{{/with}}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button id="water_now">Zalij sada</button>
|
||||
<button id="stop_water_now">Prekini zalijevanje</button>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
52
app/client/state.js
Normal file
52
app/client/state.js
Normal file
@@ -0,0 +1,52 @@
|
||||
if (Meteor.isClient) {
|
||||
|
||||
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.state.helpers({
|
||||
controller_state: controller_state,
|
||||
pretty_valve: function(state) {
|
||||
if (state === 'open') return "Otvoren";
|
||||
if (state === 'opening') return "Otvara se";
|
||||
if (state === 'closing') return "Zatvara se";
|
||||
if (state === 'closed') return "Zatvoren";
|
||||
}
|
||||
});
|
||||
|
||||
Template.state.events({
|
||||
'click #water_now': function() {
|
||||
var state = controller_state();
|
||||
ControllerState.update(state._id, {
|
||||
'$set': {
|
||||
'state.out_valve': 'opening',
|
||||
'time': new Date(),
|
||||
'set_by': 'server'
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
'click #stop_water_now': function() {
|
||||
var state = controller_state();
|
||||
ControllerState.update(state._id, {
|
||||
'$set': {
|
||||
'state.out_valve': 'closing',
|
||||
'time': new Date(),
|
||||
'set_by': 'server'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
10
app/client/tabs.html
Normal file
10
app/client/tabs.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<template name="tabs">
|
||||
<ul class="nav nav-tabs">
|
||||
<li role="presentation" class="{{ class_for 'start' }}"><a href="#">Stanje</a></li>
|
||||
<li role="presentation" class="{{ class_for 'weather' }}"><a href="#">Vrijeme</a></li>
|
||||
<li role="presentation" class="{{ class_for 'log' }}"><a href="#">Novosti</a></li>
|
||||
<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>
|
||||
|
||||
</template>
|
||||
39
app/client/tabs.js
Normal file
39
app/client/tabs.js
Normal file
@@ -0,0 +1,39 @@
|
||||
if (Meteor.isClient) {
|
||||
|
||||
Template.tabs.helpers({
|
||||
class_for: function(tab_name) {
|
||||
var templateName = Session.get('templateName');
|
||||
|
||||
if (templateName === tab_name) {
|
||||
return tab_name + ' active';
|
||||
} else if (templateName === 'display' && tab_name === 'news') {
|
||||
return tab_name + ' active'
|
||||
} else {
|
||||
return tab_name;
|
||||
}
|
||||
},
|
||||
|
||||
selected_controller: function() {
|
||||
return Session.get('controller_id');
|
||||
},
|
||||
});
|
||||
|
||||
Template.tabs.events({
|
||||
'click .start': function() {
|
||||
Session.set('templateName', 'start');
|
||||
},
|
||||
'click .weather': function() {
|
||||
Session.set('templateName', 'weather');
|
||||
},
|
||||
'click .log': function() {
|
||||
Session.set('templateName', 'log');
|
||||
},
|
||||
|
||||
'click #switch': function() {
|
||||
var instance = Template.instance();
|
||||
controller_id = instance.$('#controller').val();
|
||||
Session.setPersistent('controller_id', controller_id);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user