(function() { 'use strict'; angular .module('hyperion') .controller('system.ScenesController.index', ['$http', '$scope', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', '$stateParams', 'timerange', 'modalDialog', 'authService', 'CONFIG', function($http, $scope, $mdDialog, $timeout, $location, $sessionStorage, $filter, $stateParams, timerange, modalDialog, authService, CONFIG) { // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } var scopeIsActive = true; $scope.$on('$destroy', function() { scopeIsActive = false; }); $scope.ismanager = $sessionStorage.currentUser.ismanager; $scope.isLoading = false; // hide ajax loader authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'lightscene { ' + 'id ' + 'name ' + 'isactive ' + 'created ' + 'members_count ' + 'location { ' + 'id ' + 'name ' + '} ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.scenes = response.data.data.lightscene; $scope.isLoading = false; // hide ajax loader console.log($scope.scenes); },function(error) { // failure console.error(error); } ); }); $scope.viewScene = (scene_id) => { $location.path('/system/scenes/view/' + scene_id); } $scope.editScene = (scene_id) => { $location.path('/system/scenes/edit/' + scene_id); } $scope.removeScene = (scene_id) => { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'lightscenedelete(light_scene_id: "' + scene_id + '")' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); $scope.scenes.splice($scope.scenes.indexOf($filter('filter')($scope.scenes, {id: scene_id})[0]), 1); },function(error) { // failure console.error(error); } ); }); } $scope.addScene = () => { $location.path('/system/scenes/new'); } $scope.executeScene = (scene_id) => { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'lightsceneexec(light_scene_id: "' + scene_id + '")' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); },function(error) { // failure console.error(error); } ); }); } }]) .controller('system.ScenesController.view', ['$http', '$scope', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', '$stateParams', 'timerange', 'modalDialog', 'authService', 'CONFIG', function($http, $scope, $mdDialog, $timeout, $location, $sessionStorage, $filter, $stateParams, timerange, modalDialog, authService, CONFIG) { // null => element disabled const 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}, ]; // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } var scopeIsActive = true; $scope.$on('$destroy', function() { scopeIsActive = false; }); $scope.ismanager = $sessionStorage.currentUser.ismanager; $scope.isLoading = true; // show ajax loader authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'lightscene(id:"' + $stateParams.scene_id + '") { ' + 'id ' + 'name ' + 'isactive ' + 'created ' + 'members_count ' + 'location { ' + 'id ' + 'name ' + '} ' + 'members { ' + 'id ' + 'name ' + 'member_type ' + 'state ' + 'mode_id ' + 'brightness ' + 'temperature ' + 'speed ' + 'color_r ' + 'color_g ' + 'color_b ' + 'color_c ' + 'color_w ' + '} ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve if(response.data.data.lightscene.length) { $scope.scene = response.data.data.lightscene[0]; $scope.scene.isvisible = true; $scope.members = $scope.scene.members; $scope.members.forEach(member => { member.scene = $filter('filter')(scenes, {id: member.mode_id})[0]; if(member.color_r && member.color_g && member.color_b) { member.color_rgb = member.color_r.toString(16) + member.color_g.toString(16) + member.color_b.toString(16); } else { member.color_rgb = null; } }); } else { // object not found console.warn('light scene object not found'); } $scope.isLoading = false; // hide ajax loader },function(error) { // failure console.error(error); } ); }); $scope.executeScene = (scene_id) => { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'lightsceneexec(light_scene_id: "' + scene_id + '")' + '}' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); },function(error) { // failure console.error(error); } ); }); } $scope.editScene = (scene_id) => { $location.path('/system/scenes/edit/' + scene_id); } $scope.removeScene = (scene_id) => { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'lightscenedelete(light_scene_id: "' + scene_id + '")' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); $location.path('/system/scenes'); },function(error) { // failure console.error(error); } ); }); } $scope.back = () => { $location.path('/system/scenes'); } }]) .controller('system.ScenesController.new', ['$http', '$scope', '$element', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', '$stateParams', 'timerange', 'modalDialog', 'authService', 'CONFIG', function($http, $scope, $element, $mdDialog, $timeout, $location, $sessionStorage, $filter, $stateParams, timerange, modalDialog, authService, CONFIG) { // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } var scopeIsActive = true; $scope.$on('$destroy', function() { scopeIsActive = false; }); $scope.isLoading = false; // hide ajax loader ////////////// $scope.searchDevice = ''; $scope.clearSearchDevice = () => { $scope.searchDevice = ''; }; $element.find('input').on('keydown', function(event) { event.stopPropagation(); }); ////////////// var time = timerange.calc($sessionStorage.currentUser.timerange); let time_start = moment(time.start).format('YYYY-MM-DDTHH:mm:ss'); let time_end = moment(time.today).format('YYYY-MM-DDTHH:mm:ss'); console.log('time_start: ' + time_start); console.log('time_end: ' + time_end); authService.getJWTAuth().then(authHeader => { $scope.isLoading = true; // show ajax loader var request = {'query': 'query { ' + 'locations(time_start:"' + time_start + '", time_end:"' + time_end + '") { ' + 'id ' + 'name ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.locations = response.data.data.locations; $scope.isLoading = false; // hide ajax loader },function(error) { // failure console.error(error); } ); }); $scope.selectLocation = () => { $scope.newscene.devices = []; // reset selected devices authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'equipment_index(location_id:"' + $scope.newscene.location + '", type_id:2, groups_included:true) { ' + 'id ' + 'name ' + 'object ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.devices = response.data.data.equipment_index; $scope.devices.forEach(device => { device.settings = { id: 0, state: false, name: 'OFF', brightness: null, color: null, temperature: null, speed: null }; }); $scope.isLoading = false; // hide ajax loader },function(error) { // failure console.error(error); } ); }); } $scope.displaySelected = () => { if($scope.newscene && $scope.newscene.devices) { let count = $scope.newscene.devices.length; if(count > 0) { return 'selected ' + count + ' device' + (count!=1?'s':''); } } return null; }; $scope.sceneSettings = (device_id) => { let device = $filter('filter')($scope.newscene.devices, {id: device_id})[0]; modalDialog.showDialog({ 'template':'modal.scene.settings.html', 'controller':'modalSceneSettingsController', 'settings': device.settings }).then( // settings applied function(settings){ device.settings = settings; } ) }; $scope.removeMember = (device_id) => { $scope.newscene.devices.splice($scope.newscene.devices.indexOf($filter('filter')($scope.newscene.devices, {id: device_id})[0]), 1); if($scope.newscene.devices.length == 0) { $scope.newscene.devices = null; } }; const json2string = (JSONObject) => { let JSONString = JSON.stringify(JSONObject) let unquoted = JSONString.replace(/"([^"]+)":/g, '$1:'); return unquoted; }; const colorSplit = (hexColor) => { let color = { r: null, g: null, b: null, c: null, w: null }; if(hexColor) { color.r = parseInt(hexColor.substring(0, 2), 16); color.g = parseInt(hexColor.substring(2, 4), 16); color.b = parseInt(hexColor.substring(4, 6), 16); } return color; }; $scope.save = () => { console.log($scope.newscene); let devices = []; $scope.newscene.devices.forEach(device => { let newdevice = {}; newdevice.type = device.object; newdevice.id = device.id; if(device.settings) { let color = colorSplit(device.settings.color); newdevice.settings = { state: device.settings.state, brightness: device.settings.brightness, color_r: color.r, color_g: color.g, color_b: color.b, color_c: color.c, color_w: color.w, temperature: device.settings.temperature, mode_id: device.settings.id, speed: device.settings.speed } } else { newdevice.settings = { state: false, brightness: null, color_r: null, color_g: null, color_b: null, color_c: null, color_w: null, temperature: null, mode_id: null, speed: null, } } devices.push(newdevice); }); authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'lightsceneadd ( ' + 'name: "' + $scope.newscene.name + '", ' + 'location_id: "' + $scope.newscene.location + '", ' + 'devices: ' + json2string(devices) + '){ id }' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $location.path('/system/scenes/view/' + response.data.data.lightsceneadd.id); },function(error) { // failure console.error(error); } ); }); }; $scope.cencel = () => { $location.path('/system/scenes'); }; }]) .controller('system.ScenesController.edit', ['$http', '$scope', '$window', '$element', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', '$stateParams', 'timerange', 'modalDialog', 'authService', 'CONFIG', function($http, $scope, $window, $element, $mdDialog, $timeout, $location, $sessionStorage, $filter, $stateParams, timerange, modalDialog, authService, CONFIG) { // null => element disabled const 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}, ]; // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } var scopeIsActive = true; $scope.$on('$destroy', function() { scopeIsActive = false; }); $scope.ismanager = $sessionStorage.currentUser.ismanager; $scope.isLoading = true; // show ajax loader $scope.searchDevice = ''; $scope.clearSearchDevice = () => { $scope.searchDevice = ''; }; $element.find('input').on('keydown', function(event) { event.stopPropagation(); }); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'lightscene(id:"' + $stateParams.scene_id + '") { ' + 'id ' + 'name ' + 'isactive ' + 'created ' + 'members_count ' + 'location { ' + 'id ' + 'name ' + '} ' + 'members { ' + 'id ' + 'member_id ' + 'name ' + 'member_type ' + 'state ' + 'mode_id ' + 'brightness ' + 'temperature ' + 'speed ' + 'color_r ' + 'color_g ' + 'color_b ' + 'color_c ' + 'color_w ' + '} ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve if(response.data.data.lightscene.length) { $scope.scene = response.data.data.lightscene[0]; $scope.scene.isvisible = true; $scope.members = $scope.scene.members; $scope.members.forEach(member => { member.scene = $filter('filter')(scenes, {id: member.mode_id})[0]; if(member.color_r && member.color_g && member.color_b) { member.color_rgb = member.color_r.toString(16) + member.color_g.toString(16) + member.color_b.toString(16); } else { member.color_rgb = null; } }); $scope.newscene = {devices:[null]}; // reset selected devices authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'equipment_index(location_id:"' + $scope.scene.location.id + '", type_id:2, groups_included:true) { ' + 'id ' + 'name ' + 'object ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.newscene.devices.shift(); // remove null element $scope.devices = response.data.data.equipment_index; $scope.devices.forEach(device => { let found = $filter('filter')($scope.members, {member_id: device.id})[0]; if(found) { device.settings = { id: found.mode_id, state: found.state, name: $filter('filter')(scenes, {id: found.mode_id})[0].name, brightness: found.brightness, color: found.color_rgb, temperature: found.temperature, speed: found.speed }; $scope.newscene.devices.push(device); } else { device.settings = { id: 0, state: false, name: 'OFF', brightness: null, color: null, temperature: null, speed: null }; } }); $scope.sceneForm.$setDirty(); $scope.isLoading = false; // hide ajax loader },function(error) { // failure console.error(error); } ); }); } else { // object not found console.warn('light scene object not found'); } $scope.isLoading = false; // hide ajax loader },function(error) { // failure console.error(error); } ); }); $scope.displaySelected = () => { if($scope.newscene && $scope.newscene.devices) { let count = $scope.newscene.devices.length; if(count > 0) { return 'selected ' + count + ' device' + (count!=1?'s':''); } } return null; }; $scope.sceneSettings = (device_id) => { let device = $filter('filter')($scope.newscene.devices, {id: device_id})[0]; modalDialog.showDialog({ 'template':'modal.scene.settings.html', 'controller':'modalSceneSettingsController', 'settings': device.settings }).then( // settings applied function(settings){ device.settings = settings; } ) }; $scope.removeMember = (device_id) => { $scope.newscene.devices.splice($scope.newscene.devices.indexOf($filter('filter')($scope.newscene.devices, {id: device_id})[0]), 1); if($scope.newscene.devices.length == 0) { $scope.newscene.devices = null; } }; const json2string = (JSONObject) => { let JSONString = JSON.stringify(JSONObject) let unquoted = JSONString.replace(/"([^"]+)":/g, '$1:'); return unquoted; }; const colorSplit = (hexColor) => { let color = { r: null, g: null, b: null, c: null, w: null }; if(hexColor) { color.r = parseInt(hexColor.substring(0, 2), 16); color.g = parseInt(hexColor.substring(2, 4), 16); color.b = parseInt(hexColor.substring(4, 6), 16); } return color; }; $scope.save = () => { console.log($scope.newscene); let devices = []; $scope.newscene.devices.forEach(device => { let newdevice = {}; if(device!==null) { newdevice.type = device.object; newdevice.id = device.id; if(device.settings) { let color = colorSplit(device.settings.color); newdevice.settings = { state: device.settings.state, brightness: device.settings.brightness, color_r: color.r, color_g: color.g, color_b: color.b, color_c: color.c, color_w: color.w, temperature: device.settings.temperature, mode_id: device.settings.id, speed: device.settings.speed } } else { newdevice.settings = { state: false, brightness: null, color_r: null, color_g: null, color_b: null, color_c: null, color_w: null, temperature: null, mode_id: null, speed: null, } } devices.push(newdevice); } }); console.log(devices); authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { ' + 'lightsceneupdate ( ' + 'light_scene_id: "' + $stateParams.scene_id + '", ' + 'devices: ' + json2string(devices) + '){ id }' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $location.path('/system/scenes/view/' + $stateParams.scene_id); },function(error) { // failure console.error(error); } ); }); }; $scope.cancel = () => { //$location.path('/system/scenes'); $window.history.back(); } }]) })();