2016-04-17 17:53:26 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.details')
|
|
|
|
.directive('retrieveProjects', retrieveProjects);
|
2016-04-26 12:23:34 +02:00
|
|
|
|
2016-05-17 05:40:36 +02:00
|
|
|
RetrieveProjectsController.$inject = ['$scope', 'nameFilter', '$filter', 'CurrentProjectMemberService', 'ListProjectService', '$routeParams', '$route', '$location'];
|
2016-04-19 19:20:07 +02:00
|
|
|
|
2016-05-17 05:40:36 +02:00
|
|
|
function RetrieveProjectsController($scope, nameFilter, $filter, CurrentProjectMemberService, ListProjectService, $routeParams, $route, $location) {
|
2016-04-26 12:23:34 +02:00
|
|
|
var vm = this;
|
2016-05-17 05:40:36 +02:00
|
|
|
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.projectName = '';
|
2016-05-04 12:42:05 +02:00
|
|
|
|
2016-05-17 05:40:36 +02:00
|
|
|
if($route.current.params.is_public) {
|
|
|
|
vm.isPublic = $route.current.params.is_public === 'true' ? 1 : 0;
|
|
|
|
vm.publicity = (vm.isPublic === 1) ? true : false;
|
|
|
|
}
|
|
|
|
|
2016-05-04 12:42:05 +02:00
|
|
|
vm.retrieve = retrieve;
|
|
|
|
vm.retrieve();
|
|
|
|
|
|
|
|
vm.checkProjectMember = checkProjectMember;
|
|
|
|
|
|
|
|
$scope.$watch('vm.selectedProject', function(current, origin) {
|
|
|
|
if(current) {
|
|
|
|
vm.selectedId = current.ProjectId;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
vm.filterInput = "";
|
|
|
|
vm.selectItem = selectItem;
|
|
|
|
|
|
|
|
$scope.$watch('vm.publicity', function(current, origin) {
|
2016-05-17 05:40:36 +02:00
|
|
|
vm.publicity = current ? 1 : 0;
|
|
|
|
vm.isPublic = vm.publicity ? 1 : 0;
|
|
|
|
vm.projectType = (vm.isPublic === 1) ? 'public_projects' : 'my_projects';
|
2016-05-11 09:57:52 +02:00
|
|
|
vm.retrieve();
|
2016-05-04 12:42:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function retrieve() {
|
|
|
|
ListProjectService(vm.projectName, vm.isPublic)
|
|
|
|
.success(getProjectSuccess)
|
|
|
|
.error(getProjectFailed);
|
|
|
|
}
|
2016-05-03 12:29:58 +02:00
|
|
|
|
|
|
|
function getProjectSuccess(data, status) {
|
|
|
|
vm.projects = data;
|
2016-05-17 05:40:36 +02:00
|
|
|
|
|
|
|
if(!angular.isDefined(vm.projects)) {
|
|
|
|
vm.isPublic = 1;
|
2016-05-11 09:57:52 +02:00
|
|
|
vm.publicity = 1;
|
2016-05-17 05:40:36 +02:00
|
|
|
vm.projectType = 'public_projects';
|
|
|
|
console.log('vm.projects is undefined, load public projects.');
|
2016-05-11 09:57:52 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 05:40:36 +02:00
|
|
|
vm.selectedProject = vm.projects[0];
|
2016-05-11 09:57:52 +02:00
|
|
|
|
2016-05-03 12:29:58 +02:00
|
|
|
if($routeParams.project_id){
|
|
|
|
angular.forEach(vm.projects, function(value, index) {
|
|
|
|
if(value['ProjectId'] == $routeParams.project_id) {
|
|
|
|
vm.selectedProject = value;
|
|
|
|
}
|
2016-05-04 12:42:05 +02:00
|
|
|
});
|
2016-05-03 12:29:58 +02:00
|
|
|
}
|
2016-05-11 09:57:52 +02:00
|
|
|
|
2016-05-04 12:42:05 +02:00
|
|
|
$location.search('project_id', vm.selectedProject.ProjectId);
|
|
|
|
vm.checkProjectMember(vm.selectedProject.ProjectId);
|
2016-05-03 12:29:58 +02:00
|
|
|
vm.resultCount = vm.projects.length;
|
|
|
|
|
|
|
|
$scope.$watch('vm.filterInput', function(current, origin) {
|
|
|
|
vm.resultCount = $filter('name')(vm.projects, vm.filterInput, 'Name').length;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProjectFailed(response) {
|
|
|
|
console.log('Failed to list projects:' + response);
|
|
|
|
}
|
|
|
|
|
2016-05-04 12:42:05 +02:00
|
|
|
function checkProjectMember(projectId) {
|
|
|
|
CurrentProjectMemberService(projectId)
|
|
|
|
.success(getCurrentProjectMemberSuccess)
|
|
|
|
.error(getCurrentProjectMemberFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentProjectMemberSuccess(data, status) {
|
|
|
|
console.log('Successful get current project member:' + status);
|
|
|
|
vm.isProjectMember = true;
|
|
|
|
}
|
2016-04-28 19:36:39 +02:00
|
|
|
|
2016-05-04 12:42:05 +02:00
|
|
|
function getCurrentProjectMemberFailed(data, status) {
|
|
|
|
console.log('Failed get current project member:' + status);
|
|
|
|
vm.isProjectMember = false;
|
|
|
|
}
|
|
|
|
|
2016-04-26 12:23:34 +02:00
|
|
|
function selectItem(item) {
|
2016-04-27 12:29:55 +02:00
|
|
|
vm.selectedId = item.ProjectId;
|
|
|
|
vm.selectedProject = item;
|
2016-05-04 12:42:05 +02:00
|
|
|
vm.checkProjectMember(vm.selectedProject.ProjectId);
|
2016-04-27 12:29:55 +02:00
|
|
|
vm.isOpen = false;
|
2016-05-04 12:42:05 +02:00
|
|
|
|
2016-05-03 12:29:58 +02:00
|
|
|
$location.search('project_id', vm.selectedProject.ProjectId);
|
2016-04-26 12:23:34 +02:00
|
|
|
}
|
2016-04-27 12:29:55 +02:00
|
|
|
|
2016-04-17 17:53:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function retrieveProjects() {
|
|
|
|
var directive = {
|
|
|
|
restrict: 'E',
|
|
|
|
templateUrl: '/static/ng/resources/js/components/details/retrieve-projects.directive.html',
|
|
|
|
scope: {
|
2016-04-19 19:20:07 +02:00
|
|
|
'isOpen': '=',
|
2016-05-04 12:42:05 +02:00
|
|
|
'selectedProject': '=',
|
|
|
|
'publicity': '=',
|
|
|
|
'isProjectMember': '='
|
2016-04-17 17:53:26 +02:00
|
|
|
},
|
|
|
|
replace: true,
|
|
|
|
controller: RetrieveProjectsController,
|
|
|
|
bindToController: true,
|
|
|
|
controllerAs: 'vm'
|
|
|
|
}
|
|
|
|
|
|
|
|
return directive;
|
2016-04-28 19:36:39 +02:00
|
|
|
|
2016-04-17 17:53:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|