Fixes #2751 - Group by selection field has wrong counters if no value.
This commit is contained in:
parent
9ea4ce9d2f
commit
e5cd8467d4
2 changed files with 46 additions and 22 deletions
|
@ -517,7 +517,7 @@ class App.ControllerTable extends App.Controller
|
|||
if object
|
||||
position++
|
||||
if @groupBy
|
||||
groupByName = App.viewPrint(object, @groupBy, @attributesList)
|
||||
groupByName = @groupObjectName(object, @groupBy)
|
||||
if groupLastName isnt groupByName
|
||||
groupLastName = groupByName
|
||||
tableBody.push @renderTableGroupByRow(object, position, groupByName)
|
||||
|
@ -529,14 +529,11 @@ class App.ControllerTable extends App.Controller
|
|||
groupByCount = undefined
|
||||
if ui_table_group_by_show_count is true
|
||||
groupBy = @groupBy
|
||||
groupLast = object[@groupBy]
|
||||
if !groupLast
|
||||
groupBy = "#{@groupBy}_id"
|
||||
groupLast = object[groupBy]
|
||||
groupLast = @groupObjectName(object, @groupBy)
|
||||
groupByCount = 0
|
||||
if @objects
|
||||
for localObject in @objects
|
||||
if localObject[groupBy] is groupLast
|
||||
if @groupObjectName(localObject, groupBy) is groupLast
|
||||
groupByCount += 1
|
||||
|
||||
App.view('generic/table_row_group_by')(
|
||||
|
@ -799,22 +796,7 @@ class App.ControllerTable extends App.Controller
|
|||
# get groups
|
||||
groupObjects = {}
|
||||
for object in @objects
|
||||
group = object[@groupBy]
|
||||
if !group
|
||||
withId = "#{@groupBy}_id"
|
||||
if object[withId] && @attributesList[withId] && @attributesList[withId].relation
|
||||
if App[@attributesList[withId].relation].exists(object[withId])
|
||||
item = App[@attributesList[withId].relation].findNative(object[withId])
|
||||
if item && item.displayName
|
||||
group = item.displayName().toLowerCase()
|
||||
else if item.name
|
||||
group = item.name.toLowerCase()
|
||||
if _.isEmpty(group)
|
||||
group = ''
|
||||
if group.displayName
|
||||
group = group.displayName().toLowerCase()
|
||||
else if group.name
|
||||
group = group.name.toLowerCase()
|
||||
group = @groupObjectName(object, @groupBy)
|
||||
groupObjects[group] ||= []
|
||||
groupObjects[group].push object
|
||||
|
||||
|
@ -836,6 +818,20 @@ class App.ControllerTable extends App.Controller
|
|||
@objects = localObjects
|
||||
@lastSortedobjects = localObjects
|
||||
|
||||
groupObjectName: (object, key = undefined) ->
|
||||
group = object
|
||||
if key
|
||||
if key not of object
|
||||
key += '_id'
|
||||
group = App.viewPrint(object, key, @attributesList)
|
||||
if _.isEmpty(group)
|
||||
group = ''
|
||||
if group.displayName
|
||||
group = group.displayName().toLowerCase()
|
||||
else if group.name
|
||||
group = group.name.toLowerCase()
|
||||
group
|
||||
|
||||
onActionButtonClicked: (e) =>
|
||||
id = $(e.currentTarget).parents('tr').data('id')
|
||||
name = e.currentTarget.getAttribute('data-table-action')
|
||||
|
|
|
@ -142,4 +142,32 @@ RSpec.describe 'Ticket views', type: :system do
|
|||
]).to be_all note
|
||||
end
|
||||
end
|
||||
|
||||
context 'Setting "ui_table_group_by_show_count"', authenticated_as: :authenticate, db_strategy: :reset do
|
||||
let!(:ticket1) { create(:ticket, group: Group.find_by(name: 'Users')) }
|
||||
let!(:ticket2) { create(:ticket, group: Group.find_by(name: 'Users')) }
|
||||
let!(:ticket3) { create(:ticket, group: Group.find_by(name: 'Users')) }
|
||||
let!(:ticket4) { create(:ticket, group: Group.find_by(name: 'Users')) }
|
||||
|
||||
def authenticate
|
||||
create :object_manager_attribute_select, name: 'grouptest'
|
||||
ObjectManager::Attribute.migration_execute
|
||||
ticket1
|
||||
ticket2.update(grouptest: 'key_1')
|
||||
ticket3.update(grouptest: 'key_2')
|
||||
ticket4.update(grouptest: 'key_1')
|
||||
Overview.find_by(name: 'Open').update(group_by: 'grouptest')
|
||||
Setting.set('ui_table_group_by_show_count', true)
|
||||
true
|
||||
end
|
||||
|
||||
it 'shows correct ticket counts' do
|
||||
visit 'ticket/view/all_open'
|
||||
within(:active_content) do
|
||||
page.find('.js-tableBody td b', text: '(1)')
|
||||
page.find('.js-tableBody td b', text: 'value_1 (2)')
|
||||
page.find('.js-tableBody td b', text: 'value_2 (1)')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue