From 186d1b2e062ec561d8e493937acc534f82b495ec Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 13 Aug 2019 14:32:39 +0800 Subject: [PATCH] Update personal_journals_controller.rb --- .../personal_journals_controller.rb | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index a4aca2f..0499ea2 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -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" => "#{journal_paper[fs]}"} + else + if journal_paper[fs]!=nil && journal_paper[fs]!="" + t << {"value" => "#{journal_paper[fs]}, #{journal_paper[:journal_title][params[:locale]]}"} + else + t << {"value" => "#{journal_paper[fs]}"} + 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,9 +110,9 @@ 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