kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.3 KiB
105 lines
3.3 KiB
10 years ago
|
//-- copyright
|
||
|
// OpenProject is a project management system.
|
||
10 years ago
|
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
10 years ago
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
|
//++
|
||
|
|
||
8 years ago
|
import {opServicesModule} from '../../angular-modules';
|
||
|
|
||
|
function projectService($http, apiPaths, halRequest) {
|
||
|
var indentedName = function (name, level) {
|
||
9 years ago
|
var indentation = '';
|
||
8 years ago
|
|
||
9 years ago
|
for (var i = 0; i < level; i++) {
|
||
|
indentation = indentation + '--';
|
||
|
}
|
||
8 years ago
|
|
||
|
return indentation + ' ' + name;
|
||
9 years ago
|
};
|
||
8 years ago
|
var assignAncestorLevels = function (projects) {
|
||
9 years ago
|
var ancestors = [];
|
||
8 years ago
|
|
||
9 years ago
|
angular.forEach(projects, function (project) {
|
||
|
while (ancestors.length > 0 && project.parent_id !== _.last(ancestors).id) {
|
||
|
// this helper method only reflects hierarchies if nested projects follow one another
|
||
|
ancestors.pop();
|
||
|
}
|
||
|
|
||
|
project['level'] = ancestors.length;
|
||
|
project['name'] = indentedName(project['name'], project['level']);
|
||
|
|
||
|
if (!project['leaf?']) {
|
||
|
ancestors.push(project);
|
||
|
}
|
||
|
});
|
||
8 years ago
|
|
||
9 years ago
|
return projects;
|
||
|
};
|
||
11 years ago
|
|
||
|
var ProjectService = {
|
||
8 years ago
|
getProject: function (projectIdentifier) {
|
||
|
const url = apiPaths.ex.project({project: projectIdentifier});
|
||
11 years ago
|
|
||
8 years ago
|
return $http.get(url).then(function (response) {
|
||
11 years ago
|
return response.data.project;
|
||
|
});
|
||
11 years ago
|
},
|
||
|
|
||
8 years ago
|
getProjects: function () {
|
||
|
const url = apiPaths.ex.projects();
|
||
11 years ago
|
|
||
11 years ago
|
return ProjectService.doQuery(url)
|
||
8 years ago
|
.then(function (projects) {
|
||
9 years ago
|
return assignAncestorLevels(projects);
|
||
11 years ago
|
});
|
||
11 years ago
|
},
|
||
|
|
||
8 years ago
|
getSubProjects: function (projectIdentifier) {
|
||
|
const url = apiPaths.ex.project.subProjects({project: projectIdentifier});
|
||
11 years ago
|
return ProjectService.doQuery(url);
|
||
|
},
|
||
|
|
||
8 years ago
|
getWorkPackageProject: function (workPackage) {
|
||
9 years ago
|
return ProjectService.doQuery(workPackage.project.$link.href);
|
||
9 years ago
|
},
|
||
|
|
||
8 years ago
|
doQuery: function (url, params?) {
|
||
|
return $http.get(url, {params: params})
|
||
|
.then(function (response) {
|
||
11 years ago
|
return response.data.projects;
|
||
|
});
|
||
11 years ago
|
},
|
||
9 years ago
|
|
||
|
fetchProjectResource: function (projectIdentifier) {
|
||
8 years ago
|
var url = apiPaths.v3.project({project: projectIdentifier});
|
||
|
return halRequest.get(url);
|
||
9 years ago
|
}
|
||
11 years ago
|
};
|
||
|
|
||
|
return ProjectService;
|
||
8 years ago
|
}
|
||
|
|
||
|
opServicesModule.factory('ProjectService', projectService);
|