diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.coffee index 2fba8fa90..d32477773 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.coffee @@ -466,6 +466,7 @@ class App.ControllerTable extends App.Controller if @checkbox || @radio columnsLength++ groupLast = '' + groupLastName = '' tableBody = [] objectsToShow = @objectsOfPage(@shownPage) for object in objectsToShow @@ -473,16 +474,31 @@ class App.ControllerTable extends App.Controller position++ if @groupBy groupByName = App.viewPrint(object, @groupBy, @attributesList) - if groupLast isnt groupByName - groupLast = groupByName + if groupLastName isnt groupByName + groupLastName = groupByName tableBody.push @renderTableGroupByRow(object, position, groupByName) tableBody.push @renderTableRow(object, position) tableBody 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')( position: position groupByName: groupByName + groupByCount: groupByCount columnsLength: @columnsLength ) diff --git a/app/assets/javascripts/app/views/generic/table_row_group_by.jst.eco b/app/assets/javascripts/app/views/generic/table_row_group_by.jst.eco index 5b61703b0..b59254fef 100644 --- a/app/assets/javascripts/app/views/generic/table_row_group_by.jst.eco +++ b/app/assets/javascripts/app/views/generic/table_row_group_by.jst.eco @@ -1,3 +1,3 @@ - <%= @groupByName %> + <%= @groupByName %><% if @groupByCount:%> (<%= @groupByCount %>)<% end %> diff --git a/db/migrate/20180320000001_setting_table_group_by_show_count.rb b/db/migrate/20180320000001_setting_table_group_by_show_count.rb new file mode 100644 index 000000000..f415e5b14 --- /dev/null +++ b/db/migrate/20180320000001_setting_table_group_by_show_count.rb @@ -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 diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 5fdbc33fb..ecb84be0b 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -822,6 +822,33 @@ Setting.create_if_not_exists( 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( title: 'New User Accounts', name: 'user_create_account',