Only one parser for front end
Separate site map for i18n
This commit is contained in:
1 parent
f1c628f2d6
commit
fcbba6660b
20 files changed
+445
-168
No files matched your search
@@ -1,8 +1,8 @@
|
||||
class Admin::SitesController < ApplicationController
|
||||
|
||||
layout "new_admin"
|
||||
before_filter :authenticate_user!, :except => [:sitemap_frontend]
|
||||
before_filter :is_admin?, :except => [:sitemap_frontend]
|
||||
before_filter :authenticate_user!
|
||||
before_filter :is_admin?
|
||||
before_filter :get_site
|
||||
|
||||
# def index
|
||||
@@ -31,18 +31,13 @@ class Admin::SitesController < ApplicationController
|
||||
@items = get_homepage.children rescue []
|
||||
end
|
||||
|
||||
def sitemap_frontend
|
||||
@items = get_homepage.children.excludes(sitemap_enabled: false) rescue []
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def sitemap_toggle
|
||||
@item = Item.find(params[:id])
|
||||
@item.sitemap_enabled = !@item.sitemap_enabled
|
||||
@item.sitemap_enabled[params[:temp_locale]] = (!@item.show_in_sitemap_for(params[:temp_locale])).to_s
|
||||
@item.save
|
||||
if params[:parent]
|
||||
@item.children.each do |child|
|
||||
child.sitemap_enabled = @item.sitemap_enabled
|
||||
child.sitemap_enabled[params[:temp_locale]] = @item.sitemap_enabled[params[:temp_locale]].to_s
|
||||
child.save
|
||||
end
|
||||
end
|
||||
|
||||
@@ -119,7 +119,7 @@ class ApplicationController < ActionController::Base
|
||||
def render_page
|
||||
if @item
|
||||
respond_to do |format|
|
||||
format.html { render :text => parse_page_noko(@item), :layout => 'page_layout' }
|
||||
format.html { render :text => parse_page_content(@item), :layout => 'page_layout' }
|
||||
format.rss { render_main_rss }
|
||||
end
|
||||
else
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
class FrontController < ApplicationController
|
||||
|
||||
layout false
|
||||
|
||||
def show_banner
|
||||
@ad_banner = AdBanner.find(params[:id]) rescue nil
|
||||
end
|
||||
|
||||
def show_footer
|
||||
render :text => @site.footer
|
||||
end
|
||||
|
||||
def show_menu
|
||||
page = Page.find(params[:id]) rescue nil
|
||||
render :text => menu_level(Page.root, page, 1, page.design.layout.menu) if page
|
||||
end
|
||||
|
||||
def show_site_sub_menu
|
||||
render :text => @site.sub_menu
|
||||
end
|
||||
|
||||
def show_sitemap
|
||||
@items = get_homepage.children.excludes(sitemap_enabled: false) rescue []
|
||||
end
|
||||
|
||||
def show_page_sub_menu
|
||||
@menu_page = Page.find(params[:menu_page_id]) rescue nil
|
||||
@page_id = params[:page_id]
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def menu_level(page, current_page, current, menu)
|
||||
res = ''
|
||||
if page.visible_children.size > 0
|
||||
res << "<ul class='"
|
||||
res << menu.values["class_#{current}"] rescue nil
|
||||
res << "'>"
|
||||
i = nil
|
||||
i = 1 if menu.values["li_incremental_#{current}"]
|
||||
children = current == 1 ? page.visible_children.reverse : page.visible_children
|
||||
children.each do |child|
|
||||
res << menu_li(child, current_page, current, menu, i)
|
||||
i += 1 if i
|
||||
end
|
||||
if menu.values['home'] && current == 1
|
||||
res << menu_li(page, current_page, current, menu, i)
|
||||
end
|
||||
res << "</ul>"
|
||||
end
|
||||
res
|
||||
end
|
||||
|
||||
def menu_li(page, current_page, current, menu, i)
|
||||
res = "<li class='"
|
||||
res << menu.values["li_class_#{current}"] rescue nil
|
||||
res << "_#{i}" if i
|
||||
res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page))
|
||||
res << "'>"
|
||||
root = "/"
|
||||
res << "<a href='#{(page.class.to_s.eql?('Page') ? root + page.path : page.url)}'><span>#{page.title}</span></a>"
|
||||
if page.visible_children.size > 0 && current < menu.levels
|
||||
res << "<span class='dot'></span>"
|
||||
res << menu_level(page, current_page, current + 1, menu)
|
||||
end unless (page.root? rescue nil)
|
||||
res << "</li>"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -29,63 +29,62 @@ class PagesController < ApplicationController
|
||||
else
|
||||
render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
||||
end
|
||||
#rescue
|
||||
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
||||
#end
|
||||
end
|
||||
#rescue
|
||||
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
||||
#end
|
||||
end
|
||||
|
||||
def index_from_link
|
||||
url = "/#{@item.path}"
|
||||
options = ''
|
||||
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
|
||||
uri = URI::escape(url + options)
|
||||
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
|
||||
redirect_to(uri)unless save_from_no_lang_for_page
|
||||
end
|
||||
def index_from_link
|
||||
url = "/#{@item.path}"
|
||||
options = ''
|
||||
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
|
||||
uri = URI::escape(url + options)
|
||||
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
|
||||
redirect_to(uri)unless save_from_no_lang_for_page
|
||||
end
|
||||
|
||||
def show_from_link
|
||||
url = "/#{@item.path}"
|
||||
options = ''
|
||||
options << "#{options.blank? ? '?' : '&'}id=#{params[:id]}" unless params[:id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}controller_action=#{params[:controller_action]}" unless params[:controller_action].blank?
|
||||
redirect_to(url + options) unless save_from_no_lang_for_page
|
||||
end
|
||||
def show_from_link
|
||||
url = "/#{@item.path}"
|
||||
options = ''
|
||||
options << "#{options.blank? ? '?' : '&'}id=#{params[:id]}" unless params[:id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}preview=#{params[:preview]}" unless params[:preview].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}controller_action=#{params[:controller_action]}" unless params[:controller_action].blank?
|
||||
redirect_to(url + options) unless save_from_no_lang_for_page
|
||||
end
|
||||
|
||||
def load_orbit_bar
|
||||
render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer}
|
||||
end
|
||||
def load_orbit_bar
|
||||
render :partial => 'layouts/orbit_bar', :locals => {:referer => request.referer}
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def get_item
|
||||
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
||||
if !params[:category_id].blank? && !params[:tag_id].blank?
|
||||
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
|
||||
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
|
||||
elsif !params[:category_id].blank?
|
||||
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],category: params[:category_id]).any_in(tag: [nil,'']).first
|
||||
elsif !params[:tag_id].blank?
|
||||
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first
|
||||
end
|
||||
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
|
||||
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def get_item
|
||||
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
||||
if !params[:category_id].blank? && !params[:tag_id].blank?
|
||||
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
|
||||
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
|
||||
elsif !params[:category_id].blank?
|
||||
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],category: params[:category_id]).any_in(tag: [nil,'']).first
|
||||
elsif !params[:tag_id].blank?
|
||||
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first
|
||||
end
|
||||
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
|
||||
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
|
||||
end
|
||||
|
||||
def save_from_no_lang_for_page
|
||||
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
|
||||
flash[:error] = t('sys.module_page_lang_not_support')
|
||||
redirect_to '/'
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
|
||||
flash[:error] = t('sys.module_page_lang_not_support')
|
||||
redirect_to '/'
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user