2016-04-21 12:19:51 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.project.member')
|
|
|
|
.directive('listProjectMember', listProjectMember);
|
|
|
|
|
2016-06-20 10:05:14 +02:00
|
|
|
ListProjectMemberController.$inject = ['$scope', 'ListProjectMemberService', 'DeleteProjectMemberService', 'getParameterByName', '$location', 'currentUser'];
|
2016-04-21 12:19:51 +02:00
|
|
|
|
2016-06-20 10:05:14 +02:00
|
|
|
function ListProjectMemberController($scope, ListProjectMemberService, DeleteProjectMemberService, getParameterByName, $location, currentUser) {
|
2016-04-21 12:19:51 +02:00
|
|
|
var vm = this;
|
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;
|
|
|
|
vm.deleteMember = deleteMember
|
2016-04-28 19:36:39 +02:00
|
|
|
vm.retrieve = retrieve;
|
2016-06-01 08:01:35 +02:00
|
|
|
vm.username = '';
|
2016-06-20 10:05:14 +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
|
|
|
|
|
|
|
$scope.$on('$locationChangeSuccess', function() {
|
|
|
|
vm.projectId = getParameterByName('project_id', $location.absUrl());
|
|
|
|
vm.retrieve();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
|
|
|
function deleteProjectMember() {
|
|
|
|
DeleteProjectMemberService(vm.selectedProjectId, vm.selectedUserId)
|
|
|
|
.success(deleteProjectMemberSuccess)
|
|
|
|
.error(deleteProjectMemberFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteMember(e) {
|
|
|
|
vm.selectedProjectId = e.projectId;
|
|
|
|
vm.selectedUserId = e.userId;
|
|
|
|
|
|
|
|
vm.modalTitle = 'Delete project member';
|
|
|
|
vm.modalMessage = 'Are you sure to delete the current member?';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteProjectMemberSuccess(data, status) {
|
|
|
|
console.log('Successful delete project member complete.');
|
|
|
|
vm.retrieve();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteProjectMemberFailed(e) {
|
|
|
|
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-04-26 12:23:34 +02:00
|
|
|
vm.projectMembers = response.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProjectMemberFailed(response) {
|
2016-05-10 12:43:52 +02:00
|
|
|
console.log('Failed get project members:' + response);
|
2016-04-26 12:23:34 +02:00
|
|
|
}
|
2016-04-21 12:19:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function listProjectMember() {
|
|
|
|
var directive = {
|
|
|
|
restrict: 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
templateUrl: '/static/resources/js/components/project-member/list-project-member.directive.html',
|
2016-05-10 12:43:52 +02:00
|
|
|
scope: true,
|
2016-04-21 12:19:51 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|