harbor/static/resources/js/components/project-member/list-project-member.directive.js

105 lines
3.1 KiB
JavaScript
Raw Normal View History

(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-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
$scope.subsTabPane = 30;
2016-06-26 06:56:58 +02:00
var vm = this;
vm.sectionHeight = {'min-height': '579px'};
vm.isOpen = false;
vm.search = search;
vm.addProjectMember = addProjectMember;
vm.deleteProjectMember = deleteProjectMember;
2016-04-28 19:36:39 +02:00
vm.retrieve = retrieve;
vm.username = '';
vm.projectId = getParameterByName('project_id', $location.absUrl());
2016-05-04 12:42:05 +02:00
vm.retrieve();
$scope.$on('$locationChangeSuccess', function() {
vm.projectId = getParameterByName('project_id', $location.absUrl());
vm.retrieve();
});
2016-07-02 12:20:31 +02:00
function search(e) {
2016-05-04 12:42:05 +02:00
vm.projectId = e.projectId;
vm.username = e.username;
retrieve();
}
function addProjectMember() {
if(vm.isOpen) {
vm.isOpen = false;
}else{
vm.isOpen = true;
}
}
function deleteProjectMember(e) {
DeleteProjectMemberService(e.projectId, e.userId)
.success(deleteProjectMemberSuccess)
.error(deleteProjectMemberFailed);
}
function deleteProjectMemberSuccess(data, status) {
console.log('Successful delete project member.');
vm.retrieve();
}
function deleteProjectMemberFailed(e) {
$scope.$emit('modalTitle', $filter('tr')('error'));
$scope.$emit('modalMessage', $filter('tr')('failed_to_delete_member'));
$scope.$emit('raiseError', true);
console.log('Failed to edit project member:' + e);
}
2016-05-04 12:42:05 +02:00
function retrieve() {
ListProjectMemberService(vm.projectId, {'username': vm.username})
.then(getProjectMemberComplete)
.catch(getProjectMemberFailed);
2016-05-04 12:42:05 +02:00
}
function getProjectMemberComplete(response) {
vm.user = currentUser.get();
2016-06-28 17:42:05 +02:00
vm.projectMembers = response.data || [];
}
function getProjectMemberFailed(response) {
console.log('Failed get project members:' + response);
2016-06-28 17:42:05 +02:00
vm.projectMembers = [];
$scope.$emit('modalTitle', $filter('tr')('error'));
$scope.$emit('modalMessage', $filter('tr')('failed_get_project_member'));
$scope.$emit('raiseError', true);
2016-06-28 17:42:05 +02:00
$location.url('repositories').search('project_id', vm.projectId);
}
}
function listProjectMember() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/resources/js/components/project-member/list-project-member.directive.html',
'scope': {
'sectionHeight': '='
},
'controller': ListProjectMemberController,
'controllerAs': 'vm',
'bindToController': true
2016-05-23 12:29:17 +02:00
};
return directive;
}
})();