Merge pull request #741 from wknet123/dev

Add project, replication policy deletion and pagination of projects.
This commit is contained in:
kun wang 2016-09-01 14:24:37 +08:00 committed by GitHub
commit b0b781a2a1
12 changed files with 234 additions and 54 deletions

View File

@ -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;
}
})();

View File

@ -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,

View File

@ -62,7 +62,7 @@
 
<a href="javascript:void(0);" data-toggle="modal" data-target="#createPolicyModal" ng-click="vm.editReplication(r.id)" title="// 'edit_policy' | tr //"><span class="glyphicon glyphicon-pencil"></span></a>
&nbsp;
<!--a href="javascript:void(0);"><span class="glyphicon glyphicon-trash"></span></a -->
<a href="javascript:void(0);" ng-click="vm.confirmToDelete(r.id, r.name)" title="// 'delete_policy' | tr //"><span class="glyphicon glyphicon-trash"></span></a>
</td>
<td width="5%">
<a ng-if= "r.error_job_count > 0" title = "// 'found_error_in_replication_job' | tr: [r.error_job_count] //"><span class="glyphicon glyphicon-exclamation-sign color-danger" ></span></a>

View File

@ -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;

View File

@ -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.');
}
}
})();

View File

@ -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.',

View File

@ -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': '修改目标失败。',

View File

@ -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);
}
}
})();

View File

@ -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

View File

@ -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);
}
}
})();

View File

@ -37,16 +37,19 @@
<button ng-if="!vm.isOpen" class="btn btn-success" type="button" ng-show="vm.showAddButton()" ng-click="vm.showAddProject()"><span class="glyphicon glyphicon-plus"></span> // 'new_project' | tr //</button>
</div>
</div>
<add-project ng-show="vm.isOpen" is-open="vm.isOpen"></add-project>
<add-project ng-show="vm.isOpen" is-open="vm.isOpen"></add-project>
<div class="each-tab-pane">
<div class="sub-pane">
<div class="table-head-container">
<table class="table table-pane table-header">
<thead>
<th width="15%">// 'project_name' | tr //</th>
<th width="20%">// 'repositories' | tr //</th>
<th width="20%">// 'project_name' | tr //</th>
<th width="15%">// 'repositories' | tr //</th>
<th width="15%" ng-if="!vm.publicity">// 'role' | tr //</th>
<th width="30%">// 'creation_time' | tr //</th>
<th width="20%">// 'creation_time' | tr //</th>
<th width="15%">// 'publicity' | tr //</th>
<th width="10%">// 'operation' | tr //</th>
</thead>
</table>
</div>
@ -57,17 +60,21 @@
<td colspan="5" height="320px" class="empty-hint" ng-if="vm.projects.length === 0"><h4 class="text-muted">// 'no_projects_add_new_project' | tr //</h4></td>
</tr>
<tr ng-if="vm.projects.length > 0" ng-repeat="p in vm.projects">
<td width="15%"><a href="/repository#/repositories?project_id=//p.project_id//&is_public=//p.public//">//p.name//</a></td>
<td width="20%">//p.repo_count//</td>
<td width="20%"><a href="/repository#/repositories?project_id=//p.project_id//&is_public=//p.public//">//p.name//</a></td>
<td width="15%">//p.repo_count//</td>
<td width="15%" ng-if="!vm.publicity">//vm.getProjectRole(p.current_user_role_id) | tr//</td>
<td width="30%">//p.creation_time | dateL : 'YYYY-MM-DD HH:mm:ss'//</td>
<td width="15%"><publicity-button is-public="p.public" owned="p.owner_id == vm.user.user_id" project-id="p.project_id"></publicity-button></td>
<td width="20%">//p.creation_time | dateL : 'YYYY-MM-DD HH:mm:ss'//</td>
<td width="15%"><publicity-button is-public="p.public" project-id="p.project_id"></publicity-button></td>
<td width="10%">
&nbsp;&nbsp;<a href="javascript:void(0)" ng-click="vm.confirmToDelete(p.project_id, p.name)"><span class="glyphicon glyphicon-trash"></span></a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-xs-4 col-md-12 well well-sm well-custom"><div class="col-md-offset-10">//vm.projects ? vm.projects.length : 0// // 'items' | tr //</div></div>
</div>
<paginator ng-if="vm.totalCount > 0" total-count="//vm.totalCount//" page-size="//vm.pageSize//" page="vm.page" display-count="5"></paginator>
</div>
</div>
</div>

View File

@ -58,6 +58,7 @@
<script src="/static/resources/js/services/project/services.add-project.js"></script>
<script src="/static/resources/js/services/project/services.toggle-project-publicity.js"></script>
<script src="/static/resources/js/services/project/services.stat-project.js"></script>
<script src="/static/resources/js/services/project/services.delete-project.js"></script>
<script src="/static/resources/js/services/user/services.user.module.js"></script>
<script src="/static/resources/js/services/user/services.current-user.js"></script>
@ -96,6 +97,7 @@
<script src="/static/resources/js/services/replication-policy/services.create-replication-policy.js"></script>
<script src="/static/resources/js/services/replication-policy/services.toggle-replication-policy.js"></script>
<script src="/static/resources/js/services/replication-policy/services.update-replication-policy.js"></script>
<script src="/static/resources/js/services/replication-policy/services.delete-replication-policy.js"></script>
<script src="/static/resources/js/services/replication-job/services.replication-job.module.js"></script>
<script src="/static/resources/js/services/replication-job/services.list-replication-job.js"></script>