2013-10-20 22:04:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-07-23 00:16:15 +00:00
|
|
|
var gpower;
|
2015-09-16 15:33:56 +00:00
|
|
|
var laststate;
|
2014-07-23 00:16:15 +00:00
|
|
|
|
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) {
|
2014-07-23 00:45:57 +00:00
|
|
|
$scope.simple = data;
|
2014-07-23 01:33:36 +00:00
|
|
|
gpower.refresh(data.power);
|
2013-10-21 11:39:52 +00:00
|
|
|
}).
|
|
|
|
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);
|
2015-09-16 15:33:56 +00:00
|
|
|
stateNotification(message.data.state);
|
2014-07-23 00:45:57 +00:00
|
|
|
$scope.simple = message.data;
|
2014-07-23 01:33:36 +00:00
|
|
|
gpower.refresh(message.data.power);
|
2013-10-21 11:39:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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']);
|
|
|
|
|
|
|
|
|
2014-07-23 00:16:15 +00:00
|
|
|
$( document ).ready(function() {
|
|
|
|
console.log( "ready!" );
|
|
|
|
|
|
|
|
gpower = new JustGage({
|
|
|
|
id: "gauge",
|
|
|
|
value: 0,
|
|
|
|
min: 0,
|
2014-07-23 01:30:05 +00:00
|
|
|
max: 30000,
|
2014-07-23 00:45:57 +00:00
|
|
|
title: " ",
|
|
|
|
label: "Watt",
|
|
|
|
showMinMax: false
|
2014-07-23 00:16:15 +00:00
|
|
|
});
|
2013-10-21 23:40:57 +00:00
|
|
|
|
2014-07-23 00:16:15 +00:00
|
|
|
});
|
2015-09-16 15:33:56 +00:00
|
|
|
|
|
|
|
function stateNotification(state) {
|
2016-01-06 07:28:39 +00:00
|
|
|
if (state == true && laststate != true && laststate != null) {
|
2015-09-16 15:33:56 +00:00
|
|
|
laststate = true;
|
|
|
|
showNotification("CTDO - Status", "Der Chaostreff ist nun offen.", "/img/green.png", 4);
|
2016-01-06 07:28:39 +00:00
|
|
|
} else if (state == false && laststate != false && laststate != null) {
|
2015-09-16 15:33:56 +00:00
|
|
|
laststate = false;
|
|
|
|
showNotification("CTDO - Staus", "Der Chaostreff ist nun geschlossen", "/img/red.png", 4);
|
|
|
|
} else {
|
|
|
|
laststate = state;
|
|
|
|
}
|
|
|
|
}
|
2016-01-06 07:11:55 +00:00
|
|
|
|
|
|
|
function toggle() {
|
|
|
|
toggleNotifications();
|
|
|
|
if (enabledNotifications === true) {
|
|
|
|
document.getElementById("notificationButton").innerHTML = "Statusbenachrichtigungen an";
|
|
|
|
document.getElementById("notificationButton").className = "btn btn-block btn-success";
|
|
|
|
} else {
|
|
|
|
document.getElementById("notificationButton").innerHTML = "Statusbenachrichtigungen aus";
|
|
|
|
document.getElementById("notificationButton").className = "btn btn-block btn-danger";
|
|
|
|
}
|
|
|
|
}
|