Turning objects into backbone components

This commit is contained in:
Martin Donnelly 2016-07-28 13:57:16 +01:00
parent 71b5de20bb
commit 647d413a9c
14 changed files with 4424 additions and 114 deletions

2
app.js
View File

@ -56,7 +56,7 @@ if (process.env.NODE_ENV === 'production') {
isProduction = true;
}
logger.debug('isProduction:', isProduction);
logger.warn('isProduction:', isProduction);
var app = express();

View File

@ -141,9 +141,9 @@
</div>
</div>
<div class="mui-row mui--text-center">
<button id="frontLightOn" class="mui-btn mui-btn--primary">On
<button id="frontLightOn" class="mui-btn mui-btn--primary lightOn">On
</button>
<button id="frontLightOff" class="mui-btn mui-btn--danger"
<button id="frontLightOff" class="mui-btn mui-btn--danger lightOff"
style="display: none;">Off
</button>
</div>
@ -151,12 +151,12 @@
<div class="mui-col-xs-4 mui--text-center" id="auxFront"
style="display:none;">
<div>
<button class="mui-btn mui-btn--small mui-btn--accent"
<button class="mui-btn mui-btn--small mui-btn--accent lightUp"
id="frontUp">BRIGHTER
</button>
</div>
<div>
<button class="mui-btn mui-btn--small mui-btn--accent"
<button class="mui-btn mui-btn--small mui-btn--accent lightDown"
id="frontDown">DARKER
</button>
</div>
@ -195,9 +195,9 @@
</div>
</div>
<div class="mui-row mui--text-center">
<button id="backLightOn" class="mui-btn mui-btn--primary">On
<button id="backLightOn" class="mui-btn mui-btn--primary lightOn">On
</button>
<button id="backLightOff" class="mui-btn mui-btn--danger"
<button id="backLightOff" class="mui-btn mui-btn--danger lightOff"
style="display: none;">Off
</button>
</div>
@ -205,12 +205,12 @@
<div class="mui-col-xs-4 mui--text-center" id="auxBack"
style="display: none;">
<div>
<button class="mui-btn mui-btn--small mui-btn--accent"
<button class="mui-btn mui-btn--small mui-btn--accent lightUp"
id="backUp">BRIGHTER
</button>
</div>
<div>
<button class="mui-btn mui-btn--small mui-btn--accent"
<button class="mui-btn mui-btn--small mui-btn--accent lightDown"
id="backDown">DARKER
</button>
</div>
@ -296,6 +296,9 @@
integrity="sha256-laXWtGydpwqJ8JA+X9x2miwmaiKhn8tVmOVEigRNtP4="
crossorigin="anonymous"></script>
<script src="lib/chroma.js"></script>
<script src="lib/underscore.js"></script>
<script src="lib/backbone.js"></script>
<!--<script src="lib/sugar-date.js"></script>-->
<script src="lib/sugar-full.min.js"></script>
<script src="lib/skycons.js"></script>
@ -304,7 +307,12 @@
<!-- build:js -->
<script src="js/sowebsocket.js"></script>
<script src="js/colours.js"></script>
<script src="js/appv2.js"></script>
<script src="js/parts/clock.js"></script>
<script src="js/parts/meetings.js"></script>
<script src="js/parts/lights.js"></script>
<script src="js/parts/projector.js"></script>
<script src="js/appv3.js"></script>
</body>
<!-- endbuild -->
</html>

368
app/js/appv3.js Normal file
View File

@ -0,0 +1,368 @@
/*
SO App v2
*/
var skycons = new Skycons({color: '#e5f7fd'});
var SOController = (function() {
'use strict';
var path;
var wsUrl;
var local = true;
var bus = {};
var prevDate;
var prevTime;
var weatherTimer = 0;
var weatherStore = null;
var lastWeatherRequest = 0;
var soWebSocket;
var iosConfig = {
badge: true, sound: true, alert: true
};
var calendarData;
var extendTimer;
var lightArray = [];
var lightsList = {
off: ['frontLightOff', 'backLightOff'], on: ['frontLightOn', 'backLightOn'], aux: ['auxFront','auxBack']
};
console.log('Localmode',local);
if (local) {
console.log('Using local urls');
path = 'http://localhost:3000/';
wsUrl = 'ws://localhost:3001';
} else {
console.log('Using remote urls');
/*wsUrl = 'ws://ec2-52-50-147-81.eu-west-1.compute.amazonaws.com:8080';
path = 'http://ec2-52-50-147-81.eu-west-1.compute.amazonaws.com/';*/
/*wsUrl = 'ws://13.80.9.55:8080';
path = 'http://13.80.9.55/';*/
wsUrl = 'ws://smartofficehost.cloudapp.net:8080';
path = 'http://smartofficehost.cloudapp.net/';
}
MicroEvent.mixin(bus);
var iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform) >= 0;
if (iOS) {
$('#iosTaskbar').show();
// path = 'http://localhost:3000/';
}
var module = {lights: lightsList};
var storage = {};
storage.supportsLocalStorage = function() {
try {
return !localStorage ? false : true;
}
catch (e) {
return false;
}
};
storage._localStorage = storage.supportsLocalStorage();
if (storage._localStorage) {
storage.LocalStorage = {
save: function(i, v) {
localStorage[i] = v;
}, load: function(i) {
return localStorage[i];
}
};
} else {
storage.LocalStorage = {
save: function(i, v) {
document.cookie = (i) + '=' + encodeURIComponent(v);
}, load: function(i) {
var s;
var p;
s = '; ' + document.cookie + ';';
p = s.indexOf('; ' + i + '=');
if (p < 0) {
return '';
}
p = p + i.length + 3;
var p2 = s.indexOf(';', p + 1);
return decodeURIComponent(s.substring(p, p2));
}
};
}
function projectorCommand(id) {
console.log('projectorCommand',path + 'api/v1/projector/cmd');
$.post(path + 'api/v1/projector/cmd', {id: id}, function() {});
}
/*
function lightCommand(id) {
console.log('lightCommand',path + 'api/v1/lighting/cmd');
$.post(path + 'api/v1/lighting/cmd', {id: id}, function() {});
}
function turnOnLights(id) {
console.log('turnonlights',path + 'api/v1/lighting/on');
$.post(path + 'api/v1/lighting/on', {light: id}, function() {});
}
function turnOffLights(id) {
$.post(path + 'api/v1/lighting/off', {light: id}, function() {});
}
*/
function turnOnHeating() {
$.post(path + 'api/v1/heating/on', {}, function() {});
}
function turnOffHeating() {
$.post(path + 'api/v1/heating/off', {}, function() {});
}
function turnOnProjector() {
$.post(path + 'api/v1/projector/on', {}, function() {});
}
function turnOffProjector() {
$.post(path + 'api/v1/projector/off', {}, function() {});
}
function extendMeetingBy(extendBy) {
console.log('+ extendMeetingBy', extendBy);
var payload = {extendBy: extendBy};
if (Object.has(calendarData.current, 'actualEnd')) {
payload.uid = calendarData.current.uid;
}
$.post(path + 'api/v1/extend', payload, function() {});
console.log('+ extendMeetingBy', extendBy);
}
function attachClicks() {
/*
$('#projectorOn').on('click', function() {
turnOnProjector();
});
$('#projectorOff').on('click', function() {
turnOffProjector();
});
*/
$('#heatingOn').on('click', function() {
turnOnHeating();
});
$('#heatingOff').on('click', function() {
turnOffHeating();
});
$('#extend05').on('click', function() {
extendMeetingBy(5);
});
$('#extend10').on('click', function() {
extendMeetingBy(10);
});
$('#extend15').on('click', function() {
extendMeetingBy(15);
});
$('#extend30').on('click', function() {
extendMeetingBy(30);
});
$('#projectorHDMI').on('click', function(event) {
var target = $(event.target);
projectorCommand('HDMI');
delayButton(target);
});
$('#projectorVGA').on('click', function(event) {
var target = $(event.target);
projectorCommand('VGA');
delayButton(target);
});
}
function delayButton($button) {
$button.attr('disabled', true);
setTimeout(function() {
$button.prop('disabled', false);
},3000);
}
var browserNotify = function(d) {
if (Notification.permission !== 'granted') {
Notification.requestPermission();
} else {
var notification = new Notification('SmartOffice Console', {
icon: '/fav/favicon-96x96.png',
body: d.msg
});
notification.onclick = function() {
console.log('click');
};
}
};
var notifyConfirm = function(r) {
console.log('notifyConfirm', r);
};
var cordovaNotify = function(d) {
console.log('+++ CORDOVA NOTIFY +++');
try {
navigator.notification.beep(1);
} catch (e) {
console.log(e);
}
try {
navigator.notification.confirm(
d.msg, // Message
notifyConfirm, // Callback to invoke with index of button pressed
'Smartoffice Console', // Title
['Extend','Ignore'] // ButtonLabels
);
} catch (e) {
console.log(e);
}
};
var setupPushNotifications = function() {
console.log('Setting up iOS push notifications..');
var push = PushNotification.init({android: {},ios: iosConfig,windows: {}});
push.on('registration', function(d) {
$.post(path + 'api/v1/register/ios', d, function() {});
});
push.on('notification', function(d) {
console.log(d);
});
push.on('error', function(e) {
Console.error('*PUSH* Push error:', e);
});
};
//
module.init = function() {
var self = this;
// AttachClicks();
this.clock = new Clock({model: new ClockModel()});
this.meetingModel = new MeetingModel();
this.meetings = new Meetings({model: this.meetingModel});
this.frontLightData = new LightModel({device: 'front',on: 'o',off: 'f', up: '9', down: '1'});
this.frontLight = new Light({el: $('#front-light'),model: this.frontLightData});
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);
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
self.weather = new Weather({model: new WeatherModel({lat: latitude, long: longitude})});
},
function(e) {console.error(e.code + ' / ' + e.message);});
soWebSocket = new SOWEBSOCKET(this);
// Setup iOS notifications
if (window.cordova && !(window.cordova instanceof HTMLElement)) {
if (device.platform === 'iOS' || device.platform === 'ios') {
setupPushNotifications();
}
}
};
module.updateCalendar = function(data) {
console.log('module.updateCalendar','Updating data');
this.meetingModel.set('data',data);
//UpdateCalendar(data);
};
module.webSocketURL = function() {
return wsUrl;
};
module.notify = function(d) {
if (window.cordova && !(window.cordova instanceof HTMLElement)) {
if (device.platform === 'android' || device.platform === 'Android') {
cordovaNotify(d);
}
} else {
browserNotify(d);
}
};
module.addLight = function(obj) {
lightArray.push(obj);
};
module.getLight = function(n) {
return lightArray[n];
};
return module;
})();
function onDeviceReady() {
SOController.init();
}
/*
If (window.cordova && !(window.cordova instanceof HTMLElement)) {
document.addEventListener('deviceready', onDeviceReady, false);
} else {
}
*/
;(function() {
if (window.cordova && !(window.cordova instanceof HTMLElement)) {
document.addEventListener('deviceready', onDeviceReady, false);
} else {
onDeviceReady();
Notification.requestPermission();
}
})();

117
app/js/parts/clock.js Normal file
View File

@ -0,0 +1,117 @@
'use strict';
/**
*
* User: Martin Donnelly
* Date: 2016-07-27
* Time: 09:23
*
*/
var WeatherModel = Backbone.Model.extend({
initialize: function() {
this.set('url','https://api.forecast.io/forecast/0657dc0d81c037cbc89ca88e383b6bbf/' + this.get('lat').toString() + ',' + this.get('long').toString() + '?units=uk2&exclude=minutely,hourly,daily,alerts,flags');
console.log(this.get('url'));
this.update();
},
update: function() {
this.getWeather();
var now = new Date;
var mod = 1800000 - (now.getTime() % 1800000);
var weatherTrigger = function() {
this.update();
};
setTimeout(weatherTrigger.bind(this), mod + 10);
},
getWeather: function() {
var self = this;
$.ajax({
type: 'GET',
url: self.get('url'),
data: '',
dataType: 'jsonp',
timeout: 10000,
context: $('body'),
contentType: ('application/json'),
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type'
},
success: function(data) {
var stored = {
temperature: data.currently.temperature,
icon: data.currently.icon
};
self.set('data',stored);
},
error: function(xhr, type) {
console.error('ajax error');
console.error(xhr);
console.error(type);
}
});
}
});
var ClockModel = Backbone.Model.extend({
initialize: function() {
this.set('now',new Date);
this.update();
},
update: function() {
var now = new Date;
var mod = 60000 - (now.getTime() % 60000);
this.set('now',now);
var clockFn = function() {
this.update();
};
setTimeout(clockFn.bind(this), mod + 10);
}
});
var Clock = Backbone.View.extend({
tagName: 'div',
initialize: function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
this.$date = $('#date');
this.$time = $('#time');
this.render();
},
render: function() {
var now = this.model.get('now');
var curTime = now.format('<span class="hour">{24hr}</span>{mm}');
var curDate = now.format('{yyyy}-{MM}-{dd}');
if (this.prevTime !== curTime) {
this.$time.html(curTime);
this.prevTime = curTime;
}
if (this.prevDate !== curDate) {
this.$date.html(now.format(
'<span class="wd-{do}">{Weekday}</span><br><span class="mo mo-{M}">{Month} {dd}</span><br>{yyyy}'));
this.prevDate = curDate;
}
}
});
var Weather = Backbone.View.extend({
tagName: 'div',
initialize: function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
this.$weatherText = $('#weatherText');
},
render: function() {
console.log('Weather:Render');
var data = this.model.get('data');
this.$weatherText.html(parseInt(data.temperature) + '&deg;c&nbsp;');
skycons.remove('icon1');
skycons.add('icon1', data.icon);
}
});

7
app/js/parts/heating.js Normal file
View File

@ -0,0 +1,7 @@
/**
*
* User: Martin Donnelly
* Date: 2016-07-27
* Time: 09:25
*
*/

122
app/js/parts/lights.js Normal file
View File

@ -0,0 +1,122 @@
'use strict';
/**
*
* User: Martin Donnelly
* Date: 2016-07-27
* Time: 09:25
*
*/
var path = 'http://localhost:3000/';
var LightModel = Backbone.Model.extend({
urlRoot: path + 'api/v1/lighting/',
initialize: function() {
this.set('status',false);
this.set('enabled',true);
},
turnOn: function() {
this.set('id','on');
this.save({light: this.get('on')},{
type: 'POST'
});
},
turnOff: function() {
this.set('id','off');
this.save({light: this.get('off')},{
type: 'POST'
});
},
turnUp: function() {
this.set('id','cmd');
this.save({light: this.get('up')},{
type: 'POST'
});
},
turnDown: function() {
this.set('id','cmd');
this.save({light: this.get('down')},{
type: 'POST'
});
},
disable: function() {
this.set('enabled',false);
},
enable: function() {
this.set('enabled',true);
}
});
var Light = Backbone.View.extend({
tagName: 'div',
events: {
'click .lightOn': 'turnOn',
'click .lightOff': 'turnOff',
'click .lightUp': 'turnUp',
'click .lightDown': 'turnDown'
},
initialize: function() {
var tStr;
_.bindAll(this, 'render', 'update', 'turnOn','turnOff', 'turnUp','turnDown','updateStatus','updateEnabled');
this.model.bind('change', this.update);
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 = this.$('#aux' + tStr);
// This.render();
},
render: function() {
},
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();
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();
}
});

101
app/js/parts/meetings.js Normal file
View File

@ -0,0 +1,101 @@
'use strict';
/**
*
* User: Martin Donnelly
* Date: 2016-07-27
* Time: 09:24
*
*/
var MeetingModel = Backbone.Model.extend({
});
var Meetings = Backbone.View.extend({
tagName: 'div',
initialize: function() {
_.bindAll(this, 'render','update');
this.model.bind('change', this.update);
this.$extendInfo = $('#extendInfo');
this.$caltext = $('#caltext');
},
render: function() {
console.log('Meetings:render');
console.log(this.model);
var calString = [
'<div class="mui--text-subhead">', this.model.get('data').current.summary,
'</div>'
].join('');
this.$extendInfo.text('');
this.$caltext.html(calString);
$('#calendar:hidden').slideDown();
return this;
},
update: function() {
console.log('Meetings:update');
var calData = this.model.get('data');
console.log(calData);
if (calData.current !== null && Object.has(calData.current, 'dtstart') && !Object.has(calData.current,'done')) {
this.render();
} else {
console.log('Meetings:Nothing currently...');
$('#calendar:visible').slideUp();
}
}
});
function updateCalendar(d) {
var actualEnd;
var now;
var calendarData = d;
if (d.current !== null && Object.has(d.current, 'dtstart') && !Object.has(d.current,'done')) {
var calString = [
'<div class="mui--text-subhead">', d.current.summary,
'</div>'
].join('');
$('#extendInfo').text('');
$('#caltext').html(calString);
$('#calendar:hidden').slideDown();
} else {
$('#calendar:visible').slideUp();
}
//
if (Object.has(calendarData.current, 'actualEnd')) {
now = new Date();
var origEnd = new Date(calendarData.current.dtend);
actualEnd = new Date(calendarData.current.actualEnd);
var timerDistance = actualEnd.addMinutes(-5).getTime() - now.getTime();
var extendTimerFn = function() {
$('#extender:hidden').slideDown();
};
console.log('timerDistance:', timerDistance);
if (actualEnd.getTime() - origEnd.getTime() > 1000) {
var extendInfo = actualEnd.format('Meeting extended until {24hr}:{mm}');
$('#extendInfo').text( extendInfo);
}
if ((timerDistance > 5000) && (timerDistance < 300000)) {
//ExtendTimer = setTimeout(function() {$('#extender:hidden').slideDown();},timerDistance);
clearTimeout(extendTimer);
extendTimer = setTimeout(extendTimerFn,timerDistance);
} else if (timerDistance <= 5000) {
$('#extender:hidden').slideDown();
} else if (timerDistance > 299999) {
$('#extender:visible').slideUp();
}
} else {
clearTimeout(extendTimer);
extendTimer = 0;
$('#extender:visible').slideUp();
}
}

122
app/js/parts/projector.js Normal file
View File

@ -0,0 +1,122 @@
'use strict';
/**
*
* User: Martin Donnelly
* Date: 2016-07-27
* 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();
}
});

View File

@ -61,27 +61,15 @@ var SOWEBSOCKET = function(newController) {
var _id;
var _off = ['f', 'g'];
var _on = ['o', 'n'];
var $show;
var $hide;
var $aux;
_id = _off.indexOf(id);
if (_id > -1) {
controller.getLight(_id).set('status',false);
// Lights are being turnd off
$hide = ['#', controller.lights.off[_id]].join('');
$show = ['#', controller.lights.on[_id]].join('');
$aux = ['#', controller.lights.aux[_id]].join('');
$($aux).fadeOut();
} else {
_id = _on.indexOf(id);
$show = ['#', controller.lights.off[_id]].join('');
$hide = ['#', controller.lights.on[_id]].join('');
$aux = ['#', controller.lights.aux[_id]].join('');
$($aux).fadeIn(500);
controller.getLight(_id).set('status',true);
}
$($show).show();
$($hide).hide();
};
@ -105,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) {
@ -166,8 +161,9 @@ var SOWEBSOCKET = function(newController) {
switch (d.id) {
case 'LightingDataReceived':
console.log('Light data received..');
//console.log('Light data received..');
this.checks.lights = true;
// This.updateLighting(d.sensorData.d);
break;
case 'ProjectorDataReceived':
@ -177,6 +173,7 @@ var SOWEBSOCKET = function(newController) {
this.updateHeating(d.sensorData.d);
break;
case 'calendar':
//case 'calendarData':
controller.updateCalendar(d);
break;
case 'Lighting':
@ -210,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);
@ -283,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;

1920
app/lib/backbone.js Normal file

File diff suppressed because it is too large Load Diff

1548
app/lib/underscore.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,8 @@
"dependencies": {
"chroma-js": "^1.1.1",
"jquery": "^2.2.3",
"mui": "^0.5.3",
"sugarjs-date": "^1.5.1"
"mui": "^0.6.8",
"sugarjs-date": "^1.5.1",
"backbone": "^1.3.3"
}
}

View File

@ -22,51 +22,70 @@ var size = require('gulp-size');
var debug = require('gulp-debug');
var filePath = {
build_dir: './dist'
};
build_dir: './dist'
};
gulp.task('scripts', function() {
return gulp.src(['app/js/sowebsocket.js','app/js/colours.js','app/js/appv2.js'])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('app.js'))
// .pipe(stripDebug())
.pipe(jsmin())
.pipe(size({title: 'Scripts'}))
.pipe(gulp.dest('dist/js'));
});
return gulp.src([
'app/js/sowebsocket.js',
'app/js/colours.js',
'app/js/parts/clock.js',
'app/js/parts/meetings.js',
'app/js/parts/lights.js',
'app/js/appv3.js'
])
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('app.js'))
.pipe(stripDebug())
.pipe(jsmin())
.pipe(size({title: 'Scripts'}))
.pipe(gulp.dest('dist/js'));
});
gulp.task('vendor', function() {
return gulp.src(['bower_components/jquery/dist/jquery.min.js',
'bower_components/mui/packages/cdn/js/mui.min.js',
'bower_components/chroma-js/chroma.min.js',
'bower_components/sugar/release/sugar-full.min.js',
'app/lib/skycons.js',
'app/lib/microevent.js'])
.pipe(concat('vendor.js'))
.pipe(uglify({mangle: false}))
.pipe(size({title: 'Vendor'}))
.pipe(gulp.dest('dist/js'));
});
return gulp.src([
'bower_components/jquery/dist/jquery.min.js',
'bower_components/mui/packages/cdn/js/mui.min.js',
'bower_components/chroma-js/chroma.min.js',
'src/bower_modules/underscore/underscore-min.js',
'src/bower_modules/backbone/backbone-min.js',
'bower_components/sugar/release/sugar-full.min.js',
'app/lib/skycons.js',
'app/lib/microevent.js'
])
.pipe(concat('vendor.js'))
.pipe(uglify({mangle: false}))
.pipe(size({title: 'Vendor'}))
.pipe(gulp.dest('dist/js'));
});
gulp.task('styles', function() {
return gulp.src(['app/css/mui.custom.css','app/css/material-icons.css','app/css/app.css'])
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(cssnano())
.pipe(concat('app.css'))
.pipe(size({title: 'Styles'}))
.pipe(gulp.dest('dist/css'));
});
return gulp.src([
'app/css/mui.custom.css',
'app/css/material-icons.css',
'app/css/app.css'
])
.pipe(autoprefixer('last 2 version',
'safari 5',
'ie 8',
'ie 9',
'opera 12.1',
'ios 6',
'android 4'))
.pipe(cssnano())
.pipe(concat('app.css'))
.pipe(size({title: 'Styles'}))
.pipe(gulp.dest('dist/css'));
});
gulp.task('partials', function() {
// Gulp.src(['app/partials/**/*']).pipe(gulp.dest('dist/partials'));
// gulp.src(['app/libs/ejs_production.js']).pipe(gulp.dest('dist/libs'));
// gulp.src(['app/libs/microevent.js']).pipe(gulp.dest('dist/libs'));
gulp.src(['app/fav/**/*']).pipe(size({title: 'Partials'})).pipe(gulp.dest('dist/fav'));
gulp.src(['app/fav/**/*']).pipe(size({title: 'Partials'})).pipe(gulp.dest(
'dist/fav'));
gulp.src(['app/gfx/censis_logo_white.png']).pipe(gulp.dest('dist/gfx'));
});
@ -78,40 +97,41 @@ gulp.task('migrate', function() {
});
gulp.task('index', function() {
var sources = gulp.src(['js/apps.js', 'css/app.css'], {read: false});
var sources = gulp.src(['js/apps.js', 'css/app.css'], {read: false});
return gulp.src(['app/index.html'])
.pipe(htmlreplace({
css: 'css/app.css',
js: 'js/app.js',
vendor: 'js/vendor.js',
fonts: 'fonts/fonts.css'
}))
.pipe(htmlmin({removeComments: true, collapseWhitespace: true, keepClosingSlash: true}))
.pipe(size({title: 'Index'}))
.pipe(gulp.dest('dist/'));
});
return gulp.src(['app/index.html'])
.pipe(htmlreplace({
css: 'css/app.css',
js: 'js/app.js',
vendor: 'js/vendor.js',
fonts: 'fonts/fonts.css'
}))
.pipe(htmlmin({
removeComments: true,
collapseWhitespace: true,
keepClosingSlash: true
}))
.pipe(size({title: 'Index'}))
.pipe(gulp.dest('dist/'));
});
var options = { };
var options = {};
gulp.task('fonts', function() {
return gulp.src('./fonts.list')
.pipe(googleWebFonts(options))
.pipe(googleWebFonts(options))
.pipe(size({title: 'Fonts'}))
.pipe(gulp.dest('dist/fonts'))
;
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('clean', function() {
return del(['dist']);
});
return del(['dist']);
});
gulp.task('default', ['clean'], function() {
gulp.start('styles', 'scripts', 'vendor', 'fonts', 'partials', 'index');
});
gulp.start('styles', 'scripts', 'vendor', 'fonts', 'partials', 'index');
});
gulp.task('Cordova', ['clean'], function() {
gulp.start('styles', 'scripts', 'vendor', 'fonts', 'index');
});
gulp.start('styles', 'scripts', 'vendor', 'fonts', 'index');
});

View File

@ -46,6 +46,7 @@ module.exports = {
res.json({});
}, turnon: function(req, res) {
console.log(req.body);
if (!req.body.light) {
res.status(400).send({
status: 'error',
@ -57,6 +58,7 @@ module.exports = {
console.log(req.body.light);
if (req.body.hasOwnProperty('light')) {
console.log('Controling ', req.body.light);
var light = req.body.light;
doLightsOn(light);
}