2013-10-20 22:04:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
2013-10-21 11:39:52 +00:00
|
|
|
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', []).
|
2013-10-20 22:04:58 +00:00
|
|
|
factory('Socket', function ($rootScope) {
|
|
|
|
var socket = io.connect();
|
|
|
|
|
|
|
|
return {
|
|
|
|
on: function(eventName, callback) {
|
|
|
|
socket.on(eventName, function() {
|
|
|
|
var args = arguments;
|
|
|
|
$rootScope.$apply(function() {
|
|
|
|
callback.apply(socket, args);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
emit: function(eventName, data, callback) {
|
|
|
|
if(typeof data == 'function') {
|
|
|
|
callback = data;
|
|
|
|
data = {};
|
|
|
|
}
|
|
|
|
socket.emit(eventName, data, function() {
|
|
|
|
var args = arguments;
|
|
|
|
$rootScope.$apply(function() {
|
|
|
|
if(callback) {
|
|
|
|
callback.apply(socket, args);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
emitAndListen: function(eventName, data, callback) {
|
|
|
|
this.emit(eventName, data, callback);
|
|
|
|
this.on(eventName, callback);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2013-10-21 11:39:52 +00:00
|
|
|
angular.module('roomstateapp.statusfilter', []).filter('statustostring', function() {
|
|
|
|
return function(input) {
|
2013-10-21 20:02:41 +00:00
|
|
|
return input == true ? 'geöffnet' : input == false ? 'geschlossen' : 'unbekannt';
|
2013-10-21 11:39:52 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2013-10-21 23:40:57 +00:00
|
|
|
angular.module('roomstateapp', ['roomstateapp.controllers', 'roomstateapp.services', 'roomstateapp.statusfilter']);
|
|
|
|
|
|
|
|
|
|
|
|
|