From fdf5d2177e1755857b878fcd5c2f2ba49c7b2f4f Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Mon, 18 Sep 2023 17:52:18 +0300 Subject: [PATCH] setting to chooze custom field for time limit --- app/views/settings/_limit_by_estimation.erb | 22 +++++++++++++++ lib/issue_patch.rb | 31 +++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 app/views/settings/_limit_by_estimation.erb create mode 100644 lib/issue_patch.rb diff --git a/app/views/settings/_limit_by_estimation.erb b/app/views/settings/_limit_by_estimation.erb new file mode 100644 index 0000000..09e0ef6 --- /dev/null +++ b/app/views/settings/_limit_by_estimation.erb @@ -0,0 +1,22 @@ +<% + default = Setting.available_settings[SETTINGS_NAME.to_s]['default'] +%> + + + + + + + + + + + + + +
<%= t 'use_custom_field' %> + <%=check_box_tag("settings[estimated_field_use]",1, settings['estimated_field_use']) %> +
<%= t 'estimation_limit_custom_field' %> + <%= select_tag("settings[estimated_field]", + options_from_collection_for_select(IssueCustomField.where(field_format: 'float').all, "id", "name", settings['estimated_field'])) %> +
diff --git a/lib/issue_patch.rb b/lib/issue_patch.rb new file mode 100644 index 0000000..7613994 --- /dev/null +++ b/lib/issue_patch.rb @@ -0,0 +1,31 @@ +require_dependency 'issue' + +module IssuePatch + + def self.included(base) # :nodoc: + base.send(:include, InstanceMethods) + base.class_eval do + unloadable # Send unloadable so it will not be unloaded in development + end + end + + module InstanceMethods + def estimated_internal + use = Setting[SETTINGS_NAME]['estimated_field_use'] + if (use.nil? || use == false) + return estimated_hours + end + + @custom_field_estimated_id ||= CustomField.find(Setting[SETTINGS_NAME]['estimated_field']).id + @estimated_internal ||= custom_field_values.select{|item| item.custom_field_id == @custom_field_estimated_id}.shift + @estimated_internal.nil? ? 0.to_f : @estimated_internal.value.to_f + end + + def estimated_internal=(value) + @estimated_internal.value = value.to_f if !@estimated_internal.nil? + end + end +end + + +Issue.send(:include, IssuePatch)