(function () { 'use strict'; angular .module('hyperion') .controller('modalDialogController', ['$scope', '$sessionStorage', '$mdDialog', 'object', function($scope, $sessionStorage, $mdDialog, object){ $scope.object = object; }]) .controller('modalSimpleConfirmationController', ['$scope', '$sessionStorage', '$mdDialog', 'object', function($scope, $sessionStorage, $mdDialog, object){ $scope.object = object; $scope.proceedDialog = function() { $mdDialog.hide(); }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; }]) .controller('modalCodeConfirmationController', ['$scope', '$sessionStorage', '$mdDialog', 'authService', '$http', 'CONFIG', 'object', function($scope, $sessionStorage, $mdDialog, authService, $http, CONFIG, object){ $scope.object = object; authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { confirmationcodereq }'}; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve // none },function(error) { // failure console.error(error); } ); }); $scope.current_mobile = $sessionStorage.currentUser.mobile_dial; $scope.proceedDialog = function() { if($scope.security_confirmation_code == undefined || $scope.security_confirmation_code == null) { $scope.security_confirmation_code = ''; } $mdDialog.hide($scope.security_confirmation_code); }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; }]) .controller('modalErrorMessageController', ['$scope', '$sessionStorage', '$mdDialog', 'object', function($scope, $sessionStorage, $mdDialog, object){ $scope.object = object; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; }]) .controller('modalEventController', ['$scope', '$sessionStorage', '$mdDialog', 'object', function($scope, $sessionStorage, $mdDialog, object){ $scope.object = object; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.clearEvent = function(event_id) { $mdDialog.hide(event_id); }; }]) .controller('modalLightController', ['$scope', '$filter', '$mdDialog', 'wiz', 'object', function($scope, $filter, $mdDialog, wiz, object){ $scope.object = object; console.log($scope.object); $scope.scenes = [ {id:0, name:'OFF', icon:'power_settings_new', state: false, brightness: null, wiz_dimming: null, dim_disable: true }, {id:11, name:'White Light', icon:'light_mode', state: true, brightness: 100, wiz_dimming: 100, dim_disable: false }, {id:9, name:'Wake Up', icon:'alarm', state: true, brightness: null, wiz_dimming: null, dim_disable: true }, {id:10, name:'Bedtime', icon:'hotel', state: true, brightness: 50, wiz_dimming: 53, dim_disable: false }, {id:14, name:'Night Light', icon:'nights_stay', state: true, brightness: null, wiz_dimming: null, dim_disable: true } ]; $scope.equipment = {}; // default setting on modal open (White Light): var scenes_copy = angular.copy($scope.scenes); $scope.equipment.scene = $filter('filter')(scenes_copy, {id: 11})[0]; $scope.setDayMode = function() { var scenes_copy = angular.copy($scope.scenes); $scope.equipment.scene = $filter('filter')(scenes_copy, {id: 11})[0]; }; $scope.setNightMode = function() { var scenes_copy = angular.copy($scope.scenes); $scope.equipment.scene = $filter('filter')(scenes_copy, {id: 14})[0]; }; $scope.setOffMode = function() { var scenes_copy = angular.copy($scope.scenes); $scope.equipment.scene = $filter('filter')(scenes_copy, {id: 0})[0]; }; $scope.lightSlider = function() { $scope.equipment.scene.wiz_dimming = wiz.dimm2wiz($scope.equipment.scene.brightness); if($scope.equipment.scene.brightness<5) { var scenes_copy = angular.copy($scope.scenes); $scope.equipment.scene = $filter('filter')(scenes_copy, {id: 0})[0]; } }; $scope.setlightScene = function(scene_id) { var scenes_copy = angular.copy($scope.scenes); $scope.equipment.scene = $filter('filter')(scenes_copy, {id: scene_id})[0]; }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.applyDialog = function() { $mdDialog.hide($scope.equipment.scene); }; }]) .controller('modalWiZAuthController', ['$scope', '$sessionStorage', '$mdDialog', 'object', function($scope, $sessionStorage, $mdDialog, object){ $scope.object = object; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.saveCode = function(wizcode) { $mdDialog.hide(wizcode); }; }]) .controller('modalEditRoomController', ['$scope', '$sessionStorage', '$mdDialog', '$http', 'authService', 'CONFIG', 'object', function($scope, $sessionStorage, $mdDialog, $http, authService, CONFIG, object){ $scope.floors = []; $scope.room = { room_id: object.room_id, company_id: object.company_id, location: { id: object.location_id, name: object.location_name }, floor: { id: object.floor_id, name: object.floor_name }, name: object.name, sqm: object.sqm }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.saveDialog = function() { $mdDialog.hide($scope.room); }; }]) .controller('modalEditFloorController', ['$scope', '$sessionStorage', '$mdDialog', '$http', 'authService', 'CONFIG', 'object', function($scope, $sessionStorage, $mdDialog, $http, authService, CONFIG, object){ $scope.floors = []; $scope.floor = { company_id: object.company_id, location: { id: object.location_id, name: object.location_name }, name: object.name }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.saveDialog = function() { $mdDialog.hide($scope.floor); }; }]) .controller('modalEditEquipmentController', ['$scope', '$sessionStorage', '$mdDialog', '$http', 'authService', 'CONFIG', 'object', function($scope, $sessionStorage, $mdDialog, $http, authService, CONFIG, object){ console.log('object: ', object); $scope.equipment = { id: object.id, name: object.name, serial: object.serial, ip: object.ip, mac: object.mac }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.saveDialog = function() { $mdDialog.hide($scope.equipment); }; }]) .controller('modalNewDeviceController', ['$scope', '$sessionStorage', '$mdDialog', '$http', 'authService', 'CONFIG', 'object', function($scope, $sessionStorage, $mdDialog, $http, authService, CONFIG, object){ $scope.object = object; $scope.equipment = { company_id: null, location_id: null, type_id: null, type_name: null, brand_id: null, brand_name: null, model_id: null, model_name: null, name: null }; $scope.loadEquipmentBrands = function(){ authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'equipment_brand { ' + 'id ' + 'name ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.brands = response.data.data.equipment_brand; },function(error) { // failure console.error(error); } ); }); }; $scope.selectEquipmentBrand = function(){ $scope.equipmentForm.brand.$setValidity("elementSelected", true); if($scope.equipment.type) { $scope.types = null; $scope.equipmentForm.type.$setValidity("elementSelected", false); } if($scope.equipment.model) { $scope.models = null; $scope.equipmentForm.model.$setValidity("elementSelected", false); } $scope.equipment.brand_id = $scope.equipment.brand.id; }; $scope.loadEquipmentTypes = function(){ authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'equipment_type(filter:{brand_id:[' + $scope.equipment.brand_id + ']}) { ' + 'id ' + 'name ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.types = response.data.data.equipment_type; },function(error) { // failure console.error(error); } ); }); }; $scope.selectEquipmentType = function(){ $scope.equipmentForm.type.$setValidity("elementSelected", true); if($scope.equipment.model) { $scope.models = null; $scope.equipmentForm.model.$setValidity("elementSelected", false); } $scope.equipment.type_id = $scope.equipment.type.id; }; $scope.loadEquipmentModels = function(){ authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'equipment_model(filter:{type_id:[' + $scope.equipment.type_id + ']}) { ' + 'id ' + 'name ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.models = response.data.data.equipment_model; },function(error) { // failure console.error(error); } ); }); }; $scope.selectEquipmentModel = function(){ $scope.equipmentForm.model.$setValidity("elementSelected", true); $scope.equipment.model_id = $scope.equipment.model.id; }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.saveDialog = function() { $mdDialog.hide($scope.equipment); }; }]) .controller('modalCustomerSelectController', ['$scope', '$sessionStorage', '$mdDialog', 'authService', '$http', 'CONFIG', 'object', function($scope, $sessionStorage, $mdDialog, authService, $http, CONFIG, object){ $scope.object = object; $scope.companies = null; authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { companies { id name }}'}; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.customers = response.data.data.companies; },function(error) { // failure console.error(error); } ); }); $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.saveCompany = function(company) { $mdDialog.hide(company); }; }]) .controller('modalReportCreate', ['$scope', '$sessionStorage', '$mdDialog', '$timeout', 'authService', '$http', 'CONFIG', 'object', function($scope, $sessionStorage, $mdDialog, $timeout, authService, $http, CONFIG, object){ $scope.report = object; $scope.reportypes = [{ id: 1, code: 'EECR1', name: 'Electrical Energy Consumption Report' }]; $timeout(function() { $scope.report.beginDate = moment().subtract(30, 'days').toDate(); $scope.report.minBeginDate = moment().subtract(365, 'days').toDate(); $scope.report.maxBeginDate = moment().subtract(1, 'days').toDate(); $scope.report.endDate = moment().add(0, 'days').toDate(); $scope.report.minEndDate = moment($scope.report.minBeginDate).add(1, 'days').toDate(); $scope.report.maxEndDate = moment($scope.report.maxBeginDate).add(1, 'days').toDate(); $scope.report.type = $scope.reportypes[0]; }); $scope.selectReportType = function() {}; $scope.verifyDates = function(){ if($scope.report.beginDate >= $scope.report.endDate) { $scope.report.beginDate = moment($scope.report.endDate).subtract(1, 'days').toDate(); } }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.proceedDialog = function() { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'reportadd ( ' + 'company_id: "' + $sessionStorage.currentUser.company_id + '", ' + 'type_id: ' + $scope.report.type.id + ', ' + 'name: "' + $scope.report.name + '", ' + 'time_from: "' + moment($scope.report.beginDate).format('YYYYMMDD') + '", ' + 'time_to: "' + moment($scope.report.endDate).format('YYYYMMDD') + '" ' + '){ id }' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $mdDialog.hide(); },function(error) { // failure console.error(error); } ); }); }; }]) .controller('modalSceneSettingsController', ['$scope', '$filter', '$mdDialog', '$timeout', 'object', function($scope, $filter, $mdDialog, $timeout, object){ // object -> current settings of the device // null => element disabled $scope.scenes = [ {id:0, name:'OFF', icon:'power_settings_new', state: false, speed:null, brightness: null, temperature: null, color:null}, // Custom Color {id:33, name:'Custom Color', icon:'style', state: true, speed:null, brightness: 100, temperature: null, color:'#ffffff'}, // White {id:11, name:'Warm white', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, {id:12, name:'Daylight', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, {id:13, name:'Cool white', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, {id:34, name:'Custom white', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: 2700, color:null}, // Simple {id:6, name:'Cozy', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, {id:17, name:'True colors', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, {id:16, name:'Relax', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, {id:15, name:'Focus', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, {id:18, name:'TV Time', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, // Routine {id:9, name:'Wake Up', icon:'alarm', state: true, speed:null, brightness: null, temperature: null, color:null}, {id:10, name:'Bedtime', icon:'hotel', state: true, speed:null, brightness: 100, temperature: null, color:null}, // Functional {id:19, name:'Plant growth', icon:'light_mode', state: true, speed:null, brightness: 100, temperature: null, color:null}, {id:14, name:'Night Light', icon:'nights_stay', state: true, speed:null, brightness: null, temperature: null, color:null}, // Dynamic {id:1, name:'Ocean', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:2, name:'Romance', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:3, name:'Sunset', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:4, name:'Party', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:5, name:'Fireplace', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:7, name:'Forest', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:8, name:'Pastel Colors', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:20, name:'Spring', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:21, name:'Summer', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:22, name:'Fall', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:23, name:'Deep dive', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:24, name:'Jungle', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:25, name:'Mojito', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:26, name:'Club', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:29, name:'Candlelight', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:30, name:'Golden white', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:31, name:'Pulse', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:32, name:'Steampunk', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, // Special {id:27, name:'Christmas', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, {id:28, name:'Halloween', icon:'light_mode', state: true, speed:0, brightness: 100, temperature: null, color:null}, ]; // FARBTASTIC Color Picker //////////////////////////////////////////////////////////// // https://acko.net/blog/farbtastic-jquery-color-picker-plug-in/ var farbtastic = null; // farbtastic object $(document).ready(function() { farbtastic = $.farbtastic('#colorpicker'); farbtastic.linkTo(color => { $timeout(function(){ $scope.settings.color = color.slice(1); // remove '#' }); }); console.log('object: ', object); var scenes_copy = angular.copy($scope.scenes); if(object.settings) { $scope.settings = $filter('filter')(scenes_copy, {id: object.settings.id})[0]; $scope.settings.speed = object.settings.speed; $scope.settings.brightness = object.settings.brightness; $scope.settings.temperature = object.settings.temperature; $scope.settings.color = object.settings.color; if($scope.settings.color) { farbtastic.setColor($scope.settings.color); // default value - shoulw be current Light Color value } } else { // default settings: OFF $scope.settings = $filter('filter')(scenes_copy, {id: 0})[0]; } }); $scope.$watch('settings.color', function(newValue, oldValue, scope) { if(farbtastic) { farbtastic.setColor('#' + newValue); } }); /////////////////////////////////////////////////////////////////////////////////////// $scope.setLightMode = (scene_id) => { let scenes_copy = angular.copy($scope.scenes); $scope.settings = $filter('filter')(scenes_copy, {id: scene_id})[0]; if($scope.settings.color) { farbtastic.setColor($scope.settings.color); // default value - shoulw be current Light Color value } }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.applyDialog = function() { console.log($scope.settings); $mdDialog.hide($scope.settings); }; }]) .controller('modalReportController', ['$scope', '$sessionStorage', '$mdDialog', 'authService', '$http', 'CONFIG', 'object', function($scope, $sessionStorage, $mdDialog, authService, $http, CONFIG, object){ $scope.device_id = object.device; console.log('modal device ID: ', object); $scope.reports = null; authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { reports( equipment:"' + $scope.device_id + '") { ' + 'id ' + 'name ' + 'created ' + 'scheduled ' + 'published ' + 'type ' + 'status ' + 'link ' + '}}'}; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.reports = response.data.data.reports; console.log($scope.reports); },function(error) { // failure console.error(error); } ); }); $scope.downloadfile = function(link) { console.log('download: ' + link); if(link) { window.open(link); } }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; }]) .controller('modalCostBillNew', ['$rootScope', '$scope', '$sessionStorage', '$mdDialog', '$http', 'authService', 'CONFIG', 'object', function($rootScope, $scope, $sessionStorage, $mdDialog, $http, authService, CONFIG, object){ $scope.locations = []; authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'costprojectconfig(project_id: "' + $rootScope.project + '"){' + 'locations { ' + 'location { ' + 'id ' + 'name ' + '} ' + 'enabled ' + '} ' + '}' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); let locations = response.data.data.costprojectconfig.locations; locations.forEach(location => { if(location.enabled) { $scope.locations.push(location.location); } }); if($scope.locations.length === 1) { $scope.bill.location = $scope.locations[0]; } },function(error) { // failure console.error(error); }); }); $scope.billtypes = [ {id:0, name:'Electric', measure:'kWh'}, {id:1, name:'Water', measure:'CCF'}, {id:2, name:'Natural Gas', measure:'CCF'}, ]; $scope.bill = {}; $scope.selectBillType = function(type) { console.log('selectBillType: ' + $scope.bill.type.id); }; $scope.cancelDialog = function() { $mdDialog.cancel(false); }; $scope.saveDialog = function() { $mdDialog.hide($scope.bill); }; }]) })();