]> source.dussan.org Git - redmine.git/commitdiff
Changed Hook API to use a Manager class. #1296
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 10 Jun 2008 22:08:44 +0000 (15:08 -0700)
committerEric Davis <edavis@littlestreamsoftware.com>
Thu, 24 Jul 2008 04:01:43 +0000 (21:01 -0700)
app/controllers/issues_controller.rb
app/helpers/issues_helper.rb
app/views/issues/_form.rhtml
app/views/issues/bulk_edit.rhtml
app/views/issues/show.rhtml
app/views/projects/settings/_members.rhtml
lib/redmine/plugin.rb

index 75b0c794500c74c3090402653b0ec26a9b9b9114..7d36ce88d8194df1f51b0444101b51ff1ee1ad83 100644 (file)
@@ -233,9 +233,8 @@ class IssuesController < ApplicationController
         issue.start_date = params[:start_date] unless params[:start_date].blank?
         issue.due_date = params[:due_date] unless params[:due_date].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 })
-        end
+
+        Redmine::Plugin::Hook::Manager.call_hook(:issue_bulk_edit_save, {:params => params, :issue => issue })
 
         # 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
index 5b1330b6e2be89826eab6c9300adeda875284ab9..0099474243eb6fc2b185ace7578f7ef9c45a0649 100644 (file)
@@ -87,7 +87,7 @@ module IssuesHelper
       label = l(:label_attachment)
     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
     value ||= detail.value
index f933a7c357714e426e12590e692bfec3f726a1ad..cdff2e45c642fa2143c89dfbee9aa5f4a06504c2 100644 (file)
@@ -48,8 +48,6 @@
 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
 <% end %>
 
-<% if Redmine::Plugin::Hook.hook_registered?(:issue_edit) %>
-  <%= Redmine::Plugin::Hook.call_hook(:issue_edit, {:project => @project, :issue => @issue, :form => f }) %>
-<% end %>
+<%= Redmine::Plugin::Hook::Manager.call_hook(:issue_edit, {:project => @project, :issue => @issue, :form => f }) %>
 
 <%= wikitoolbar_for 'issue_description' %>
index 92a340a934ef1dae9ba08e2bb05432b776aaaa65..e001e0d871e9292c55d26a17a3bb4848d32c5f36 100644 (file)
@@ -38,9 +38,7 @@
 <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>
 </p>
-<% if Redmine::Plugin::Hook.hook_registered?(:issue_bulk_edit) %>
-  <%= Redmine::Plugin::Hook.call_hook(:issue_bulk_edit, {:project => @project, :issue => @issues }) %>
-<% end %>
+<%= Redmine::Plugin::Hook::Manager.call_hook(:issue_bulk_edit, {:project => @project, :issue => @issues }) %>
 </fieldset>
 
 <fieldset><legend><%= l(:field_notes) %></legend>
index f72ac6d2422581f1bb53df561e5c01e47d694fc0..88421862c21df62c1b4c974c284813ea2f22e38c 100644 (file)
@@ -53,9 +53,7 @@
  <%end
 end %>
 </tr>
-<% if Redmine::Plugin::Hook.hook_registered?(:issue_show) %>
-  <%= Redmine::Plugin::Hook.call_hook(:issue_show, {:project => @project, :issue => @issue}) %>
-<% end %>
+<%= Redmine::Plugin::Hook::Manager.call_hook(:issue_show, {:project => @project, :issue => @issue}) %>
        
 </table>
 <hr />
index 0ebe3285fe3ad0b5dec9fe09842bba31cbe3036f..7f894dfba0f47dea70b1d52fc869ef6472e1844c 100644 (file)
@@ -9,9 +9,7 @@
        <thead>
          <th><%= l(:label_user) %></th>
          <th><%= l(:label_role) %></th>
-          <% if Redmine::Plugin::Hook.hook_registered?(:project_member_list_header) %>
-          <%=  Redmine::Plugin::Hook.call_hook(:project_member_list_header, {:project => @project }) %>
-          <% end %>
+          <%= Redmine::Plugin::Hook::Manager.call_hook(:project_member_list_header, {:project => @project }) %>
          <th style="width:15%"></th>
        </thead>
        <tbody>
@@ -27,9 +25,7 @@
       <% end %>
     <% end %>
     </td>
-    <% if Redmine::Plugin::Hook.hook_registered?(:project_member_list_column_three) %>
-    <%=  Redmine::Plugin::Hook.call_hook(:project_member_list_column_three, {:project => @project, :member => member }) %>
-    <% end %>
+    <%= Redmine::Plugin::Hook::Manager.call_hook(:project_member_list_column_three, {:project => @project, :member => member }) %>
 
     <td align="center">
       <%= link_to_remote l(:button_delete), { :url => {:controller => 'members', :action => 'destroy', :id => member},                                              
index 3a0375bb13e9f44d9812bbb39c03889b0635f100..2366c49ff3c874f0537d5a91a92229f3cc2fe0b5 100644 (file)
@@ -118,7 +118,7 @@ module Redmine #:nodoc:
     end
     
     def add_hook(hook_name, method)
-      Redmine::Plugin::Hook.add_listener(hook_name, method)
+      Redmine::Plugin::Hook::Manager.add_listener(hook_name, method)
     end
 
     # Returns +true+ if the plugin can be configured.
@@ -128,51 +128,56 @@ module Redmine #:nodoc:
     
     # TODO: Doc
     class Hook
-      
-      # Hooks and the procs added
-      @@hooks = {
-        :issue_show => [],
-        :issue_edit => [],
-        :issue_bulk_edit => [],
-        :issue_bulk_edit_save => [],
-        :issue_update => [],
-        :project_member_list_header => [],
-        :project_member_list_column_three => [],
-         :issues_helper_show_details => []
-      }
+      class Manager
+        # Hooks and the procs added
+        @@hooks = {
+          :issue_show => [],
+          :issue_edit => [],
+          :issue_bulk_edit => [],
+          :issue_bulk_edit_save => [],
+          :issue_update => [],
+          :project_member_list_header => [],
+          :project_member_list_column_three => [],
+          :issues_helper_show_details => []
+        }
         
-      cattr_reader :hooks
+        cattr_reader :hooks
       
-      class << self
+        class << self
         
-        # TODO: Doc
-        def valid_hook?(hook_name)
-          return @@hooks.has_key?(hook_name)
-        end
+          # TODO: Doc
+          def valid_hook?(hook_name)
+            return @@hooks.has_key?(hook_name)
+          end
 
-        # TODO: Doc
-        def add_listener(hook_name, method)
-          if valid_hook?(hook_name)
-            @@hooks[hook_name.to_sym] << method
-            puts "Listener added for #{hook_name.to_s}"
+          # TODO: Doc
+          def add_listener(hook_name, method)
+            if valid_hook?(hook_name)
+              @@hooks[hook_name.to_sym] << method
+              puts "Listener added for #{hook_name.to_s}"
+            end
           end
-        end
         
-        # TODO: Doc
-        def call_hook(hook_name, context = { })
-          response = ''
-          @@hooks[hook_name.to_sym].each do |method|
-            response += method.call(context)
+          # TODO: Doc
+          def call_hook(hook_name, context = { })
+            response = ''
+            @@hooks[hook_name.to_sym].each do |method|
+              response += method.call(context)
+            end
+            response
           end
-          response
-        end
         
-        # TODO: Doc
-        def hook_registered?(hook_name)
-          return @@hooks[hook_name.to_sym].size > 0
+          # TODO: Doc
+          def hook_registered?(hook_name)
+            return @@hooks[hook_name.to_sym].size > 0
+          end
         end
       end
-      
+
+      # Default class for Hooks to subclass
+      class Base
+
+      end
     end
   end
 end