Merge pull request #2911 from floriank/feature/19759-fix-category-filter
[19759] Port category filter to OP 4.1+pull/2918/merge
commit
2f8329b9e5
@ -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; |
||||
}; |
@ -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…
Reference in new issue