”2016-09-13”

This commit is contained in:
Martin Donnelly 2016-09-13 16:45:02 +01:00
parent d635c4179e
commit 70b9b267a8
5 changed files with 48 additions and 6 deletions

View File

@ -506,6 +506,33 @@
});
var Widget = Backbone.View.extend({
tagName : 'div',
template: _.template($('#widget-template').html()),
initialize: function() {
_.bindAll(this, 'render');
this.listenTo(this.model,'change',function(d){
let data = d.get('data');
this.render();
});
this.widgetMode = this.id.split('-')[1];
this.render();
},
render: function() {
let data = this.model.get('data');
let value = (typeof data !== 'undefined') ? data[this.widgetMode] : 0;
var html = this.template({name:this.widgetMode,value:value});
console.log(html);
console.log(this.$el);
this.$el.empty();
this.$el.html('<p>hello</p>');
return this;
}});
notification.configProfile('global', {
stacking: false
});
@ -529,4 +556,7 @@
views.mainview.setSocket(webSocketModel);
views.grapher.setSocket(webSocketModel);
var tempWidget = new Widget({model:webSocketModel, id:'widget-temp'});
var co2Widget = new Widget({model:webSocketModel, id:'widget-co2'});
})(jQuery);

View File

@ -31,6 +31,11 @@ var SOCKETMANAGER = (function() {
}
});
this.on('all', function(d) {
console.log('model:all', d);
});
},
turnOn: function() {
console.log('SocketManager:turnOn');
@ -57,6 +62,7 @@ var SOCKETMANAGER = (function() {
if (item.data.deviceid === this.listeningID) {
console.log(item.data);
this.set({data:item.data});
console.log('this', this)
}
}

View File

@ -8,8 +8,6 @@
var WIDGET = (function() {
'use strict';
var Widget = Backbone.View.extend({
});
}());

View File

@ -19,15 +19,13 @@ var cn = {
// ElephantSql settings
/*
var cn = {
/*var cn = {
host: 'jumbo.db.elephantsql.com',
port: 5432,
database: 'amlrxqev',
user: 'amlrxqev',
password: 'K11cvCplk0--oNafsYj4ISN-rVQmVS3y'
};
*/
};*/
exports.dbConnection = pgp(cn);

View File

@ -55,6 +55,9 @@
</div>
</div>
</div>
<div id="widget-temp" style="color:yellow;background-color:grey;border:1px yellow solid;">
</div>
<div id="widget-co2" style="color:yellow;background-color:grey;border 1px solid yellow;"></div>
<script type="text/template" id="loaded-template">
<div
style="background-color: darkred;color: white;font-weight: 900;text-align: center">Loaded
@ -211,6 +214,13 @@
</div>
</script>
<script type="text/template" id="widget-template">
<div>
<div class="mui-col-md-2"><%= name %></div>
<div class="mui-col-md-2"><%= value %></div>
</div>
</script>
<!-- build:vendor -->
<script src="lib/mui.js"></script>
<script src="lib/notification.js"></script>