From cf57b3c43eb0157877d013192a390d22860caa19 Mon Sep 17 00:00:00 2001 From: Jan Sandbrink Date: Fri, 11 Sep 2015 10:03:32 +0200 Subject: [PATCH] Only allow to configure columns as summable, that can be summed no more "sum that subject and the versions!" --- app/helpers/settings_helper.rb | 14 +++++++++----- app/views/settings/_work_packages.html.erb | 9 ++++++++- spec/helpers/settings_helper_spec.rb | 20 ++++++++++++++++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index 9633122cc0..e84a12c639 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -149,14 +149,18 @@ module SettingsHelper def build_settings_matrix_body(settings, choices) choices.map { |choice| - text, value = (choice.is_a?(Array)) ? choice : [choice, choice] + value = choice[:value] + caption = choice[:caption] || value.to_s + exceptions = Array(choice[:except]).compact content_tag(:tr, class: 'form--matrix-row') do - content_tag(:td, text, class: 'form--matrix-cell') + + content_tag(:td, caption, class: 'form--matrix-cell') + settings.map { |setting| content_tag(:td, class: 'form--matrix-checkbox-cell') do - styled_check_box_tag("settings[#{setting}][]", value, - Setting.send(setting).include?(value), - id: "#{setting}_#{value}") + unless exceptions.include?(setting) + styled_check_box_tag("settings[#{setting}][]", value, + Setting.send(setting).include?(value), + id: "#{setting}_#{value}") + end end }.join.html_safe end diff --git a/app/views/settings/_work_packages.html.erb b/app/views/settings/_work_packages.html.erb index 037f846324..1a9f03c29f 100644 --- a/app/views/settings/_work_packages.html.erb +++ b/app/views/settings/_work_packages.html.erb @@ -36,8 +36,15 @@ See doc/COPYRIGHT.rdoc for more details.
<%= setting_text_field :work_packages_export_limit, :size => 6 %>
<%= l(:setting_column_options) %> + <% + column_choices = Query.new.available_columns.map { |column| + choice = { caption: column.caption, value: column.name.to_s } + choice[:except] = :work_package_list_summable_columns unless column.summable? + choice + } + %> <%= settings_matrix([:work_package_list_default_columns, :work_package_list_summable_columns], - Query.new.available_columns.collect {|c| [c.caption, c.name.to_s]}, :label_choices => :setting_work_package_properties) %> + column_choices, :label_choices => :setting_work_package_properties) %>
<%= styled_button_tag l(:button_save), class: '-highlight -with-icon icon-yes' %> <% end %> diff --git a/spec/helpers/settings_helper_spec.rb b/spec/helpers/settings_helper_spec.rb index 76355b6055..448be8677e 100644 --- a/spec/helpers/settings_helper_spec.rb +++ b/spec/helpers/settings_helper_spec.rb @@ -87,9 +87,25 @@ describe SettingsHelper, type: :helper do end subject(:output) { - helper.settings_matrix [:field_a, :field_b], [ - ['Popsickle', '1'], ['Jello', '2'], ['Ice Cream', '3'], 'Quarkspeise' + settings = [:field_a, :field_b] + choices = [ + { + caption: 'Popsickle', + value: '1' + }, + { + caption: 'Jello', + value: '2' + }, + { + caption: 'Ice Cream', + value: '3' + }, + { + value: 'Quarkspeise' + } ] + helper.settings_matrix settings, choices } it_behaves_like 'not wrapped in container'