Feature #42335 » 0001-Adds-interval-ratio-setting-to-progressbar-custom-fi.patch
| app/models/custom_field.rb | ||
|---|---|---|
|
'version_status',
|
||
|
'extensions_allowed',
|
||
|
'full_width_layout',
|
||
|
'thousands_delimiter'
|
||
|
'thousands_delimiter',
|
||
|
'ratio_interval'
|
||
|
)
|
||
|
def copy_from(arg, options={})
|
||
| app/views/custom_fields/formats/_progressbar.html.erb | ||
|---|---|---|
|
<p>
|
||
|
<%= f.select :ratio_interval, [5, 10].collect {|i| ["#{i} %", i]}, selected: Redmine::FieldFormat::ProgressbarFormat::DEFAULT_RATIO_INTERVAL, required: true %>
|
||
|
</p>
|
||
| lib/redmine/field_format.rb | ||
|---|---|---|
|
class ProgressbarFormat < Numeric
|
||
|
add 'progressbar'
|
||
|
self.form_partial = nil
|
||
|
self.form_partial = 'custom_fields/formats/progressbar'
|
||
|
self.totalable_supported = false
|
||
|
field_attributes :ratio_interval
|
||
|
# Take the default value from Setting.issue_done_ratio_interval.to_i
|
||
|
# in order to have a consistent behaviour for default ratio interval.
|
||
|
DEFAULT_RATIO_INTERVAL = Setting.issue_done_ratio_interval.to_i
|
||
|
def label
|
||
|
"label_progressbar"
|
||
| ... | ... | |
|
order_statement(custom_field)
|
||
|
end
|
||
|
def before_custom_field_save(custom_field)
|
||
|
super
|
||
|
if custom_field.ratio_interval.blank?
|
||
|
custom_field.ratio_interval = DEFAULT_RATIO_INTERVAL
|
||
|
end
|
||
|
end
|
||
|
def edit_tag(view, tag_id, tag_name, custom_value, options={})
|
||
|
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;")
|
||
| ... | ... | |
|
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
|
||
| test/functional/custom_fields_controller_test.rb | ||
|---|---|---|
|
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=?][selected=?]', '10', 'selected'
|
||
|
end
|
||
|
end
|
||
|
def test_new_js
|
||
|
get(
|
||
|
:new,
|
||
| test/functional/issues_controller_test.rb | ||
|---|---|---|
|
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(
|
||
| test/unit/lib/redmine/field_format/progressbar_format_test.rb | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
options = @format.query_filter_options(@field, nil)
|
||
|
assert_equal :integer, options[:type]
|
||
|
end
|
||
|
def test_default_ratio_interval_should_be_default_issue_done_ratio_interval
|
||
|
@field.save
|
||
|
assert_equal 10, @field.ratio_interval
|
||
|
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
|
||
- « Previous
- 1
- …
- 4
- 5
- 6
- Next »