working on nicer angular integration

This commit is contained in:
Lucas Pleß 2013-10-21 13:39:52 +02:00
parent 16b8a0fd1a
commit 9d969c94d3
5 changed files with 39 additions and 43 deletions

View File

@ -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']);
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']);

View File

@ -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;
});
});

View File

@ -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)

View File

@ -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}}

View File

@ -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")