Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create utils class and use it for retrieving information about contro…
…llers, new informations in init.rb
- Loading branch information
1 parent
5dac2d6
commit e42fc12
Showing
4 changed files
with
52 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |