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