1(function() { 2 "use strict"; 3 angular 4 .module("cidadao.module", [ 5 "ui.router", 6 "ngMessages", 7 "oc.lazyLoad", 8 "ngAnimate", 9 "ngStorage", 10 "ngSanitize", 11 "ngAria", 12 "ngNotify", 13 "ngFileUpload", 14 "ui.utils.masks", 15 "vcRecaptcha", 16 "oitozero.ngSweetAlert", 17 "angularMoment", 18 "EmailMatcher", 19 "AccessibleForm", 20 "NumbersOnlyForm", 21 "httpInterceptor", 22 "ui.bootstrap", 23 "ngGeolocation", 24 "ngMap" 25 ]) 26 //USADO PARA TESTES - DEIXAR EM BRANCO PARA PRODUCAO 27 .constant("SERVER_PATH", "") 28 .run([ 29 "$rootScope", 30 "$transitions", 31 "$http", 32 "ngNotify", 33 "amMoment", 34 "$localStorage", 35 "moment", 36 function( 37 $rootScope, 38 $transitions, 39 $http, 40 ngNotify, 41 amMoment, 42 $localStorage, 43 moment 44 ) { 45 //==================== CONFIGS ==================== 46 ngNotify.config({ 47 theme: "pure", 48 position: "top", 49 duration: 5000, 50 html: true 51 }); 52 amMoment.changeLocale("pt-br"); 53 54 //=============== GLOBAL STATE HOOKS ============== 55 56 //=========================================== 57 // CARREGA TITLE PARA AS TRANSICOES 58 //=========================================== 59 $transitions.onStart({}, function(transition) { 60 $rootScope.currentState = transition.to(); 61 $rootScope.currentStateParams = transition.params("to"); 62 63 //SET TITLE DO NAVBAR 64 if ($rootScope.currentState.data.title) { 65 $rootScope.title = $rootScope.currentState.data.title; 66 } else if ( 67 $rootScope.currentState.name == "manifestacao.cadastro" && 68 $rootScope.currentStateParams.servico == 1 69 ) { 70 $rootScope.title = "Ouvidoria"; 71 } else if ( 72 $rootScope.currentState.name == "manifestacao.cadastro" && 73 $rootScope.currentStateParams.servico == 2 74 ) { 75 $rootScope.title = "Sala de Atendimento ao Cidadão"; 76 } else { 77 $rootScope.title = "Sistema Ouvidoria Cidadã"; 78 } 79 80 //NOTE: TALVEZ SEJA PRECISO USAR - AVALIANDO 81 //$rootScope.previousState = transition.from(); 82 //$rootScope.previousStateParams = transition.params("from"); 83 //transition.promise.finally(($rootScope.showSpinner = false)); 84 }); 85 86 //============================================ 87 // VERIFICA SE O STATE PRECISA DE AUTENTICACAO 88 //============================================ 89 $transitions.onBefore({}, function(transition) { 90 let autenticar = transition.to().data.autenticar; 91 let autenticado = false; 92 let toState = transition.to(); 93 94 if ($localStorage.session) { 95 let ultimoTimestamp = moment( 96 JSON.parse($localStorage.session).timestamp 97 ); 98 let tempoLogado = moment().diff(ultimoTimestamp, "minutes"); 99 if (tempoLogado < 60) { 100 autenticado = true; 101 } 102 } 103 104 //DEFINE SERVICO PARA OUVIDORIA 105 if ( 106 toState.name === "manifestacao.cadastro" && 107 transition.params("to").servico == 1 108 ) { 109 $rootScope.servico = 1; 110 } else { 111 $rootScope.servico = 2; 112 } 113 114 //VALIDA SESSAO DO USUARIO SE LOGADO NA TELA DE CADASTRO DE MANIFESTACAO/PUSH PESQUISA 115 if ( 116 autenticado && 117 (toState.name === "manifestacao.cadastro" || 118 toState.name === "push.pesquisa") 119 ) { 120 $http 121 .get("/siscidadao/rest/v1/publico/sessao/cidadao") 122 .then(function(response) { 123 return true; 124 }) 125 .catch(function(response) { 126 return transition.router.stateService.target("login", { 127 erro: "1" 128 }); 129 }); 130 } 131 132 // SE ESTA AUTENTICADO E FOI PARA TELA DE LOGIN, ENVIA PARA O PAINEL DA MANIFESTACAO 133 if (autenticado && toState.name == "login") { 134 return transition.router.stateService.target("manifestacao.painel"); 135 } 136 137 // SE NAO AUTENTICADO, FOI PARA O PAINEL E POSSUI PARAM email -> 138 if (!autenticado && toState.name == "manifestacao.painel" && transition.params("to").email) { 139 // SALVA LOCALSTORAGE COM EMAIL/TIMESTAMP DO USUARIO 140 $localStorage.session = JSON.stringify({ 141 timestamp: new Date() 142 }); 143 $localStorage.user = JSON.stringify({ 144 email: transition.params("to").email 145 }); 146 autenticado = true; 147 } 148 149 // SE PRECISA DE AUTENTICACAO E NAO ESTA AUTENTICADO, ENVIA PARA LOGIN 150 if (autenticar && !autenticado) { 151 //APAGA LOCALSTORAGE COM INFO DO USUARIO 152 $localStorage.$reset(); 153 return transition.router.stateService.target("login"); 154 } 155 156 $rootScope.autenticado = autenticado; 157 158 }); 159 } 160 ]) 161 .config([ 162 "$stateProvider", 163 "$urlRouterProvider", 164 "$ocLazyLoadProvider", 165 "$httpProvider", 166 "$locationProvider", 167 168 function( 169 $stateProvider, 170 $urlRouterProvider, 171 $ocLazyLoadProvider, 172 $httpProvider, 173 $locationProvider 174 ) { 175 //=============== INTERCEPTORS =============== 176 $httpProvider.interceptors.push("httpInterceptor"); 177 //=============== INTERCEPTORS =============== 178 179 //=============== ocLazyLoad DEBUG ===============
180 //https://oclazyload.readme.io/docs 181 $ocLazyLoadProvider.config({ 182 debug: false 183 }); 184 //=============== ocLazyLoad DEBUG =============== 185 186 //=============== ROTAS =============== 187 //https://ui-router.github.io/guide/ 188 $stateProvider 189 190 //================================================== 191 //================== LOGIN STATE =================== 192 //================================================== 193 //TODO pegar params da url de login error 194 .state("login", { 195 url: "/login?erro", 196 controller: "cidadao.controller", 197 controllerAs: "cidadaoCtrl", 198 data: { 199 autenticar: false 200 }, 201 templateUrl: "templates/login.html" 202 }) 203 204 //================================================== 205 //============== USUARIO FUTURE STATE ============== 206 //================================================== 207 .state("usuario.**", { 208 url: "/usuario", 209 lazyLoad: function($transition$) { 210 return $transition$ 211 .injector() 212 .get("$ocLazyLoad") 213 .load({ 214 serie: true, 215 cache: false, 216 insertBefore: "#modules", 217 files: [ 218 "usuario/usuario.module.js", 219 "usuario/usuario.controller.js" 220 ] 221 }); 222 } 223 }) 224 225 //================================================== 226 //=========== MANIFESTACAO FUTURE STATE ============ 227 //================================================== 228 .state("manifestacao.**", { 229 url: "/manifestacao", 230 lazyLoad: function($transition$) { 231 return $transition$ 232 .injector() 233 .get("$ocLazyLoad") 234 .load({ 235 serie: true, 236 cache: false, 237 insertBefore: "#modules", 238 files: [ 239 "manifestacao/manifestacao.module.js", 240 "manifestacao/manifestacao.service.js", 241 "manifestacao/manifestacao.comum.controller.js", 242 "manifestacao/manifestacao.cadastro.controller.js" 243 ] 244 }); 245 } 246 }) 247 248 //================================================== 249 //================ PUSH FUTURE STATE =============== 250 //================================================== 251 //CNMP 252 // .state("push.**", { 253 // url: "/push", 254 // lazyLoad: function($transition$) { 255 // return $transition$ 256 // .injector() 257 // .get("$ocLazyLoad") 258 // .load({ 259 // serie: true, 260 // cache: false, 261 // insertBefore: "#modules", 262 // files: ["push/push.module.js", "push/push.controller.js"] 263 // }); 264 // } 265 // }) 266 //CNMP 267 268 //================================================== 269 //============= SATISFACAO FUTURE STATE ============ 270 //================================================== 271 .state("satisfacao.**", { 272 url: "/satisfacao", 273 lazyLoad: function($transition$) { 274 return $transition$ 275 .injector() 276 .get("$ocLazyLoad") 277 .load({ 278 serie: true, 279 cache: false, 280 insertBefore: "#modules", 281 files: [ 282 "satisfacao/satisfacao.module.js", 283 "satisfacao/satisfacao.controller.js" 284 ] 285 }); 286 } 287 }) 288 289 //================================================== 290 //============== CONTATO FUTURE STATE ============== 291 //================================================== 292 .state("contato.**", { 293 url: "/contato", 294 lazyLoad: function($transition$) { 295 return $transition$ 296 .injector() 297 .get("$ocLazyLoad") 298 .load({ 299 serie: true, 300 cache: false, 301 insertBefore: "#modules", 302 files: [ 303 "contato/contato.module.js", 304 "contato/contato.controller.js" 305 ] 306 }); 307 } 308 }) 309 310 //================================================== 311 //============== CERTIDÃO FUTURE STATE ============== 312 //================================================== 313 .state("certidao.**", { 314 url: "/certidao", 315 lazyLoad: function($transition$) { 316 return $transition$ 317 .injector() 318 .get("$ocLazyLoad") 319 .load({ 320 serie: true, 321 cache: false, 322 insertBefore: "#modules", 323 files: [ 324 "certidao/certidao.module.js", 325 "certidao/certidao.controller.js" 326 ] 327 }); 328 } 329 }); 330 //ROTA PADRAO 331 $urlRouterProvider.otherwise("/login"); 332 333 // use the HTML5 History API 334 $locationProvider.html5Mode(true); 335 } 336 ]); 337})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.