diff --git a/smartoffice/SODashServer/SODashServer/app.js b/smartoffice/SODashServer/SODashServer/app.js index cbe7911..f9706e2 100644 --- a/smartoffice/SODashServer/SODashServer/app.js +++ b/smartoffice/SODashServer/SODashServer/app.js @@ -56,7 +56,7 @@ if (process.env.NODE_ENV === 'production') { isProduction = true; } -logger.debug('isProduction:', isProduction); +logger.warn('isProduction:', isProduction); var app = express(); diff --git a/smartoffice/SODashServer/SODashServer/app/index.html b/smartoffice/SODashServer/SODashServer/app/index.html index 5fe3c4d..23dbd4f 100644 --- a/smartoffice/SODashServer/SODashServer/app/index.html +++ b/smartoffice/SODashServer/SODashServer/app/index.html @@ -5,13 +5,13 @@
diff --git a/smartoffice/SODashServer/SODashServer/app/js/appv3.js b/smartoffice/SODashServer/SODashServer/app/js/appv3.js index e7fa414..8f252a7 100644 --- a/smartoffice/SODashServer/SODashServer/app/js/appv3.js +++ b/smartoffice/SODashServer/SODashServer/app/js/appv3.js @@ -105,6 +105,7 @@ var SOController = (function() { } +/* function lightCommand(id) { console.log('lightCommand',path + 'api/v1/lighting/cmd'); $.post(path + 'api/v1/lighting/cmd', {id: id}, function() {}); @@ -118,6 +119,7 @@ var SOController = (function() { function turnOffLights(id) { $.post(path + 'api/v1/lighting/off', {light: id}, function() {}); } +*/ function turnOnHeating() { $.post(path + 'api/v1/heating/on', {}, function() {}); @@ -147,6 +149,7 @@ var SOController = (function() { } function attachClicks() { +/* $('#projectorOn').on('click', function() { turnOnProjector(); }); @@ -154,6 +157,7 @@ var SOController = (function() { $('#projectorOff').on('click', function() { turnOffProjector(); }); +*/ $('#heatingOn').on('click', function() { turnOnHeating(); @@ -163,33 +167,6 @@ var SOController = (function() { turnOffHeating(); }); - $('#frontLightOn').on('click', function() { - // 1 for board lights - turnOnLights('o'); - }); - - $('#middleLightOn').on('click', function() { - turnOnLights(2); - }); - - $('#backLightOn').on('click', function() { - // 3 for board lights - turnOnLights('n'); - }); - - $('#frontLightOff').on('click', function() { - // A for board lights - turnOffLights('f'); - }); - - $('#middleLightOff').on('click', function() { - turnOffLights('b'); - }); - - $('#backLightOff').on('click', function() { - turnOffLights('g'); - }); - $('#extend05').on('click', function() { extendMeetingBy(5); @@ -207,33 +184,6 @@ var SOController = (function() { extendMeetingBy(30); }); - $('#frontUp').on('click', function(event) { - var target = $(event.target); - - lightCommand('9'); - delayButton(target); - }); - - $('#frontDown').on('click', function(event) { - var target = $(event.target); - lightCommand('1'); - delayButton(target); - }); - - $('#backUp').on('click', function(event) { - var target = $(event.target); - - lightCommand('8'); - delayButton(target); - }); - - $('#backDown').on('click', function(event) { - var target = $(event.target); - - lightCommand('2'); - delayButton(target); - }); - $('#projectorHDMI').on('click', function(event) { var target = $(event.target); @@ -339,7 +289,8 @@ var SOController = (function() { this.backLightData = new LightModel({device: 'back',on: 'n',off: 'g', up: '8', down: '2'}); this.backLight = new Light({el: $('#back-light'),model: this.backLightData}); - + this.projectorData = new ProjectorModel({device: 'projector', up: '8', down: '2'}); + this.projector = new Projector({el: $('#projector-panel'),model: this.projectorData}); this.addLight(this.frontLightData); this.addLight(this.backLightData); diff --git a/smartoffice/SODashServer/SODashServer/app/js/parts/lights.js b/smartoffice/SODashServer/SODashServer/app/js/parts/lights.js index 6fd572d..aa71b78 100644 --- a/smartoffice/SODashServer/SODashServer/app/js/parts/lights.js +++ b/smartoffice/SODashServer/SODashServer/app/js/parts/lights.js @@ -8,39 +8,41 @@ */ var path = 'http://localhost:3000/'; var LightModel = Backbone.Model.extend({ - //$.post(path + 'api/v1/lighting/on', {light: id}, function() {}); urlRoot: path + 'api/v1/lighting/', initialize: function() { this.set('status',false); + this.set('enabled',true); }, turnOn: function() { - console.log('LightModel:TurnOn'); this.set('id','on'); this.save({light: this.get('on')},{ type: 'POST' }); }, turnOff: function() { - console.log('LightModel:TurnOff'); this.set('id','off'); this.save({light: this.get('off')},{ type: 'POST' }); }, turnUp: function() { - console.log('LightModel:TurnOff'); this.set('id','cmd'); this.save({light: this.get('up')},{ type: 'POST' }); }, turnDown: function() { - console.log('LightModel:TurnDown'); this.set('id','cmd'); this.save({light: this.get('down')},{ type: 'POST' }); + }, + disable: function() { + this.set('enabled',false); + }, + enable: function() { + this.set('enabled',true); } }); @@ -49,24 +51,35 @@ var Light = Backbone.View.extend({ events: { 'click .lightOn': 'turnOn', 'click .lightOff': 'turnOff', - 'click .lightPp': 'turnup' + 'click .lightUp': 'turnUp', + 'click .lightDown': 'turnDown' }, initialize: function() { var tStr; - _.bindAll(this, 'render', 'update', 'turnOn','turnOff'); + _.bindAll(this, 'render', 'update', 'turnOn','turnOff', 'turnUp','turnDown','updateStatus','updateEnabled'); this.model.bind('change', this.update); - this.$onButton = $('#' + this.model.get('device') + 'LightOn'); - this.$offButton = $('#' + this.model.get('device') + 'LightOff'); + this.$onButton = this.$('#' + this.model.get('device') + 'LightOn'); + this.$offButton = this.$('#' + this.model.get('device') + 'LightOff'); + this.$upButton = this.$('#' + this.model.get('device') + 'Up'); + this.$downButton = this.$('#' + this.model.get('device') + 'Down'); + tStr = this.model.get('device')[0].toUpperCase() + this.model.get('device').substring(1); - this.$aux = $('#aux' + tStr); + this.$aux = this.$('#aux' + tStr); // This.render(); }, render: function() { - console.log('Light:Render'); - console.log(this); }, update: function() { + if (this.model.hasChanged('status')) { + this.updateStatus(); + } + + if (this.model.hasChanged('enabled')) { + this.updateEnabled(); + } + }, + updateStatus: function() { if (this.model.get('status') === true) { // Lights are on.. this.$onButton.hide(); @@ -78,17 +91,32 @@ var Light = Backbone.View.extend({ this.$aux.fadeOut(); } + }, + updateEnabled: function() { + var enabled = this.model.get('enabled'); + if (enabled) { + this.$el.removeClass('lostConnection'); + } else { + this.$el.addClass('lostConnection'); + } + + this.$onButton.attr('disabled', !enabled); + this.$offButton.attr('disabled', !enabled); + this.$upButton.attr('disabled', !enabled); + this.$downButton.attr('disabled', !enabled); + }, turnOn: function() { - console.log('Light:On'); this.model.turnOn(); }, turnOff: function() { - console.log('Light:Off'); this.model.turnOff(); }, turnUp: function() { - console.log('Light:Up'); this.model.turnUp(); + }, + turnDown: function() { + this.model.turnDown(); } + }); diff --git a/smartoffice/SODashServer/SODashServer/app/js/parts/projector.js b/smartoffice/SODashServer/SODashServer/app/js/parts/projector.js index 833aa04..b01aa6b 100644 --- a/smartoffice/SODashServer/SODashServer/app/js/parts/projector.js +++ b/smartoffice/SODashServer/SODashServer/app/js/parts/projector.js @@ -1,3 +1,4 @@ +'use strict'; /** * * User: Martin Donnelly @@ -5,3 +6,117 @@ * Time: 09:25 * */ +var path = 'http://localhost:3000/'; +var ProjectorModel = Backbone.Model.extend({ + urlRoot: path + 'api/v1/projector/', + initialize: function() { + this.set('status',false); + this.set('enabled',true); + }, + turnOn: function() { + this.set('id','on'); + this.save({projector: this.get('on')},{ + type: 'POST' + }); + }, + turnOff: function() { + this.set('id','off'); + this.save({projector: this.get('off')},{ + type: 'POST' + }); + }, + turnUp: function() { + this.set('id','cmd'); + this.save({projector: this.get('up')},{ + type: 'POST' + }); + }, + turnDown: function() { + this.set('id','cmd'); + this.save({projector: this.get('down')},{ + type: 'POST' + }); + + }, + disable: function() { + this.set('enabled',false); + }, + enable: function() { + this.set('enabled',true); + } +}); + +var Projector = Backbone.View.extend({ + tagName: 'div', + events: { + 'click .projectorOn': 'turnOn', + 'click .projectorOff': 'turnOff', + 'click .projectorUp': 'turnUp', + 'click .projectorDown': 'turnDown' + }, + initialize: function() { + var tStr; + _.bindAll(this, 'render', 'update', 'turnOn','turnOff', 'updateStatus','updateEnabled'); + this.model.bind('change', this.update); + console.log('Projector:initialize',this.model.get('device')); + this.$onButton = this.$('#' + this.model.get('device') + 'On'); + this.$offButton = this.$('#' + this.model.get('device') + 'Off'); + + tStr = this.model.get('device')[0].toUpperCase() + this.model.get('device').substring(1); + + this.$aux = this.$('#aux' + tStr); + // This.render(); + }, + render: function() { + }, + update: function() { + console.log('Projector:update'); + if (this.model.hasChanged('status')) { + this.updateStatus(); + } + + if (this.model.hasChanged('enabled')) { + this.updateEnabled(); + } + }, + updateStatus: function() { + if (this.model.get('status') === true) { + // projectors are on.. + this.$onButton.hide(); + this.$offButton.show(); + this.$aux.fadeIn(500); + } else { + this.$onButton.show(); + this.$offButton.hide(); + this.$aux.fadeOut(); + } + + }, + updateEnabled: function() { + var enabled = this.model.get('enabled'); + if (enabled) { + this.$el.removeClass('lostConnection'); + } else { + this.$el.addClass('lostConnection'); + } + + this.$onButton.attr('disabled', !enabled); + this.$offButton.attr('disabled', !enabled); + this.$upButton.attr('disabled', !enabled); + this.$downButton.attr('disabled', !enabled); + + }, + turnOn: function() { + this.model.turnOn(); + }, + turnOff: function() { + this.model.turnOff(); + }, + turnUp: function() { + this.model.turnUp(); + }, + turnDown: function() { + this.model.turnDown(); + } + +}); diff --git a/smartoffice/SODashServer/SODashServer/app/js/sowebsocket.js b/smartoffice/SODashServer/SODashServer/app/js/sowebsocket.js index 808698a..9f0b6a1 100644 --- a/smartoffice/SODashServer/SODashServer/app/js/sowebsocket.js +++ b/smartoffice/SODashServer/SODashServer/app/js/sowebsocket.js @@ -93,17 +93,24 @@ var SOWEBSOCKET = function(newController) { $aux = $('#auxProjector'); if (status) { + + controller.projectorData.set('status',true); +/* $hide = $('#projectorOn'); $show = $('#projectorOff'); $aux.fadeIn(); +*/ } else { + controller.projectorData.set('status',false); +/* $show = $('#projectorOn'); $hide = $('#projectorOff'); $aux.fadeOut(); +*/ } - $($show).show(); + /* $($show).show(); $($hide).hide(); - +*/ }; this.updateLighting = function(obj) { @@ -200,20 +207,8 @@ var SOWEBSOCKET = function(newController) { $('#longWait').hide(); $('#noSocket').slideUp(); - $('#front-light').removeClass('lostConnection'); - $('#back-light').removeClass('lostConnection'); - - - $('#frontLightOn').attr('disabled', false); - $('#frontLightOff').attr('disabled', false); - $('#frontUp').attr('disabled', false); - $('#frontDown').attr('disabled', false); - - $('#backLightOn').attr('disabled', false); - $('#backLightOff').attr('disabled', false); - $('#backUp').attr('disabled', false); - $('#backDown').attr('disabled', false); - + controller.getLight(0).set('enabled',true); + controller.getLight(1).set('enabled',true); var now = new Date; var mod = 60000 - (now.getTime() % 60000); @@ -273,21 +268,10 @@ var SOWEBSOCKET = function(newController) { if (this.retry === 3) { $('#longWait:hidden').fadeIn(); - $('#front-light').addClass('lostConnection'); - $('#back-light').addClass('lostConnection'); - $('#frontLightOn').attr('disabled', true); - $('#frontLightOff').attr('disabled', true); - $('#frontUp').attr('disabled', true); - $('#frontDown').attr('disabled', true); - - $('#backLightOn').attr('disabled', true); - $('#backLightOff').attr('disabled', true); - $('#backUp').attr('disabled', true); - $('#backDown').attr('disabled', true); - - //LostConnection - } + controller.getLight(0).set('enabled',false); + controller.getLight(1).set('enabled',false); + } if (this.retry > 0) { delay = 5000 * this.retry; diff --git a/smartoffice/SODashServer/SODashServer/app/test.html b/smartoffice/SODashServer/SODashServer/app/test.html new file mode 100644 index 0000000..9ebff91 --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/app/test.html @@ -0,0 +1,134 @@ + + +
+ +
+ +
+