From e2aa9b0177cdfeb9e3f26c511f541c37a03134aa Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 30 Oct 2014 11:52:50 +0000
Subject: [PATCH] #2021 feature - Added menu color based on element status in packs and licenses listings
---
securis/src/main/resources/static/js/main.js | 123 ++++++++++++++++++++--------------------
1 files changed, 62 insertions(+), 61 deletions(-)
diff --git a/securis/src/main/resources/static/js/main.js b/securis/src/main/resources/static/js/main.js
index 1c7c442..ff529be 100644
--- a/securis/src/main/resources/static/js/main.js
+++ b/securis/src/main/resources/static/js/main.js
@@ -1,6 +1,6 @@
(function() {
'use strict';
-
+
var m = angular.module('securis', [ 'ngRoute', 'ngResource', 'toaster', 'localytics.directives', 'catalogs', 'i18n' ]);
m.service('$store', function() {
@@ -20,75 +20,76 @@
return store.getAll();
}
});
-
+
m.factory('securisHttpInterceptor', function($q, $location, $store, toaster) {
var isUnauthorizedAccess = function(rejection) {
return rejection.status === 401 /* Unauthorized */;
}
- return {
- 'request': function(config) {
- var token = $store.get('token');
- if (token) {
- var la = $store.get('last_access');
- var now = new Date().getTime();
- if (la !== null) {
- if (now > (la + 1800000)) { // Session timeout is 1/2 hour
- $store.clear();
- $location.path('/login');
- toaster.pop('warning', 'Session has expired', null, 4000);
- } else {
- console.debug('Last access recent');
- }
- }
- $store.set('last_access', now);
- }
- return config || $q.when(config);
- },
- 'responseError': function(rejection) {
- // do something on error
- if (isUnauthorizedAccess(rejection)) {
- if ($location.path() !== '/login') {
- $store.clear();
- $location.path('/login');
- console.error('There was an unathorized access to url {0}, method: {1}'.$i18n(rejection.config.url, rejection.config.method));
- } else {
- // console.log('Error on login ...')
- }
- }
- return $q.reject(rejection);
- }
- };
- });
+ return {
+ 'request': function(config) {
+ var token = $store.get('token');
+ if (token) {
+ var la = $store.get('last_access');
+ var now = new Date().getTime();
+ if (la !== null) {
+ if (now > (la + 1800000)) { // Session timeout is 1/2
+ // hour
+ $store.clear();
+ $location.path('/login');
+ toaster.pop('warning', 'Session has expired', null, 4000);
+ } else {
+ console.debug('Last access recent');
+ }
+ }
+ $store.set('last_access', now);
+ }
+ return config || $q.when(config);
+ },
+ 'responseError': function(rejection) {
+ // do something on error
+ if (isUnauthorizedAccess(rejection)) {
+ if ($location.path() !== '/login') {
+ $store.clear();
+ $location.path('/login');
+ console.error('There was an unathorized access to url {0}, method: {1}'.$i18n(rejection.config.url, rejection.config.method));
+ } else {
+ // console.log('Error on login ...')
+ }
+ }
+ return $q.reject(rejection);
+ }
+ };
+ });
m.config(function($routeProvider, $locationProvider, $httpProvider) {
console.debug('Configuring routes...');
- $routeProvider.when('/login', {
- templateUrl: 'login.html',
- controller: 'LoginCtrl'
- });
- $routeProvider.when('/licenses', {
- templateUrl: 'licenses.html',
- controller: 'PackAndLicensesCtrl'
- });
- $routeProvider.when('/admin', {
- templateUrl: 'admin.html',
- controller: 'AdminCtrl'
- });
-
- // configure html5 to get links working on jsfiddle
- $locationProvider.html5Mode(true);
- $httpProvider.interceptors.push('securisHttpInterceptor');
+ $routeProvider.when('/login', {
+ templateUrl: 'login.html',
+ controller: 'LoginCtrl'
});
-
+ $routeProvider.when('/licenses', {
+ templateUrl: 'licenses.html',
+ controller: 'PackAndLicensesCtrl'
+ });
+ $routeProvider.when('/admin', {
+ templateUrl: 'admin.html',
+ controller: 'AdminCtrl'
+ });
+
+ // configure html5 to get links working on jsfiddle
+ $locationProvider.html5Mode(true);
+ $httpProvider.interceptors.push('securisHttpInterceptor');
+ });
+
m.controller('MainCtrl', ['$scope', '$http', '$location', '$L', '$store',
- function($scope, $http, $location, $L, $store) {
-
+ function($scope, $http, $location, $L, $store) {
+
$scope.currentRoute = null;
console.log('Current location: ' + $location);
console.log($location);
$location.path('/login');
if ($store.get('token') != null) {
-
+
$http.get('/check', {
headers: {
'X-SECURIS-TOKEN': $store.get('token')
@@ -98,18 +99,18 @@
$http.defaults.headers.common['X-SECURIS-TOKEN'] = $store.get('token');
var location = $store.get('location') || '/licenses';
- $location.path(location);
+ $location.path(location);
$store.set('user', data.user);
}
});
}
-
+
$scope.logout = function() {
$store.remove('user');
$store.remove('token');
$location.path('/login');
}
-
- }]);
-
+
+ }]);
+
})();
\ No newline at end of file
--
Gitblit v1.3.2