Source: components/admin/admin.controller.js

/**
 * @ngdoc controllers
 * @name AdminCtrl
 * @module s4c.controllers.Admin.Controller
 *
 * @description
 * `AdminCtrl` Controller da tela inicial do módulo de administração
 * 
 * 
 */
(function () {
    'use strict';

    /**
     * @method AdminCtrl
     * @param {*} $rootScope 
     * @param {*} $scope 
     * @param {*} $state 
     * @param {*} UserInfo 
     * @param {*} localize 
     * @param {*} AuthService 
     * @param {*} CamadasService 
     * @param {*} DetalhamentoManager 
     * @param {*} Menu 
     * @param {*} MainState 
     * @param {*} $interval 
     * @param {*} VoipManager 
     * @param {*} CommService 
     */
    function AdminCtrl($rootScope, $scope, $state, UserInfo, localize, AuthService, CamadasService,
        DetalhamentoManager, Menu, MainState, $interval, VoipManager, CommService) {
        $scope.res = $scope.$root.res;

        $scope.version = MainState.getVersion();

        $scope.VoipManager = VoipManager;

        $interval(function () {
            $scope.noError = MainState.noError();
            $scope.errorMessage = MainState.getErrorMessage();
        }, 1000);

        /**
         * @method ativarSessao
         * @param {*} sessao 
         */
        function ativarSessao(sessao) {
            $scope.sessoes = _.map($scope.sessoes, function (sessao) {
                sessao.ativo = false;
                return sessao;
            });

            sessao.ativo = true;
            $scope.subItens = sessao.subItens;
        }

        /**
         * @method onunload
         */
        window.onunload = function () {
            if (MainState.getDirective('voip') != null) {
                MainState.getDirective('voip').deslogar();
            }

            AuthService.logout();
        }

        /**
         * @method onclose
         */
        window.onclose = function () {
            if (MainState.getDirective('voip') != null) {
                MainState.getDirective('voip').deslogar();
            }

            AuthService.logout();
        }

        /**
         * @method logout
         */
        function logout() {
        	CommService.stop();
            AuthService.logout();
            CamadasService.clearReloadNodes();
            DetalhamentoManager.fechar();
            Menu.clearPromise();
            $state.go('inicio');

            if (MainState.getDirective('voip') != null) {
                MainState.getDirective('voip').deslogar();
            }
        }

        $scope.usuario = UserInfo;

        $scope.sessoes = [{
            nome: localize.getLocalizedString('CONFIGURACAO_TITULO'),
            ativo: true,
            exibir: true,
            subItens: [{
                nome: localize.getLocalizedString('SCROLLER_TITULO'),
                route: 'admin.scroller',
                exibir: MainState.isToShow('scroller')
            }, {
                nome: localize.getLocalizedString('BRIEFING_TITULO'),
                route: 'admin.briefing_operacional',
                exibir: MainState.isToShow('briefing')
            }, {
                nome: localize.getLocalizedString('PARAMETRIZACAO_TITULO'),
                route: 'admin.parametrizacao',
                exibir: true
            }, {
                nome: localize.getLocalizedString('COMUM_ALARMES_TITULO'),
                route: 'admin.alarmes',
                exibir: MainState.isToShow('alarmes')
            }, {
                nome: localize.getLocalizedString('MSI_NOME'),
                route: 'admin.incidentes',
                exibir: true
            }, {
                nome: localize.getLocalizedString('POP_TITULO'),
                route: 'admin.pop',
                exibir: MainState.isToShow('pop')
            }, {
                nome: localize.getLocalizedString('PLANEJAMENTO_TITULO'),
                route: 'admin.planejamentos',
                exibir: MainState.isToShow('lista_menu')
            }, {
                nome: localize.getLocalizedString('BASECONHECIMENTO_TITULO_PLURAL'),
                route: 'admin.bases',
                exibir: MainState.isToShow('lista_menu')
            }, {
                nome: localize.getLocalizedString('PONTOSDEINTERESSE_TITULO'),
                route: 'admin.tipopois',
                exibir: true
            }]
        }, {
            nome: localize.getLocalizedString('PERFILACESSO_TITULO'),
            ativo: false,
            exibir: true,
            subItens: [{
                nome: localize.getLocalizedString('PERFIL_USUARIOS'),
                route: 'admin.usuarios_agencias_perfis',
                exibir: true
            }, {
                nome: localize.getLocalizedString('PERFIL_USUARIOSEGRUPOS'),
                route: 'admin.usuarios_grupos_perfis',
                exibir: true
            }, {
                nome: localize.getLocalizedString('PERFIL_ACERVOSEMODULOS'),
                route: 'admin.grupo_usuarios',
                exibir: true
            }, {
                nome: 'Telegram',
                route: 'admin.telegram',
                exibir: MainState.isToShow('mensageria_externa')
            }, {
                nome: localize.getLocalizedString('PERMISSAO_AREAATUACAO'),
                route: 'admin.permissoes_area_atuacao',
                exibir: MainState.isToShow('area_atuacao')
            }]
        }, {
            nome: localize.getLocalizedString('MANUTENCAO_TITULO'),
            ativo: false,
            exibir: true,
            subItens: [{
                nome: localize.getLocalizedString('PONTOSDEINTERESSE_TITULO'),
                route: 'admin.pois',
                exibir: true
            }, {
                nome: localize.getLocalizedString('CAMERAS_TITULO'),
                route: 'admin.cameras',
                exibir: true
            }, {
                nome: localize.getLocalizedString('AREADEATUACAO_TITULO_PLURAL'),
                route: 'admin.area_atuacao',
                exibir: MainState.isToShow('area_atuacao')
            }, {
                nome: localize.getLocalizedString('CAMADAS_TITULO'),
                route: 'admin.camadas',
                exibir: true
            }, {
                nome: localize.getLocalizedString('LOGS_TITULO'),
                route: 'admin.logs',
                exibir: true
            }, {
                nome: localize.getLocalizedString('PONTO_MOVEL_TITULO'),
                route: 'admin.ponto_movel',
                exibir: false
            }, {
                nome: localize.getLocalizedString('COMUM_ICONE'),
                route: 'admin.icons',
                exibir: true
            }, {
                nome: localize.getLocalizedString('REPRESENTACOES'),
                route: 'admin.reps',
                exibir: true
            }]
        },
        {
            nome: localize.getLocalizedString('INTEGRACAO_TITULO'),
            ativo: false,
            exibir: MainState.isToShow('integracao'),
            subItens: [{
                nome: 'BySat',
                route: 'admin.bysat',
                exibir: MainState.isToShow('by_sat')
            }, {
                nome: localize.getLocalizedString('MODERACAOALERTAS_TITULO'),
                route: 'admin.moderacao_alertas_telegram',
                exibir: MainState.isToShow('moderacao_de_alertas')
            }]
        }];

        /* Encontrando pelo $state a sessão ativa */

        var currentSessao = _.chain($scope.sessoes)
            .flatten()
            .find(function (sessao) {
                return _.find(sessao.subItens, { 'route': $state.current.name }) !== undefined;
            })
            .value();

        if (currentSessao) {
            ativarSessao(currentSessao);
        } else {
            ativarSessao($scope.sessoes[0]);
        }

        /**
         * @method showMainDiv
         */
        function showMainDiv() {
            $state.go('main');
        }

        $scope.isElectron = navigator.userAgent.indexOf("Electron") != -1
        /**
         * @method updateCockpit
         */
        function updateCockpit() {
            MainState.updateCockpit(logout);
        }

        angular.extend($scope, {
            ativarSessao: ativarSessao,
            logout: logout,
            showMainDiv: showMainDiv,
            updateCockpit: updateCockpit
        });
    }

    angular.module('s4c.controllers.AdminCtrl', [
        'ngMaterial',
        's4c.controllers.AdminGrupoUsuariosCtrl',
        's4c.controllers.AdminUsuarioCtrl',
        's4c.controllers.AdminCamadasCtrl',
        's4c.controllers.AdminAlarmesCtrl',
        's4c.controllers.AdminBriefingCtrl',
        's4c.controllers.DepartamentoCtrl',
        's4c.controllers.AdminParametrizacaoCtrl',
        's4c.controllers.AdminPoisCtrl',
        's4c.controllers.AdminCamerasCtrl',
        's4c.controllers.AdminAreaAtuacaoCtrl',
        's4c.controllers.ModeracaoAlertasTelegramCtrl',
        's4c.telegram',
        's4c.controllers.AdminPlanejamentosCtrl',
        's4c.controllers.AdminBasesCtrl',
        's4c.controllers.AdminTipoPoiCtrl',
        's4c.controllers.AdminIncidentesCtrl',
        's4c.controllers.AdminAuditoriaCtrl',
        's4c.controllers.AdminIconesCtrl',
        's4c.controllers.AdminRepresentacoesCtrl',
        's4c.controllers.AdminPermissaoAreaAtuacaoCtrl',
        's4c.controllers.AdminPontoMovelCtrl',
        's4c.controllers.AdminPopCtrl',
        's4c.components.voip'
    ])
        .controller('AdminCtrl', AdminCtrl);

    AdminCtrl.$inject = ['$rootScope', '$scope', '$state', 'UserInfo', 'localize', 'AuthService', 'CamadasService', 'DetalhamentoManager', 'Menu', 'MainState', '$interval', 'VoipManager', 'CommService'];
}());