diff --git a/app/js/temp.js b/app/js/temp.js index dbaf017..c2d2949 100644 --- a/app/js/temp.js +++ b/app/js/temp.js @@ -1,108 +1,54 @@ -var app = angular.module( "Temp", []); -app.controller( - "TempController", - function( $scope, tempService) { +var app = angular.module( "Temp", []) + .controller("TempController", function( $scope, tempService) { - $scope.tempData = []; + $scope.tempData = []; - loadRemoteData(); + 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")); + function applyRemoteData(newData) + { + $scope.tempData = newData; } - return($q.reject(response.data.message)); + function loadRemoteData() { + console.log('Loading data...'); + tempService.getTemp() + .then( + function(tempData) { + applyRemoteData(tempData); + } + ) + } } + ).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 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); -})(); + ); \ No newline at end of file diff --git a/app/js/tempSocket.js b/app/js/tempSocket.js new file mode 100644 index 0000000..caf4321 --- /dev/null +++ b/app/js/tempSocket.js @@ -0,0 +1,47 @@ + + +(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 index 4ec6621..eb81db2 100644 --- a/app/js/weight.js +++ b/app/js/weight.js @@ -1,17 +1,22 @@ var app = angular.module("Weight", []); -app.controller("WeightController", function ($scope, weightService) { - $scope.newWeight = 0; +app.controller("WeightController", function ($scope, weightService) { + $scope.newWeight = 0.0; $scope.weightData = []; - loadRemoteData(); + $scope.submitForm = function () { + "use strict"; + console.log('Submitting..'); + console.log($scope.newWeight); + $http({method: 'post', url: '/weight', params: {weight: $scope.newWeight}}); + }; + loadRemoteData(); function applyRemoteData(newData) { $scope.weightData = newData; } - function loadRemoteData() { weightService.getWeight() .then( @@ -21,14 +26,9 @@ app.controller("WeightController", function ($scope, weightService) { ) } - $scope.submitForm = function() { - "use strict"; - console.log('Submitting..'); - }; } ); - app.service( "weightService", function ($http, $q) { @@ -52,7 +52,6 @@ app.service( } - function handleError(response) { if (!angular.isObject(response.data) || !response.data.message) { return ( $q.reject("An unknown error occured")); diff --git a/single.js b/single.js new file mode 100644 index 0000000..9ea2c14 --- /dev/null +++ b/single.js @@ -0,0 +1,41 @@ +var express = require('express'), path = require('path'), http = require('http') + ; +var app = express(); +GLOBAL.lastcheck = 0; +var btcCache = {}, fxCache = {} , trainCache = {}; + +app.configure(function () { + app.set('port', process.env.PORT || 4545); + app.set('view engine', 'ejs'); + app.use(express.logger('dev')); + app.use(express.cookieParser()); + app.use(express.session({secret: '1234567890QWERTY'})); + /* 'default', 'short', 'tiny', 'dev' */ + app.use(express.methodOverride()); + + app.use(express.bodyParser()); + + app.use(function (req, res, next) { + res.header("Access-Control-Allow-Origin", "*"); + res.header("Access-Control-Allow-Headers", "X-Requested-With"); + next(); + }); + app.use(app.router); + app.use(express.static(path.join(__dirname, 'app'))); + app.use(express.errorHandler({dumpExceptions: true, showStack: true})); + + app.get('/temp', function (req, res) { + res.render('pages/temp'); + }); + + app.get('/weight', function (req, res) { + res.render('pages/weight'); + }); +}); + +/** + * create the server + */ +http.createServer(app).listen(app.get('port'), function () { + console.log("Express server listening on port " + app.get('port')); +}); diff --git a/views/pages/temp.ejs b/views/pages/temp.ejs index 62115ff..1eabc19 100644 --- a/views/pages/temp.ejs +++ b/views/pages/temp.ejs @@ -1,12 +1,34 @@ -<% include ../partials/angular_head %> + + + + Temp + + + + + + + + + -
- - - - - +
+
DateReading
+ + + + @@ -14,7 +36,11 @@ - + + + + + \ No newline at end of file diff --git a/views/partials/angular_head.ejs b/views/partials/angular_head.ejs index 9428709..688e7d3 100644 --- a/views/partials/angular_head.ejs +++ b/views/partials/angular_head.ejs @@ -1,5 +1,5 @@ - + @@ -12,51 +12,7 @@
DateReading
{{ entry.date }}{{ entry.reading }}