From dd2960270c8a5bd15f79379fa011f960424f3f57 Mon Sep 17 00:00:00 2001 From: kunw Date: Wed, 14 Sep 2016 00:40:42 +0800 Subject: [PATCH] refinements on toggling project publicity and rollback changes on popular repos. --- .../details/retrieve-projects.directive.js | 63 ++++++------- .../js/components/log/list-log.directive.js | 4 +- .../list-project-member.directive.js | 6 +- .../repository/list-repository.directive.js | 7 +- .../repository/list-tag.directive.js | 1 - .../top-repository.directive.html | 2 +- .../top-repository.directive.js | 27 +----- .../user-log/user-log.directive.html | 16 ++-- .../js/layout/details/details.controller.js | 11 ++- .../js/layout/project/project.controller.js | 14 +-- views/project.htm | 92 +++++++++---------- views/repository.htm | 35 ++++--- 12 files changed, 122 insertions(+), 156 deletions(-) diff --git a/static/resources/js/components/details/retrieve-projects.directive.js b/static/resources/js/components/details/retrieve-projects.directive.js index be739b01a..f7006404c 100644 --- a/static/resources/js/components/details/retrieve-projects.directive.js +++ b/static/resources/js/components/details/retrieve-projects.directive.js @@ -28,60 +28,50 @@ vm.projectName = ''; vm.isOpen = false; vm.isProjectMember = false; - vm.target = $location.path().substr(1) || 'repositories'; - vm.isPublic = Number(getParameterByName('is_public', $location.absUrl())); - vm.publicity = (vm.isPublic === 1) ? true : false; - + vm.retrieve = retrieve; vm.filterInput = ''; vm.selectItem = selectItem; vm.checkProjectMember = checkProjectMember; - - $scope.$watch('vm.selectedProject', function(current, origin) { - if(current) { - vm.selectedId = current.project_id; - } - }); - - $scope.$watch('vm.publicity', function(current, origin) { - vm.publicity = current ? true : false; - vm.isPublic = vm.publicity ? 1 : 0; - vm.projectType = (vm.isPublic === 1) ? 'public_projects' : 'my_projects'; - vm.retrieve(); - }); - + function retrieve() { ListProjectService(vm.projectName, vm.isPublic) .success(getProjectSuccess) .error(getProjectFailed); } + + vm.retrieve(); + + $scope.$watch('vm.isPublic', function(current) { + vm.projectType = vm.isPublic === 0 ? 'my_project_count' : 'public_project_count'; + }); + + $scope.$watch('vm.selectedProject', function(current) { + if(current) { + vm.selectedId = current.project_id; + } + }); + function getProjectSuccess(data, status) { 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(vm.projects.length == 0 && vm.isPublic === 0){ + $window.location.href = '/project'; } - - if(angular.isArray(vm.projects) && vm.projects.length > 0) { - vm.selectedProject = vm.projects[0]; - } - + if(getParameterByName('project_id', $location.absUrl())){ - angular.forEach(vm.projects, function(value, index) { - if(value['project_id'] === Number(getParameterByName('project_id', $location.absUrl()))) { - vm.selectedProject = value; + for(var i in vm.projects) { + var project = vm.projects[i]; + if(project['project_id'] == getParameterByName('project_id', $location.absUrl())) { + vm.selectedProject = project; + console.log('matched project_id:' + angular.toJson(vm.selectedProject)); + break; } - }); + } } $location.search('project_id', vm.selectedProject.project_id); @@ -127,6 +117,7 @@ function getCurrentProjectMemberFailed(data, status) { vm.isProjectMember = false; console.log('Current user has no member for the project:' + status + ', location.url:' + $location.url()); + vm.target = 'repositories'; } } @@ -139,7 +130,7 @@ 'target': '=', 'isOpen': '=', 'selectedProject': '=', - 'publicity': '=', + 'isPublic': '=', 'isProjectMember': '=' }, link: link, diff --git a/static/resources/js/components/log/list-log.directive.js b/static/resources/js/components/log/list-log.directive.js index 84c123158..ae0f60fce 100644 --- a/static/resources/js/components/log/list-log.directive.js +++ b/static/resources/js/components/log/list-log.directive.js @@ -148,9 +148,7 @@ 'restrict': 'E', 'templateUrl': '/static/resources/js/components/log/list-log.directive.html', 'scope': { - 'sectionHeight': '=', - 'target': '=', - 'publicity': '=' + 'sectionHeight': '=' }, 'link': link, 'controller': ListLogController, 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 b9ee3fccd..992b1d598 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 @@ -94,8 +94,7 @@ function getProjectMemberFailed(response) { console.log('Failed to get project members:' + response); - vm.projectMembers = []; - vm.target = 'repositories'; + vm.projectMembers = []; $location.url('repositories').search('project_id', vm.projectId); } @@ -106,8 +105,7 @@ 'restrict': 'E', 'templateUrl': '/static/resources/js/components/project-member/list-project-member.directive.html', 'scope': { - 'sectionHeight': '=', - 'target': '=' + 'sectionHeight': '=' }, 'link': link, 'controller': ListProjectMemberController, diff --git a/static/resources/js/components/repository/list-repository.directive.js b/static/resources/js/components/repository/list-repository.directive.js index 3ad1108b9..655ac6764 100644 --- a/static/resources/js/components/repository/list-repository.directive.js +++ b/static/resources/js/components/repository/list-repository.directive.js @@ -31,7 +31,7 @@ vm.filterInput = ''; vm.toggleInProgress = []; - + var hashValue = $location.hash(); if(hashValue) { var slashIndex = hashValue.indexOf('/'); @@ -54,10 +54,10 @@ if(val) { vm.projectId = getParameterByName('project_id', $location.absUrl()); vm.filterInput = ''; - vm.retrieve(); + vm.retrieve(); } }); - + $scope.$watch('vm.repositories', function(current) { if(current) { @@ -93,6 +93,7 @@ vm.deleteImage = deleteImage; function retrieve(){ + console.log('retrieve repositories, project_id:' + vm.projectId); ListRepositoryService(vm.projectId, vm.filterInput, vm.page, vm.pageSize) .then(getRepositoryComplete, getRepositoryFailed); } diff --git a/static/resources/js/components/repository/list-tag.directive.js b/static/resources/js/components/repository/list-tag.directive.js index fde155265..f47b0b917 100644 --- a/static/resources/js/components/repository/list-tag.directive.js +++ b/static/resources/js/components/repository/list-tag.directive.js @@ -30,7 +30,6 @@ $scope.$watch('vm.repoName', function(current, origin) { if(current) { - console.log('vm.repoName in tags:' + current); vm.retrieve(); } }); diff --git a/static/resources/js/components/top-repository/top-repository.directive.html b/static/resources/js/components/top-repository/top-repository.directive.html index 3dc0129e7..e6567e7f6 100644 --- a/static/resources/js/components/top-repository/top-repository.directive.html +++ b/static/resources/js/components/top-repository/top-repository.directive.html @@ -29,7 +29,7 @@

// 'no_top_repositories' | tr //

- //t.name// + //t.name// //t.count// diff --git a/static/resources/js/components/top-repository/top-repository.directive.js b/static/resources/js/components/top-repository/top-repository.directive.js index a385c8808..bb02890b4 100644 --- a/static/resources/js/components/top-repository/top-repository.directive.js +++ b/static/resources/js/components/top-repository/top-repository.directive.js @@ -20,17 +20,15 @@ .module('harbor.top.repository') .directive('topRepository', topRepository); - TopRepositoryController.$inject = ['$scope', 'ListTopRepositoryService', 'SearchService', '$filter', 'trFilter', '$window']; + TopRepositoryController.$inject = ['$scope', 'ListTopRepositoryService', '$filter', 'trFilter']; - function TopRepositoryController($scope, ListTopRepositoryService, SearchService, $filter, trFilter, $window) { + function TopRepositoryController($scope, ListTopRepositoryService, $filter, trFilter) { var vm = this; ListTopRepositoryService(5) .success(listTopRepositorySuccess) .error(listTopRepositoryFailed); - vm.gotoRepo = gotoRepo; - function listTopRepositorySuccess(data) { vm.top10Repositories = data || []; } @@ -41,26 +39,7 @@ $scope.$emit('raiseError', true); console.log('Failed to get top repo:' + data); } - - function gotoRepo(repoName) { - SearchService(repoName) - .success(searchSuccess) - .error(searchFailed); - } - - function searchSuccess(data, status) { - var repoInfo = data['repository']; - if(repoInfo && repoInfo.length > 0) { - var projectId = repoInfo[0]['project_id']; - var publicity = repoInfo[0]['project_public']; - var repoName = repoInfo[0]['repository_name']; - $window.location.href = '/repository#/repositories?project_id=' + projectId + '&is_public=' + publicity +'#' + repoName; - } - } - - function searchFailed(data) { - console.log('Failed to get repo info:' + data); - } + } function topRepository() { diff --git a/static/resources/js/components/user-log/user-log.directive.html b/static/resources/js/components/user-log/user-log.directive.html index d3a9a1241..4fd762d5e 100644 --- a/static/resources/js/components/user-log/user-log.directive.html +++ b/static/resources/js/components/user-log/user-log.directive.html @@ -16,10 +16,11 @@
- - - - + + + + +
// 'operation' | tr //// 'details' | tr //// 'user' | tr //// 'creation_time' | tr //// 'username' | tr //// 'repository_name' | tr //// 'tag' | tr //// 'operation' | tr //// 'timestamp' | tr //
@@ -30,9 +31,10 @@

// 'no_user_logs' | tr //

- //t.operation// - //t.repo_name// - //t.username// + //t.username// + //t.repo_name// + //t.repo_tag// + //t.operation// //t.op_time | dateL : 'YYYY-MM-DD HH:mm:ss'// diff --git a/static/resources/js/layout/details/details.controller.js b/static/resources/js/layout/details/details.controller.js index d07679cbc..9e697686e 100644 --- a/static/resources/js/layout/details/details.controller.js +++ b/static/resources/js/layout/details/details.controller.js @@ -20,12 +20,12 @@ .module('harbor.details') .controller('DetailsController', DetailsController); - DetailsController.$inject = ['$scope', '$timeout']; + DetailsController.$inject = ['$scope', '$timeout', '$window']; - function DetailsController($scope, $timeout) { + function DetailsController($scope, $timeout, $window) { var vm = this; - vm.publicity = false; + vm.isPublic = 0; vm.isProjectMember = false; vm.togglePublicity = togglePublicity; @@ -75,8 +75,9 @@ }); function togglePublicity(e) { - vm.publicity = e.publicity; - vm.target = 'repositories'; + vm.isPublic = e.isPublic; + $window.location='/project?is_public=' + vm.isPublic; + return; } } diff --git a/static/resources/js/layout/project/project.controller.js b/static/resources/js/layout/project/project.controller.js index 51f401432..c9360ee77 100644 --- a/static/resources/js/layout/project/project.controller.js +++ b/static/resources/js/layout/project/project.controller.js @@ -20,14 +20,14 @@ .module('harbor.layout.project') .controller('ProjectController', ProjectController); - ProjectController.$inject = ['$scope', 'ListProjectService', 'DeleteProjectService', '$timeout', 'currentUser', 'getRole', '$filter', 'trFilter']; + ProjectController.$inject = ['$scope', 'ListProjectService', 'DeleteProjectService', '$timeout', 'currentUser', 'getRole', '$filter', 'trFilter', 'getParameterByName', '$location']; - function ProjectController($scope, ListProjectService, DeleteProjectService, $timeout, currentUser, getRole, $filter, trFilter) { + function ProjectController($scope, ListProjectService, DeleteProjectService, $timeout, currentUser, getRole, $filter, trFilter, getParameterByName, $location) { var vm = this; vm.isOpen = false; vm.projectName = ''; - vm.publicity = 0; + vm.isPublic = Number(getParameterByName('is_public', $location.absUrl())) || 0; vm.page = 1; vm.pageSize = 15; @@ -44,6 +44,7 @@ vm.confirmToDelete = confirmToDelete; vm.deleteProject = deleteProject; + //Error message dialog handler for project. $scope.$on('modalTitle', function(e, val) { @@ -89,7 +90,7 @@ }); function retrieve() { - ListProjectService(vm.projectName, vm.publicity, vm.page, vm.pageSize) + ListProjectService(vm.projectName, vm.isPublic, vm.page, vm.pageSize) .then(listProjectSuccess) .catch(listProjectFailed); } @@ -127,15 +128,14 @@ } function showAddButton() { - return (vm.publicity === 0); + return (vm.isPublic === 0); } function togglePublicity(e) { - vm.publicity = e.publicity; + vm.isPublic = e.isPublic; vm.isOpen = false; vm.page = 1; vm.retrieve(); - console.log('vm.publicity:' + vm.publicity); } function searchProjectByKeyPress($event) { diff --git a/views/project.htm b/views/project.htm index aa002e020..f56c5b0fd 100644 --- a/views/project.htm +++ b/views/project.htm @@ -19,13 +19,13 @@
-
+ // 'my_projects' | tr // + // 'my_projects' | tr // + | + // 'public_projects' | tr // + // 'public_projects' | tr // + +
@@ -33,50 +33,48 @@
- - + +
-
- - -
-
-
- - - - - - - - - -
// 'project_name' | tr //// 'repositories' | tr //// 'role' | tr //// 'creation_time' | tr //// 'publicity' | tr //// 'operation' | tr //
-
-
- - - - - - - - - - - - - - -

// 'no_projects_add_new_project' | tr //

//p.name////p.repo_count////vm.getProjectRole(p.current_user_role_id) | tr////p.creation_time | dateL : 'YYYY-MM-DD HH:mm:ss'// -    -
-
+
+ +
+
+
+ + + + + + + + + +
// 'project_name' | tr //// 'repositories' | tr //// 'role' | tr //// 'creation_time' | tr //// 'publicity' | tr //// 'operation' | tr //
+
+
+ + + + + + + + + + + + + + +

// 'no_projects_add_new_project' | tr //

//p.name////p.repo_count////vm.getProjectRole(p.current_user_role_id) | tr////p.creation_time | dateL : 'YYYY-MM-DD HH:mm:ss'// +    +
- +
+
-
diff --git a/views/repository.htm b/views/repository.htm index 5c543b53c..0ee168ccc 100644 --- a/views/repository.htm +++ b/views/repository.htm @@ -16,29 +16,28 @@
-
+
+ // 'my_projects' | tr // + // 'my_projects' | tr // + | + // 'public_projects' | tr // + // 'public_projects' | tr //
- - - - + + + +
- - + +
- - - - - -
+ + + + +