From 565d4cb8271f686937f0b558a806a005331d160a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C4=82LTEANU?= Date: Fri, 28 Mar 2025 00:33:10 +0200 Subject: [PATCH] Adds interval ratio setting to progressbar custom field. diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index ec8c5de8d..1db4cb95f 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -101,7 +101,8 @@ class CustomField < ApplicationRecord 'version_status', 'extensions_allowed', 'full_width_layout', - 'thousands_delimiter' + 'thousands_delimiter', + 'ratio_interval' ) def copy_from(arg, options={}) @@ -231,6 +232,10 @@ class CustomField < ApplicationRecord thousands_delimiter == '1' end + def ratio_interval + [5, read_attribute(:ratio_interval).to_i].max + end + # Returns a ORDER BY clause that can used to sort customized # objects by their value of the custom field. # Returns nil if the custom field can not be used for sorting. diff --git a/app/views/custom_fields/formats/_progressbar.html.erb b/app/views/custom_fields/formats/_progressbar.html.erb new file mode 100644 index 000000000..2b114d578 --- /dev/null +++ b/app/views/custom_fields/formats/_progressbar.html.erb @@ -0,0 +1,3 @@ +

+ <%= f.select :ratio_interval, [5, 10].collect {|i| ["#{i} %", i]} %> +

\ No newline at end of file diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index c4fd1b592..6b78c7109 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -1086,8 +1086,9 @@ module Redmine class ProgressbarFormat < Numeric add 'progressbar' - self.form_partial = nil + self.form_partial = 'custom_fields/formats/progressbar' self.totalable_supported = false + field_attributes :ratio_interval def label "label_progressbar" @@ -1116,7 +1117,7 @@ module Redmine view.select_tag( tag_name, view.options_for_select( - (0..100).step(Setting.issue_done_ratio_interval.to_i).to_a.collect {|r| ["#{r} %", r]}, + (0..100).step(custom_value.custom_field.ratio_interval.to_i).to_a.collect {|r| ["#{r} %", r]}, custom_value.value ), options.merge(id: tag_id, style: "width: 75px;") @@ -1124,7 +1125,7 @@ module Redmine end def bulk_edit_tag(view, tag_id, tag_name, custom_field, objects, value, options={}) - 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]}) + 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]}) view.select_tag(tag_name, opts, options.merge(id: tag_id, style: "width: 75px;")) + bulk_clear_tag(view, tag_id, tag_name, custom_field, value) end diff --git a/test/functional/custom_fields_controller_test.rb b/test/functional/custom_fields_controller_test.rb index 0706a2eda..6fe17122c 100644 --- a/test/functional/custom_fields_controller_test.rb +++ b/test/functional/custom_fields_controller_test.rb @@ -282,6 +282,23 @@ class CustomFieldsControllerTest < Redmine::ControllerTest assert_select '[name=?]', 'custom_field[full_width_layout]', 0 end + def test_setting_ratio_interval_should_be_present_only_for_progressbar_format + get( + :new, + :params => { + :type => 'IssueCustomField', + :custom_field => { + :field_format => 'progressbar' + } + } + ) + assert_response :success + assert_select '[name=?]', 'custom_field[ratio_interval]' do + assert_select 'option[value=?]', '5' + assert_select 'option[value=?]', '10' + end + end + def test_new_js get( :new, diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 5b2ac0d8c..e6b187626 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -5970,6 +5970,17 @@ class IssuesControllerTest < Redmine::ControllerTest end end + def test_get_edit_with_custom_field_progress_bar + cf = IssueCustomField.generate!(:tracker_ids => [1], :is_for_all => true, :field_format => 'progressbar') + + @request.session[:user_id] = 1 + get(:edit, :params => {:id => 1}) + assert_response :success + + puts response.body + assert_select "select[id=?]", "issue_custom_field_values_#{cf.id}", 1 + end + def test_get_edit_with_me_assigned_to_id @request.session[:user_id] = 2 get( diff --git a/test/unit/lib/redmine/field_format/progressbar_format_test.rb b/test/unit/lib/redmine/field_format/progressbar_format_test.rb index d507f9ddb..fe422062a 100644 --- a/test/unit/lib/redmine/field_format/progressbar_format_test.rb +++ b/test/unit/lib/redmine/field_format/progressbar_format_test.rb @@ -21,7 +21,7 @@ require_relative '../../../../test_helper' require 'redmine/field_format' module Redmine::FieldFormat - class ProgressbarFormatTest < ActiveSupport::TestCase + class ProgressbarFormatTest < ActionView::TestCase def setup @field = IssueCustomField.new(name: 'ProgressbarTest', field_format: 'progressbar') @format = Redmine::FieldFormat::ProgressbarFormat.instance @@ -81,5 +81,35 @@ module Redmine::FieldFormat options = @format.query_filter_options(@field, nil) assert_equal :integer, options[:type] end + + def test_ratio_interval + @field.update(ratio_interval: 5) + assert_equal 5, @field.ratio_interval + end + + def test_edit_tag_possible_values_with_ratio_interval + [5, 10].each do |ratio_interval| + @field.update(ratio_interval: ratio_interval) + value = CustomValue.new(custom_field: @field, value: '90') + + tag = @field.format.edit_tag(self, 'id', 'name', value) + assert_select_in tag, 'select' do + assert_select 'option', 100 / ratio_interval + 1 + end + end + end + + def test_bulk_edit_tag_possible_values_with_ratio_interval + [5, 10].each do |ratio_interval| + @field.update(ratio_interval: ratio_interval) + value = CustomValue.new(custom_field: @field, value: '90') + objects = [Issue.new, Issue.new] + + tag = @field.format.bulk_edit_tag(self, 'id', 'name', @field, objects, value) + assert_select_in tag, 'select' do |select| + assert_select select.first, 'option', 100 / ratio_interval + 2 + end + end + end end end -- 2.39.5 (Apple Git-154)