(function () { 'use strict'; angular .module('hyperion') .controller('system.ReportsController', ['$scope', '$http', '$filter', '$timeout', 'CONFIG', '$sessionStorage', 'authService', 'modalDialog', function($scope, $http, $filter, $timeout, CONFIG, $sessionStorage, authService, modalDialog) { // 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 $scope.query = {order: '-begin_time'}; function load_data() { $scope.isLoading = true; // show ajax loader authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { ' + 'report { ' + 'id ' + 'name ' + 'created ' + 'scheduled ' + 'published ' + 'type_code ' + 'type_name ' + 'status ' + 'link ' + 'creator_name ' + 'report_date_from ' + 'report_date_to' + '} ' + '}' }; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve $scope.reports = response.data.data.report; $scope.reports.forEach(report => { switch(report.status) { case -1: report.status_name = 'Error'; report.error = true; report.link = null; break; case 0: report.status_name = 'Created'; report.error = false; break; case 1: report.status_name = 'Scheduled'; report.error = false; break; case 2: report.status_name = 'Published'; report.error = false; break; } }); console.log($scope.reports); $scope.isLoading = false; // hide ajax loader },function(error) { // failure console.error(error); } ); }); } $timeout(function() { load_data(); }, 100); $scope.$on('report:update', function(event, source) { $.each($scope.reports, function(index, report) { if(report.id === source.id) { authService.getJWTAuth().then(authHeader => { var request = {'query': 'query { report(id:"' + report.id + '") { link } }'}; $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response.data.data.report); report.status_name = 'Published'; report.link = response.data.data.report[0].link; },function(error) { // failure console.error(error); } ); }); } }); }); $scope.getReportDocument = function(link) { if(link) window.open(link); }; $scope.createReport = function() { modalDialog.showDialog({ 'template':'modal.newreport.html', 'controller':'modalReportCreate' }).then(() => { load_data(); }) }; $scope.removeReport = function(report_id) { authService.getJWTAuth().then(authHeader => { var request = {'query': 'mutation { reportdelete (report_id: "' + report_id + '") }' }; console.log(request); $http({ method: 'POST', url: CONFIG.APP_API, data: request, headers: authHeader }).then( function(response){ // resolve console.log(response); load_data(); },function(error) { // failure console.error(error); } ); }); }; }]) })();