Skip to content

Commit

Permalink
setting to chooze custom field for time limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ASGAlex committed Sep 18, 2023
1 parent 6ef0724 commit fdf5d21
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/views/settings/_limit_by_estimation.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%
default = Setting.available_settings[SETTINGS_NAME.to_s]['default']
%>
<table>
<tbody>

<tr>
<th align="right"><%= t 'use_custom_field' %></th>
<td colspan="2">
<%=check_box_tag("settings[estimated_field_use]",1, settings['estimated_field_use']) %>
</td>
</tr>

<tr>
<th align="right"><%= t 'estimation_limit_custom_field' %></th>
<td colspan="2">
<%= select_tag("settings[estimated_field]",
options_from_collection_for_select(IssueCustomField.where(field_format: 'float').all, "id", "name", settings['estimated_field'])) %>
</td>
</tr>
</tbody>
</table>
31 changes: 31 additions & 0 deletions lib/issue_patch.rb
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit fdf5d21

Please sign in to comment.