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-05-01 19:46:50 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.layout.project')
|
|
|
|
.controller('ProjectController', ProjectController);
|
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
ProjectController.$inject = ['$scope', 'ListProjectService', '$timeout', 'currentUser', 'getRole', '$filter', 'trFilter'];
|
2016-05-01 19:46:50 +02:00
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
function ProjectController($scope, ListProjectService, $timeout, currentUser, getRole, $filter, trFilter) {
|
2016-05-02 12:24:58 +02:00
|
|
|
var vm = this;
|
2016-06-25 21:12:17 +02:00
|
|
|
|
2016-05-01 19:46:50 +02:00
|
|
|
vm.isOpen = false;
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.projectName = '';
|
|
|
|
vm.publicity = 0;
|
2016-05-04 12:42:05 +02:00
|
|
|
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.retrieve = retrieve;
|
|
|
|
vm.showAddProject = showAddProject;
|
|
|
|
vm.searchProject = searchProject;
|
2016-05-02 12:24:58 +02:00
|
|
|
vm.showAddButton = showAddButton;
|
2016-07-07 11:11:40 +02:00
|
|
|
vm.togglePublicity = togglePublicity;
|
|
|
|
vm.user = currentUser.get();
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.retrieve();
|
2016-06-06 09:39:17 +02:00
|
|
|
vm.getProjectRole = getProjectRole;
|
2016-05-03 12:29:58 +02:00
|
|
|
|
2016-07-11 10:11:54 +02:00
|
|
|
vm.searchProjectByKeyPress = searchProjectByKeyPress;
|
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
|
|
|
|
//Error message dialog handler for project.
|
|
|
|
$scope.$on('modalTitle', function(e, val) {
|
|
|
|
vm.modalTitle = val;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('modalMessage', function(e, val) {
|
|
|
|
vm.modalMessage = val;
|
|
|
|
});
|
2016-05-11 09:57:52 +02:00
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
$scope.$on('raiseError', function(e, val) {
|
|
|
|
if(val) {
|
|
|
|
vm.action = function() {
|
|
|
|
$scope.$broadcast('showDialog', false);
|
|
|
|
};
|
|
|
|
vm.contentType = 'text/plain';
|
|
|
|
vm.confirmOnly = true;
|
|
|
|
$scope.$broadcast('showDialog', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function retrieve() {
|
2016-05-10 12:43:52 +02:00
|
|
|
ListProjectService(vm.projectName, vm.publicity)
|
|
|
|
.success(listProjectSuccess)
|
|
|
|
.error(listProjectFailed);
|
2016-05-03 12:29:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function listProjectSuccess(data, status) {
|
2016-05-24 12:22:06 +02:00
|
|
|
vm.projects = data || [];
|
2016-06-06 09:39:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getProjectRole(roleId) {
|
2016-06-17 09:22:58 +02:00
|
|
|
if(roleId !== 0) {
|
|
|
|
var role = getRole({'key': 'roleId', 'value': roleId});
|
|
|
|
return role.name;
|
|
|
|
}
|
|
|
|
return '';
|
2016-05-03 12:29:58 +02:00
|
|
|
}
|
|
|
|
|
2016-07-01 12:37:17 +02:00
|
|
|
function listProjectFailed(data, status) {
|
|
|
|
$scope.$emit('modalTitle', $filter('tr')('error'));
|
2016-07-07 11:11:40 +02:00
|
|
|
$scope.$emit('modalMessage', $filter('tr')('failed_to_get_project'));
|
2016-07-01 12:37:17 +02:00
|
|
|
$scope.$emit('raiseError', true);
|
2016-07-07 11:11:40 +02:00
|
|
|
console.log('Failed to get Project.');
|
2016-05-03 12:29:58 +02:00
|
|
|
}
|
2016-05-10 12:43:52 +02:00
|
|
|
|
2016-05-01 19:46:50 +02:00
|
|
|
$scope.$on('addedSuccess', function(e, val) {
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.retrieve();
|
2016-05-01 19:46:50 +02:00
|
|
|
});
|
2016-07-08 03:24:27 +02:00
|
|
|
|
2016-05-01 19:46:50 +02:00
|
|
|
function showAddProject() {
|
|
|
|
if(vm.isOpen){
|
2016-06-25 21:12:17 +02:00
|
|
|
vm.isOpen = false;
|
2016-05-01 19:46:50 +02:00
|
|
|
}else{
|
2016-06-25 21:12:17 +02:00
|
|
|
vm.isOpen = true;
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchProject() {
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.retrieve();
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
2016-05-02 12:24:58 +02:00
|
|
|
|
|
|
|
function showAddButton() {
|
2016-05-23 12:29:17 +02:00
|
|
|
if(vm.publicity === 0) {
|
2016-05-02 12:24:58 +02:00
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function togglePublicity(e) {
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.publicity = e.publicity;
|
2016-05-14 07:34:54 +02:00
|
|
|
vm.isOpen = false;
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.retrieve();
|
|
|
|
console.log('vm.publicity:' + vm.publicity);
|
2016-05-02 12:24:58 +02:00
|
|
|
}
|
|
|
|
|
2016-07-11 10:11:54 +02:00
|
|
|
function searchProjectByKeyPress($event) {
|
|
|
|
var keyCode = $event.which || $event.keyCode;
|
|
|
|
if(keyCode === 13) {
|
|
|
|
vm.retrieve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|