enable category sort feature
This commit is contained in:
parent
893fbfe884
commit
c028b62f05
|
@ -77,7 +77,15 @@ class EPapersController < ApplicationController
|
||||||
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|
|
||||||
|
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|
|
topics_data = Array(topics).compact.collect do |topic|
|
||||||
{
|
{
|
||||||
"title" => topic.title,
|
"title" => topic.title,
|
||||||
|
@ -94,6 +102,7 @@ class EPapersController < ApplicationController
|
||||||
"topics" => topics_data
|
"topics" => topics_data
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
{
|
{
|
||||||
"categories" => data,
|
"categories" => data,
|
||||||
"extras" => {}
|
"extras" => {}
|
||||||
|
@ -159,7 +168,15 @@ 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|
|
||||||
|
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|
|
topics_data = Array(topics).compact.collect do |topic|
|
||||||
{
|
{
|
||||||
"title" => topic.title,
|
"title" => topic.title,
|
||||||
|
@ -175,6 +192,7 @@ class EPapersController < ApplicationController
|
||||||
"topics" => topics_data
|
"topics" => topics_data
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
{
|
{
|
||||||
"categories" => data,
|
"categories" => data,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
|
@ -187,7 +205,15 @@ 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|
|
||||||
|
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|
|
topics_data = Array(topics).compact.collect do |topic|
|
||||||
{
|
{
|
||||||
"title" => topic.title,
|
"title" => topic.title,
|
||||||
|
@ -203,6 +229,7 @@ class EPapersController < ApplicationController
|
||||||
"topics" => topics_data
|
"topics" => topics_data
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
{
|
{
|
||||||
"categories" => data,
|
"categories" => data,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
|
@ -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