Project

General



Profile

Feature #42335 » 0001-Adds-interval-ratio-setting-to-progressbar-custom-fi.patch

Marius BĂLTEANU, 2025-04-03 22:18

View differences:

app/models/custom_field.rb
101 101
    'version_status',
102 102
    'extensions_allowed',
103 103
    'full_width_layout',
104
    'thousands_delimiter'
104
    'thousands_delimiter',
105
    'ratio_interval'
105 106
  )
106 107

  
107 108
  def copy_from(arg, options={})
app/views/custom_fields/formats/_progressbar.html.erb
1
<p>
2
  <%= f.select :ratio_interval, [5, 10].collect {|i| ["#{i} %", i]}, selected: Redmine::FieldFormat::ProgressbarFormat::DEFAULT_RATIO_INTERVAL, required: true %>
3
</p>
lib/redmine/field_format.rb
1086 1086
    class ProgressbarFormat < Numeric
1087 1087
      add 'progressbar'
1088 1088

  
1089
      self.form_partial = nil
1089
      self.form_partial = 'custom_fields/formats/progressbar'
1090 1090
      self.totalable_supported = false
1091
      field_attributes :ratio_interval
1092

  
1093
      # Take the default value from Setting.issue_done_ratio_interval.to_i
1094
      # in order to have a consistent behaviour for default ratio interval.
1095
      DEFAULT_RATIO_INTERVAL = Setting.issue_done_ratio_interval.to_i
1091 1096

  
1092 1097
      def label
1093 1098
        "label_progressbar"
......
1112 1117
        order_statement(custom_field)
1113 1118
      end
1114 1119

  
1120
      def before_custom_field_save(custom_field)
1121
        super
1122

  
1123
        if custom_field.ratio_interval.blank?
1124
          custom_field.ratio_interval = DEFAULT_RATIO_INTERVAL
1125
        end
1126
      end
1127

  
1115 1128
      def edit_tag(view, tag_id, tag_name, custom_value, options={})
1116 1129
        view.select_tag(
1117 1130
          tag_name,
1118 1131
          view.options_for_select(
1119
            (0..100).step(Setting.issue_done_ratio_interval.to_i).to_a.collect {|r| ["#{r} %", r]},
1132
            (0..100).step(custom_value.custom_field.ratio_interval.to_i).to_a.collect {|r| ["#{r} %", r]},
1120 1133
            custom_value.value
1121 1134
          ),
1122 1135
          options.merge(id: tag_id, style: "width: 75px;")
......
1124 1137
      end
1125 1138

  
1126 1139
      def bulk_edit_tag(view, tag_id, tag_name, custom_field, objects, value, options={})
1127
        opts = view.options_for_select([[l(:label_no_change_option), '']] + (0..100).step(Setting.issue_done_ratio_interval.to_i).to_a.collect {|r| ["#{r} %", r]})
1140
        opts = view.options_for_select([[l(:label_no_change_option), '']] + (0..100).step(custom_field.ratio_interval.to_i).to_a.collect {|r| ["#{r} %", r]})
1128 1141
        view.select_tag(tag_name, opts, options.merge(id: tag_id, style: "width: 75px;")) +
1129 1142
          bulk_clear_tag(view, tag_id, tag_name, custom_field, value)
1130 1143
      end
test/functional/custom_fields_controller_test.rb
282 282
    assert_select '[name=?]', 'custom_field[full_width_layout]', 0
283 283
  end
284 284

  
285
  def test_setting_ratio_interval_should_be_present_only_for_progressbar_format
286
    get(
287
      :new,
288
      :params => {
289
        :type => 'IssueCustomField',
290
          :custom_field => {
291
            :field_format => 'progressbar'
292
          }
293
      }
294
    )
295
    assert_response :success
296
    assert_select '[name=?]', 'custom_field[ratio_interval]' do
297
      assert_select 'option[value=?]', '5'
298
      assert_select 'option[value=?][selected=?]', '10', 'selected'
299
    end
300
  end
301

  
285 302
  def test_new_js
286 303
    get(
287 304
      :new,
test/functional/issues_controller_test.rb
5970 5970
    end
5971 5971
  end
5972 5972

  
5973
  def test_get_edit_with_custom_field_progress_bar
5974
    cf = IssueCustomField.generate!(:tracker_ids => [1], :is_for_all => true, :field_format => 'progressbar')
5975

  
5976
    @request.session[:user_id] = 1
5977
    get(:edit, :params => {:id => 1})
5978
    assert_response :success
5979

  
5980
    puts response.body
5981
    assert_select "select[id=?]", "issue_custom_field_values_#{cf.id}", 1
5982
  end
5983

  
5973 5984
  def test_get_edit_with_me_assigned_to_id
5974 5985
    @request.session[:user_id] = 2
5975 5986
    get(
test/unit/lib/redmine/field_format/progressbar_format_test.rb
21 21
require 'redmine/field_format'
22 22

  
23 23
module Redmine::FieldFormat
24
  class ProgressbarFormatTest < ActiveSupport::TestCase
24
  class ProgressbarFormatTest < ActionView::TestCase
25 25
    def setup
26 26
      @field = IssueCustomField.new(name: 'ProgressbarTest', field_format: 'progressbar')
27 27
      @format = Redmine::FieldFormat::ProgressbarFormat.instance
......
81 81
      options = @format.query_filter_options(@field, nil)
82 82
      assert_equal :integer, options[:type]
83 83
    end
84

  
85
    def test_default_ratio_interval_should_be_default_issue_done_ratio_interval
86
      @field.save
87
      assert_equal 10, @field.ratio_interval
88
    end
89

  
90
    def test_ratio_interval
91
      @field.update(ratio_interval: 5)
92
      assert_equal 5, @field.ratio_interval
93
    end
94

  
95
    def test_edit_tag_possible_values_with_ratio_interval
96
      [5, 10].each do |ratio_interval|
97
        @field.update(ratio_interval: ratio_interval)
98
        value = CustomValue.new(custom_field: @field, value: '90')
99

  
100
        tag = @field.format.edit_tag(self, 'id', 'name', value)
101
        assert_select_in tag, 'select' do
102
          assert_select 'option', 100 / ratio_interval + 1
103
        end
104
      end
105
    end
106

  
107
    def test_bulk_edit_tag_possible_values_with_ratio_interval
108
      [5, 10].each do |ratio_interval|
109
        @field.update(ratio_interval: ratio_interval)
110
        value = CustomValue.new(custom_field: @field, value: '90')
111
        objects = [Issue.new, Issue.new]
112

  
113
        tag = @field.format.bulk_edit_tag(self, 'id', 'name', @field, objects, value)
114
        assert_select_in tag, 'select' do |select|
115
          assert_select select.first, 'option', 100 / ratio_interval + 2
116
        end
117
      end
118
    end
84 119
  end
85 120
end
(6-6/6)