From 9d969c94d31e05c6e71cfb67ea29a0b61d4a2a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Mon, 21 Oct 2013 13:39:52 +0200 Subject: [PATCH] working on nicer angular integration --- node/public/js/app.js | 31 +++++++++++++++++++++++++++++-- node/public/js/controllers.js | 24 ------------------------ node/statusbot.js | 19 +++++-------------- node/views/index.jade | 7 +++++-- node/views/layout.jade | 1 - 5 files changed, 39 insertions(+), 43 deletions(-) delete mode 100644 node/public/js/controllers.js diff --git a/node/public/js/app.js b/node/public/js/app.js index e363263..14fd97c 100644 --- a/node/public/js/app.js +++ b/node/public/js/app.js @@ -1,6 +1,27 @@ 'use strict'; -angular.module('Services', []). +angular.module('roomstateapp.controllers', []). + controller('StatusCtrl', function ($scope, $http, Socket) { + + $http({ + method: 'GET', + url: '/api/simple/v2' + }). + success(function (data, status, headers, config) { + $scope.simple = data; + }). + error(function (data, status, headers, config) { + //$scope.name = 'Error!' + console.log("error getting data"); + }); + + Socket.on('sdata', function(message) { + console.log("received data from server: " + message.data.names); + $scope.simple = message.data; + }); +}); + +angular.module('roomstateapp.services', []). factory('Socket', function ($rootScope) { var socket = io.connect(); @@ -34,4 +55,10 @@ angular.module('Services', []). }; }); -angular.module('roomstateapp', ['roomstateapp.controllers', 'Services']); \ No newline at end of file +angular.module('roomstateapp.statusfilter', []).filter('statustostring', function() { + return function(input) { + return input == true ? 'geöffnet' : input == false ? 'geschlossen' : 'unbekannt'; + }; +}); + +angular.module('roomstateapp', ['roomstateapp.controllers', 'roomstateapp.services', 'roomstateapp.statusfilter']); \ No newline at end of file diff --git a/node/public/js/controllers.js b/node/public/js/controllers.js deleted file mode 100644 index dd65a0f..0000000 --- a/node/public/js/controllers.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - - -angular.module('roomstateapp.controllers', []). - controller('StatusCtrl', function ($scope, $http, Socket) { - - $http({ - method: 'GET', - url: '/api/simple/v2' - }). - success(function (data, status, headers, config) { - $scope.simple = data; - }). - error(function (data, status, headers, config) { - //$scope.name = 'Error!' - console.log("error getting data"); - }); - - Socket.on('sdata', function(message) { - console.log("received data from server: " + message.data.names); - $scope.simple = message.data; - }); - - }); diff --git a/node/statusbot.js b/node/statusbot.js index e67d72e..1ea4faf 100644 --- a/node/statusbot.js +++ b/node/statusbot.js @@ -42,25 +42,20 @@ var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23"); var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.20-62 195.160.169.70-126"); snmpMac.on('done', function (res) { -// console.log(res); simpleanswer.names = res; - simpleanswer.lastchange = parseInt((new Date().getTime()) / 1000); + simpleanswer.lastchange = new Date(); }); ippoll.on('doneCount', function (num) { -// console.log("there are " + num + " hosts up"); simpleanswer.count = num; - simpleanswer.lastchange = parseInt((new Date().getTime()) / 1000); - + simpleanswer.lastchange = new Date(); io.sockets.emit('sdata', { "data": simpleanswer }); }); ippoll.on('doneState', function (state) { -// console.log("room state is: " + state); - simpleanswer.state = state; spaceanswer.state.open = state; - - spaceanswer.state.lastchange = parseInt((new Date().getTime()) / 1000); + spaceanswer.state.lastchange = new Date(); + simpleanswer.state = state; simpleanswer.lastchange = spaceanswer.state.lastchange; io.sockets.emit('sdata', { "data": simpleanswer }); @@ -69,10 +64,6 @@ ippoll.on('doneState', function (state) { io.configure(function () { io.set('log level', 0); }); -io.sockets.on('connection', function (socket) { -// socket.emit('news', { hello: 'world' }); -}); - function work() { @@ -81,7 +72,7 @@ function work() { ippoll.pollState(); } -setInterval(work, 60000); +setInterval(work, 20000); work(); app.set('snmpMac', snmpMac); //TODO: wie kann man das schoener machen? (Modul in die Routes reintun) diff --git a/node/views/index.jade b/node/views/index.jade index b3077c8..d25d48d 100644 --- a/node/views/index.jade +++ b/node/views/index.jade @@ -11,10 +11,13 @@ block content dl dt aktueller Status: - dd#stnow {{simple.state}} + dd {{simple.state | statustostring}} dt letzte Abfrage: - dd#sttime {{simple.lastchange}} + dd {{simple.lastchange | date:'dd.MM.yyyy HH:mm:ss'}} + + dt aktive Geräte: + dd {{simple.count}} diff --git a/node/views/layout.jade b/node/views/layout.jade index 1fd7ce1..a7e2c4d 100644 --- a/node/views/layout.jade +++ b/node/views/layout.jade @@ -41,4 +41,3 @@ html(ng-app="roomstateapp") //script(type="text/javascript",src="/js/vendor/prettify.js") //script(type="text/javascript",src="/js/vendor/modernizr.js") script(type="text/javascript",src="/js/app.js") - script(type="text/javascript",src="/js/controllers.js")