Implemented config setting to show total number of objects in a grouping in a table view.

This commit is contained in:
Martin Edenhofer 2018-03-30 13:09:57 +02:00
parent 76df6d32f9
commit 2688c23d9a
4 changed files with 80 additions and 3 deletions

View file

@ -466,6 +466,7 @@ class App.ControllerTable extends App.Controller
if @checkbox || @radio if @checkbox || @radio
columnsLength++ columnsLength++
groupLast = '' groupLast = ''
groupLastName = ''
tableBody = [] tableBody = []
objectsToShow = @objectsOfPage(@shownPage) objectsToShow = @objectsOfPage(@shownPage)
for object in objectsToShow for object in objectsToShow
@ -473,16 +474,31 @@ class App.ControllerTable extends App.Controller
position++ position++
if @groupBy if @groupBy
groupByName = App.viewPrint(object, @groupBy, @attributesList) groupByName = App.viewPrint(object, @groupBy, @attributesList)
if groupLast isnt groupByName if groupLastName isnt groupByName
groupLast = groupByName groupLastName = groupByName
tableBody.push @renderTableGroupByRow(object, position, groupByName) tableBody.push @renderTableGroupByRow(object, position, groupByName)
tableBody.push @renderTableRow(object, position) tableBody.push @renderTableRow(object, position)
tableBody tableBody
renderTableGroupByRow: (object, position, groupByName) => renderTableGroupByRow: (object, position, groupByName) =>
ui_table_group_by_show_count = @Config.get('ui_table_group_by_show_count')
groupByCount = undefined
if ui_table_group_by_show_count is true
groupBy = @groupBy
groupLast = object[@groupBy]
if !groupLast
groupBy = "#{@groupBy}_id"
groupLast = object[groupBy]
groupByCount = 0
if @objects
for localObject in @objects
if localObject[groupBy] is groupLast
groupByCount += 1
App.view('generic/table_row_group_by')( App.view('generic/table_row_group_by')(
position: position position: position
groupByName: groupByName groupByName: groupByName
groupByCount: groupByCount
columnsLength: @columnsLength columnsLength: @columnsLength
) )

View file

@ -1,3 +1,3 @@
<tr> <tr>
<td colspan="<%= @columnsLength %>"><b><%= @groupByName %></b></td> <td colspan="<%= @columnsLength %>"><b><%= @groupByName %><% if @groupByCount:%> (<%= @groupByCount %>)<% end %></b></td>
</tr> </tr>

View file

@ -0,0 +1,34 @@
class SettingTableGroupByShowCount < ActiveRecord::Migration[5.1]
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
Setting.create_if_not_exists(
title: 'Open ticket indicator',
name: 'ui_table_group_by_show_count',
area: 'UI::Base',
description: 'Total display of the number of objects in a grouping.',
options: {
form: [
{
display: '',
null: true,
name: 'ui_table_group_by_show_count',
tag: 'boolean',
translate: true,
options: {
true => 'yes',
false => 'no',
},
},
],
},
state: false,
preferences: {
permission: ['admin.ui'],
},
frontend: true
)
end
end

View file

@ -822,6 +822,33 @@ Setting.create_if_not_exists(
frontend: true frontend: true
) )
Setting.create_if_not_exists(
title: 'Open ticket indicator',
name: 'ui_table_group_by_show_count',
area: 'UI::Base',
description: 'Total display of the number of objects in a grouping.',
options: {
form: [
{
display: '',
null: true,
name: 'ui_table_group_by_show_count',
tag: 'boolean',
translate: true,
options: {
true => 'yes',
false => 'no',
},
},
],
},
state: false,
preferences: {
permission: ['admin.ui'],
},
frontend: true
)
Setting.create_if_not_exists( Setting.create_if_not_exists(
title: 'New User Accounts', title: 'New User Accounts',
name: 'user_create_account', name: 'user_create_account',