From e7880ea2a1821374dd5fce7d70e85ff7aa268122 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 13 Aug 2019 17:16:37 +0800 Subject: [PATCH] Update personal_journals_controller.rb --- .../personal_journals_controller.rb | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/app/controllers/personal_journals_controller.rb b/app/controllers/personal_journals_controller.rb index 3afe4f4..383c6d9 100644 --- a/app/controllers/personal_journals_controller.rb +++ b/app/controllers/personal_journals_controller.rb @@ -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