From de4349cad861029b30e010d319bc0e197e2e07f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Kolsj=C3=B6?= Date: Sun, 17 Jan 2010 15:51:51 +0100 Subject: [PATCH] Adding support for keeping points synked if you have a custom field named "Points" on the issues. --- README.rdoc | 4 ++++ app/models/item.rb | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index 88aecb86c2..c8f5918362 100644 --- a/README.rdoc +++ b/README.rdoc @@ -12,6 +12,10 @@ A scrum/agile tool. Useful for product planning, sprint planning, and daily stan You will need to enable the Backlogs module per project via Settings > Modules. Also, make check that the right roles have permission to use the module by going to Administration > Roles and Permissions > Permissions Report. += Points sync + +If you have a custom field called "Points" on the issues, that value will be kept in sync with the corresponding Backlog issue points. + = Chart Data Generator You may schedule a cron job to run the rake task named redmine:backlogs_plugin:generate_chart_data. I recommend you run it a few minutes after midnight to ensure that your backlogs have data everyday even when no user views the charts. diff --git a/app/models/item.rb b/app/models/item.rb index b2d4d7584d..07f8cfd52e 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -4,6 +4,8 @@ class Item < ActiveRecord::Base belongs_to :backlog acts_as_list :scope => 'items.backlog_id=#{backlog_id} AND items.parent_id=#{parent_id}' acts_as_tree :order => "items.position ASC, created_at ASC" + + after_save :update_issue_points def append_comment(user, comment) journal = issue.init_journal(User.current, @notes) @@ -99,14 +101,19 @@ class Item < ActiveRecord::Base find_by_issue_id(issue.id).destroy end + def update_issue_points + Item.custom_points(issue).update_attribute(:value, points) if Item.custom_points(issue) + end + def self.update_from_issue(issue) backlog = Backlog.find_by_version_id(issue.fixed_version_id) item = find_by_issue_id(issue.id) || Item.new() item.issue_id = issue.id item.backlog_id = (backlog.nil? ? 0 : backlog.id) - item.save - end - + item.points = custom_points(issue).value if custom_points(issue) + item.save + end + def determine_new_position(params) if params[:prev]=="" || params[:prev].nil? 1 @@ -120,4 +127,10 @@ class Item < ActiveRecord::Base insert_at determine_new_position(params) end + private + + def self.custom_points(issue) + issue.custom_values.to_a.find { |value| value.custom_field.name == "Points" } + end + end