picture display ready
This commit is contained in:
@@ -2,7 +2,7 @@ Tracker.autorun(function () {
|
|||||||
var id = Session.get('controller_id');
|
var id = Session.get('controller_id');
|
||||||
if (id) {
|
if (id) {
|
||||||
Meteor.subscribe("sensor_data", id);
|
Meteor.subscribe("sensor_data", id);
|
||||||
var hamo = Meteor.subscribe("controller_state", id);
|
Meteor.subscribe("controller_state", id);
|
||||||
console.log(hamo);
|
Meteor.subscribe('pictures', id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<div class="col-md-12 chart">
|
<div class="col-md-12 chart">
|
||||||
<div><strong>Otpusni ventil:</strong> {{pretty_valve state.out_valve }}</div>
|
<div><strong>Otpusni ventil:</strong> {{pretty_valve state.out_valve }}</div>
|
||||||
<div><strong>Ulazni ventil/pumpa:</strong> {{pretty_valve state.in_valve }}</div>
|
<div><strong>Ulazni ventil/pumpa:</strong> {{pretty_valve state.in_valve }}</div>
|
||||||
|
<div><strong>Dobavlja sliku:</strong> {{picture_requested state }}</div>
|
||||||
<div><strong>Zadnja komunikacija: {{ last_communication_time }}</strong>
|
<div><strong>Zadnja komunikacija: {{ last_communication_time }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<div><strong>Zadnje zaljevanje: {{ last_out_valve_open }}</strong>
|
<div><strong>Zadnje zaljevanje: {{ last_out_valve_open }}</strong>
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ Template.state_details.helpers({
|
|||||||
return moment(this.time).fromNow();
|
return moment(this.time).fromNow();
|
||||||
},
|
},
|
||||||
last_out_valve_open: function() {
|
last_out_valve_open: function() {
|
||||||
return moment(this.significantEvents.lastOutValveOpen).fromNow();
|
return "";
|
||||||
},
|
},
|
||||||
last_in_valve_open: function() {
|
last_in_valve_open: function() {
|
||||||
return moment(this.significantEvents.lastInValveOpen).fromNow();
|
return "";
|
||||||
|
},
|
||||||
|
picture_requested: function(state) {
|
||||||
|
return (state.picture_requested === 'true') ? 'DA' : 'NE';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
15
app/client/surveillance.html
Normal file
15
app/client/surveillance.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<template name="surveillance">
|
||||||
|
<div> </div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 text-center">
|
||||||
|
Fotografisano: {{ picture_time }}
|
||||||
|
<button id="request_new_picture">Zatraži Novu</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row"> </div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<img src="{{ picture_src }}" class="img-responsive center-block" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
49
app/client/surveillance.js
Normal file
49
app/client/surveillance.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
function controller_state() {
|
||||||
|
var controllerId = Session.get('controller_id');
|
||||||
|
result = ControllerState.findOne({});
|
||||||
|
if (!result) {
|
||||||
|
result = {}
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
function picture() {
|
||||||
|
var controllerId = Session.get('controller_id');
|
||||||
|
result = Picture.findOne({
|
||||||
|
controller_id: controllerId
|
||||||
|
});
|
||||||
|
console.log("rez je", result);
|
||||||
|
if (!result) {
|
||||||
|
result = {}
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Template.surveillance.helpers({
|
||||||
|
controller_state: controller_state,
|
||||||
|
picture_src: function() {
|
||||||
|
var picture_base64 = picture().picture_base64;
|
||||||
|
var picture_src = '/images/noImage.png';
|
||||||
|
if (picture_base64) {
|
||||||
|
picture_src = 'data:image/jpeg;charset=utf-8;base64,' + picture_base64;
|
||||||
|
}
|
||||||
|
return picture_src;
|
||||||
|
},
|
||||||
|
picture_time: function() {
|
||||||
|
var picture_entry = picture();
|
||||||
|
if (picture_entry) {
|
||||||
|
return moment(picture_entry.time).fromNow();
|
||||||
|
} else {
|
||||||
|
return "Nikad!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Template.surveillance.events({
|
||||||
|
'click #request_new_picture': function() {
|
||||||
|
var controller_id = Session.get('controller_id');
|
||||||
|
Meteor.call('requestNewPicture', controller_id)
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
<li role="presentation" class="{{ class_for 'start' }}"><a href="#">Stanje</a></li>
|
<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 'weather' }}"><a href="#">Vrijeme</a></li>
|
||||||
<li role="presentation" class="{{ class_for 'log' }}"><a href="#">Novosti</a></li>
|
<li role="presentation" class="{{ class_for 'log' }}"><a href="#">Novosti</a></li>
|
||||||
|
<li role="presentation" class="{{ class_for 'surveillance' }}"><a href="#">Videonadzor</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 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>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ Template.tabs.events({
|
|||||||
'click .log': function() {
|
'click .log': function() {
|
||||||
Session.set('templateName', 'log');
|
Session.set('templateName', 'log');
|
||||||
},
|
},
|
||||||
|
'click .surveillance': function() {
|
||||||
|
Session.set('templateName', 'surveillance');
|
||||||
|
},
|
||||||
'click .settings': function() {
|
'click .settings': function() {
|
||||||
Session.set('templateName', 'settings');
|
Session.set('templateName', 'settings');
|
||||||
},
|
},
|
||||||
|
|
||||||
'click #switch': function() {
|
'click #switch': function() {
|
||||||
var instance = Template.instance();
|
var instance = Template.instance();
|
||||||
controller_id = instance.$('#controller').val();
|
controller_id = instance.$('#controller').val();
|
||||||
|
|||||||
@@ -130,21 +130,6 @@ Api.addRoute('picture/:id', {
|
|||||||
'time': new Date()
|
'time': new Date()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
|
||||||
get: function() {
|
|
||||||
var id = this.urlParams.id;
|
|
||||||
var res = this.response;
|
|
||||||
var picture_src = "/images/noImage.png";
|
|
||||||
var pictureEntry = Picture.findOne({
|
|
||||||
controller_id: id
|
|
||||||
});
|
|
||||||
if (pictureEntry) {
|
|
||||||
var imageData = pictureEntry.picture_base64;
|
|
||||||
picture_src = "data:image/jpeg;charset=utf-8;base64," + imageData;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
picture: picture_src
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,17 @@ function setInValveTo(controller_id, nextState) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requestNewPicture(controller_id) {
|
||||||
|
var state = controller_state(controller_id);
|
||||||
|
ControllerState.update(state._id, {
|
||||||
|
'$set': {
|
||||||
|
'state.picture_requested': 'true',
|
||||||
|
'time': new Date(),
|
||||||
|
'set_by': 'server'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function openInValve(controller_id) {
|
function openInValve(controller_id) {
|
||||||
var state = controller_state(controller_id);
|
var state = controller_state(controller_id);
|
||||||
var config = state.config;
|
var config = state.config;
|
||||||
@@ -174,5 +185,6 @@ Meteor.methods({
|
|||||||
openInValve: openInValve,
|
openInValve: openInValve,
|
||||||
closeInValve: closeInValve,
|
closeInValve: closeInValve,
|
||||||
clearLog: clearLog,
|
clearLog: clearLog,
|
||||||
saveControllerConfig: saveControllerConfig
|
saveControllerConfig: saveControllerConfig,
|
||||||
|
requestNewPicture: requestNewPicture
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,3 +16,11 @@ Meteor.publish("controller_state", function(controllerId) {
|
|||||||
controller_id: controllerId
|
controller_id: controllerId
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// This code only runs on the server
|
||||||
|
Meteor.publish("pictures", function(controllerId) {
|
||||||
|
return Picture.find({
|
||||||
|
controller_id: controllerId
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user