Made project service for (sub)projects. Can use sub-project filter.

There is an existing bug that prevents sub-project filtering working, will look into that now. Also still need to know before hand if there are any sub-projects so we can hide the filter if there are none.
pull/1093/head
Richard 11 years ago
parent c4738eedef
commit 984d318112
  1. 2
      app/assets/javascripts/angular/config/work-packages-config.js
  2. 1
      app/assets/javascripts/angular/controllers/work-packages-controller.js
  3. 6
      app/assets/javascripts/angular/helpers/components/path-helper.js
  4. 26
      app/assets/javascripts/angular/models/query.js
  5. 27
      app/assets/javascripts/angular/services/project-service.js
  6. 9
      app/assets/javascripts/angular/services/query-service.js
  7. 60
      app/controllers/api/v3/projects_controller.rb
  8. 4
      app/views/api/v3/projects/index.api.rabl
  9. 4
      app/views/api/v3/projects/sub_projects.api.rabl
  10. 1
      config/routes.rb

@ -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')

@ -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,

@ -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';
},

@ -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
*

@ -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;
}]);

@ -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) {

@ -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

@ -0,0 +1,4 @@
collection @projects => :projects
attributes :id,
:name

@ -0,0 +1,4 @@
collection @sub_projects => :projects
attributes :id,
:name

@ -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]

Loading…
Cancel
Save