2016-07-07 18:03:32 +02:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2016-04-21 12:19:51 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.project.member')
|
|
|
|
.directive('listProjectMember', listProjectMember);
|
|
|
|
|
2016-06-28 17:42:05 +02:00
|
|
|
ListProjectMemberController.$inject = ['$scope', 'ListProjectMemberService', 'DeleteProjectMemberService', 'getParameterByName', '$location', 'currentUser', '$filter', 'trFilter', '$window'];
|
2016-04-21 12:19:51 +02:00
|
|
|
|
2016-06-28 17:42:05 +02:00
|
|
|
function ListProjectMemberController($scope, ListProjectMemberService, DeleteProjectMemberService, getParameterByName, $location, currentUser, $filter, trFilter, $window) {
|
2016-06-26 06:56:58 +02:00
|
|
|
|
2016-06-28 07:19:02 +02:00
|
|
|
$scope.subsTabPane = 30;
|
2016-06-26 06:56:58 +02:00
|
|
|
|
2016-04-21 12:19:51 +02:00
|
|
|
var vm = this;
|
2016-06-28 07:19:02 +02:00
|
|
|
|
|
|
|
vm.sectionHeight = {'min-height': '579px'};
|
2016-05-20 11:43:47 +02:00
|
|
|
|
|
|
|
vm.isOpen = false;
|
2016-04-22 18:49:52 +02:00
|
|
|
vm.search = search;
|
|
|
|
vm.addProjectMember = addProjectMember;
|
2016-06-20 10:05:14 +02:00
|
|
|
vm.deleteProjectMember = deleteProjectMember;
|
2016-04-28 19:36:39 +02:00
|
|
|
vm.retrieve = retrieve;
|
2016-06-01 08:01:35 +02:00
|
|
|
vm.username = '';
|
2016-07-06 01:57:09 +02:00
|
|
|
|
2016-05-31 12:49:16 +02:00
|
|
|
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
2016-05-04 12:42:05 +02:00
|
|
|
vm.retrieve();
|
2016-06-01 08:01:35 +02:00
|
|
|
|
2016-09-05 12:09:05 +02:00
|
|
|
$scope.$on('retrieveData', function(e, val) {
|
|
|
|
if(val) {
|
|
|
|
console.log('received retrieve data:' + val);
|
|
|
|
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
|
|
|
vm.username = '';
|
|
|
|
vm.retrieve();
|
|
|
|
}
|
2016-06-01 08:01:35 +02:00
|
|
|
});
|
2016-07-02 12:20:31 +02:00
|
|
|
|
2016-04-22 18:49:52 +02:00
|
|
|
function search(e) {
|
2016-05-04 12:42:05 +02:00
|
|
|
vm.projectId = e.projectId;
|
|
|
|
vm.username = e.username;
|
|
|
|
retrieve();
|
2016-04-22 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addProjectMember() {
|
2016-04-21 12:19:51 +02:00
|
|
|
if(vm.isOpen) {
|
|
|
|
vm.isOpen = false;
|
|
|
|
}else{
|
|
|
|
vm.isOpen = true;
|
|
|
|
}
|
|
|
|
}
|
2016-06-20 10:05:14 +02:00
|
|
|
|
2016-06-25 10:15:50 +02:00
|
|
|
function deleteProjectMember(e) {
|
|
|
|
DeleteProjectMemberService(e.projectId, e.userId)
|
2016-06-20 10:05:14 +02:00
|
|
|
.success(deleteProjectMemberSuccess)
|
|
|
|
.error(deleteProjectMemberFailed);
|
|
|
|
}
|
2016-06-25 10:15:50 +02:00
|
|
|
|
2016-06-20 10:05:14 +02:00
|
|
|
function deleteProjectMemberSuccess(data, status) {
|
2016-07-01 12:37:17 +02:00
|
|
|
console.log('Successful delete project member.');
|
2016-06-20 10:05:14 +02:00
|
|
|
vm.retrieve();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteProjectMemberFailed(e) {
|
2016-07-01 12:37:17 +02:00
|
|
|
$scope.$emit('modalTitle', $filter('tr')('error'));
|
|
|
|
$scope.$emit('modalMessage', $filter('tr')('failed_to_delete_member'));
|
|
|
|
$scope.$emit('raiseError', true);
|
2016-06-20 10:05:14 +02:00
|
|
|
console.log('Failed to edit project member:' + e);
|
|
|
|
}
|
2016-05-10 12:43:52 +02:00
|
|
|
|
2016-05-04 12:42:05 +02:00
|
|
|
function retrieve() {
|
2016-05-10 12:43:52 +02:00
|
|
|
ListProjectMemberService(vm.projectId, {'username': vm.username})
|
|
|
|
.then(getProjectMemberComplete)
|
2016-05-11 09:57:52 +02:00
|
|
|
.catch(getProjectMemberFailed);
|
2016-05-04 12:42:05 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 09:57:52 +02:00
|
|
|
function getProjectMemberComplete(response) {
|
2016-05-20 11:43:47 +02:00
|
|
|
vm.user = currentUser.get();
|
2016-06-28 17:42:05 +02:00
|
|
|
vm.projectMembers = response.data || [];
|
2016-04-26 12:23:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getProjectMemberFailed(response) {
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to get project members:' + response);
|
2016-06-28 17:42:05 +02:00
|
|
|
vm.projectMembers = [];
|
2016-07-06 01:57:09 +02:00
|
|
|
vm.target = 'repositories';
|
2016-06-28 17:42:05 +02:00
|
|
|
$location.url('repositories').search('project_id', vm.projectId);
|
2016-04-26 12:23:34 +02:00
|
|
|
}
|
2016-04-21 12:19:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function listProjectMember() {
|
|
|
|
var directive = {
|
2016-06-28 07:12:25 +02:00
|
|
|
'restrict': 'E',
|
|
|
|
'templateUrl': '/static/resources/js/components/project-member/list-project-member.directive.html',
|
|
|
|
'scope': {
|
2016-07-05 10:12:20 +02:00
|
|
|
'sectionHeight': '=',
|
|
|
|
'target': '='
|
2016-06-28 07:12:25 +02:00
|
|
|
},
|
2016-07-11 10:11:54 +02:00
|
|
|
'link': link,
|
2016-06-28 07:12:25 +02:00
|
|
|
'controller': ListProjectMemberController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
2016-05-23 12:29:17 +02:00
|
|
|
};
|
|
|
|
|
2016-04-21 12:19:51 +02:00
|
|
|
return directive;
|
2016-07-11 10:11:54 +02:00
|
|
|
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
|
|
|
element.find('#txtSearchInput').on('keydown', function(e) {
|
|
|
|
if($(this).is(':focus') && e.keyCode === 13) {
|
|
|
|
ctrl.retrieve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-04-21 12:19:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|