|
|
|
@@ -64,23 +64,25 @@ class PagesController < ApplicationController
|
|
|
|
|
url = "/#{@item.path}"
|
|
|
|
|
options = ''
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}click=#{params[:click]}" unless params[:click].blank?
|
|
|
|
|
# options << "#{options.blank? ? '?' : '&'}part_id=#{params[:page_part_id]}" unless params[:page_part_id].blank?
|
|
|
|
|
|
|
|
|
|
if params[:category_id].is_a? Array
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('category_id',params[:category_id])}" unless params[:category_id].blank?
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('filter_category_id',params[:category_id])}" unless params[:category_id].blank?
|
|
|
|
|
elsif params[:category_id].is_a? String
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}filter_category_id=#{params[:category_id]}" unless params[:category_id].blank?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if params[:tag_id].is_a? Array
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('tag_id',params[:tag_id])}" unless params[:tag_id].blank?
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('filter_tag_id',params[:tag_id])}" unless params[:tag_id].blank?
|
|
|
|
|
elsif params[:category_id].is_a? String
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
|
|
|
|
|
options << "#{options.blank? ? '?' : '&'}filter_tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 + options)
|
|
|
|
|
uri = url + options
|
|
|
|
|
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
|
|
|
|
|
redirect_to(uri)unless save_from_no_lang_for_page
|
|
|
|
|
end
|
|
|
|
@@ -105,26 +107,94 @@ class PagesController < ApplicationController
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
|
|
def get_item
|
|
|
|
|
# if params[:page_id]
|
|
|
|
|
# @item = Item.find(params[:page_id])
|
|
|
|
|
# elsif params[:same_page_id]
|
|
|
|
|
# @item = Item.find(params[:same_page_id])
|
|
|
|
|
# else
|
|
|
|
|
# category_ids = Array(params[:category_id]) unless params[:category_id].nil?
|
|
|
|
|
# tag_ids = Array(params[:tag_id]) unless params[:tag_id].nil?
|
|
|
|
|
# module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
|
|
|
|
|
|
|
|
|
# default_query = { is_published: true, module_app_id: module_app.id, :app_frontend_url.in => [params[:app_action], 'default_widget'] }
|
|
|
|
|
# specific_categories = { :category => category_ids }
|
|
|
|
|
# in_categories = { :category.in => category_ids }
|
|
|
|
|
# nil_categories = { :category.in => [nil, []] }
|
|
|
|
|
# specific_tags = { :tag => tag_ids }
|
|
|
|
|
# in_tags = { :tag.in => tag_ids }
|
|
|
|
|
# nil_tags = { :tag.in => [nil, []] }
|
|
|
|
|
|
|
|
|
|
# if !category_ids.blank? && !tag_ids.blank?
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories).merge(specific_tags)).first
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories).merge(in_tags)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories).merge(nil_tags)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_tags).merge(in_categories)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_tags).merge(nil_categories)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(in_categories).merge(in_tags)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(in_categories).merge(nil_tags)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(in_tags).merge(nil_categories)).first unless @item
|
|
|
|
|
# elsif !category_ids.blank?
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories).merge(nil_tags)).first
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_categories)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(in_categories).merge(nil_tags)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(in_categories)).first unless @item
|
|
|
|
|
# elsif !tag_ids.blank?
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_tags).merge(nil_categories)).first
|
|
|
|
|
# @item = Item.where(default_query.merge(specific_tags)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(in_tags).merge(nil_categories)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query.merge(in_tags)).first unless @item
|
|
|
|
|
# end
|
|
|
|
|
# @item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank?
|
|
|
|
|
# @item = Item.where(default_query.merge(nil_categories).merge(nil_tags)).first unless @item
|
|
|
|
|
# @item = Item.where(default_query).first unless @item
|
|
|
|
|
# end
|
|
|
|
|
# raise PageError, 'Missing Frontend Page' if @item.nil?
|
|
|
|
|
|
|
|
|
|
# if params[:page_id]
|
|
|
|
|
# @item = Item.find(params[:page_id])
|
|
|
|
|
# elsif params[:same_page_id]
|
|
|
|
|
# @item = Item.find(params[:same_page_id])
|
|
|
|
|
# else
|
|
|
|
|
# category_ids = params[:category_id].is_a?(Array) ? params[:category_id] : [params[:category_id]]
|
|
|
|
|
# tag_ids = params[:tag_id].is_a?(Array) ? params[:tag_id] : [params[:tag_id]]
|
|
|
|
|
# module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
|
|
|
|
# if !category_ids.blank? && !tag_ids.blank?
|
|
|
|
|
# @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => category_ids, :tag.in => tag_ids})
|
|
|
|
|
# @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => category_ids, :tag.in => [nil, []]}) unless @item
|
|
|
|
|
# elsif !category_ids.blank?
|
|
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], :category.in => category_ids).any_in(tag: [nil, []]).first
|
|
|
|
|
# elsif !tag_ids.blank?
|
|
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], :tag.in => tag_ids).any_in(category: [nil, []]).first
|
|
|
|
|
# end
|
|
|
|
|
# @item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank?
|
|
|
|
|
# @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
|
|
|
|
|
# # @item = Item.root.children.where(:module_app_id => module_app.id).first
|
|
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first unless @item
|
|
|
|
|
# @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item
|
|
|
|
|
# end
|
|
|
|
|
# raise PageError,'Missing Frontend Page' if @item.nil?
|
|
|
|
|
|
|
|
|
|
if params[:page_id]
|
|
|
|
|
@item = Item.find(params[:page_id])
|
|
|
|
|
elsif params[:same_page_id]
|
|
|
|
|
@item = Item.find(params[:same_page_id])
|
|
|
|
|
else
|
|
|
|
|
category_ids = params[:category_id].is_a?(Array) ? params[:category_id] : [params[:category_id]]
|
|
|
|
|
tag_ids = params[:tag_id].is_a?(Array) ? params[:tag_id] : [params[:tag_id]]
|
|
|
|
|
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
|
|
|
|
if !category_ids.blank? && !tag_ids.blank?
|
|
|
|
|
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => category_ids, :tag.in => tag_ids})
|
|
|
|
|
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => category_ids, :tag.in => [nil, []]}) unless @item
|
|
|
|
|
elsif !category_ids.blank?
|
|
|
|
|
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], :category.in => category_ids).any_in(tag: [nil, []]).first
|
|
|
|
|
elsif !tag_ids.blank?
|
|
|
|
|
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], :tag.in => tag_ids).any_in(category: [nil, []]).first
|
|
|
|
|
category_ids = params[:category_id] ? (params[:category_id].is_a?(Array) ? params[:category_id] : [params[:category_id]]) : []
|
|
|
|
|
tag_ids = params[:tag_id].is_a?(Array) ? params[:tag_id] : [params[:tag_id]]
|
|
|
|
|
|
|
|
|
|
if !category_ids.blank?
|
|
|
|
|
@item = Item.where(:category => category_ids).first
|
|
|
|
|
else
|
|
|
|
|
if params[:action] && params[:action] == "show_from_link"
|
|
|
|
|
default_widget = module_app.get_default_widget
|
|
|
|
|
model = eval(default_widget["query"])
|
|
|
|
|
item = model.find(params[:id])
|
|
|
|
|
@item = Item.where(:category => [item.category_id.to_s]).first
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank?
|
|
|
|
|
@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
|
|
|
|
|
@item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first unless @item
|
|
|
|
|
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item
|
|
|
|
|
|
|
|
|
|
@item = Item.root.children.where(:module_app_id => module_app.id).first unless @item
|
|
|
|
|
end
|
|
|
|
|
raise PageError,'Missing Frontend Page' if @item.nil?
|
|
|
|
|
end
|
|
|
|
|