-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop the custom field for user pain, it's now computed. Added a sorta…
…ble column in issue list.
- Loading branch information
Showing
6 changed files
with
97 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
field_user_pain: User Pain | ||
text_user_pain: User Pain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
field_user_pain: User Pain | ||
text_user_pain: User Pain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require_dependency 'issue' | ||
|
||
module RedmineUserPain | ||
# Patches Redmine's Issues dynamically. Adds a +after_save+ filter. | ||
module IssuePatch | ||
def self.included(base) # :nodoc: | ||
base.send(:include, InstanceMethods) | ||
end | ||
|
||
module InstanceMethods | ||
def user_pain | ||
# get the last custom field | ||
likelihood = CustomField.find_by_name("Likelihood") | ||
likelihood_values_length = likelihood['possible_values'].length | ||
pain = 1 | ||
|
||
# add likelihood value to total pain | ||
self.custom_values.each do |x| | ||
if x.custom_field_id == likelihood.id | ||
pain *= likelihood_values_length - likelihood['possible_values'].index(x.value) | ||
end | ||
end | ||
|
||
tracker_pain = 0 | ||
# get enabled tracker for the current project | ||
@project.trackers.each do |t| | ||
if self.tracker_id == t.id | ||
pain *= @project.trackers.length - tracker_pain | ||
end | ||
tracker_pain += 1 | ||
end | ||
|
||
# add type value to total pain | ||
pain *= IssuePriority.all.length - (IssuePriority.find_by_id(self.priority_id).position - 1) | ||
|
||
max_pain = @project.trackers.length * IssuePriority.all.length * likelihood_values_length | ||
return 100 * pain / max_pain | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
Issue.send(:include, RedmineUserPain::IssuePatch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require_dependency 'query' | ||
|
||
module QueryPatch | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
|
||
# Same as typing in the class | ||
base.class_eval do | ||
unloadable # Send unloadable so it will not be unloaded in development | ||
base.add_available_column(QueryColumn.new(:user_pain, { | ||
:sortable => true | ||
})) | ||
|
||
alias_method :redmine_available_filters, :available_filters | ||
end | ||
|
||
end | ||
|
||
module ClassMethods | ||
def available_columns=(v) | ||
self.available_columns = (v) | ||
end | ||
|
||
def add_available_column(column) | ||
self.available_columns << (column) | ||
end | ||
end | ||
|
||
end | ||
|
||
# Add module to Query | ||
Query.send(:include, QueryPatch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Hooks to attach to the Redmine Issues. | ||
class BudgetIssueHook < Redmine::Hook::ViewListener | ||
|
||
# Renders the Deliverable subject | ||
# | ||
# Context: | ||
# * :issue => Issue being rendered | ||
# | ||
def view_issues_show_details_bottom(context = { }) | ||
data = "<td><b>#{l(:user_pain)}:</b></td><td>#{context[:issue].user_pain}</td>" | ||
return "<tr>#{data}<td></td></tr>" | ||
end | ||
|
||
end |