Skip to content

Commit

Permalink
create utils class and use it for retrieving information about contro…
Browse files Browse the repository at this point in the history
…llers, new informations in init.rb
  • Loading branch information
mszczytowski committed Jan 15, 2009
1 parent 5dac2d6 commit e42fc12
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
27 changes: 20 additions & 7 deletions init.rb
@@ -1,18 +1,31 @@
require 'redmine'

RAILS_DEFAULT_LOGGER.info 'Starting Charts plugin for RedMine'

require_dependency 'redmine_charts/date_format'
require_dependency 'redmine_charts/utils'

Redmine::Plugin.register :charts do
name 'Charts'
Redmine::Plugin.register :charts_plugin do
name 'Charts Plugin'
author 'Maciej Szczytowski'
description 'Charts plugin contains some useful project statistics.'
description 'Plugin for Redmine to show useful charts for all projects.'
url 'http://github.com/mszczytowski/redmine_charts/'
version '0.1.0'

controllers = %w{burndown groups hours deviation}.collect { |name| "charts_#{name}".to_sym }
# Minimum version of Redmine.

requires_redmine :version_or_higher => '0.8.0'

# Default settings for plugin.
# settings :default => {'list_size' => '5', 'precision' => '2'}, :partial => 'settings/timesheet_settings'

# Configuring permissions for plugin's controllers.

project_module :charts do
permission :view_charts, Hash[*(controllers.collect { |controller| [controller, :index] }.flatten)]
permission :view_charts, RedmineCharts::Utils.controllers_for_permissions, :require => :member
end

menu :project_menu, :charts, { :controller => controllers.first.to_s, :action => :index.to_s }, :caption => :charts_menu_label, :after => :new_issue, :param => :project_id

# Creating menu entry. It appears in project menu, after 'new_issue' entry.

menu :project_menu, :charts, { :controller => RedmineCharts::Utils.default_controller, :action => 'index' }, :caption => :charts_menu_label, :after => :new_issue, :param => :project_id
end
1 change: 0 additions & 1 deletion lib/redmine_charts/date_format.rb
Expand Up @@ -16,7 +16,6 @@ def format_date(format_in, column_name, diff_value)
"(DATE_FORMAT('#{format_in}', #{column_name}) + DATE_FORMAT('%Y', #{column_name}) - #{diff_value})"
end
when /postgres.*/i
print "MACIEK :D"
def format_date(format_in, column_name, diff_value)
case format_in
when :weeks
Expand Down
25 changes: 25 additions & 0 deletions lib/redmine_charts/utils.rb
@@ -0,0 +1,25 @@
module RedmineCharts
module Utils

@@controllers = %w{burndown groups hours deviation}.collect { |name| [name.to_sym, "charts_#{name}".to_sym] }

# Returns default controller name, which should be entry when user click 'charts' label in project menu.
# See init.rb.
def self.default_controller
@@controllers.first[1].to_s
end

# Returns array of controllers for builing permissions configuration.
# See init.rb.
def self.controllers_for_permissions
Hash[*(@@controllers.collect { |controller| [controller[1], :index] }.flatten)]
end

# Get block and call it with two parameters - controller path name and controller name.
# See routes.rb.
def self.controllers_for_routing &block
@@controllers.each { |controller| block.call(controller[0].to_s, controller[1].to_s) }
end

end
end
11 changes: 7 additions & 4 deletions routes.rb
@@ -1,4 +1,7 @@
connect 'projects/:project_id/charts/groups/:action', :controller => 'charts_groups'
connect 'projects/:project_id/charts/burndown/:action', :controller => 'charts_burndown'
connect 'projects/:project_id/charts/hours/:action', :controller => 'charts_hours'
connect 'projects/:project_id/charts/deviation/:action', :controller => 'charts_deviation'
require_dependency 'redmine_charts/utils'

# Configuring routing for plugin's controllers.

RedmineCharts::Utils.controllers_for_routing do |name, controller|
connect "projects/:project_id/charts/#{name}/:action", :controller => controller
end

0 comments on commit e42fc12

Please sign in to comment.