Fixes #3663 - Custom date attributes provide inconsistent sorting within grouping.

This commit is contained in:
Rolf Schmidt 2021-08-19 09:42:56 +02:00 committed by Thorsten Eckel
parent b238e695eb
commit 58c685f833
3 changed files with 56 additions and 18 deletions

View file

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

View file

@ -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('<hr><h1>table Group By Direction ASC</h1><div id="table7"></div>')
el = $('#table7')

View file

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