Update personal_journals_controller.rb

This commit is contained in:
chiu 2019-08-13 17:16:37 +08:00
parent ab5b44aafb
commit e7880ea2a1
1 changed files with 27 additions and 25 deletions

View File

@ -21,33 +21,35 @@ class PersonalJournalsController < ApplicationController
]
end
if params[:selectbox] !=nil
journal_papers = JournalPaper.where(:is_hidden=>false)#Mongoid::Sessions.default[:journal_papers].find()
journal_papers_count = journal_papers.count
journal_papers_temp = journal_papers.take(journal_papers_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] }
case params[:selectbox]
when "paper_title"
if page.custom_string_field == "table"
journal_papers_show = journal_papers_temp.select {|value| value.paper_title.include? params[:keywords]}
else
journal_papers_show = journal_papers_temp.select {|value| value.create_link.include? params[:keywords]}
end
when "level_type"
journal_papers_show = journal_papers_temp.select {|value| value.journal_levels.collect{|x| x.title}.join(', ').to_s.include? params[:keywords]}
when "publication_date"
journal_papers_show = journal_papers_temp.select {|value| value.send("publication_date").strftime("%Y/%m").collect{|x| x.title}.join(', ').include? params[:keywords]}
when "author_type"
journal_papers_show = journal_papers_temp.select {|value| value.journal_paper_author_types.collect{|jat| jat.title}.join(", ").include? params[:keywords]}
journal_papers = JournalPaper.where(:is_hidden=>false)#Mongoid::Sessions.default[:journal_papers].find()
journal_papers_count = journal_papers.count
journal_papers_temp = journal_papers.take(journal_papers_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] }
case params[:selectbox]
when "paper_title"
if page.custom_string_field == "table"
journal_papers_show = journal_papers_temp.select {|value| value.paper_title.include? params[:keywords]}
else
journal_papers_show = journal_papers_temp.select {|value| value.send(params[:selectbox]).to_s.include? params[:keywords]}
journal_papers_show = journal_papers_temp.select {|value| value.create_link.include? params[:keywords]}
end
if params[:page_no].nil?
page_to_show = 1
else
page_to_show = params[:page_no].to_i
end
journal_papers_show_last = journal_papers_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count]
journal_papers = journal_papers_show_last
when "level_type"
journal_papers_show = journal_papers_temp.select {|value| value.journal_levels.collect{|x| x.title}.join(', ').to_s.include? params[:keywords]}
when "publication_date"
journal_papers_show = journal_papers_temp.select {|value| value.send("publication_date").strftime("%Y/%m").collect{|x| x.title}.join(', ').include? params[:keywords]}
when "author_type"
journal_papers_show = journal_papers_temp.select {|value| value.journal_paper_author_types.collect{|jat| jat.title}.join(", ").include? params[:keywords]}
else
journal_papers_show = journal_papers_temp.select {|value| value.send(params[:selectbox]).to_s.include? params[:keywords]}
end
if params[:page_no].nil?
page_to_show = 1
else
page_to_show = params[:page_no].to_i
end
journal_papers_show_last = journal_papers_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count]
journal_papers = journal_papers_show_last
journal_papers_total_pages = (journal_papers_show.length/OrbitHelper.page_data_count.to_f).ceil
else
journal_papers_total_pages = journal_papers.total_pages
end
journal_paper_list = []
journal_papers.each do |journal_paper|
@ -95,7 +97,7 @@ class PersonalJournalsController < ApplicationController
"journal_papers" => journal_paper_list,
"headers" => headers,
"extras" => {"widget-title" => t("module_name.journal_paper")},
"total_pages" => journal_papers.total_pages,
"total_pages" => journal_papers_total_pages,
"choice" => {"choice_value" => choice_value ,"choice_show" => choice_show},
"url" => "/"+params[:locale]+params[:url],
"all" => journal_papers_show_last