Adds .find and .all Plugin class methods.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2039 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
97252c26ee
commit
fefc6e6bec
|
@ -50,7 +50,7 @@ class AdminController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def plugins
|
def plugins
|
||||||
@plugins = Redmine::Plugin.registered_plugins.values.sort
|
@plugins = Redmine::Plugin.all
|
||||||
end
|
end
|
||||||
|
|
||||||
# Loads the default configuration
|
# Loads the default configuration
|
||||||
|
|
|
@ -45,14 +45,15 @@ class SettingsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def plugin
|
def plugin
|
||||||
plugin_id = params[:id].to_sym
|
@plugin = Redmine::Plugin.find(params[:id])
|
||||||
@plugin = Redmine::Plugin.registered_plugins[plugin_id]
|
|
||||||
if request.post?
|
if request.post?
|
||||||
Setting["plugin_#{plugin_id}"] = params[:settings]
|
Setting["plugin_#{@plugin.id}"] = params[:settings]
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'plugin', :id => params[:id]
|
redirect_to :action => 'plugin', :id => @plugin.id
|
||||||
end
|
end
|
||||||
@partial = @plugin.settings[:partial]
|
@partial = @plugin.settings[:partial]
|
||||||
@settings = Setting["plugin_#{plugin_id}"]
|
@settings = Setting["plugin_#{@plugin.id}"]
|
||||||
|
rescue Redmine::PluginNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,9 +75,9 @@ class Setting < ActiveRecord::Base
|
||||||
|
|
||||||
cattr_accessor :available_settings
|
cattr_accessor :available_settings
|
||||||
@@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
|
@@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
|
||||||
Redmine::Plugin.registered_plugins.each do |id, plugin|
|
Redmine::Plugin.all.each do |plugin|
|
||||||
next unless plugin.settings
|
next unless plugin.settings
|
||||||
@@available_settings["plugin_#{id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
|
@@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
|
||||||
end
|
end
|
||||||
|
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
module Redmine #:nodoc:
|
module Redmine #:nodoc:
|
||||||
|
|
||||||
|
class PluginNotFound < StandardError; end
|
||||||
|
|
||||||
# Base class for Redmine plugins.
|
# Base class for Redmine plugins.
|
||||||
# Plugins are registered using the <tt>register</tt> class method that acts as the public constructor.
|
# Plugins are registered using the <tt>register</tt> class method that acts as the public constructor.
|
||||||
#
|
#
|
||||||
|
@ -62,7 +64,17 @@ module Redmine #:nodoc:
|
||||||
def self.register(id, &block)
|
def self.register(id, &block)
|
||||||
p = new(id)
|
p = new(id)
|
||||||
p.instance_eval(&block)
|
p.instance_eval(&block)
|
||||||
Plugin.registered_plugins[id] = p
|
registered_plugins[id] = p
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns an array off all registered plugins
|
||||||
|
def self.all
|
||||||
|
registered_plugins.values.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
# Finds a plugin by its id
|
||||||
|
def self.find(id)
|
||||||
|
registered_plugins[id.to_sym] || raise(PluginNotFound)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(id)
|
def initialize(id)
|
||||||
|
|
Loading…
Reference in New Issue