Change get_item
Add category and tags to default widget link to object
This commit is contained in:
parent
b37643147f
commit
71e8b3c042
|
@ -44,29 +44,13 @@ class PagesController < ApplicationController
|
|||
# render :file => "#{Rails.root}/public/404.html", :status => :not_found
|
||||
#end
|
||||
end
|
||||
|
||||
def convert_array_param(key,array)
|
||||
array.collect{|t| "#{key}[]=#{t}"}.join("&")
|
||||
end
|
||||
|
||||
def index_from_link
|
||||
url = "/#{@item.path}"
|
||||
options = ''
|
||||
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
|
||||
|
||||
if params[:category_id].is_a? Array
|
||||
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('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?
|
||||
end
|
||||
|
||||
if params[:tag_id].is_a? Array
|
||||
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('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?
|
||||
end
|
||||
|
||||
|
||||
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('category_id', params[:category_id])}" unless params[:category_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('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)
|
||||
|
@ -78,8 +62,8 @@ class PagesController < ApplicationController
|
|||
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? ? '?' : '&'}#{convert_array_param('category_id', params[:category_id])}" unless params[:category_id].blank?
|
||||
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('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?
|
||||
options << "#{options.blank? ? '?' : '&'}clicked_field_name=#{params[:clicked_field_name]}" unless params[:clicked_field_name].blank?
|
||||
|
@ -98,22 +82,43 @@ class PagesController < ApplicationController
|
|||
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]] unless params[:category_id].nil?
|
||||
tag_ids = params[:tag_id].is_a?(Array) ? params[:tag_id] : [params[:tag_id]] unless params[:tag_id].nil?
|
||||
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.first(:conditions => {is_published: true, :module_app_id => module_app.id, :app_frontend_url.in => [params[:app_action], 'default_widget'], :category.in => category_ids, :tag.in => tag_ids})
|
||||
@item = Item.first(:conditions => {is_published: true, :module_app_id => module_app.id, :app_frontend_url.in => [params[:app_action], 'default_widget'], :category.in => category_ids, :tag.in => [nil, []]}) unless @item
|
||||
@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(is_published: true, module_app_id: module_app.id, :app_frontend_url.in => [params[:app_action], 'default_widget'], :category.in => category_ids).any_in(tag: [nil, []]).first
|
||||
@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(is_published: true, module_app_id: module_app.id, :app_frontend_url.in => [params[:app_action], 'default_widget'], :tag.in => tag_ids).any_in(category: [nil, []]).first
|
||||
@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(is_published: true, module_app_id: module_app.id, :app_frontend_url.in => [params[:app_action], 'default_widget']).all_of("tag" => {"$in" => [nil, []]},"category" => { "$in" => [nil, []]}).first unless @item
|
||||
@item = Item.where(is_published: true, module_app_id: module_app.id, :app_frontend_url.in => [params[:app_action], 'default_widget']).first unless @item
|
||||
@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?
|
||||
raise PageError, 'Missing Frontend Page' if @item.nil?
|
||||
end
|
||||
|
||||
def save_from_no_lang_for_page
|
||||
|
|
|
@ -315,4 +315,8 @@ module ApplicationHelper
|
|||
link_to title, params.merge({direction: direction, sort: column, sort_options: column}), {:class => "#{css_class} sortable", :remote => options[:remote]}
|
||||
end
|
||||
|
||||
def convert_array_param(key, array)
|
||||
Array(array).collect{|t| "#{key}[]=#{t}"}.join("&")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -84,4 +84,13 @@ module DefaultWidgetHelper
|
|||
content_tag(:span,get_display(row_data,field_setting),:class=>field_setting[:class])
|
||||
end
|
||||
end
|
||||
|
||||
def get_row_category(row_data)
|
||||
row_data.send("#{row_data.class.to_s.underscore}_category_id") rescue nil
|
||||
end
|
||||
|
||||
def get_row_tags(row_data)
|
||||
row_data.tagged_ids rescue nil
|
||||
end
|
||||
|
||||
end
|
|
@ -1,19 +1,22 @@
|
|||
<%= content_tag :div,:class=>@tag_class do%>
|
||||
<%= content_tag :div, class: @tag_class do %>
|
||||
<div class="default_widget_type_A">
|
||||
<table class="default_widget_tb" border="0" cellpadding="0" cellspacing="0" >
|
||||
<thead>
|
||||
<tr>
|
||||
<% @frontend_field_names.each_with_index do |field,index|%>
|
||||
<%= content_tag(:th,content_tag(:span,get_field_header(field),:class=>@frontend_classes[index]))unless field.blank?%>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<% @data.each do |row_data| %>
|
||||
<tr class="<%= get_top_hot_class(row_data) %>">
|
||||
<% @frontend_field_names.each_with_index do |field,index|%>
|
||||
<%= content_tag(:td,content_tag(:span,link_to_field(row_data,field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s}),:class=>@frontend_classes[index]))unless field.blank?%>
|
||||
<thead>
|
||||
<tr>
|
||||
<% @frontend_field_names.each_with_index do |field, index| %>
|
||||
<%= content_tag(:th, content_tag(:span, get_field_header(field), class: @frontend_classes[index])) unless field.blank? %>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @data.each do |row_data| %>
|
||||
<tr class="<%= get_top_hot_class(row_data) %>">
|
||||
<% @frontend_field_names.each_with_index do |field, index|%>
|
||||
<%= content_tag(:td, content_tag(:span, link_to_field(row_data, field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s, category_id: get_row_category(row_data), tag_id: get_row_tags(row_data)}), class: @frontend_classes[index])) unless field.blank? %>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<%= content_tag :div,:class=>@tag_class do%>
|
||||
<%= content_tag :div, class: @tag_class do %>
|
||||
<ul class="default_widget_list">
|
||||
<% @data.each do |row_data| %>
|
||||
<%= content_tag(:li,:class=>get_top_hot_class(row_data)) do %>
|
||||
<%= content_tag(:li, class: get_top_hot_class(row_data)) do %>
|
||||
<div class="img app-pic">
|
||||
<%= image_tag row_data.send(@widget_image_field)%>
|
||||
<%= image_tag row_data.send(@widget_image_field) %>
|
||||
</div>
|
||||
<div class="wrap">
|
||||
<% @frontend_field_names.each_with_index do |field,index|%>
|
||||
<%= content_tag(:span,link_to_field(row_data,field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s}),:class=>@frontend_classes[index]) unless field.blank?%>
|
||||
<% @frontend_field_names.each_with_index do |field, index| %>
|
||||
<%= content_tag(:span, link_to_field(row_data,field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s, category_id: get_row_category(row_data), tag_id: get_row_tags(row_data)}), class: @frontend_classes[index]) unless field.blank? %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<%= content_tag :div,:class=>@tag_class do%>
|
||||
<%= content_tag :div, class: @tag_class do %>
|
||||
<div class="img app-pic">
|
||||
<%= image_tag @data.first.send(@widget_image_field)%>
|
||||
<%= image_tag @data.first.send(@widget_image_field) %>
|
||||
</div>
|
||||
<ul class="default_widget_list">
|
||||
<% @data.each do |row_data| %>
|
||||
<%= content_tag(:li,:class=>get_top_hot_class(row_data)) do %>
|
||||
<% @frontend_field_names.each_with_index do |field,index|%>
|
||||
<%= content_tag(:span, link_to_field(row_data,field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s}),:class=>@frontend_classes[index]) unless field.blank?%>
|
||||
<%= content_tag(:li, class: get_top_hot_class(row_data)) do %>
|
||||
<% @frontend_field_names.each_with_index do |field, index|%>
|
||||
<%= content_tag(:span, link_to_field(row_data, field, @frontend_sat_to_links[index], {orig_page: @page_id.to_s, category_id: get_row_category(row_data), tag_id: get_row_tags(row_data)}), class: @frontend_classes[index]) unless field.blank? %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -41,7 +41,6 @@ class Panel::WebResource::FrontEnd::WebLinksController < OrbitWidgetController
|
|||
if params[:tag_id].blank?
|
||||
categories[category.title] = category.web_links.can_display.desc( :is_top, :created_at )
|
||||
else
|
||||
debugger
|
||||
categories[category.title] = category.web_links.can_display.any_in(:tagged_ids => params[:tag_id]).desc( :is_top, :created_at )
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue