fixed 谭 domain bug in development environment.
This commit is contained in:
parent
6198c3565b
commit
52fe99d71c
|
@ -1500,7 +1500,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_dynamic_nav
|
def render_dynamic_nav
|
||||||
home_link = link_to l(:field_homepage), "http://"+Setting.forge_domain+":3000"
|
home_link = link_to l(:field_homepage), Setting.forge_domain.nil? ? nil : "http://"+Setting.forge_domain+":3000"
|
||||||
course_all_course_link = link_to l(:label_course_all), {:controller => 'projects', :action => 'course', :project_type => 1,}
|
course_all_course_link = link_to l(:label_course_all), {:controller => 'projects', :action => 'course', :project_type => 1,}
|
||||||
course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher'}
|
course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher'}
|
||||||
courses_link = link_to l(:label_course_practice), {:host=>Setting.course_domain}
|
courses_link = link_to l(:label_course_practice), {:host=>Setting.course_domain}
|
||||||
|
|
|
@ -1,178 +1,185 @@
|
||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Setting < ActiveRecord::Base
|
class Setting < ActiveRecord::Base
|
||||||
|
|
||||||
DATE_FORMATS = [
|
DATE_FORMATS = [
|
||||||
'%Y-%m-%d',
|
'%Y-%m-%d',
|
||||||
'%d/%m/%Y',
|
'%d/%m/%Y',
|
||||||
'%d.%m.%Y',
|
'%d.%m.%Y',
|
||||||
'%d-%m-%Y',
|
'%d-%m-%Y',
|
||||||
'%m/%d/%Y',
|
'%m/%d/%Y',
|
||||||
'%d %b %Y',
|
'%d %b %Y',
|
||||||
'%d %B %Y',
|
'%d %B %Y',
|
||||||
'%b %d, %Y',
|
'%b %d, %Y',
|
||||||
'%B %d, %Y'
|
'%B %d, %Y'
|
||||||
]
|
]
|
||||||
|
|
||||||
TIME_FORMATS = [
|
TIME_FORMATS = [
|
||||||
'%H:%M',
|
'%H:%M',
|
||||||
'%I:%M %p'
|
'%I:%M %p'
|
||||||
]
|
]
|
||||||
|
|
||||||
ENCODINGS = %w(US-ASCII
|
ENCODINGS = %w(US-ASCII
|
||||||
windows-1250
|
windows-1250
|
||||||
windows-1251
|
windows-1251
|
||||||
windows-1252
|
windows-1252
|
||||||
windows-1253
|
windows-1253
|
||||||
windows-1254
|
windows-1254
|
||||||
windows-1255
|
windows-1255
|
||||||
windows-1256
|
windows-1256
|
||||||
windows-1257
|
windows-1257
|
||||||
windows-1258
|
windows-1258
|
||||||
windows-31j
|
windows-31j
|
||||||
ISO-2022-JP
|
ISO-2022-JP
|
||||||
ISO-2022-KR
|
ISO-2022-KR
|
||||||
ISO-8859-1
|
ISO-8859-1
|
||||||
ISO-8859-2
|
ISO-8859-2
|
||||||
ISO-8859-3
|
ISO-8859-3
|
||||||
ISO-8859-4
|
ISO-8859-4
|
||||||
ISO-8859-5
|
ISO-8859-5
|
||||||
ISO-8859-6
|
ISO-8859-6
|
||||||
ISO-8859-7
|
ISO-8859-7
|
||||||
ISO-8859-8
|
ISO-8859-8
|
||||||
ISO-8859-9
|
ISO-8859-9
|
||||||
ISO-8859-13
|
ISO-8859-13
|
||||||
ISO-8859-15
|
ISO-8859-15
|
||||||
KOI8-R
|
KOI8-R
|
||||||
UTF-8
|
UTF-8
|
||||||
UTF-16
|
UTF-16
|
||||||
UTF-16BE
|
UTF-16BE
|
||||||
UTF-16LE
|
UTF-16LE
|
||||||
EUC-JP
|
EUC-JP
|
||||||
Shift_JIS
|
Shift_JIS
|
||||||
CP932
|
CP932
|
||||||
GB18030
|
GB18030
|
||||||
GBK
|
GBK
|
||||||
ISCII91
|
ISCII91
|
||||||
EUC-KR
|
EUC-KR
|
||||||
Big5
|
Big5
|
||||||
Big5-HKSCS
|
Big5-HKSCS
|
||||||
TIS-620)
|
TIS-620)
|
||||||
|
|
||||||
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.all.each do |plugin|
|
Redmine::Plugin.all.each do |plugin|
|
||||||
next unless plugin.settings
|
next unless plugin.settings
|
||||||
@@available_settings["plugin_#{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
|
||||||
validates_inclusion_of :name, :in => @@available_settings.keys
|
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' }
|
validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
|
||||||
|
|
||||||
# Hash used to cache setting values
|
# Hash used to cache setting values
|
||||||
@cached_settings = {}
|
@cached_settings = {}
|
||||||
@cached_cleared_on = Time.now
|
@cached_cleared_on = Time.now
|
||||||
|
|
||||||
def value
|
def value
|
||||||
v = read_attribute(:value)
|
v = read_attribute(:value)
|
||||||
# Unserialize serialized settings
|
# Unserialize serialized settings
|
||||||
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
|
v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
|
||||||
v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
|
v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
def value=(v)
|
def value=(v)
|
||||||
v = v.to_yaml if v && @@available_settings[name] && @@available_settings[name]['serialized']
|
v = v.to_yaml if v && @@available_settings[name] && @@available_settings[name]['serialized']
|
||||||
write_attribute(:value, v.to_s)
|
write_attribute(:value, v.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the value of the setting named name
|
# Returns the value of the setting named name
|
||||||
def self.[](name)
|
def self.[](name)
|
||||||
v = @cached_settings[name]
|
v = @cached_settings[name]
|
||||||
v ? v : (@cached_settings[name] = find_or_default(name).value)
|
v ? v : (@cached_settings[name] = find_or_default(name).value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.[]=(name, v)
|
def self.[]=(name, v)
|
||||||
setting = find_or_default(name)
|
setting = find_or_default(name)
|
||||||
setting.value = (v ? v : "")
|
setting.value = (v ? v : "")
|
||||||
@cached_settings[name] = nil
|
@cached_settings[name] = nil
|
||||||
setting.save
|
setting.save
|
||||||
setting.value
|
setting.value
|
||||||
end
|
end
|
||||||
|
|
||||||
# Defines getter and setter for each setting
|
# Defines getter and setter for each setting
|
||||||
# Then setting values can be read using: Setting.some_setting_name
|
# Then setting values can be read using: Setting.some_setting_name
|
||||||
# or set using Setting.some_setting_name = "some value"
|
# or set using Setting.some_setting_name = "some value"
|
||||||
@@available_settings.each do |name, params|
|
@@available_settings.each do |name, params|
|
||||||
src = <<-END_SRC
|
src = <<-END_SRC
|
||||||
def self.#{name}
|
def self.#{name}
|
||||||
self[:#{name}]
|
self[:#{name}]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.#{name}?
|
def self.#{name}?
|
||||||
self[:#{name}].to_i > 0
|
self[:#{name}].to_i > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.#{name}=(value)
|
def self.#{name}=(value)
|
||||||
self[:#{name}] = value
|
self[:#{name}] = value
|
||||||
end
|
end
|
||||||
END_SRC
|
END_SRC
|
||||||
class_eval src, __FILE__, __LINE__
|
class_eval src, __FILE__, __LINE__
|
||||||
end
|
end
|
||||||
|
|
||||||
# Helper that returns an array based on per_page_options setting
|
# Helper that returns an array based on per_page_options setting
|
||||||
def self.per_page_options_array
|
def self.per_page_options_array
|
||||||
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
|
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.openid?
|
def self.openid?
|
||||||
Object.const_defined?(:OpenID) && self[:openid].to_i > 0
|
Object.const_defined?(:OpenID) && self[:openid].to_i > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if settings have changed since the values were read
|
# Checks if settings have changed since the values were read
|
||||||
# and clears the cache hash if it's the case
|
# and clears the cache hash if it's the case
|
||||||
# Called once per request
|
# Called once per request
|
||||||
def self.check_cache
|
def self.check_cache
|
||||||
settings_updated_on = Setting.maximum(:updated_on)
|
settings_updated_on = Setting.maximum(:updated_on)
|
||||||
if settings_updated_on && @cached_cleared_on <= settings_updated_on
|
if settings_updated_on && @cached_cleared_on <= settings_updated_on
|
||||||
clear_cache
|
clear_cache
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clears the settings cache
|
# Clears the settings cache
|
||||||
def self.clear_cache
|
def self.clear_cache
|
||||||
@cached_settings.clear
|
@cached_settings.clear
|
||||||
@cached_cleared_on = Time.now
|
@cached_cleared_on = Time.now
|
||||||
logger.info "Settings cache cleared." if logger
|
logger.info "Settings cache cleared." if logger
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
# fixed domain url in development. tantantan's bug
|
||||||
# Returns the Setting instance for the setting named name
|
if Rails.env.development?
|
||||||
# (record found in database or new record with default value)
|
methods.map do |m|
|
||||||
def self.find_or_default(name)
|
define_singleton_method m do; nil; end if m.to_s =~ /([a-zA-Z]+_domain)$/
|
||||||
name = name.to_s
|
end
|
||||||
raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)
|
end
|
||||||
setting = find_by_name(name)
|
|
||||||
unless setting
|
private
|
||||||
setting = new(:name => name)
|
# Returns the Setting instance for the setting named name
|
||||||
setting.value = @@available_settings[name]['default']
|
# (record found in database or new record with default value)
|
||||||
end
|
def self.find_or_default(name)
|
||||||
setting
|
name = name.to_s
|
||||||
end
|
raise "There's no setting named #{name}" unless @@available_settings.has_key?(name)
|
||||||
end
|
setting = find_by_name(name)
|
||||||
|
unless setting
|
||||||
|
setting = new(:name => name)
|
||||||
|
setting.value = @@available_settings[name]['default']
|
||||||
|
end
|
||||||
|
setting
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue