diff --git a/app/assets/javascripts/angular/config/work-packages-config.js b/app/assets/javascripts/angular/config/work-packages-config.js index 40991f445b..588d567f1f 100644 --- a/app/assets/javascripts/angular/config/work-packages-config.js +++ b/app/assets/javascripts/angular/config/work-packages-config.js @@ -61,7 +61,7 @@ angular.module('openproject.workPackages.config') estimated_hours: { type: 'integer', order: 15, name: 'Estimated time' }, done_ratio: { type: 'integer', order: 16, name: '% done' }, project_id: { type: 'list_model', modelName: 'project', order: 17, name: 'Project' }, - subproject_id: { type: 'list_model', modelName: 'project', order: 18, name: 'Sub-project' }, + subproject_id: { type: 'list_model', modelName: 'sub_project', order: 18, name: 'Sub-project' }, }) .constant('DEFAULT_SORT_CRITERIA', 'parent:desc') diff --git a/app/assets/javascripts/angular/controllers/work-packages-controller.js b/app/assets/javascripts/angular/controllers/work-packages-controller.js index 7e4d136d12..9b9d93cec2 100644 --- a/app/assets/javascripts/angular/controllers/work-packages-controller.js +++ b/app/assets/javascripts/angular/controllers/work-packages-controller.js @@ -53,6 +53,7 @@ angular.module('openproject.workPackages.controllers') function initQuery(queryData) { $scope.query = new Query({ id: $scope.queryId, + project_id: queryData.project_id, displaySums: queryData.display_sums, groupSums: queryData.group_sums, sums: queryData.sums, diff --git a/app/assets/javascripts/angular/helpers/components/path-helper.js b/app/assets/javascripts/angular/helpers/components/path-helper.js index 668be6ab18..ff11235911 100644 --- a/app/assets/javascripts/angular/helpers/components/path-helper.js +++ b/app/assets/javascripts/angular/helpers/components/path-helper.js @@ -55,6 +55,9 @@ angular.module('openproject.helpers') versionPath: function(versionId) { return PathHelper.versionsPath() + '/' + versionId; }, + subProjectsPath: function() { + return '/sub_projects'; + }, apiV2ProjectPath: function(projectIdentifier) { return PathHelper.apiPrefixV2 + PathHelper.projectPath(projectIdentifier); @@ -68,6 +71,9 @@ angular.module('openproject.helpers') apiProjectWorkPackagesPath: function(projectIdentifier) { return PathHelper.apiV3ProjectPath(projectIdentifier) + PathHelper.workPackagesPath(); }, + apiProjectSubProjectsPath: function(projectIdentifier) { + return PathHelper.apiV3ProjectPath(projectIdentifier) + PathHelper.subProjectsPath(); + }, apiAvailableColumnsPath: function() { return PathHelper.apiPrefixV3 + '/queries/available_columns'; }, diff --git a/app/assets/javascripts/angular/models/query.js b/app/assets/javascripts/angular/models/query.js index b4a1508ece..fc661c2b6c 100644 --- a/app/assets/javascripts/angular/models/query.js +++ b/app/assets/javascripts/angular/models/query.js @@ -31,22 +31,32 @@ angular.module('openproject.models') .factory('Query', ['Filter', 'Sortation', 'AVAILABLE_WORK_PACKAGE_FILTERS', function(Filter, Sortation, AVAILABLE_WORK_PACKAGE_FILTERS) { Query = function (data, options) { - this.available_work_package_filters = AVAILABLE_WORK_PACKAGE_FILTERS; angular.extend(this, data, options); this.group_by = this.group_by || ''; - if (this.filters === undefined){ - this.filters = []; - } else { - this.filters = this.filters.map(function(filterData){ - return new Filter(filterData); - }); - } + this.initFilters(); }; Query.prototype = { + initFilters: function() { + this.available_work_package_filters = AVAILABLE_WORK_PACKAGE_FILTERS; + if (this.project_id){ + // Remove project + delete this.available_work_package_filters["project_id"] + } + // TODO RS: Need to assertain if there are any sub-projects and remove this filter if not. + // The project will have to be fetch prior to this. + + if (this.filters === undefined){ + this.filters = []; + } else { + this.filters = this.filters.map(function(filterData){ + return new Filter(filterData); + }); + } + }, /** * @name toParams * diff --git a/app/assets/javascripts/angular/services/project-service.js b/app/assets/javascripts/angular/services/project-service.js new file mode 100644 index 0000000000..01feb491d1 --- /dev/null +++ b/app/assets/javascripts/angular/services/project-service.js @@ -0,0 +1,27 @@ +angular.module('openproject.services') + +.service('ProjectService', ['$http', 'PathHelper', function($http, PathHelper) { + + var ProjectService = { + getProject: function(projectIdentifier) { + var url = PathHelper.apiV3ProjectPath(projectIdentifier); + + return ProjectService.doQuery(url); + }, + + getSubProjects: function(projectIdentifier) { + var url = PathHelper.apiProjectSubProjectsPath(projectIdentifier); + + return ProjectService.doQuery(url); + }, + + doQuery: function(url, params) { + return $http.get(url, { params: params }) + .then(function(response){ + return response.data.projects; + }); + } + }; + + return ProjectService; +}]); diff --git a/app/assets/javascripts/angular/services/query-service.js b/app/assets/javascripts/angular/services/query-service.js index 23799b70a8..8bb3520a52 100644 --- a/app/assets/javascripts/angular/services/query-service.js +++ b/app/assets/javascripts/angular/services/query-service.js @@ -28,7 +28,8 @@ angular.module('openproject.services') -.service('QueryService', ['$http', 'PathHelper', '$q', 'AVAILABLE_WORK_PACKAGE_FILTERS', 'StatusService', 'TypeService', 'PriorityService', 'UserService', 'VersionService', 'RoleService', 'GroupService', function($http, PathHelper, $q, AVAILABLE_WORK_PACKAGE_FILTERS, StatusService, TypeService, PriorityService, UserService, VersionService, RoleService, GroupService) { +.service('QueryService', ['$http', 'PathHelper', '$q', 'AVAILABLE_WORK_PACKAGE_FILTERS', 'StatusService', 'TypeService', 'PriorityService', 'UserService', 'VersionService', 'RoleService', 'GroupService', 'ProjectService', + function($http, PathHelper, $q, AVAILABLE_WORK_PACKAGE_FILTERS, StatusService, TypeService, PriorityService, UserService, VersionService, RoleService, GroupService, ProjectService) { var availableColumns = [], availableFilterValues = {}; @@ -69,6 +70,12 @@ angular.module('openproject.services') case 'group': retrieveAvailableValues = GroupService.getGroups(); break; + case 'project': + retrieveAvailableValues = ProjectService.getProject(); + break; + case 'sub_project': + retrieveAvailableValues = ProjectService.getSubProjects(projectIdentifier); + break; } return retrieveAvailableValues.then(function(values) { diff --git a/app/controllers/api/v3/projects_controller.rb b/app/controllers/api/v3/projects_controller.rb new file mode 100644 index 0000000000..91613f79a1 --- /dev/null +++ b/app/controllers/api/v3/projects_controller.rb @@ -0,0 +1,60 @@ +#-- encoding: UTF-8 +#-- copyright +# OpenProject is a project management system. +# Copyright (C) 2012-2014 the OpenProject Foundation (OPF) +# +# 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. +#++ + +module Api + module V3 + + class ProjectsController < ApplicationController + before_filter :find_project + + include ::Api::V3::ApiController + + def show + respond_to do |format| + format.api + end + end + + def sub_projects + @sub_projects = @project.descendants.visible + + respond_to do |format| + format.api + end + end + + private + + def find_project + @project = Project.find(params[:project_id]) + end + + end + end +end diff --git a/app/views/api/v3/projects/index.api.rabl b/app/views/api/v3/projects/index.api.rabl new file mode 100644 index 0000000000..2aaea58e7a --- /dev/null +++ b/app/views/api/v3/projects/index.api.rabl @@ -0,0 +1,4 @@ + +collection @projects => :projects +attributes :id, + :name \ No newline at end of file diff --git a/app/views/api/v3/projects/sub_projects.api.rabl b/app/views/api/v3/projects/sub_projects.api.rabl new file mode 100644 index 0000000000..e0874daab9 --- /dev/null +++ b/app/views/api/v3/projects/sub_projects.api.rabl @@ -0,0 +1,4 @@ + +collection @sub_projects => :projects +attributes :id, + :name \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c96384017c..8936d07813 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -133,6 +133,7 @@ OpenProject::Application.routes.draw do get :available_columns, on: :collection end resources :versions, only: [:index] + get :sub_projects end resources :groups, only: [:index]