From 597b865cf51ab2b37acb5925cde6103a44793577 Mon Sep 17 00:00:00 2001 From: kunw Date: Tue, 5 Jul 2016 09:06:36 +0800 Subject: [PATCH] update for interceptor of global session check and others. --- .../log/advanced-search.directive.js | 3 +- .../js/components/log/list-log.directive.js | 26 ++++++-------- .../list-project-member.directive.js | 1 + .../project-member/switch-role.directive.html | 2 +- static/resources/js/harbor.config.js | 35 ++++++++++--------- .../js/session/session.current-user.js | 16 +-------- 6 files changed, 35 insertions(+), 48 deletions(-) diff --git a/static/resources/js/components/log/advanced-search.directive.js b/static/resources/js/components/log/advanced-search.directive.js index 4e4f3ad71..a64775de7 100644 --- a/static/resources/js/components/log/advanced-search.directive.js +++ b/static/resources/js/components/log/advanced-search.directive.js @@ -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'); } diff --git a/static/resources/js/components/log/list-log.directive.js b/static/resources/js/components/log/list-log.directive.js index 686979177..567f035c6 100644 --- a/static/resources/js/components/log/list-log.directive.js +++ b/static/resources/js/components/log/list-log.directive.js @@ -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); diff --git a/static/resources/js/components/project-member/list-project-member.directive.js b/static/resources/js/components/project-member/list-project-member.directive.js index e8be0a7d5..77415f6dc 100644 --- a/static/resources/js/components/project-member/list-project-member.directive.js +++ b/static/resources/js/components/project-member/list-project-member.directive.js @@ -28,6 +28,7 @@ $scope.$on('$locationChangeSuccess', function() { vm.projectId = getParameterByName('project_id', $location.absUrl()); + vm.username = ''; vm.retrieve(); }); diff --git a/static/resources/js/components/project-member/switch-role.directive.html b/static/resources/js/components/project-member/switch-role.directive.html index f55c2154f..13721d691 100644 --- a/static/resources/js/components/project-member/switch-role.directive.html +++ b/static/resources/js/components/project-member/switch-role.directive.html @@ -1,5 +1,5 @@ //vm.currentRole.name// - \ No newline at end of file diff --git a/static/resources/js/harbor.config.js b/static/resources/js/harbor.config.js index 0b8cd4abc..cef6741cd 100644 --- a/static/resources/js/harbor.config.js +++ b/static/resources/js/harbor.config.js @@ -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() { diff --git a/static/resources/js/session/session.current-user.js b/static/resources/js/session/session.current-user.js index 417596903..d2cf42397 100644 --- a/static/resources/js/session/session.current-user.js +++ b/static/resources/js/session/session.current-user.js @@ -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.'); } }