(function() { 'use strict'; angular .module('hyperion') .controller('system.EventsController', ['$http', '$rootScope', '$scope', '$mdDialog', '$timeout', '$location', '$sessionStorage', '$filter', '$stateParams', 'modalDialog', 'authService', 'timerange', 'sysClock', 'CONFIG', function($http, $rootScope, $scope, $mdDialog, $timeout, $location, $sessionStorage, $filter, $stateParams, modalDialog, authService, timerange, sysClock, 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; }); 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 => { // dashboard data 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'); authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'event(project:"' + $rootScope.project + '", time_start:"' + time_start + '", time_end:"' + time_end + '", timezone:"' + sysClock.getTimeZone() + '") { ' + 'id ' + 'created ' + 'company { ' + 'id ' + 'name ' + '} ' + 'project { ' + 'id ' + 'name ' + '} ' + 'location { ' + 'id ' + 'name ' + 'address_street1 ' + 'address_street2 ' + 'address_city ' + 'address_zipcode ' + 'address_country { ' + 'id ' + 'name ' + '} ' + 'address_state ' + '} ' + 'floor { ' + 'id ' + 'name ' + '} ' + 'room { ' + 'id ' + 'name ' + '} ' + 'equipment { ' + 'id ' + 'name ' + '} ' + 'text ' + 'type { ' + 'id ' + 'name ' + '} ' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.events = response.data.data.event; console.log($scope.events); $scope.isLoading = false; // hide ajax loader resolve(null); },function(error) { // failure console.error(error); } ); }); }); } $timeout(function() { load_data().then(() => { // nothing }).catch(error => { console.warn(error); }); }, 100); $scope.showEvent = function(event_id) { var event = $filter('filter')($scope.events, {id: event_id})[0]; modalDialog.showDialog({ 'template':'modal.event.html', 'controller':'modalEventController', 'event': event }).then( // acknowledge function(event_id){ if(event_id!==null) { } } ) }; }]); })();