mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-archive.git
synced 2025-02-04 13:40:13 +00:00
”2016-09-09”
This commit is contained in:
parent
146d769405
commit
b1212ea9bd
@ -17,16 +17,6 @@
|
|||||||
|_| |_|\___/|___/|___|____|___/
|
|_| |_|\___/|___/|___|____|___/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var SocketManager = Backbone.Model.extend({
|
|
||||||
initialize: function() {
|
|
||||||
// _.bindAll(this, 'processAdded');
|
|
||||||
this.webSocket = new WEBSOCKET(this);
|
|
||||||
|
|
||||||
this.on('message', function(o) {
|
|
||||||
console.log('Message', o);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var MainModel = Backbone.Model.extend({
|
var MainModel = Backbone.Model.extend({
|
||||||
|
|
||||||
@ -239,7 +229,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}, initialize: function() {
|
}, initialize: function() {
|
||||||
_.bindAll(this, 'render', 'changeDevice', 'updateDevice');
|
_.bindAll(this, 'render', 'changeDevice', 'updateDevice','setSocket');
|
||||||
this.model.on('change', this.updateDevice);
|
this.model.on('change', this.updateDevice);
|
||||||
this.render();
|
this.render();
|
||||||
}, render: function() {
|
}, render: function() {
|
||||||
@ -248,9 +238,21 @@
|
|||||||
}, changeDevice: function() {
|
}, changeDevice: function() {
|
||||||
var newDevice;
|
var newDevice;
|
||||||
newDevice = this.$el.find('#device')[0].value;
|
newDevice = this.$el.find('#device')[0].value;
|
||||||
|
console.log('NewDevice', newDevice);
|
||||||
|
|
||||||
this.model.set('device', newDevice);
|
this.model.set('device', newDevice);
|
||||||
|
|
||||||
|
if (this.socketHandler) {
|
||||||
|
this.socketHandler.listenFor(newDevice);
|
||||||
|
}
|
||||||
}, updateDevice: function() {
|
}, updateDevice: function() {
|
||||||
var fetchObj = {beforeSend: sendAuthentication};
|
var fetchObj = {beforeSend: sendAuthentication};
|
||||||
|
console.log('this:',this);
|
||||||
|
|
||||||
|
if (this.socketHandler) {
|
||||||
|
this.socketHandler.turnOff();
|
||||||
|
}
|
||||||
|
|
||||||
notification.clearAll();
|
notification.clearAll();
|
||||||
if (this.model.has('device')) {
|
if (this.model.has('device')) {
|
||||||
this.collection.url = '/apiv2/mdot/' + this.model.get('device');
|
this.collection.url = '/apiv2/mdot/' + this.model.get('device');
|
||||||
@ -261,6 +263,9 @@
|
|||||||
console.error('Nothing to get!');
|
console.error('Nothing to get!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
setSocket: function(newSocket) {
|
||||||
|
this.socketHandler = newSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -283,6 +288,11 @@
|
|||||||
this.collection.on('update', function() {
|
this.collection.on('update', function() {
|
||||||
// Trigger the redraw
|
// Trigger the redraw
|
||||||
this.updateGraphV2();
|
this.updateGraphV2();
|
||||||
|
console.log(this);
|
||||||
|
if (typeof this.socketHandler === 'object') {
|
||||||
|
this.socketHandler.turnOn();
|
||||||
|
}
|
||||||
|
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
}, events: {
|
}, events: {
|
||||||
@ -457,6 +467,9 @@
|
|||||||
|
|
||||||
self.doChartV2(chartData);
|
self.doChartV2(chartData);
|
||||||
console.timeEnd('updateGraphV2');
|
console.timeEnd('updateGraphV2');
|
||||||
|
},
|
||||||
|
setSocket: function(newSocket) {
|
||||||
|
this.socketHandler = newSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -464,7 +477,8 @@
|
|||||||
notification.configProfile('global', {
|
notification.configProfile('global', {
|
||||||
stacking: false
|
stacking: false
|
||||||
});
|
});
|
||||||
var webSocketModel = new SocketManager();
|
//Var webSocketModel = new SocketManager();
|
||||||
|
var webSocketModel = new SOCKETMANAGER();
|
||||||
|
|
||||||
var DeviceCollection = new Backbone.Collection;
|
var DeviceCollection = new Backbone.Collection;
|
||||||
var mdotCollection = new mDotCollection();
|
var mdotCollection = new mDotCollection();
|
||||||
@ -475,8 +489,12 @@
|
|||||||
collection: mdotCollection, model: mainSettings
|
collection: mdotCollection, model: mainSettings
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
views.mdot = new MDOT({collection: mdotCollection});
|
views.mdot = new MDOT({collection: mdotCollection});
|
||||||
|
|
||||||
views.grapher = new GraphView({collection: DeviceCollection});
|
views.grapher = new GraphView({collection: DeviceCollection});
|
||||||
|
|
||||||
|
views.mainview.setSocket(webSocketModel);
|
||||||
|
views.grapher.setSocket(webSocketModel);
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* User: Martin Donnelly
|
||||||
|
* Date: 2016-09-09
|
||||||
|
* Time: 11:38
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/* global Backbone, _, $, AmCharts, notification, WEBSOCKET */
|
||||||
|
/* global mainview */
|
||||||
|
/* jshint browser: true , devel: true*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
var SOCKETMANAGER = (function() {
|
||||||
|
|
||||||
|
var SocketManager = Backbone.Model.extend({
|
||||||
|
deviceId : ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1----','HIE-mobile-2----','HIE-smart-campus-1','HIE-smart-campus-2','HIE-smart-campus-3','HIE-smart-campus-4','HIE-smart-campus-5','HIE-smart-campus-6','HIE-smart-campus-7','HIE-mDot-1'],
|
||||||
|
|
||||||
|
initialize: function() {
|
||||||
|
_.bindAll(this, 'turnOn', 'turnOff');
|
||||||
|
this.listeningID = null;
|
||||||
|
this.listening = false;
|
||||||
|
this.webSocket = new WEBSOCKET(this);
|
||||||
|
|
||||||
|
this.on('message', function(o) {
|
||||||
|
if (this.listening)
|
||||||
|
{
|
||||||
|
console.log('Message', o);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
turnOn: function() {
|
||||||
|
console.log('SocketManager:turnOn');
|
||||||
|
|
||||||
|
this.listening = true;
|
||||||
|
|
||||||
|
},
|
||||||
|
turnOff: function() {
|
||||||
|
console.log('SocketManager:turnOff');
|
||||||
|
this.listening = false;
|
||||||
|
},
|
||||||
|
listenFor: function(id) {
|
||||||
|
|
||||||
|
console.log('index of', this.deviceId.indexOf(id));
|
||||||
|
this.listeningID = id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return SocketManager;
|
||||||
|
}());
|
||||||
|
|
||||||
|
|
@ -30,13 +30,6 @@ var WEBSOCKET = function(model) {
|
|||||||
|
|
||||||
model.trigger('message',d);
|
model.trigger('message',d);
|
||||||
switch (d.id) {
|
switch (d.id) {
|
||||||
/*
|
|
||||||
case 'LightingDataReceived':
|
|
||||||
|
|
||||||
// This.updateLighting(d.sensorData.d);
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Default:',d);
|
console.log('Default:',d);
|
||||||
break;
|
break;
|
||||||
|
@ -228,6 +228,7 @@
|
|||||||
<!-- endbuild -->
|
<!-- endbuild -->
|
||||||
<!-- build:js -->
|
<!-- build:js -->
|
||||||
<script src="js/websocket.js"></script>
|
<script src="js/websocket.js"></script>
|
||||||
|
<script src="js/socketmanager.js"></script>
|
||||||
<script src="js/mdot.js"></script>
|
<script src="js/mdot.js"></script>
|
||||||
<!-- endbuild -->
|
<!-- endbuild -->
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user