##// END OF EJS Templates
Added custom fields marked as "For all projects" to the csv export of the cross project issue list....
Added custom fields marked as "For all projects" to the csv export of the cross project issue list. git-svn-id: http://redmine.rubyforge.org/svn/trunk@933 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r892:e4ce95c3a184
r920:c383486d711d
Show More
setting.rb
119 lines | 3.6 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 # redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Setting < ActiveRecord::Base
Jean-Philippe Lang
Added a couple of new formats for the 'date format' setting....
r892 DATE_FORMATS = [
'%Y-%m-%d',
'%d/%m/%Y',
'%d.%m.%Y',
'%d-%m-%Y',
'%m/%d/%Y',
'%d %b %Y',
'%d %B %Y',
'%b %d, %Y',
'%B %d, %Y'
]
TIME_FORMATS = [
'%H:%M',
'%I:%M %p'
]
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 cattr_accessor :available_settings
@@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
Jean-Philippe Lang
Basic plugin support....
r741 Redmine::Plugin.registered_plugins.each do |id, plugin|
next unless plugin.settings
@@available_settings["plugin_#{id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
end
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 validates_uniqueness_of :name
validates_inclusion_of :name, :in => @@available_settings.keys
validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674
# Hash used to cache setting values
@cached_settings = {}
@cached_cleared_on = Time.now
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717
def value
v = read_attribute(:value)
# Unserialize serialized settings
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
v
end
Jean-Philippe Lang
Fixed: Oracle error when saving serialized setting (eg. mail notifications)...
r731 def value=(v)
Jean-Philippe Lang
Fixed setting value serialization....
r733 v = v.to_yaml if v && @@available_settings[name]['serialized']
Jean-Philippe Lang
Fixed: Oracle error when saving serialized setting (eg. mail notifications)...
r731 write_attribute(:value, v)
end
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 # Returns the value of the setting named name
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 def self.[](name)
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717 v = @cached_settings[name]
v ? v : (@cached_settings[name] = find_or_default(name).value)
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 end
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717 def self.[]=(name, v)
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 setting = find_or_default(name)
Jean-Philippe Lang
Mail notification options restored (default is: issue_added and issue_updated)....
r717 setting.value = (v ? v : "")
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 @cached_settings[name] = nil
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 setting.save
setting.value
end
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674 # Defines getter and setter for each setting
# Then setting values can be read using: Setting.some_setting_name
# or set using Setting.some_setting_name = "some value"
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 @@available_settings.each do |name, params|
src = <<-END_SRC
def self.#{name}
self[:#{name}]
end
def self.#{name}?
Jean-Philippe Lang
Added autologin feature (disabled by default)....
r511 self[:#{name}].to_i > 0
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 end
def self.#{name}=(value)
Jean-Philippe Lang
* fixed a variable name error in Setting...
r210 self[:#{name}] = value
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 end
END_SRC
class_eval src, __FILE__, __LINE__
end
Jean-Philippe Lang
Added cache for application settings (Setting model)....
r674
# Checks if settings have changed since the values were read
# and clears the cache hash if it's the case
# Called once per request
def self.check_cache
settings_updated_on = Setting.maximum(:updated_on)
if settings_updated_on && @cached_cleared_on <= settings_updated_on
@cached_settings.clear
@cached_cleared_on = Time.now
logger.info "Settings cache cleared." if logger
end
end
private
# Returns the Setting instance for the setting named name
# (record found in database or new record with default value)
def self.find_or_default(name)
name = name.to_s
raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)
setting = find_by_name(name)
setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name
end
Jean-Philippe Lang
settings are now stored in the database (config_custom.rb no more used) and editable through the application in: Admin -> Settings...
r164 end