enable category sort feature
This commit is contained in:
parent
893fbfe884
commit
c028b62f05
|
@ -72,27 +72,36 @@ class EPapersController < ApplicationController
|
|||
params = OrbitHelper.params
|
||||
criteria = PaperCriteria.where(:uid => params[:uid]).first
|
||||
if params["category"].present?
|
||||
papers = criteria.epaper_topics.where(:category_id => params["category"]).group_by(&:category)
|
||||
papers = criteria.epaper_topics.where(:category_id => params["category"]).group_by(&:category)
|
||||
else
|
||||
papers = criteria.epaper_topics.group_by(&:category)
|
||||
papers = criteria.epaper_topics.group_by(&:category)
|
||||
end
|
||||
data = []
|
||||
papers.each do |category, topics|
|
||||
topics_data = Array(topics).compact.collect do |topic|
|
||||
{
|
||||
"title" => topic.title,
|
||||
"link_to_show" => OrbitHelper.url_to_show(topic.to_param),
|
||||
"description" => topic.description,
|
||||
"img_url" => topic.image.url,
|
||||
"img_url_thumb" => topic.image.thumb.url,
|
||||
"category" => category.title
|
||||
papers_sorted = get_all_categories.map do |v|
|
||||
tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)}
|
||||
if tmp.count==0
|
||||
tmp = nil
|
||||
end
|
||||
tmp
|
||||
end.compact
|
||||
papers_sorted.each do |paper|
|
||||
paper.each do |category, topics|
|
||||
topics_data = Array(topics).compact.collect do |topic|
|
||||
{
|
||||
"title" => topic.title,
|
||||
"link_to_show" => OrbitHelper.url_to_show(topic.to_param),
|
||||
"description" => topic.description,
|
||||
"img_url" => topic.image.url,
|
||||
"img_url_thumb" => topic.image.thumb.url,
|
||||
"category" => category.title
|
||||
}
|
||||
end
|
||||
data << {
|
||||
"category_title" => category.title,
|
||||
"category_link" => params["url"] + "/" + params["page"] + "?method=topics&category=#{category.id.to_s}",
|
||||
"topics" => topics_data
|
||||
}
|
||||
end
|
||||
data << {
|
||||
"category_title" => category.title,
|
||||
"category_link" => params["url"] + "/" + params["page"] + "?method=topics&category=#{category.id.to_s}",
|
||||
"topics" => topics_data
|
||||
}
|
||||
end
|
||||
{
|
||||
"categories" => data,
|
||||
|
@ -159,21 +168,30 @@ class EPapersController < ApplicationController
|
|||
criteria = PaperCriteria.last
|
||||
papers = criteria.epaper_topics.group_by(&:category)
|
||||
data = []
|
||||
papers.each do |category, topics|
|
||||
topics_data = Array(topics).compact.collect do |topic|
|
||||
{
|
||||
"title" => topic.title,
|
||||
"link_to_show" => OrbitHelper.widget_item_url(topic.to_param),
|
||||
"description" => topic.description,
|
||||
"img_url" => topic.image.url,
|
||||
"img_url_thumb" => topic.image.thumb.url,
|
||||
"category" => (category.title rescue nil)
|
||||
papers_sorted = get_all_categories.map do |v|
|
||||
tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)}
|
||||
if tmp.count==0
|
||||
tmp = nil
|
||||
end
|
||||
tmp
|
||||
end.compact
|
||||
papers_sorted.each do |paper|
|
||||
paper.each do |category, topics|
|
||||
topics_data = Array(topics).compact.collect do |topic|
|
||||
{
|
||||
"title" => topic.title,
|
||||
"link_to_show" => OrbitHelper.widget_item_url(topic.to_param),
|
||||
"description" => topic.description,
|
||||
"img_url" => topic.image.url,
|
||||
"img_url_thumb" => topic.image.thumb.url,
|
||||
"category" => (category.title rescue nil)
|
||||
}
|
||||
end
|
||||
data << {
|
||||
"category_title" => (category.title rescue nil),
|
||||
"topics" => topics_data
|
||||
}
|
||||
end
|
||||
data << {
|
||||
"category_title" => (category.title rescue nil),
|
||||
"topics" => topics_data
|
||||
}
|
||||
end
|
||||
{
|
||||
"categories" => data,
|
||||
|
@ -187,21 +205,30 @@ class EPapersController < ApplicationController
|
|||
criteria = PaperCriteria.last
|
||||
papers = criteria.epaper_topics.group_by(&:category)
|
||||
data = []
|
||||
papers.each do |category, topics|
|
||||
topics_data = Array(topics).compact.collect do |topic|
|
||||
{
|
||||
"title" => topic.title,
|
||||
"link_to_show" => OrbitHelper.widget_item_url(topic.to_param),
|
||||
"description" => topic.description,
|
||||
"img_url" => topic.image.url,
|
||||
"img_url_thumb" => topic.image.thumb.url,
|
||||
"category" => (category.title rescue nil)
|
||||
papers_sorted = get_all_categories.map do |v|
|
||||
tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)}
|
||||
if tmp.count==0
|
||||
tmp = nil
|
||||
end
|
||||
tmp
|
||||
end.compact
|
||||
papers_sorted.each do |paper|
|
||||
paper.each do |category, topics|
|
||||
topics_data = Array(topics).compact.collect do |topic|
|
||||
{
|
||||
"title" => topic.title,
|
||||
"link_to_show" => OrbitHelper.widget_item_url(topic.to_param),
|
||||
"description" => topic.description,
|
||||
"img_url" => topic.image.url,
|
||||
"img_url_thumb" => topic.image.thumb.url,
|
||||
"category" => (category.title rescue nil)
|
||||
}
|
||||
end
|
||||
data << {
|
||||
"category_title" => (category.title rescue nil),
|
||||
"topics" => topics_data
|
||||
}
|
||||
end
|
||||
data << {
|
||||
"category_title" => (category.title rescue nil),
|
||||
"topics" => topics_data
|
||||
}
|
||||
end
|
||||
{
|
||||
"categories" => data,
|
||||
|
@ -244,5 +271,12 @@ class EPapersController < ApplicationController
|
|||
end
|
||||
render :json => data.to_json
|
||||
end
|
||||
|
||||
def get_all_categories
|
||||
app = ModuleApp.where(key: 'e_paper').first
|
||||
asc_flag = app.asc rescue true
|
||||
app.categories.enabled.sort_by do |category|
|
||||
tmp = category.sort_number.to_i rescue 0
|
||||
asc_flag ? tmp : -tmp
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue