From 191221908d295a9e3cfd4a913d6ad89f946e9afa Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 11 Jun 2008 09:20:22 -0700 Subject: [PATCH] Added rdoc comments and using the Base class now --- lib/budget_issue_hook.rb | 60 +++++++++++++++++++++++++++----------- lib/budget_project_hook.rb | 34 +++++++-------------- lib/issue_patch.rb | 6 +++- lib/query_patch.rb | 13 +++++---- 4 files changed, 67 insertions(+), 46 deletions(-) diff --git a/lib/budget_issue_hook.rb b/lib/budget_issue_hook.rb index 1caed72..198903c 100644 --- a/lib/budget_issue_hook.rb +++ b/lib/budget_issue_hook.rb @@ -1,29 +1,33 @@ -class BudgetIssueHook - - # http://snippets.dzone.com/posts/show/1799 - def self.help - Helper.instance - end +# Hooks to attach to the Redmine Issues. They are attached in init.rb by the +# +add_hook+ method +class BudgetIssueHook < Redmine::Plugin::Hook::Base - class Helper - include Singleton - include ERB::Util - include ActionView::Helpers::TagHelper - include ActionView::Helpers::FormHelper - include ActionView::Helpers::FormTagHelper - include ActionView::Helpers::FormOptionsHelper - end - + # Renders the Deliverable subject + # + # Context: + # * :issue => Issue being rendered + # def self.issue_show(context = { }) data = "Deliverable :#{help.html_escape context[:issue].deliverable.subject unless context[:issue].deliverable.nil?}" return "#{data}" end + # Renders a select tag with all the Deliverables + # + # Context: + # * :form => Edit form + # * :project => Current project + # def self.issue_edit(context = { }) select = context[:form].select :deliverable_id, Deliverable.find_all_by_project_id(context[:project]).collect { |d| [d.subject, d.id] }, :include_blank => true return "

#{select}

" end + # Renders a select tag with all the Deliverables for the bulk edit page + # + # Context: + # * :project => Current project + # def self.issue_bulk_edit(context = { }) select = help.select_tag('deliverable_id', help.content_tag('option', GLoc.l(:label_no_change_option), :value => '') + @@ -33,13 +37,35 @@ class BudgetIssueHook return help.content_tag(:p, "") end + # Saves the Deliverable assignment to the issue + # + # Context: + # * :issue => Issue being saved + # * :params => HTML parameters + # def self.issue_bulk_edit_save(context = { }) - context[:issue].deliverable = Deliverable.find(context[:params][:deliverable_id]) unless context[:params][:deliverable_id].blank? + case true + + when context[:params][:deliverable_id].blank? + # Do nothing + when context[:params][:deliverable_id] == 'none' + # Unassign deliverable + context[:issue].deliverable = nil + else + context[:issue].deliverable = Deliverable.find(context[:params][:deliverable_id]) + end + return '' end - # TODO Later: Overwritting the caller is bad juju + # Deliverable changes for the journal use the Deliverable subject + # instead of the id + # + # Context: + # * :detail => Detail about the journal change + # def self.issue_helper_show_details(context = { }) + # TODO Later: Overwritting the caller is bad juju if context[:detail].prop_key == 'deliverable_id' d = Deliverable.find_by_id(context[:detail].value) context[:detail].value = d.subject unless d.nil? || d.subject.nil? diff --git a/lib/budget_project_hook.rb b/lib/budget_project_hook.rb index 02f8d63..7507f48 100644 --- a/lib/budget_project_hook.rb +++ b/lib/budget_project_hook.rb @@ -1,31 +1,19 @@ -class BudgetProjectHook - - # http://snippets.dzone.com/posts/show/1799 - def self.help - Helper.instance - end - - class Helper - include Singleton - include ActionView::Helpers::TagHelper - include ActionView::Helpers::UrlHelper - include ActionView::Helpers::FormHelper - include ActionView::Helpers::FormTagHelper - include ActionView::Helpers::FormOptionsHelper - include ActionView::Helpers::JavaScriptHelper - include ActionView::Helpers::PrototypeHelper - - include ActionController::UrlWriter - - def protect_against_forgery? - false - end - end +# Hooks to attach to the Redmine Projects. They are attached in init.rb by the +# +add_hook+ method +class BudgetProjectHook < Redmine::Plugin::Hook::Base + # Renders an additional table header to the membership setting + # + # Context: none def self.member_list_header(context ={ }) return "#{GLoc.l(:label_member_rate) }" end + # Renders an AJAX from to update the member's billing rate + # + # Context: + # * :member => Current Member record + # def self.member_list_column_three(context = { }) # Build a form_remote_tag by hand since this isn't in the scope of a controller diff --git a/lib/issue_patch.rb b/lib/issue_patch.rb index 7ccc4da..468db54 100644 --- a/lib/issue_patch.rb +++ b/lib/issue_patch.rb @@ -1,7 +1,9 @@ require_dependency 'issue' +# Patches Redmine's Issues dynamically. Adds a relationship +# Issue +belongs_to+ to Deliverable module IssuePatch - def self.included(base) + def self.included(base) # :nodoc: base.extend(ClassMethods) base.send(:include, InstanceMethods) @@ -36,6 +38,8 @@ module IssuePatch end module InstanceMethods + # Wraps the association to get the Deliverable subject. Needed for the + # Query and filtering def deliverable_subject unless self.deliverable.nil? return self.deliverable.subject diff --git a/lib/query_patch.rb b/lib/query_patch.rb index eda585a..b1a6e7b 100644 --- a/lib/query_patch.rb +++ b/lib/query_patch.rb @@ -1,7 +1,9 @@ require_dependency 'query' +# Patches Redmine's Queries dynamically, adding the Deliverable +# to the available query columns module QueryPatch - def self.included(base) + def self.included(base) # :nodoc: base.extend(ClassMethods) base.send(:include, InstanceMethods) @@ -18,20 +20,21 @@ module QueryPatch end module ClassMethods - def hello - puts 'hello' - end - + + # Setter for +available_columns+ that isn't provided by the core. def available_columns=(v) self.available_columns = (v) end + # Method to add a column to the +available_columns+ that isn't provided by the core. def add_available_column(column) self.available_columns << (column) end end module InstanceMethods + + # Wrapper around the +available_filters+ to add a new Deliverable filter def budget_available_filters @available_filters = redmine_available_filters