2015-03-25 19:31:05 +00:00
|
|
|
/**
|
|
|
|
* Element for managing the teams of an organization.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('teamsManager', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/teams-manager.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: false,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
2015-04-21 20:07:24 +00:00
|
|
|
'organization': '=organization',
|
|
|
|
'isEnabled': '=isEnabled'
|
2015-03-25 19:31:05 +00:00
|
|
|
},
|
2017-05-05 19:10:06 +00:00
|
|
|
controller: function($scope, $element, ApiService, $timeout, UserService, TableService, UIService, Config, Features, $location) {
|
2016-08-18 21:44:36 +00:00
|
|
|
$scope.TableService = TableService;
|
2017-02-22 02:07:48 +00:00
|
|
|
$scope.Config = Config;
|
2017-02-23 18:26:47 +00:00
|
|
|
$scope.Features = Features;
|
2016-08-18 21:44:36 +00:00
|
|
|
|
|
|
|
$scope.options = {
|
|
|
|
'predicate': 'ordered_team_index',
|
|
|
|
'reverse': false,
|
|
|
|
'filter': ''
|
|
|
|
};
|
|
|
|
|
2015-03-25 19:31:05 +00:00
|
|
|
$scope.teamRoles = [
|
|
|
|
{ 'id': 'member', 'title': 'Member', 'kind': 'default' },
|
|
|
|
{ 'id': 'creator', 'title': 'Creator', 'kind': 'success' },
|
|
|
|
{ 'id': 'admin', 'title': 'Admin', 'kind': 'primary' }
|
|
|
|
];
|
|
|
|
|
2015-07-02 14:04:12 +00:00
|
|
|
UserService.updateUserIn($scope);
|
|
|
|
|
2016-08-18 21:44:36 +00:00
|
|
|
$scope.teams = null;
|
|
|
|
$scope.orderedTeams = null;
|
2015-07-02 14:04:12 +00:00
|
|
|
$scope.showingMembers = false;
|
|
|
|
$scope.fullMemberList = null;
|
2015-07-14 09:28:53 +00:00
|
|
|
$scope.feedback = null;
|
2016-05-12 21:59:49 +00:00
|
|
|
$scope.createTeamInfo = null;
|
2015-03-30 21:55:04 +00:00
|
|
|
|
2016-08-18 21:44:36 +00:00
|
|
|
var getRoleIndex = function(name) {
|
|
|
|
for (var i = 0; i < $scope.teamRoles.length; ++i) {
|
|
|
|
if ($scope.teamRoles[i]['id'] == name) {
|
|
|
|
return i;
|
|
|
|
}
|
2015-04-21 20:07:24 +00:00
|
|
|
}
|
2015-03-30 21:55:04 +00:00
|
|
|
|
2016-08-18 21:44:36 +00:00
|
|
|
return -1;
|
2015-03-30 21:55:04 +00:00
|
|
|
};
|
|
|
|
|
2016-08-18 21:44:36 +00:00
|
|
|
var setTeamsState = function() {
|
2015-04-21 20:07:24 +00:00
|
|
|
if (!$scope.organization || !$scope.organization.ordered_teams || !$scope.isEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-30 21:55:04 +00:00
|
|
|
|
2016-08-18 21:44:36 +00:00
|
|
|
$scope.teams = [];
|
|
|
|
$scope.organization.ordered_teams.map(function(name, index) {
|
|
|
|
var team = $scope.organization.teams[name];
|
|
|
|
team['ordered_team_index'] = $scope.organization.ordered_teams.length - index;
|
|
|
|
team['role_index'] = getRoleIndex(team['role']);
|
|
|
|
$scope.teams.push(team);
|
2015-03-30 21:55:04 +00:00
|
|
|
});
|
|
|
|
|
2016-08-18 21:44:36 +00:00
|
|
|
$scope.orderedTeams = TableService.buildOrderedItems(
|
|
|
|
$scope.teams, $scope.options,
|
|
|
|
['name'],
|
|
|
|
['ordered_team_index', 'member_count', 'repo_count', 'role_index']);
|
|
|
|
};
|
2015-04-21 20:07:24 +00:00
|
|
|
|
2015-03-25 19:31:05 +00:00
|
|
|
$scope.setRole = function(role, teamname) {
|
|
|
|
var previousRole = $scope.organization.teams[teamname].role;
|
|
|
|
$scope.organization.teams[teamname].role = role;
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
'orgname': $scope.organization.name,
|
|
|
|
'teamname': teamname
|
|
|
|
};
|
|
|
|
|
|
|
|
var data = $scope.organization.teams[teamname];
|
|
|
|
|
|
|
|
var errorHandler = ApiService.errorDisplay('Cannot update team', function(resp) {
|
|
|
|
$scope.organization.teams[teamname].role = previousRole;
|
|
|
|
});
|
|
|
|
|
|
|
|
ApiService.updateOrganizationTeam(data, params).then(function(resp) {
|
2015-07-14 09:28:53 +00:00
|
|
|
$scope.feedback = {
|
|
|
|
'kind': 'success',
|
|
|
|
'message': 'Team {team} role changed to {role}',
|
|
|
|
'data': {
|
|
|
|
'team': teamname,
|
|
|
|
'role': role
|
|
|
|
}
|
|
|
|
};
|
2015-03-25 19:31:05 +00:00
|
|
|
}, errorHandler);
|
|
|
|
};
|
|
|
|
|
2016-05-12 21:59:49 +00:00
|
|
|
$scope.askCreateTeam = function(teamname) {
|
|
|
|
$scope.createTeamInfo = {
|
|
|
|
'namespace': $scope.organization.name
|
|
|
|
};
|
|
|
|
};
|
2015-07-14 09:28:53 +00:00
|
|
|
|
2016-05-12 21:59:49 +00:00
|
|
|
$scope.handleTeamCreated = function(created) {
|
2018-02-15 21:03:09 +00:00
|
|
|
if (!created.new_team) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:59:49 +00:00
|
|
|
var teamname = created.name;
|
2016-08-18 21:44:36 +00:00
|
|
|
created['member_count'] = 0;
|
|
|
|
|
2016-05-12 21:59:49 +00:00
|
|
|
$scope.organization.teams[teamname] = created;
|
|
|
|
$scope.organization.ordered_teams.push(teamname);
|
|
|
|
$scope.orderedTeams.push(created);
|
|
|
|
|
|
|
|
$scope.feedback = {
|
|
|
|
'kind': 'success',
|
|
|
|
'message': 'Team {team} created',
|
|
|
|
'data': {
|
|
|
|
'team': teamname
|
|
|
|
}
|
|
|
|
};
|
2015-03-25 19:31:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.askDeleteTeam = function(teamname) {
|
|
|
|
bootbox.confirm('Are you sure you want to delete team ' + teamname + '?', function(resp) {
|
|
|
|
if (resp) {
|
|
|
|
$scope.deleteTeam(teamname);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteTeam = function(teamname) {
|
|
|
|
var params = {
|
|
|
|
'orgname': $scope.organization.name,
|
|
|
|
'teamname': teamname
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.deleteOrganizationTeam(null, params).then(function() {
|
2015-03-30 21:55:04 +00:00
|
|
|
var index = $scope.organization.ordered_teams.indexOf(teamname);
|
|
|
|
if (index >= 0) {
|
|
|
|
$scope.organization.ordered_teams.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:31:05 +00:00
|
|
|
delete $scope.organization.teams[teamname];
|
2016-08-18 21:44:36 +00:00
|
|
|
setTeamsState();
|
2015-07-14 09:28:53 +00:00
|
|
|
|
|
|
|
$scope.feedback = {
|
|
|
|
'kind': 'success',
|
|
|
|
'message': 'Team {team} deleted',
|
|
|
|
'data': {
|
|
|
|
'team': teamname
|
|
|
|
}
|
|
|
|
};
|
2015-03-25 19:31:05 +00:00
|
|
|
}, ApiService.errorDisplay('Cannot delete team'));
|
|
|
|
};
|
2015-07-02 14:04:12 +00:00
|
|
|
|
2015-10-15 16:05:55 +00:00
|
|
|
$scope.viewTeam = function(teamName) {
|
2017-05-05 19:10:06 +00:00
|
|
|
$location.path('/organization/' + $scope.organization.name + '/teams/' + teamName);
|
2015-10-15 16:05:55 +00:00
|
|
|
};
|
|
|
|
|
2015-07-02 14:04:12 +00:00
|
|
|
$scope.showMembers = function(value) {
|
|
|
|
$scope.showingMembers = value;
|
|
|
|
if (value && !$scope.fullMemberList) {
|
|
|
|
var params = {
|
|
|
|
'orgname': $scope.organization.name
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.getOrganizationMembers(null, params).then(function(resp) {
|
|
|
|
$scope.fullMemberList = resp['members'];
|
|
|
|
}, ApiService.errorDisplay('Could not load full membership list'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeMember = function(memberInfo, callback) {
|
|
|
|
var params = {
|
|
|
|
'orgname': $scope.organization.name,
|
|
|
|
'membername': memberInfo.name
|
|
|
|
};
|
|
|
|
|
|
|
|
var errorHandler = ApiService.errorDisplay('Could not remove member', function() {
|
|
|
|
callback(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
ApiService.removeOrganizationMember(null, params).then(function(resp) {
|
|
|
|
// Reset the state of the directive.
|
|
|
|
$scope.fullMemberList = null;
|
|
|
|
$scope.showMembers(true);
|
|
|
|
|
|
|
|
callback(true);
|
2015-07-14 09:28:53 +00:00
|
|
|
|
|
|
|
$scope.feedback = {
|
|
|
|
'kind': 'success',
|
|
|
|
'message': 'User {user} removed from the organization',
|
|
|
|
'data': {
|
|
|
|
'user': memberInfo.name
|
|
|
|
}
|
|
|
|
};
|
2015-07-02 14:04:12 +00:00
|
|
|
}, errorHandler)
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.askRemoveMember = function(memberInfo) {
|
|
|
|
$scope.removeMemberInfo = $.extend({}, memberInfo);
|
|
|
|
};
|
2016-08-18 21:44:36 +00:00
|
|
|
|
2016-08-22 18:42:35 +00:00
|
|
|
$scope.setRepoPermissions = function(teamName) {
|
|
|
|
$scope.setRepoPermissionsInfo = {
|
|
|
|
'namespace': $scope.organization.name,
|
|
|
|
'entityName': teamName,
|
|
|
|
'entityKind': 'team',
|
|
|
|
'entityIcon': 'fa-group'
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.handlePermissionsSet = function(info, repositories) {
|
|
|
|
var team = $scope.organization.teams[info.entityName];
|
|
|
|
team['repo_count'] = repositories.length;
|
|
|
|
};
|
|
|
|
|
2016-08-18 21:44:36 +00:00
|
|
|
$scope.$watch('organization', setTeamsState);
|
|
|
|
$scope.$watch('isEnabled', setTeamsState);
|
|
|
|
|
|
|
|
$scope.$watch('options.predicate', setTeamsState);
|
|
|
|
$scope.$watch('options.reverse', setTeamsState);
|
|
|
|
$scope.$watch('options.filter', setTeamsState);
|
2015-03-25 19:31:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|