update for interceptor of global session check and others.

This commit is contained in:
kunw 2016-07-05 09:06:36 +08:00
parent ae3bfba3c8
commit 597b865cf5
6 changed files with 35 additions and 48 deletions

View File

@ -58,10 +58,11 @@
vm.opDelete = vm.opAll;
vm.opOthers = vm.opAll;
}else {
vm.op = [];
vm.opAll = false;
}
vm.op = [];
if(vm.opCreate) {
vm.op.push('create');
}

View File

@ -20,8 +20,8 @@
vm.beginTimestamp = 0;
vm.endTimestamp = 0;
vm.keywords = "";
vm.username = "";
vm.keywords = '';
vm.username = '';
vm.op = [];
vm.opOthers = true;
@ -48,24 +48,20 @@
'projectId': vm.projectId,
'username' : vm.username
};
vm.username = '';
retrieve(vm.queryParams);
});
function search(e) {
if(e.op[0] === 'all') {
if(vm.opOthers && $.trim(vm.others) !== '') {
e.op = [];
e.op.push(vm.others);
vm.queryParams.keywords = e.op.join('/');
}else{
vm.queryParams.keywords = '';
}
}else {
if(vm.opOthers && $.trim(vm.others) !== '') {
e.op.push(vm.others);
}
vm.queryParams.keywords = e.op.join('/');
}
e.op = ['create', 'pull', 'push', 'delete'];
}
if(vm.opOthers && $.trim(vm.others) !== '') {
e.op.push(vm.others);
}
vm.queryParams.keywords = e.op.join('/');
vm.queryParams.username = e.username;
vm.queryParams.beginTimestamp = toUTCSeconds(vm.fromDate, 0, 0, 0);

View File

@ -28,6 +28,7 @@
$scope.$on('$locationChangeSuccess', function() {
vm.projectId = getParameterByName('project_id', $location.absUrl());
vm.username = '';
vm.retrieve();
});

View File

@ -1,5 +1,5 @@
<ng-switch on="vm.editMode">
<span ng-switch-default>//vm.currentRole.name//</span>
<select ng-switch-when="true" ng-model="vm.currentRole" ng-options="role as role.name for role in vm.roles track by role.roleName" ng-change="vm.selectRole(vm.currentRole)">
<select class="form-control" style="width: auto; height: auto; padding: 0;" ng-switch-when="true" ng-model="vm.currentRole" ng-options="role as role.name for role in vm.roles track by role.roleName" ng-change="vm.selectRole(vm.currentRole)">
</select>
</ng-switch>

View File

@ -10,28 +10,31 @@
$httpProvider.defaults.headers.common = {'Accept': 'application/json, text/javascript, */*; q=0.01'};
$httpProvider.interceptors.push('redirectInterceptor');
})
.factory('redirectInterceptor', RedirectInterceptorFactory)
.service('redirectInterceptor', RedirectInterceptorService)
.factory('getParameterByName', getParameterByName)
.filter('dateL', localizeDate)
.filter('tr', tr);
RedirectInterceptorFactory.$inject = ['$q', '$window'];
RedirectInterceptorService.$inject = ['$q', '$window'];
function RedirectInterceptorFactory($q, $window) {
return redirectInterceptor;
function redirectInterceptor() {
return {
'request' : function(r) {
console.log('global interceptor has being triggered, "Request"');
},
'response': function(r) {
console.log('global interceptor has being triggered, "Response"');
},
'responseError': function(rejection) {
console.log('global interceptor has being triggered. "ResponseError"');
function RedirectInterceptorService($q, $window) {
return {
'responseError': function(rejection) {
var pathname = $window.location.pathname;
var exclusions = ['/', '/search', '/reset_password', '/sign_up', '/forgot_password'];
var isExcluded = false;
for(var i in exclusions) {
if(exclusions[i] === pathname) {
isExcluded = true;
break;
}
}
};
}
if(rejection.status === 401 && !isExcluded) {
$window.location.href = '/';
}
return $q.reject(rejection);
}
};
}
function getParameterByName() {

View File

@ -26,21 +26,7 @@
}
function getCurrentUserFailed(e){
var url = location.pathname;
var exclusions = [
'/',
'/forgot_password',
'/sign_up',
'/reset_password',
'/search',
'/repository'
];
for(var i = 0; i < exclusions.length; i++) {
if(exclusions[i]===url) {
return;
}
}
$window.location.href = '/';
console.log('No session of current user.');
}
}