diff --git a/app/assets/javascripts/app/controllers/_application_controller/table.coffee b/app/assets/javascripts/app/controllers/_application_controller/table.coffee index 809c767f4..64e809fe3 100644 --- a/app/assets/javascripts/app/controllers/_application_controller/table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller/table.coffee @@ -504,24 +504,33 @@ class App.ControllerTable extends App.Controller groupLastName = '' tableBody = [] objectsToShow = @objectsOfPage(@pagerShownPage) - for object in objectsToShow - objectActions = [] + if @groupBy + # group by raw (and not printable) value so dates work also + objectsGrouped = _.groupBy(objectsToShow, (object) => object[@groupBy]) + else + objectsGrouped = { '': objectsToShow } - if object - position++ - if @groupBy - groupByName = @groupObjectName(object, @groupBy) - if groupLastName isnt groupByName - groupLastName = groupByName - tableBody.push @renderTableGroupByRow(object, position, groupByName) - for action in @actions - # Check if the available key is used, it can be a Boolean or a function which should be called. - if !action.available? || action.available == true - objectActions.push action - else if typeof action.available is 'function' && action.available(object) == true - objectActions.push action + for groupValue in Object.keys(objectsGrouped).sort() + groupObjects = objectsGrouped[groupValue] - tableBody.push @renderTableRow(object, position, objectActions) + for object in groupObjects + objectActions = [] + + if object + position++ + if @groupBy + groupByName = @groupObjectName(object, @groupBy) + if groupLastName isnt groupByName + groupLastName = groupByName + tableBody.push @renderTableGroupByRow(object, position, groupByName) + for action in @actions + # Check if the available key is used, it can be a Boolean or a function which should be called. + if !action.available? || action.available == true + objectActions.push action + else if typeof action.available is 'function' && action.available(object) == true + objectActions.push action + + tableBody.push @renderTableRow(object, position, objectActions) tableBody renderTableGroupByRow: (object, position, groupByName) => diff --git a/public/assets/tests/table.js b/public/assets/tests/table.js index b7eac8557..02ca59876 100644 --- a/public/assets/tests/table.js +++ b/public/assets/tests/table.js @@ -370,8 +370,8 @@ test('table test', function() { groupBy: 'priority', groupDirection: 'DESC', }) - equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), '2 normal', 'check row 1') - equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1)').text().trim(), '1 niedrig', 'check row 3') + equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), '1 niedrig', 'check row 1') + equal(el.find('tbody > tr:nth-child(4) > td:nth-child(1)').text().trim(), '2 normal', 'check row 3') $('#table').append('

table Group By Direction ASC

') el = $('#table7') diff --git a/spec/system/ticket/view_spec.rb b/spec/system/ticket/view_spec.rb index 80d4c1fb6..67dd7631c 100644 --- a/spec/system/ticket/view_spec.rb +++ b/spec/system/ticket/view_spec.rb @@ -344,4 +344,33 @@ RSpec.describe 'Ticket views', type: :system do expect(page).to have_text(ticket.title, wait: 10) end end + + describe 'Grouping' do + context 'when sorted by custom object date', authenticated_as: :authenticate, db_strategy: :reset do + let(:ticket1) { create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2018-01-17') } + let(:ticket2) { create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2018-08-19') } + let(:ticket3) { create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2019-01-19') } + let(:ticket4) { create(:ticket, group: Group.find_by(name: 'Users'), cdate: '2021-08-18') } + + def authenticate + create :object_manager_attribute_date, name: 'cdate' + ObjectManager::Attribute.migration_execute + ticket4 + ticket3 + ticket2 + ticket1 + Overview.find_by(link: 'all_unassigned').update(group_by: 'cdate') + true + end + + it 'does show the date groups sorted' do + visit 'ticket/view/all_unassigned' + text = page.find('.js-tableBody').text(:all) + + expect(text.index('01/17/2018') < text.index('08/19/2018')).to eq(true) + expect(text.index('08/19/2018') < text.index('01/19/2019')).to eq(true) + expect(text.index('01/19/2019') < text.index('08/18/2021')).to eq(true) + end + end + end end