Update personal_journals_controller.rb

This commit is contained in:
chiu 2019-08-13 14:32:39 +08:00
parent dbea87909c
commit 186d1b2e06
1 changed files with 32 additions and 12 deletions

View File

@ -23,22 +23,42 @@ class PersonalJournalsController < ApplicationController
if params[:selectbox] !=nil if params[:selectbox] !=nil
journal_papers = Mongoid::Sessions.default[:journal_papers].find() journal_papers = Mongoid::Sessions.default[:journal_papers].find()
journal_papers_count = journal_papers.count journal_papers_count = journal_papers.count
journal_papers_temp = Mongoid::Sessions.default[:journal_papers].find().take(journal_papers_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] } journal_papers_temp = journal_papers.take(journal_papers_count).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] }
journal_papers_show = journal_papers_temp.select {|value| value[params[:selectbox]][params[:locale]].include? params[:keywords]} journal_papers_show = journal_papers_temp.select {|value| value[params[:selectbox]][params[:locale]].include? params[:keywords]}
journal_papers.total_pages = (journal_papers_temp.length / OrbitHelper.page_data_count.to_f).ceil
if params[:page_no].nil? if params[:page_no].nil?
page_to_show = 1 page_to_show = 1
else else
page_to_show = params[:page_no].to_i page_to_show = params[:page_no].to_i
end 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_show_last = journal_papers_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count]
{ journal_paper_list = []
"journal_papers" => [{"jps"=>[{"value"=>"2019"}, {"value"=>"123, 456"}]}], journal_papers_show_last.each do |journal_paper|
"headers" => [{"head-title"=>"年度", "col"=>2}, {"head-title"=>"論文名稱", "col"=>3}], t = []
"extras" => {"widget-title" => "module_name.journal_paper"}, fields_to_show.each do |fs|
"total_pages" => 1, case fs
"choice" => 1, when "paper_title"
"all" => journal_papers_show_last if page.custom_string_field == "table"
} t << {"value" => "<a href='#{OrbitHelper.url_to_show([journal_paper[fs],journal_paper[:uid]].to_param)}'>#{journal_paper[fs]}</a>"}
else
if journal_paper[fs]!=nil && journal_paper[fs]!=""
t << {"value" => "<a href='#{OrbitHelper.url_to_show([journal_paper[fs],journal_paper[:uid]].to_param)}'>#{journal_paper[fs]}, #{journal_paper[:journal_title][params[:locale]]}</a>"}
else
t << {"value" => "<a href='#{OrbitHelper.url_to_show([journal_paper[fs],journal_paper[:uid]].to_param)}'>#{journal_paper[fs]}</a>"}
end
end
when "level_type"
t << {"value" => ( !journal_paper.journal_levels.blank? ? "(#{journal_paper.journal_levels.collect{|x| x.title}.join(', ')})" : nil)}
when "publication_date"
t << {"value" => (journal_paper[fs].strftime("%Y/%m") rescue "")}
when "author_type"
t << {"value" => (journal_paper.journal_paper_author_types.collect{|jat| jat.title}.join(", ") rescue "")}
else
t << {"value" => "#{journal_paper[fs]}"}
end
end
journal_paper_list << {"jps" => t}
end
else else
journal_paper_list = [] journal_paper_list = []
journal_papers.each do |journal_paper| journal_papers.each do |journal_paper|
@ -63,7 +83,7 @@ class PersonalJournalsController < ApplicationController
end end
journal_paper_list << {"jps" => t} journal_paper_list << {"jps" => t}
end end
end
headers = [] headers = []
choice_show = [] choice_show = []
fields_to_show.each do |fs| fields_to_show.each do |fs|
@ -90,9 +110,9 @@ class PersonalJournalsController < ApplicationController
"total_pages" => journal_papers.total_pages, "total_pages" => journal_papers.total_pages,
"choice" => {"choice_value" => choice_value ,"choice_show" => choice_show}, "choice" => {"choice_value" => choice_value ,"choice_show" => choice_show},
"url" => "/"+params[:locale]+params[:url], "url" => "/"+params[:locale]+params[:url],
"all" => journal_papers_show "all" => journal_papers_show,
"all_n" => JournalPaper.where(:is_hidden=>false).take(2)
} }
end
end end
def show def show