diff --git a/static/resources/js/components/project/add-project.directive.js b/static/resources/js/components/project/add-project.directive.js index 3ecf4ac..8325f56 100644 --- a/static/resources/js/components/project/add-project.directive.js +++ b/static/resources/js/components/project/add-project.directive.js @@ -28,7 +28,7 @@ $scope.p = {}; var vm0 = $scope.p; vm0.projectName = ''; - vm.isPublic = false; + vm.isPublic = 0; vm.addProject = addProject; vm.cancel = cancel; @@ -37,9 +37,20 @@ vm.hasError = false; vm.errorMessage = ''; + + $scope.$watch('vm.isOpen', function(current) { + if(current) { + $scope.form.$setPristine(); + $scope.form.$setUntouched(); + vm0.projectName = ''; + vm.isPublic = 0; + } + }); + function addProject(p) { if(p && angular.isDefined(p.projectName)) { + vm.isPublic = vm.isPublic ? 1 : 0; AddProjectService(p.projectName, vm.isPublic) .success(addProjectSuccess) .error(addProjectFailed); @@ -74,9 +85,9 @@ } vm.isOpen = false; vm0.projectName = ''; - vm.isPublic = false; + vm.isPublic = 0; - vm.hasError = false; vm.close = close; + vm.hasError = false; vm.errorMessage = ''; } @@ -94,16 +105,10 @@ 'scope' : { 'isOpen': '=' }, - 'link': link, 'controllerAs': 'vm', 'bindToController': true }; - return directive; - - function link(scope, element, attrs, ctrl) { - scope.form.$setPristine(); - scope.form.$setUntouched(); - } + return directive; } })(); diff --git a/static/resources/js/components/project/publicity-button.directive.js b/static/resources/js/components/project/publicity-button.directive.js index 2bb5d3b..7f108b8 100644 --- a/static/resources/js/components/project/publicity-button.directive.js +++ b/static/resources/js/components/project/publicity-button.directive.js @@ -27,11 +27,7 @@ vm.toggle = toggle; function toggle() { - if(vm.isPublic) { - vm.isPublic = false; - }else{ - vm.isPublic = true; - } + vm.isPublic = vm.isPublic ? 0 : 1; ToggleProjectPublicityService(vm.projectId, vm.isPublic) .success(toggleProjectPublicitySuccess) .error(toggleProjectPublicityFailed); @@ -53,12 +49,7 @@ $scope.$emit('modalMessage', message); $scope.$emit('raiseError', true); - if(vm.isPublic) { - vm.isPublic = false; - }else{ - vm.isPublic = true; - } - + vm.isPublic = vm.isPublic ? 0 : 1; console.log('Failed to toggle project publicity:' + e); } } @@ -69,7 +60,6 @@ 'templateUrl': '/static/resources/js/components/project/publicity-button.directive.html', 'scope': { 'isPublic': '=', - 'owned': '=', 'projectId': '=' }, 'link': link, diff --git a/static/resources/js/components/replication/list-replication.directive.html b/static/resources/js/components/replication/list-replication.directive.html index a7d7036..2269f65 100644 --- a/static/resources/js/components/replication/list-replication.directive.html +++ b/static/resources/js/components/replication/list-replication.directive.html @@ -62,7 +62,7 @@     - + diff --git a/static/resources/js/components/replication/list-replication.directive.js b/static/resources/js/components/replication/list-replication.directive.js index 7316662..eae2df2 100644 --- a/static/resources/js/components/replication/list-replication.directive.js +++ b/static/resources/js/components/replication/list-replication.directive.js @@ -37,9 +37,9 @@ }; } - ListReplicationController.$inject = ['$scope', 'getParameterByName', '$location', 'ListReplicationPolicyService', 'ToggleReplicationPolicyService', 'ListReplicationJobService', '$window', '$filter', 'trFilter', 'jobStatus']; + ListReplicationController.$inject = ['$scope', 'getParameterByName', '$location', 'ListReplicationPolicyService', 'ToggleReplicationPolicyService', 'DeleteReplicationPolicyService', 'ListReplicationJobService', '$window', '$filter', 'trFilter', 'jobStatus']; - function ListReplicationController($scope, getParameterByName, $location, ListReplicationPolicyService, ToggleReplicationPolicyService, ListReplicationJobService, $window, $filter, trFilter, jobStatus) { + function ListReplicationController($scope, getParameterByName, $location, ListReplicationPolicyService, ToggleReplicationPolicyService, DeleteReplicationPolicyService, ListReplicationJobService, $window, $filter, trFilter, jobStatus) { var vm = this; vm.sectionHeight = {'min-height': '1260px'}; @@ -51,6 +51,9 @@ vm.addReplication = addReplication; vm.editReplication = editReplication; + vm.deleteReplicationPolicy = deleteReplicationPolicy; + + vm.confirmToDelete = confirmToDelete; vm.searchReplicationPolicy = searchReplicationPolicy; vm.searchReplicationJob = searchReplicationJob; @@ -176,6 +179,40 @@ console.log('Selected policy ID:' + vm.policyId); } + function deleteReplicationPolicy() { + DeleteReplicationPolicyService(vm.policyId) + .success(deleteReplicationPolicySuccess) + .error(deleteReplicationPolicyFailed); + } + + function deleteReplicationPolicySuccess(data, status) { + console.log('Successful delete replication policy.'); + vm.retrievePolicy(); + } + + function deleteReplicationPolicyFailed(data, status) { + $scope.$emit('modalTitle', $filter('tr')('error')); + $scope.$emit('modalMessage', $filter('tr')('failed_to_delete_replication_policy')); + $scope.$emit('raiseError', true); + console.log('Failed to delete replication policy.'); + } + + function confirmToDelete(policyId, policyName) { + vm.policyId = policyId; + + $scope.$emit('modalTitle', $filter('tr')('confirm_delete_policy_title')); + $scope.$emit('modalMessage', $filter('tr')('confirm_delete_policy', [policyName])); + + var emitInfo = { + 'confirmOnly': false, + 'contentType': 'text/plain', + 'action': vm.deleteReplicationPolicy + }; + + $scope.$emit('raiseInfo', emitInfo); + } + + function confirmToTogglePolicy(policyId, enabled, name) { vm.policyId = policyId; vm.enabled = enabled; diff --git a/static/resources/js/layout/project/project.controller.js b/static/resources/js/layout/project/project.controller.js index 9a7291e..2478189 100644 --- a/static/resources/js/layout/project/project.controller.js +++ b/static/resources/js/layout/project/project.controller.js @@ -20,14 +20,17 @@ .module('harbor.layout.project') .controller('ProjectController', ProjectController); - ProjectController.$inject = ['$scope', 'ListProjectService', '$timeout', 'currentUser', 'getRole', '$filter', 'trFilter']; + ProjectController.$inject = ['$scope', 'ListProjectService', 'DeleteProjectService', '$timeout', 'currentUser', 'getRole', '$filter', 'trFilter']; - function ProjectController($scope, ListProjectService, $timeout, currentUser, getRole, $filter, trFilter) { + function ProjectController($scope, ListProjectService, DeleteProjectService, $timeout, currentUser, getRole, $filter, trFilter) { var vm = this; vm.isOpen = false; vm.projectName = ''; vm.publicity = 0; + + vm.page = 1; + vm.pageSize = 20; vm.retrieve = retrieve; vm.showAddProject = showAddProject; @@ -39,6 +42,8 @@ vm.getProjectRole = getProjectRole; vm.searchProjectByKeyPress = searchProjectByKeyPress; + vm.confirmToDelete = confirmToDelete; + vm.deleteProject = deleteProject; //Error message dialog handler for project. @@ -57,19 +62,42 @@ }; vm.contentType = 'text/plain'; vm.confirmOnly = true; + $timeout(function() { + $scope.$broadcast('showDialog', true); + }, 350); + } + }); + + $scope.$on('raiseInfo', function(e, val) { + if(val) { + vm.action = function() { + val.action(); + $scope.$broadcast('showDialog', false); + }; + vm.contentType = val.contentType; + vm.confirmOnly = val.confirmOnly; + $scope.$broadcast('showDialog', true); } }); + $scope.$watch('vm.page', function(current) { + if(current) { + vm.page = current; + vm.retrieve(); + } + }); + function retrieve() { - ListProjectService(vm.projectName, vm.publicity) - .success(listProjectSuccess) - .error(listProjectFailed); + ListProjectService(vm.projectName, vm.publicity, vm.page, vm.pageSize) + .then(listProjectSuccess) + .catch(listProjectFailed); } - function listProjectSuccess(data, status) { - vm.projects = data || []; + function listProjectSuccess(response) { + vm.totalCount = response.headers('X-Total-Count'); + vm.projects = response.data || []; } function getProjectRole(roleId) { @@ -80,7 +108,7 @@ return ''; } - function listProjectFailed(data, status) { + function listProjectFailed(response) { $scope.$emit('modalTitle', $filter('tr')('error')); $scope.$emit('modalMessage', $filter('tr')('failed_to_get_project')); $scope.$emit('raiseError', true); @@ -92,11 +120,7 @@ }); function showAddProject() { - if(vm.isOpen){ - vm.isOpen = false; - }else{ - vm.isOpen = true; - } + vm.isOpen = vm.isOpen ? false : true; } function searchProject() { @@ -104,11 +128,7 @@ } function showAddButton() { - if(vm.publicity === 0) { - return true; - }else{ - return false; - } + return (vm.publicity === 0); } function togglePublicity(e) { @@ -125,6 +145,39 @@ } } + function confirmToDelete(projectId, projectName) { + vm.selectedProjectId = projectId; + + $scope.$emit('modalTitle', $filter('tr')('confirm_delete_project_title')); + $scope.$emit('modalMessage', $filter('tr')('confirm_delete_project', [projectName])); + + var emitInfo = { + 'confirmOnly': false, + 'contentType': 'text/plain', + 'action': vm.deleteProject + }; + + $scope.$emit('raiseInfo', emitInfo); + } + + function deleteProject() { + DeleteProjectService(vm.selectedProjectId) + .success(deleteProjectSuccess) + .error(deleteProjectFailed); + } + + function deleteProjectSuccess(data, status) { + console.log('Successful delete project.'); + vm.retrieve(); + } + + function deleteProjectFailed(data, status) { + $scope.$emit('modalTitle', $filter('tr')('error')); + $scope.$emit('modalMessage', $filter('tr')('failed_to_delete_project')); + $scope.$emit('raiseError', true); + console.log('Failed to delete project.'); + } + } })(); \ No newline at end of file diff --git a/static/resources/js/services/i18n/locale_messages_en-US.js b/static/resources/js/services/i18n/locale_messages_en-US.js index 5eb0b1d..f434c3f 100644 --- a/static/resources/js/services/i18n/locale_messages_en-US.js +++ b/static/resources/js/services/i18n/locale_messages_en-US.js @@ -149,8 +149,13 @@ var locale_messages = { 'failed_to_add_member': 'Project member can not be added, insuffient permissions.', 'failed_to_change_member': 'Project member can not be changed, insuffient permissions.', 'failed_to_delete_member': 'Project member can not be deleted, insuffient permissions.', + 'failed_to_delete_project': 'Project can not be deleted, insuffient permissions.', + 'confirm_delete_project_title': 'Project Deletion', + 'confirm_delete_project': 'Are you sure to delete the project "$0" ?', 'confirm_delete_user_title': 'User Deletion', 'confirm_delete_user': 'Are you sure to delete the user "$0" ?', + 'confirm_delete_policy_title': 'Replication Policy Deletion', + 'confirm_delete_policy': 'Are you sure to delete the replication policy "$0" ?', 'confirm_delete_destination_title': 'Destination Deletion', 'confirm_delete_destination': 'Are you sure to delete the destination "$0" ?', 'replication': 'Replication', @@ -194,6 +199,7 @@ var locale_messages = { 'successful_signed_up': 'Signed up successfully.', 'add_new_policy': 'Add New Policy', 'edit_policy': 'Edit Policy', + 'delete_policy': 'Delete Policy', 'add_new_title': 'Add User', 'add_new': 'Add', 'successful_added': 'New user added successfully.', @@ -246,6 +252,7 @@ var locale_messages = { 'failed_to_get_destination_policies': 'Failed to get destination policies.', 'failed_to_get_replication_policy': 'Failed to get replication policy.', 'failed_to_update_replication_policy': 'Failed to update replication policy.', + 'failed_to_delete_replication_policy': 'Failed to delete replication policy.', 'failed_to_delete_destination': 'Failed to delete destination.', 'failed_to_create_destination': 'Failed to create destination.', 'failed_to_update_destination': 'Failed to update destination.', diff --git a/static/resources/js/services/i18n/locale_messages_zh-CN.js b/static/resources/js/services/i18n/locale_messages_zh-CN.js index 6c2d241..4a03a07 100644 --- a/static/resources/js/services/i18n/locale_messages_zh-CN.js +++ b/static/resources/js/services/i18n/locale_messages_zh-CN.js @@ -148,8 +148,13 @@ var locale_messages = { 'failed_to_add_member': '无法添加项目成员,权限不足。', 'failed_to_change_member': '无法修改项目成员,权限不足。', 'failed_to_delete_member': '无法删除项目成员,权限不足。', + 'failed_to_delete_project' : '无法删除项目,权限不足。', + 'confirm_delete_project_title': '删除项目', + 'confirm_delete_project': '确认删除项目 "$0" ?', 'confirm_delete_user_title': '删除用户', 'confirm_delete_user': '确认删除用户 "$0" ?', + 'confirm_delete_policy_title': '删除复制策略', + 'confirm_delete_policy': '确认删除复制策略 "$0" ?', 'confirm_delete_destination_title': '删除目标', 'confirm_delete_destination': '确认删除目标 "$0"?', 'replication': '复制', @@ -194,6 +199,7 @@ var locale_messages = { 'successful_signed_up': '注册成功。', 'add_new_policy': '新增策略', 'edit_policy': '修改策略', + 'delete_policy': '删除策略', 'add_new_title': '新增用户', 'add_new': '新增', 'successful_added': '新增用户成功。', @@ -246,6 +252,7 @@ var locale_messages = { 'failed_to_get_destination_policies': '获取目标关联策略数据失败。', 'failed_to_get_replication_policy': '获取复制策略失败。', 'failed_to_update_replication_policy': '修改复制策略失败。', + 'failed_to_delete_replication_policy': '删除复制策略失败。', 'failed_to_delete_destination': '删除目标失败。', 'failed_to_create_destination': '创建目标失败。', 'failed_to_update_destination': '修改目标失败。', diff --git a/static/resources/js/services/project/services.delete-project.js b/static/resources/js/services/project/services.delete-project.js new file mode 100644 index 0000000..4105c82 --- /dev/null +++ b/static/resources/js/services/project/services.delete-project.js @@ -0,0 +1,34 @@ +/* + Copyright (c) 2016 VMware, Inc. All Rights Reserved. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +(function() { + 'use strict'; + + angular + .module('harbor.services.project') + .factory('DeleteProjectService', DeleteProjectService); + + DeleteProjectService.$inject = ['$http', '$log']; + + function DeleteProjectService($http, $log) { + + return DeleteProject; + + function DeleteProject(projectId) { + return $http + .delete('/api/projects/' + projectId); + } + } + +})(); \ No newline at end of file diff --git a/static/resources/js/services/project/services.list-project.js b/static/resources/js/services/project/services.list-project.js index 91d5d5d..c2cc39b 100644 --- a/static/resources/js/services/project/services.list-project.js +++ b/static/resources/js/services/project/services.list-project.js @@ -25,10 +25,14 @@ return ListProject; - function ListProject(projectName, isPublic) { + function ListProject(projectName, isPublic, page, pageSize) { $log.info('list project projectName:' + projectName, ', isPublic:' + isPublic); + var urlParams = ''; + if(angular.isDefined(page, pageSize)) { + urlParams = '?page=' + page + '&page_size=' + pageSize; + } return $http - .get('/api/projects', { + .get('/api/projects' + urlParams, { 'params' : { 'is_public': isPublic, 'project_name': projectName diff --git a/static/resources/js/services/replication-policy/services.delete-replication-policy.js b/static/resources/js/services/replication-policy/services.delete-replication-policy.js new file mode 100644 index 0000000..4f02ed8 --- /dev/null +++ b/static/resources/js/services/replication-policy/services.delete-replication-policy.js @@ -0,0 +1,34 @@ +/* + Copyright (c) 2016 VMware, Inc. All Rights Reserved. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +(function() { + + 'use strict'; + + angular + .module('harbor.services.replication.policy') + .factory('DeleteReplicationPolicyService', DeleteReplicationPolicyService); + + DeleteReplicationPolicyService.$inject = ['$http']; + + function DeleteReplicationPolicyService($http) { + return deleteReplicationPolicy; + + function deleteReplicationPolicy(policyId) { + return $http + .delete('/api/policies/replication/' + policyId); + } + } + +})(); diff --git a/views/project.htm b/views/project.htm index ac5da5e..aa002e0 100644 --- a/views/project.htm +++ b/views/project.htm @@ -37,16 +37,19 @@ - + + +
- - + + - + +
// 'project_name' | tr //// 'repositories' | tr //// 'project_name' | tr //// 'repositories' | tr // // 'role' | tr //// 'creation_time' | tr //// 'creation_time' | tr // // 'publicity' | tr //// 'operation' | tr //
@@ -57,17 +60,21 @@

// 'no_projects_add_new_project' | tr //

- //p.name// - //p.repo_count// + //p.name// + //p.repo_count// //vm.getProjectRole(p.current_user_role_id) | tr// - //p.creation_time | dateL : 'YYYY-MM-DD HH:mm:ss'// - + //p.creation_time | dateL : 'YYYY-MM-DD HH:mm:ss'// + + +    +
-
//vm.projects ? vm.projects.length : 0// // 'items' | tr //
+ + diff --git a/views/sections/script-include.htm b/views/sections/script-include.htm index 9c2776b..f07b606 100644 --- a/views/sections/script-include.htm +++ b/views/sections/script-include.htm @@ -58,6 +58,7 @@ + @@ -96,6 +97,7 @@ +