fix get enable_manually_sort nil error

This commit is contained in:
chiu 2024-10-17 03:02:40 +00:00
parent e328e1eb12
commit 6e2a4ac3e9
1 changed files with 38 additions and 35 deletions

View File

@ -1,4 +1,6 @@
module EventNewsHelper module EventNewsHelper
extend self
def data_to_human_type(a,set_tag_ids=nil) def data_to_human_type(a,set_tag_ids=nil)
statuses = a.statuses_with_classname.collect do |status| statuses = a.statuses_with_classname.collect do |status|
{ {
@ -88,7 +90,7 @@ module EventNewsHelper
sort_maps = {event_date: :asc, is_top: :desc, postdate: :asc, id: :asc} sort_maps = {event_date: :asc, is_top: :desc, postdate: :asc, id: :asc}
else else
sort_maps = {is_top: :desc} sort_maps = {is_top: :desc}
if EventNewsHelper.is_postdate_sort_first if is_postdate_sort_first
sort_maps = sort_maps.merge({postdate: :desc, event_date: :desc, id: :desc}) sort_maps = sort_maps.merge({postdate: :desc, event_date: :desc, id: :desc})
else else
sort_maps = sort_maps.merge({event_date: :desc, postdate: :desc, id: :desc}) sort_maps = sort_maps.merge({event_date: :desc, postdate: :desc, id: :desc})
@ -234,8 +236,7 @@ module EventNewsHelper
end end
def sort_event_news(event_news_list) def sort_event_news(event_news_list)
enable_manually_sort = enable_manually_sort if @show_today_data_first || !is_postdate_sort_first
if @show_today_data_first || !EventNewsHelper.is_postdate_sort_first
if enable_manually_sort if enable_manually_sort
event_news_list = event_news_list.sort_by { |event_news| event_news_list = event_news_list.sort_by { |event_news|
tmp1 = event_news["event_date"].blank? tmp1 = event_news["event_date"].blank?
@ -551,41 +552,43 @@ module EventNewsHelper
</div> </div>
</div>").html_safe </div>").html_safe
end end
class << self
def complementaryColor(my_hex) def complementaryColor(my_hex)
if my_hex[0] == '#' if my_hex[0] == '#'
my_hex = my_hex[1..-1] my_hex = my_hex[1..-1]
end
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
comp = rgb.map{|a| (255 - a.to_i(16)).to_s(16).rjust(2,'0')}
'#'+comp.join
end end
def lighten_color(my_hex,percent) rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
if my_hex[0] == '#' comp = rgb.map{|a| (255 - a.to_i(16)).to_s(16).rjust(2,'0')}
my_hex = my_hex[1..-1] '#'+comp.join
end end
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
comp = rgb.collect do |a| def lighten_color(my_hex,percent)
tmp = a.to_i(16)*(1+percent/100.0) if my_hex[0] == '#'
tmp = 255 if tmp>255 my_hex = my_hex[1..-1]
tmp = 0 if tmp < 0
tmp.to_i.to_s(16).rjust(2,'0')
end
'#'+comp.join
end end
def enable_manually_sort rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash comp = rgb.collect do |a|
OrbitHelper::SharedHash['event_news_mod'][:enable_manually_sort] tmp = a.to_i(16)*(1+percent/100.0)
else tmp = 255 if tmp>255
EventNewsSetting.first.enable_manually_sort rescue false tmp = 0 if tmp < 0
end tmp.to_i.to_s(16).rjust(2,'0')
end end
def is_postdate_sort_first '#'+comp.join
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash end
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first]
else def enable_manually_sort
EventNewsSetting.first.is_postdate_sort_first rescue false if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
end OrbitHelper::SharedHash['event_news_mod'][:enable_manually_sort]
else
EventNewsSetting.first.enable_manually_sort rescue false
end
end
def is_postdate_sort_first
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first]
else
EventNewsSetting.first.is_postdate_sort_first rescue false
end end
end end
end end