diff --git a/api/core/task/task.init.js b/api/core/task/task.init.js index 280c0ec39e..73f423fc0d 100644 --- a/api/core/task/task.init.js +++ b/api/core/task/task.init.js @@ -67,7 +67,7 @@ module.exports = function(cb){ // checking for update on module now gladys.module.checkUpdate(); - + // CheckUserPresence every XX minutes, default is 5 minutes const DEFAULT_CHECK_USER_PRESENCE_FREQUENCY = 5; @@ -75,7 +75,9 @@ module.exports = function(cb){ .catch(() => DEFAULT_CHECK_USER_PRESENCE_FREQUENCY) .then((checkFrequency) => { setInterval(function() { - gladys.house.checkUsersPresence(); + if(userHasCheckPresence()){ + gladys.house.checkUsersPresence(); + } }, checkFrequency * 60 * 1000); }); @@ -85,4 +87,17 @@ module.exports = function(cb){ gladys.module.checkUpdate(); }, sails.config.update.checkUpdateInterval); -}; \ No newline at end of file +}; + +function userHasCheckPresence(){ + return gladys.param.getValue('CHECK_USER_PRESENCE') + .catch((err) => { + if(err.message === 'Param CHECK_USER_PRESENCE not found'){ + gladys.param.setValue({name: 'CHECK_USER_PRESENCE', value: 'false', type: 'secret'}); + } else { + sails.log.err(err); + } + return false; + }) + .then((value) => value); +} \ No newline at end of file diff --git a/assets/js/app/house/house.controller.js b/assets/js/app/house/house.controller.js index e839f6e5c9..3d776cd9b2 100644 --- a/assets/js/app/house/house.controller.js +++ b/assets/js/app/house/house.controller.js @@ -6,9 +6,9 @@ .module('gladys') .controller('HouseCtrl', HouseCtrl); - HouseCtrl.$inject = ['houseService', 'roomService', 'notificationService']; + HouseCtrl.$inject = ['houseService', 'roomService', 'notificationService', 'paramService']; - function HouseCtrl(houseService, roomService, notificationService) { + function HouseCtrl(houseService, roomService, notificationService, paramService) { /* jshint validthis: true */ var vm = this; @@ -22,18 +22,21 @@ vm.newRoom = {}; vm.updateRoom = updateRoom; vm.updateHouse = updateHouse; + vm.updateCheckUserPresence = updateCheckUserPresence; vm.houses = []; vm.rooms = []; vm.savingHouse = false; vm.savingRoom = false; + vm.checkUserPresence = false; activate(); function activate() { getHouses(); getRooms(); + getCheckUserPresenceValue() return ; } @@ -97,6 +100,16 @@ }); } + function updateCheckUserPresence(){ + paramService.create({name: 'CHECK_USER_PRESENCE', value: !vm.checkUserPresence}) + .then(function(data){ + vm.checkUserPresence = !vm.checkUserPresence + }) + .catch(function(){ + notificationService.errorNotificationTranslated('DEFAULT.ERROR'); + }) + } + function deleteHouse(index, id) { return houseService.destroy(id) .then(function(data){ @@ -129,6 +142,13 @@ }); } + function getCheckUserPresenceValue(){ + paramService.getValue('CHECK_USER_PRESENCE') + .then(function(data){ + vm.checkUserPresence = data.data.value + }) + } + function resetNewHouseFields() { vm.newHouse = {}; } diff --git a/assets/js/app/param/param.service.js b/assets/js/app/param/param.service.js index 926037441c..b562c271c9 100644 --- a/assets/js/app/param/param.service.js +++ b/assets/js/app/param/param.service.js @@ -13,6 +13,7 @@ var service = { get: get, getByModule: getByModule, + getValue: getValue, create: create, update: update, destroy: destroy, @@ -32,6 +33,10 @@ function getByModule(id) { return $http({method: 'GET', url: '/module/' + id + '/param'}); } + + function getValue(name) { + return $http({method: 'GET', url: '/param/' + name}); + } function create(param) { return $http({method: 'POST', url: '/param', data: param}); diff --git a/config/locales/en.json b/config/locales/en.json index 52086243f0..48adc3266f 100755 --- a/config/locales/en.json +++ b/config/locales/en.json @@ -188,7 +188,9 @@ "area-tooltip-longitude": "Enter the longitude e. g. 4.5487", "area-tooltip-radius": "Enter a radius in meters e. g. 25", "house-box-title": "Houses", - "house-box-description": "You can define here your houses in Gladys. Latitude and longitude can be found on Google Maps, and must be entered with the format (example): Latitude = 42.1, Longitude = 40.1. Remember, all this is saved on your machine and do not leave your Gladys installation.", + "house-box-description": "You can define here your houses in Gladys. Latitude and longitude can be found on Google Maps, and must be entered with the format (example): Latitude = 42.1, Longitude = 40.1. Remember, all this is saved on your machine and do not leave your Gladys installation.", + "house-box-check-presence": "Presence detection:", + "house-box-check-presence-description": "Enable/Disable the presence detection of the house. For more information go to the official documentation in the configuration tab then housing.", "room-box-title": "Rooms", "mode-box-title": "Modes", "mode-box-description": "Modes are states the house can take. A house can be in one and only one mode at the same time.", diff --git a/config/locales/fr.json b/config/locales/fr.json index c560fa096c..901d7b8adc 100755 --- a/config/locales/fr.json +++ b/config/locales/fr.json @@ -351,6 +351,8 @@ "area-delete": "Supprimer", "house-box-title": "Maisons", "house-box-description": "Vous pouvez définir ici votre maison dans Gladys. Pour la latitude et la longitude, vous pouvez utiliser Google Maps pour trouver la latitude et la longitude votre maison, et la rentrer au format (par exemple) : latitude = 42.1, longitude = 43.2. Rappel: Toutes ces données restent en locale sur votre machine, et ne sont jamais envoyées nulle part.", + "house-box-check-presence": "Détection de présence:", + "house-box-check-presence-description": "Activer/Désactiver la détection de présence de la maison. Pour plus d'information rendez-vous sur la documentation officielle dans l'onglet configuration puis logement.", "room-box-title": "Pièces", "mode-box-title": "Modes", "mode-box-description": "Les modes sont des états que la maison peut prendre. Une maison peut être dans un et un seul mode à la fois.", diff --git a/views/partials/houses.ejs b/views/partials/houses.ejs index 6c57f0203d..95297bda69 100644 --- a/views/partials/houses.ejs +++ b/views/partials/houses.ejs @@ -4,6 +4,21 @@

<%= __('house-box-title') %> <%= __('house-box-saving') %>

+ +
+
+
+ <%= __('house-box-check-presence') %> +
+
+
+ + +
+
+
+
+