This document discusses Redmine, an open source project management tool. It describes Redmine plugins that can be used to add functionality, how to generate a plugin, and how to create a ViewListener plugin that will display additional information on user account pages by hooking into Redmine's view rendering system. The ViewListener is implemented in a Ruby class that is registered as a plugin.
21. ViewListener
vender/plugins/redmine_account_tichets/lib/account_listener.rb
class AccountListener < Redmine::Hook::ViewListener
def view_account_left_bottom(context) :view_account_left_bottom
user = context[:user]
assigned_issues = Issue.visible.open.?nd(:all,
:conditions => {:assigned_to_id => User.current.id})
reported_issues = Issue.visible.?nd(:all,
:conditions => {:author_id => User.current.id })
html = ''
html << '<h3>Tickets</h3><ul>'
html << '<li>assigned: ' + assigned_issues.size.to_s + ' Tickets</li>'
html << '<li>reported: ' + reported_issues.size.to_s + ' Tickets</li>'
html << '</ul>'
html
end
end
-[ ]-
2010 4 29 21
22. ViewListener
vender/plugins/redmine_account_tichets/init.rb
require 'redmine'
require 'account_listener' #
Redmine::Plugin.register :redmine_account_tichets do
name 'Redmine Account Tichets plugin'
author 'Author name'
description 'This is a plugin for Redmine'
version '0.0.1'
end
-[ ]-
2010 4 29 22
24. Redmine::Hook::Listener
class Listener
include Singleton
include Redmine::I18n
# Registers the listener
def self.inherited(child)
Redmine::Hook.add_listener(child)
super
end
end
-[ ]-
2010 4 29 24