From e28af6ffce81d4d3163dd17943c91e2c130d9f22 Mon Sep 17 00:00:00 2001 From: kunw Date: Fri, 2 Sep 2016 18:16:58 +0800 Subject: [PATCH] updates for interactions of retrieving project list in repositories. --- .../details/retrieve-projects.directive.js | 48 ++++++++++--------- .../js/components/log/list-log.directive.js | 6 +-- .../navigation-details.directive.js | 19 +++++--- views/repository.htm | 2 +- 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/static/resources/js/components/details/retrieve-projects.directive.js b/static/resources/js/components/details/retrieve-projects.directive.js index ab4850718..baeb6a389 100644 --- a/static/resources/js/components/details/retrieve-projects.directive.js +++ b/static/resources/js/components/details/retrieve-projects.directive.js @@ -27,12 +27,12 @@ vm.projectName = ''; vm.isOpen = false; + vm.isProjectMember = false; + vm.target = 'repositories'; + + vm.isPublic = Number(getParameterByName('is_public', $location.absUrl())); + vm.publicity = (vm.isPublic === 1) ? true : false; - if(getParameterByName('is_public', $location.absUrl())) { - vm.isPublic = getParameterByName('is_public', $location.absUrl()) === 'true' ? 1 : 0; - vm.publicity = (vm.isPublic === 1) ? true : false; - } - vm.retrieve = retrieve; vm.filterInput = ''; vm.selectItem = selectItem; @@ -58,20 +58,20 @@ } function getProjectSuccess(data, status) { - vm.projects = data; - - if(vm.projects == null) { - vm.isPublic = 1; - vm.publicity = true; - vm.projectType = 'public_projects'; - console.log('vm.projects is null, load public projects.'); - return; + vm.projects = data || []; + + if(vm.projects.length == 0){ + if(vm.isPublic === 0) { + $window.location.href = '/project'; + }else{ + vm.publicity = true; + vm.projectType = 'public_projects'; + vm.target = 'repositories'; + } } - + if(angular.isArray(vm.projects) && vm.projects.length > 0) { vm.selectedProject = vm.projects[0]; - }else{ - $window.location.href = '/project'; } if(getParameterByName('project_id', $location.absUrl())){ @@ -81,10 +81,10 @@ } }); } - + $location.search('project_id', vm.selectedProject.project_id); - - vm.checkProjectMember(vm.selectedProject.project_id); + vm.checkProjectMember(vm.selectedProject.project_id); + vm.resultCount = vm.projects.length; $scope.$watch('vm.filterInput', function(current, origin) { @@ -102,11 +102,12 @@ function selectItem(item) { vm.selectedProject = item; $location.search('project_id', vm.selectedProject.project_id); + vm.checkProjectMember(vm.selectedProject.project_id); } $scope.$on('$locationChangeSuccess', function(e) { - var projectId = getParameterByName('project_id', $location.absUrl()); - vm.isOpen = false; + vm.projectId = getParameterByName('project_id', $location.absUrl()); + vm.isOpen = false; }); function checkProjectMember(projectId) { @@ -121,7 +122,7 @@ } function getCurrentProjectMemberFailed(data, status) { - vm.isProjectMember = false; + vm.isProjectMember = false; console.log('Current user has no member for the project:' + status + ', location.url:' + $location.url()); } @@ -132,6 +133,7 @@ restrict: 'E', templateUrl: '/static/resources/js/components/details/retrieve-projects.directive.html', scope: { + 'target': '=', 'isOpen': '=', 'selectedProject': '=', 'publicity': '=', @@ -147,7 +149,7 @@ function link(scope, element, attrs, ctrl) { $(document).on('click', clickHandler); - + function clickHandler(e) { $('[data-toggle="popover"]').each(function () { if (!$(this).is(e.target) && diff --git a/static/resources/js/components/log/list-log.directive.js b/static/resources/js/components/log/list-log.directive.js index 369bf5c5b..3925a95d3 100644 --- a/static/resources/js/components/log/list-log.directive.js +++ b/static/resources/js/components/log/list-log.directive.js @@ -65,11 +65,7 @@ retrieve(vm.queryParams, vm.page, vm.pageSize); $scope.$on('$locationChangeSuccess', function() { - - if(vm.publicity) { - vm.target = 'repositories'; - } - + vm.projectId = getParameterByName('project_id', $location.absUrl()); vm.queryParams = { 'beginTimestamp' : vm.beginTimestamp, diff --git a/static/resources/js/layout/navigation/navigation-details.directive.js b/static/resources/js/layout/navigation/navigation-details.directive.js index bf9b027c7..5d6b06d45 100644 --- a/static/resources/js/layout/navigation/navigation-details.directive.js +++ b/static/resources/js/layout/navigation/navigation-details.directive.js @@ -24,13 +24,14 @@ function NavigationDetailsController($window, $location, $scope, getParameterByName) { var vm = this; + vm.projectId = getParameterByName('project_id', $location.absUrl()); $scope.$on('$locationChangeSuccess', function() { vm.projectId = getParameterByName('project_id', $location.absUrl()); }); - + vm.path = $location.path(); } @@ -51,19 +52,23 @@ return directive; function link(scope, element, attrs, ctrl) { - + var visited = ctrl.path.substring(1); - if(visited.indexOf('?') >= 0) { - visited = ctrl.url.substring(1, ctrl.url.indexOf('?')); - } if(visited) { element.find('a[tag="' + visited + '"]').addClass('active'); }else{ element.find('a:first').addClass('active'); } - - ctrl.target = visited; + + scope.$watch('vm.target', function(current) { + if(current) { + ctrl.target = current; + element.find('a').removeClass('active'); + element.find('a[tag="' + ctrl.target + '"]').addClass('active'); + } + }); + element.find('a').on('click', click); function click(event) { diff --git a/views/repository.htm b/views/repository.htm index 5248b7430..5c543b53c 100644 --- a/views/repository.htm +++ b/views/repository.htm @@ -30,7 +30,7 @@ - +