0001-Add-system-setting-for-default-results-display-forma.patch

Marius BALTEANU, 2020-02-09 23:17

Download (3.51 KB)

View differences:

app/models/project_query.rb
82 82
    @default_columns_names = Setting.project_list_defaults.symbolize_keys[:column_names].map(&:to_sym)
83 83
  end
84 84

  
85
  def default_display_type
86
    Setting.project_list_display_type
87
  end
88

  
85 89
  def default_sort_criteria
86 90
    [[]]
87 91
  end
app/models/query.rb
766 766
    []
767 767
  end
768 768

  
769
  def default_display_type
770
    self.available_display_types.first
771
  end
772

  
769 773
  def column_names=(names)
770 774
    if names
771 775
      names = names.select {|n| n.is_a?(Symbol) || !n.blank? }
......
997 1001
  end
998 1002

  
999 1003
  def display_type
1000
    options[:display_type] || self.available_display_types.first
1004
    options[:display_type] || self.default_display_type
1001 1005
  end
1002 1006

  
1003 1007
  def display_type=(type)
app/views/settings/_projects.html.erb
19 19
<fieldset class="box">
20 20
  <legend><%= l(:setting_project_list_defaults) %></legend>
21 21
  <% query = ProjectQuery.new(Setting.project_list_defaults) %>
22
  <p>
23
    <label><%= l(:label_display_type) %></label>
24
    <% query.available_display_types.each do |t| %>
25
      <%= radio_button_tag('settings[project_list_display_type]', t, Setting.project_list_display_type == t, :id => "setting_project_list_display_type_#{t}") %>
26
      <%= content_tag('label', l(:"label_display_type_#{t}"), :for => "settings_project_list_display_type_#{t}", :class => "inline") %>
27
    <% end %>
28
  </p>
22 29
  <%= render_query_columns_selection(query,
23 30
        :name => 'settings[project_list_defaults][column_names]') %>
24 31
</fieldset>
config/settings.yml
230 230
    - hours
231 231
    totalable_names:
232 232
    - hours
233
project_list_display_type:
234
  default: board
233 235
project_list_defaults:
234 236
  serialized: true
235 237
  default:
test/unit/project_query_test.rb
60 60
    query = ProjectQuery.new
61 61
    assert_include :cf_3, query.available_columns.map(&:name)
62 62
  end
63

  
64
  def test_display_type_default_should_equal_with_setting_project_list_display_type
65
    ProjectQuery.new.available_display_types.each do |t|
66
      with_settings :project_list_display_type => t do
67
        q = ProjectQuery.new
68
        assert_equal t, q.display_type
69
      end
70
    end
71
  end
63 72
end
64
-