forked from saurabh/personal-journal
Update personal_journals_controller.rb
This commit is contained in:
parent
dbea87909c
commit
186d1b2e06
|
@ -23,22 +23,42 @@ class PersonalJournalsController < ApplicationController
|
|||
if params[:selectbox] !=nil
|
||||
journal_papers = Mongoid::Sessions.default[:journal_papers].find()
|
||||
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.total_pages = (journal_papers_temp.length / OrbitHelper.page_data_count.to_f).ceil
|
||||
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" => [{"jps"=>[{"value"=>"2019"}, {"value"=>"123, 456"}]}],
|
||||
"headers" => [{"head-title"=>"年度", "col"=>2}, {"head-title"=>"論文名稱", "col"=>3}],
|
||||
"extras" => {"widget-title" => "module_name.journal_paper"},
|
||||
"total_pages" => 1,
|
||||
"choice" => 1,
|
||||
"all" => journal_papers_show_last
|
||||
}
|
||||
journal_paper_list = []
|
||||
journal_papers_show_last.each do |journal_paper|
|
||||
t = []
|
||||
fields_to_show.each do |fs|
|
||||
case fs
|
||||
when "paper_title"
|
||||
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
|
||||
journal_paper_list = []
|
||||
journal_papers.each do |journal_paper|
|
||||
|
@ -63,7 +83,7 @@ class PersonalJournalsController < ApplicationController
|
|||
end
|
||||
journal_paper_list << {"jps" => t}
|
||||
end
|
||||
|
||||
end
|
||||
headers = []
|
||||
choice_show = []
|
||||
fields_to_show.each do |fs|
|
||||
|
@ -90,10 +110,10 @@ class PersonalJournalsController < ApplicationController
|
|||
"total_pages" => journal_papers.total_pages,
|
||||
"choice" => {"choice_value" => choice_value ,"choice_show" => choice_show},
|
||||
"url" => "/"+params[:locale]+params[:url],
|
||||
"all" => journal_papers_show
|
||||
"all" => journal_papers_show,
|
||||
"all_n" => JournalPaper.where(:is_hidden=>false).take(2)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
params = OrbitHelper.params
|
||||
|
|
Loading…
Reference in New Issue