(function () { 'use strict'; angular .module('hyperion') .controller('system.ResourcesController.index', ['$rootScope', '$scope', '$http', '$location', '$timeout', '$sessionStorage', 'timerange', 'modalDialog', 'authService', 'sysClock', 'CONFIG', function($rootScope, $scope, $http, $location, $timeout, $sessionStorage, timerange, modalDialog, authService, sysClock, CONFIG){ // set #content div margin if($sessionStorage.currentUser !== undefined) { if($sessionStorage.currentUser.smallMenu) { $("#content").css('margin-left', 50); } } $scope.ismanager = $sessionStorage.currentUser.ismanager; $scope.isLoading = true; // show ajax loader var time = timerange.calc($sessionStorage.currentUser.timerange); $scope.$on('trUpdate', function(event, payload) { // time range update event console.log('trUpdate event: ' + $sessionStorage.currentUser.timerange); time = timerange.calc($sessionStorage.currentUser.timerange); load_data().catch(error => { console.warn(error); }); }); function load_data() { return new Promise((resolve, reject) => { $scope.isLoading = true; // show ajax loader 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 => { var request = {'query': 'query { ' + 'locations(project:"' + $rootScope.project + '", time_start:"' + time_start + '", time_end:"' + time_end + '", timezone:"' + sysClock.getTimeZone() + '") { ' + 'id ' + 'name ' + 'created ' + 'location_floors_total ' + 'location_rooms_total ' + 'location_equipment_total ' + 'power_consumption ' + 'co2_emission ' + 'status ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.locations = response.data.data.locations; $scope.equipment = $scope.locations.equipment; $scope.isLoading = false; // hide ajax loader console.log($scope.locations); resolve(null); },function(error) { // failure console.error(error); reject(error); } ); }); }); } $timeout(function() { load_data(); }, 100); $scope.viewLocation = function(location_id) { $location.path('/system/locations/view/'+location_id); }; }]) })();