Merge pull request #2911 from floriank/feature/19759-fix-category-filter

[19759] Port category filter to OP 4.1+
pull/2918/merge
Jan Sandbrink 10 years ago
commit 2f8329b9e5
  1. 1
      config/locales/js-de.yml
  2. 1
      config/locales/js-en.yml
  3. 6
      frontend/app/helpers/path-helper.js
  4. 52
      frontend/app/services/category-service.js
  5. 3
      frontend/app/services/index.js
  6. 28
      frontend/app/services/query-service.js
  7. 3
      frontend/app/work_packages/config/index.js
  8. 49
      frontend/tests/unit/tests/helpers/path-helper-test.js
  9. 75
      frontend/tests/unit/tests/services/category-service-test.js

@ -161,6 +161,7 @@ de:
assigned_to: "Zugewiesen an"
assigned_to_role: "Zuständigkeitsrolle"
author: "Autor"
category: "Kategorie"
created_at: "Angelegt"
done_ratio: "% erledigt"
due_date: "Abgabedatum"

@ -160,6 +160,7 @@ en:
assigned_to: "Assignee"
assigned_to_role: "Assignee's role"
author: "Author"
category: "Category"
created_at: "Created on"
done_ratio: "% done"
due_date: "Due date"

@ -253,6 +253,12 @@ module.exports = function() {
apiV3WorkPackagePath: function(workPackageId) {
return PathHelper.apiV3 + '/work_packages/' + workPackageId;
},
apiV3ProjectsPath: function(projectIdentifier) {
return PathHelper.apiV3 + PathHelper.projectsPath() + '/' + projectIdentifier;
},
apiV3ProjectCategoriesPath: function(projectIdentifier) {
return PathHelper.apiV3ProjectsPath(projectIdentifier) + '/categories';
},
// Static
staticAttachmentPath: function(attachmentId, fileName) {
return PathHelper.staticBase + PathHelper.attachmentPath(attachmentId, fileName);

@ -0,0 +1,52 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 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.exports = function($http, PathHelper) {
var CategoryService = {
getCategories: function(projectIdentifier) {
if(!projectIdentifier) {
return [];
}
var url = PathHelper.apiV3ProjectCategoriesPath(projectIdentifier);
return CategoryService.doQuery(url);
},
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response) {
var elements = response.data._embedded.elements;
return _.sortBy(elements, 'name');
});
}
};
return CategoryService;
};

@ -58,6 +58,7 @@ angular.module('openproject.services')
'PriorityService',
'UserService',
'VersionService',
'CategoryService',
'RoleService',
'GroupService',
'ProjectService',
@ -83,6 +84,8 @@ angular.module('openproject.services')
])
.service('VersionService', ['$http', 'PathHelper', require(
'./version-service')])
.service('CategoryService', ['$http', 'PathHelper', require(
'./category-service')])
.constant('DEFAULT_FILTER_PARAMS', {
'fields[]': 'status_id',
'operators[status_id]': 'o'

@ -26,7 +26,30 @@
// See doc/COPYRIGHT.rdoc for more details.
//++
module.exports = function(Query, Sortation, $http, PathHelper, $q, AVAILABLE_WORK_PACKAGE_FILTERS, StatusService, TypeService, PriorityService, UserService, VersionService, RoleService, GroupService, ProjectService, WorkPackagesTableHelper, I18n, queryMenuItemFactory, $rootScope, QUERY_MENU_ITEM_TYPE) {
/* jshint camelcase: false */
module.exports = function(
Query,
Sortation,
$http,
PathHelper,
$q,
AVAILABLE_WORK_PACKAGE_FILTERS,
StatusService,
TypeService,
PriorityService,
UserService,
VersionService,
CategoryService,
RoleService,
GroupService,
ProjectService,
WorkPackagesTableHelper,
I18n,
queryMenuItemFactory,
$rootScope,
QUERY_MENU_ITEM_TYPE
) {
var query;
@ -286,6 +309,9 @@ module.exports = function(Query, Sortation, $http, PathHelper, $q, AVAILABLE_WOR
case 'version':
retrieveAvailableValues = VersionService.getVersions(projectIdentifier);
break;
case 'category':
retrieveAvailableValues = CategoryService.getCategories(projectIdentifier);
break;
case 'role':
retrieveAvailableValues = RoleService.getRoles();
break;

@ -26,6 +26,8 @@
// See doc/COPYRIGHT.rdoc for more details.
//++
/* jshint camelcase: false */
angular.module('openproject.workPackages.config')
.constant('INITIALLY_SELECTED_COLUMNS', [{ name: 'id' }, { name: 'project' }, { name: 'type' }, { name: 'status' }, { name: 'priority' }, { name: 'subject' }, { name: 'assigned_to_id' }, { name: 'updated_at' }])
@ -52,6 +54,7 @@ angular.module('openproject.workPackages.config')
watcher_id: {type: 'list_model', modelName: 'user', order: 6, locale_name: 'watcher'},
responsible_id: {type: 'list_optional', modelName: 'user', order: 6, locale_name: 'responsible'},
fixed_version_id: {type: 'list_optional', modelName: 'version', order: 7, locale_name: 'fixed_version'},
category_id: { type: 'list_optional', modelName: 'category', order: 7, locale_name: 'category' },
member_of_group: {type: 'list_optional', modelName: 'group', order: 8, locale_name: 'member_of_group'},
assigned_to_role: {type: 'list_optional', modelName: 'role', order: 9, locale_name: 'assigned_to_role'},
subject: { type: 'text', order: 10, locale_name: 'subject' },

@ -0,0 +1,49 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 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.
//++
describe('PathHelper', function() {
var PathHelper;
beforeEach(module('openproject.helpers'));
beforeEach(inject(function(_PathHelper_) {
PathHelper = _PathHelper_;
}));
context('apiV3', function() {
var projectIdentifier = 'majora';
it('should provide the project\'s path', function() {
expect(PathHelper.apiV3ProjectsPath(projectIdentifier)).to.equal('/api/v3/projects/majora');
});
it('should provide a path to the project\'s categories', function() {
expect(
PathHelper.apiV3ProjectCategoriesPath(projectIdentifier)
).to.equal('/api/v3/projects/majora/categories');
});
});
});

@ -0,0 +1,75 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 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.
//++
/*jshint expr: true*/
describe('CategoryService', function() {
var CategoryService, $httpBackend;
var projectIdentifier = 'ocarina',
apiPath = '/api/v3/projects/' + projectIdentifier + '/categories';
beforeEach(module('openproject.services'));
beforeEach(inject(function(_$httpBackend_, _CategoryService_){
$httpBackend = _$httpBackend_;
CategoryService = _CategoryService_;
}));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
describe('getCategories', function() {
var categories = [
{ id: 1, name: 'Happy Mask' },
{ id: 2, name: 'A Salesman' }
];
beforeEach(function() {
$httpBackend.when('GET', apiPath)
.respond({ _embedded: { elements: categories } });
});
it('loads the categories sorted by their name', function() {
$httpBackend.expectGET(apiPath);
var callback = sinon.spy();
CategoryService.getCategories(projectIdentifier).then(callback);
$httpBackend.flush();
expect(callback).to.have.been.calledWith(sinon.match([
{ id: 2, name: 'A Salesman' },
{ id: 1, name: 'Happy Mask' }
]));
});
});
});
Loading…
Cancel
Save