Merge pull request #3544 from ulferts/fix/alphabetic_version_sorting

Fix/alphabetic version sorting
pull/3556/head
Oliver Günther 9 years ago
commit f8a352970c
  1. 2
      app/models/version.rb
  2. 5
      frontend/app/services/version-service.js
  3. 4
      frontend/app/work_packages/services/work-package-field-configuration-service.js
  4. 43
      spec/models/version_spec.rb

@ -205,7 +205,7 @@ class Version < ActiveRecord::Base
# tie the comparison to the presentation as sorting is mostly
# used within sorted tables.
# Thus, when the representation changes, the sorting will change as well.
to_s_with_project <=> version.to_s_with_project
to_s_with_project.downcase <=> version.to_s_with_project.downcase
end
# Returns the sharings that +user+ can set the version to

@ -30,7 +30,6 @@ module.exports = function($http, PathHelper) {
var VersionService = {
// TODO: check if code invoked anywere
getVersions: function(projectIdentifier) {
var url;
@ -46,7 +45,9 @@ module.exports = function($http, PathHelper) {
doQuery: function(url, params) {
return $http.get(url, { params: params })
.then(function(response){
return _.sortBy(response.data.versions, 'name');
return _.sortBy(response.data.versions, function(version) {
return version.name.toLowerCase();
});
});
}
};

@ -32,7 +32,9 @@ module.exports = function() {
switch(field) {
case 'version':
sorting = 'title';
sorting = function(field) {
return field.title.toLowerCase();
};
break;
default:
sorting = null;

@ -127,6 +127,49 @@ describe Version, type: :model do
expect(version1 <=> version2).to eql 1
end
it 'is 0 if name and project are equal except for case' do
version1.project.name = version2.project.name.upcase
version1.name = version2.name.upcase
expect(version1 <=> version2).to be 0
end
it "is -1 if the project name is alphabetically before the other's project name ignoring case" do
version1.name = 'BBBB'
version1.project.name = 'aaaa'
version2.name = 'AAAA'
version2.project.name = 'BBBB'
expect(version1 <=> version2).to eql -1
end
it "is 1 if the project name is alphabetically after the other's project name ignoring case" do
version1.name = 'AAAA'
version1.project.name = 'BBBB'
version2.name = 'BBBB'
version2.project.name = 'aaaa'
expect(version1 <=> version2).to eql 1
end
it "is -1 if the project name is equal
and the version's name is alphabetically before the other's name ignoring case" do
version1.project.name = version2.project.name
version1.name = 'aaaa'
version2.name = 'BBBB'
expect(version1 <=> version2).to eql -1
end
it "is 1 if the project name is equal
and the version's name is alphabetically after the other's name ignoring case" do
version1.project.name = version2.project.name
version1.name = 'BBBB'
version2.name = 'aaaa'
expect(version1 <=> version2).to eql 1
end
end
context '#projects' do

Loading…
Cancel
Save