From ef8ef39c1793062485c8277207c199829b6ea26d Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Thu, 18 Feb 2016 10:56:59 +0000 Subject: [PATCH] added temp to see if it works with api --- app/js/temp.js | 108 ++++++++++++++++++++++++++++++ app/js/weight.js | 69 +++++++++++++++++++ lib/today.js | 15 ++++- views/partials/angular_footer.ejs | 4 ++ views/partials/angular_head.ejs | 64 ++++++++++++++++++ 5 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 app/js/temp.js create mode 100644 app/js/weight.js create mode 100644 views/partials/angular_footer.ejs create mode 100644 views/partials/angular_head.ejs diff --git a/app/js/temp.js b/app/js/temp.js new file mode 100644 index 0000000..dbaf017 --- /dev/null +++ b/app/js/temp.js @@ -0,0 +1,108 @@ +var app = angular.module( "Temp", []); +app.controller( + "TempController", + function( $scope, tempService) { + + $scope.tempData = []; + + loadRemoteData(); + + function applyRemoteData(newData) + { + $scope.tempData = newData; + } + + function loadRemoteData() { + tempService.getTemp() + .then( + function(tempData) { + applyRemoteData(tempData); + } + ) + } + } +); + + +app.service( + "tempService", + function($http, $q) { + return({getTemp:getTemp}); + + function getTemp() { + var request = $http({ + method: "get", + url:"http://api.silvrtree.co.uk/temp/all", + params: { + /* action:"get"*/ + } + }); + return (request.then(handleSuccess, handleError)); + } + + + function handleError(response) { + if ( !angular.isObject(response.data) || !response.data.message) { + return( $q.reject("An unknown error occured")); + } + + return($q.reject(response.data.message)); + } + + function handleSuccess(response) + { + return(response.data); + } + + } +); + + + + + +(function () { + console.log('Starting socket?'); + var url = "ws://api.silvrtree.co.uk:8039"; + + var wsCtor = window['MozWebSocket'] ? MozWebSocket : WebSocket; + this.socket = new wsCtor(url, 'stream'); + + + + + this.handleData = function(d) { + switch(d.id) { + case 'LightingDataReceived': + // this.updateLighting(d.sensorData.d); + break; + case 'ProjectorDataReceived': + // this.updateProj(d.sensorData.d); + break; + case 'HeatingDataReceived': + break; + default: + } + }; + + + this.handleWebsocketMessage = function (message) { + try { + var command = JSON.parse(message.data); + } + catch (e) { /* do nothing */ + } + + if (command) { + //this.dispatchCommand(command); + this.handleData(command); + } + }; + + this.handleWebsocketClose = function () { + alert("WebSocket Connection Closed."); + }; + + this.socket.onmessage = this.handleWebsocketMessage.bind(this); + this.socket.onclose = this.handleWebsocketClose.bind(this); +})(); diff --git a/app/js/weight.js b/app/js/weight.js new file mode 100644 index 0000000..4ec6621 --- /dev/null +++ b/app/js/weight.js @@ -0,0 +1,69 @@ +var app = angular.module("Weight", []); +app.controller("WeightController", function ($scope, weightService) { + $scope.newWeight = 0; + + $scope.weightData = []; + + loadRemoteData(); + + + function applyRemoteData(newData) { + $scope.weightData = newData; + } + + + function loadRemoteData() { + weightService.getWeight() + .then( + function (weightData) { + applyRemoteData(weightData); + } + ) + } + + $scope.submitForm = function() { + "use strict"; + console.log('Submitting..'); + }; + } +); + + +app.service( + "weightService", + function ($http, $q) { + return ({getWeight: getWeight}); + + function getWeight() { + var request = $http({ + method: "get", + url: "/weight/all", + params: { + /* action:"get"*/ + } + }); + return (request.then(handleSuccess, handleError)); + } + + function setWeight(w) { + "use strict"; + + $http({method: 'post', url: '/weight', params: {weight: w}}); + + } + + + function handleError(response) { + if (!angular.isObject(response.data) || !response.data.message) { + return ( $q.reject("An unknown error occured")); + } + + return ($q.reject(response.data.message)); + } + + function handleSuccess(response) { + return (response.data); + } + + } +); \ No newline at end of file diff --git a/lib/today.js b/lib/today.js index 5f33568..1a60e31 100644 --- a/lib/today.js +++ b/lib/today.js @@ -334,12 +334,25 @@ module.exports = { try { calHandler.getSimpleCalV2('https://calendar.google.com/calendar/ical/martind2000%40gmail.com/private-40cfebc9f7dcfa7fde6b9bf2f0092c93/basic.ics', function(v) { - todayCache.data.cal = v; + todayCache.data.cal.entries = todayCache.data.cal.entries.concat(v.entries) ; }); } catch (e) { logger.error(e); } + + try { + calHandler.getSimpleCalV2('https://calendar.google.com/calendar/ical/mt5pgdhknvgoc8usfnrso9vkv0%40group.calendar.google.com/public/basic.ics', function(v) { + todayCache.data.cal.entries = todayCache.data.cal.entries.concat(v.entries) ; + }); + } + catch (e) { + logger.error(e); + } + + + + } } ; diff --git a/views/partials/angular_footer.ejs b/views/partials/angular_footer.ejs new file mode 100644 index 0000000..5accc4c --- /dev/null +++ b/views/partials/angular_footer.ejs @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/views/partials/angular_head.ejs b/views/partials/angular_head.ejs new file mode 100644 index 0000000..7d43d12 --- /dev/null +++ b/views/partials/angular_head.ejs @@ -0,0 +1,64 @@ + + + + + + + + Events + + + + + + + + + + \ No newline at end of file