1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-31 05:01:13 +00:00

Changed Hook API to use a Manager class. #1296

This commit is contained in:
Eric Davis 2008-06-10 15:08:44 -07:00
parent fe22ef95a8
commit 04434cd6ef
7 changed files with 49 additions and 55 deletions

View File

@ -233,9 +233,8 @@ class IssuesController < ApplicationController
issue.start_date = params[:start_date] unless params[:start_date].blank? issue.start_date = params[:start_date] unless params[:start_date].blank?
issue.due_date = params[:due_date] unless params[:due_date].blank? issue.due_date = params[:due_date] unless params[:due_date].blank?
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank? issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
if Redmine::Plugin::Hook.hook_registered?(:issue_bulk_edit_save)
Redmine::Plugin::Hook.call_hook(:issue_bulk_edit_save, {:params => params, :issue => issue }) Redmine::Plugin::Hook::Manager.call_hook(:issue_bulk_edit_save, {:params => params, :issue => issue })
end
# Don't save any change to the issue if the user is not authorized to apply the requested status # Don't save any change to the issue if the user is not authorized to apply the requested status
if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save if (status.nil? || (issue.status.new_status_allowed_to?(status, current_role, issue.tracker) && issue.status = status)) && issue.save

View File

@ -87,7 +87,7 @@ module IssuesHelper
label = l(:label_attachment) label = l(:label_attachment)
end end
Redmine::Plugin::Hook.call_hook(:issues_helper_show_details, {:detail => detail, :label => label, :value => value, :old_value => old_value }) Redmine::Plugin::Hook::Manager.call_hook(:issues_helper_show_details, {:detail => detail, :label => label, :value => value, :old_value => old_value })
label ||= detail.prop_key label ||= detail.prop_key
value ||= detail.value value ||= detail.value

View File

@ -48,8 +48,6 @@
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
<% end %> <% end %>
<% if Redmine::Plugin::Hook.hook_registered?(:issue_edit) %> <%= Redmine::Plugin::Hook::Manager.call_hook(:issue_edit, {:project => @project, :issue => @issue, :form => f }) %>
<%= Redmine::Plugin::Hook.call_hook(:issue_edit, {:project => @project, :issue => @issue, :form => f }) %>
<% end %>
<%= wikitoolbar_for 'issue_description' %> <%= wikitoolbar_for 'issue_description' %>

View File

@ -38,9 +38,7 @@
<label><%= l(:field_done_ratio) %>: <label><%= l(:field_done_ratio) %>:
<%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label> <%= select_tag 'done_ratio', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></label>
</p> </p>
<% if Redmine::Plugin::Hook.hook_registered?(:issue_bulk_edit) %> <%= Redmine::Plugin::Hook::Manager.call_hook(:issue_bulk_edit, {:project => @project, :issue => @issues }) %>
<%= Redmine::Plugin::Hook.call_hook(:issue_bulk_edit, {:project => @project, :issue => @issues }) %>
<% end %>
</fieldset> </fieldset>
<fieldset><legend><%= l(:field_notes) %></legend> <fieldset><legend><%= l(:field_notes) %></legend>

View File

@ -53,9 +53,7 @@
<%end <%end
end %> end %>
</tr> </tr>
<% if Redmine::Plugin::Hook.hook_registered?(:issue_show) %> <%= Redmine::Plugin::Hook::Manager.call_hook(:issue_show, {:project => @project, :issue => @issue}) %>
<%= Redmine::Plugin::Hook.call_hook(:issue_show, {:project => @project, :issue => @issue}) %>
<% end %>
</table> </table>
<hr /> <hr />

View File

@ -9,9 +9,7 @@
<thead> <thead>
<th><%= l(:label_user) %></th> <th><%= l(:label_user) %></th>
<th><%= l(:label_role) %></th> <th><%= l(:label_role) %></th>
<% if Redmine::Plugin::Hook.hook_registered?(:project_member_list_header) %> <%= Redmine::Plugin::Hook::Manager.call_hook(:project_member_list_header, {:project => @project }) %>
<%= Redmine::Plugin::Hook.call_hook(:project_member_list_header, {:project => @project }) %>
<% end %>
<th style="width:15%"></th> <th style="width:15%"></th>
</thead> </thead>
<tbody> <tbody>
@ -27,9 +25,7 @@
<% end %> <% end %>
<% end %> <% end %>
</td> </td>
<% if Redmine::Plugin::Hook.hook_registered?(:project_member_list_column_three) %> <%= Redmine::Plugin::Hook::Manager.call_hook(:project_member_list_column_three, {:project => @project, :member => member }) %>
<%= Redmine::Plugin::Hook.call_hook(:project_member_list_column_three, {:project => @project, :member => member }) %>
<% end %>
<td align="center"> <td align="center">
<%= link_to_remote l(:button_delete), { :url => {:controller => 'members', :action => 'destroy', :id => member}, <%= link_to_remote l(:button_delete), { :url => {:controller => 'members', :action => 'destroy', :id => member},

View File

@ -118,7 +118,7 @@ module Redmine #:nodoc:
end end
def add_hook(hook_name, method) def add_hook(hook_name, method)
Redmine::Plugin::Hook.add_listener(hook_name, method) Redmine::Plugin::Hook::Manager.add_listener(hook_name, method)
end end
# Returns +true+ if the plugin can be configured. # Returns +true+ if the plugin can be configured.
@ -128,51 +128,56 @@ module Redmine #:nodoc:
# TODO: Doc # TODO: Doc
class Hook class Hook
class Manager
# Hooks and the procs added # Hooks and the procs added
@@hooks = { @@hooks = {
:issue_show => [], :issue_show => [],
:issue_edit => [], :issue_edit => [],
:issue_bulk_edit => [], :issue_bulk_edit => [],
:issue_bulk_edit_save => [], :issue_bulk_edit_save => [],
:issue_update => [], :issue_update => [],
:project_member_list_header => [], :project_member_list_header => [],
:project_member_list_column_three => [], :project_member_list_column_three => [],
:issues_helper_show_details => [] :issues_helper_show_details => []
} }
cattr_reader :hooks cattr_reader :hooks
class << self class << self
# TODO: Doc # TODO: Doc
def valid_hook?(hook_name) def valid_hook?(hook_name)
return @@hooks.has_key?(hook_name) return @@hooks.has_key?(hook_name)
end end
# TODO: Doc # TODO: Doc
def add_listener(hook_name, method) def add_listener(hook_name, method)
if valid_hook?(hook_name) if valid_hook?(hook_name)
@@hooks[hook_name.to_sym] << method @@hooks[hook_name.to_sym] << method
puts "Listener added for #{hook_name.to_s}" puts "Listener added for #{hook_name.to_s}"
end
end end
end
# TODO: Doc # TODO: Doc
def call_hook(hook_name, context = { }) def call_hook(hook_name, context = { })
response = '' response = ''
@@hooks[hook_name.to_sym].each do |method| @@hooks[hook_name.to_sym].each do |method|
response += method.call(context) response += method.call(context)
end
response
end end
response
end
# TODO: Doc # TODO: Doc
def hook_registered?(hook_name) def hook_registered?(hook_name)
return @@hooks[hook_name.to_sym].size > 0 return @@hooks[hook_name.to_sym].size > 0
end
end end
end end
# Default class for Hooks to subclass
class Base
end
end end
end end
end end