accelerate!

This commit is contained in:
BoHung Chiu 2021-10-10 17:35:14 +08:00
parent 0b3084bcd1
commit a8c015f3e5
1 changed files with 25 additions and 27 deletions

View File

@ -171,37 +171,35 @@ class AnnouncementsController < ApplicationController
end
cats = cats.uniq
tags = tags.uniq
tags_translations = tags.map{|tag_id|
if tag_id == "all"
t = I18n.t(:all)
else
t = Tag.find(tag_id).name rescue ""
end
[tag_id,t]
}.to_h
cats_translations = cats.map{|cat_id|
if cat_id == "all"
t = I18n.t(:all)
else
t = Category.find(cat_id).title rescue ""
end
[cat_id,t]
}.to_h
tags_translations = Tag.where(:id.in=>tags).map{|t| [t.id.to_s,t.name]}
if tags.include?("all")
tags_translations = ["all",I18n.t(:all)] + tags_translations
end
tags_translations = tags_translations.to_h
cats_translations = Category.where(:id.in=>cats).map{|c| [c.id.to_s,c.title]}
if cats.include?("all")
cats_translations = ["all",I18n.t(:all)] + cats_translations
end
cats_translations = cats_translations.to_h
cats_relations = cats_translations.map{|cat_id,t|
if cat_id == "all"
t = "all"
end
[cat_id,t]
}.to_h
home_page = Page.first
page = nil
home_page = subpart.page_part.page rescue Page.first
page_url = (subpart.get_read_more_page_url rescue nil)
locale = I18n.locale.to_s
if home_page.respond_to?(:find_page)
page = home_page.find_page(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil
page = home_page.find_page(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil?
else
page = Page.where(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil
page = Page.where(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil?
if page_url.nil?
page = nil
if home_page.respond_to?(:find_page)
page = home_page.find_page(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil
page = home_page.find_page(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil?
else
page = Page.where(:page_id=> subpart.read_more_page_id,:enabled_for=>locale).first rescue nil
page = Page.where(:module=>"announcement",:enabled_for=>locale).first rescue nil if page.nil?
end
page_url = page.get_url
end
all_cats = cats.dup
all_cats.delete "all"
@ -219,7 +217,7 @@ class AnnouncementsController < ApplicationController
"<div style=\"clear: both;\"></div>" +
"<ul class=\"nav_tabs_filter\">" +
(use_tag ? tags.map.with_index{|tag,i|
read_more_url = "/#{locale + page.url}" rescue ""
read_more_url = "/#{locale + page_url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>(tag == 'all' ? all_tags : [tag])}.to_param if read_more_url != ""
read_more_text = I18n.t("announcement.more")
if tag != "all"
@ -231,7 +229,7 @@ class AnnouncementsController < ApplicationController
end
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" #{(tag == 'all' && @all_setting_option == 0) ? "data-count_limit=\"#{max_all_count}\"" : ''} data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-tags=\"#{tag}\">#{tags_translations[tag]}</li>"
}.join("") : cats.map.with_index{|cat,i|
read_more_url = "/#{locale + page.url}" rescue ""
read_more_url = "/#{locale + page_url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != ""
read_more_text = I18n.t("announcement.more")
if cat != "all"
@ -374,7 +372,7 @@ class AnnouncementsController < ApplicationController
"
end
if @tab_option == 0
read_more_url = "/#{locale + page.url}" rescue ""
read_more_url = "/#{locale + page_url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>all_cats,"tags"=>all_tags}.to_param if read_more_url != ""
extra_after_html += "
<script>