Merge branch 'master' into 'master'

Master

I add search function and fix some translation error

See merge request !1
This commit is contained in:
wmcheng 2019-08-16 12:45:17 +08:00
commit d910320806
1 changed files with 58 additions and 4 deletions

View File

@ -1,4 +1,9 @@
class PersonalJournalsController < ApplicationController
def search_all_words(target,word)
target=target.upcase
words=word.upcase.split(' ')
return words.select{|value| target.include? value}==words
end
def index
params = OrbitHelper.params
journal_papers = JournalPaper.where(:is_hidden=>false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
@ -20,6 +25,36 @@ class PersonalJournalsController < ApplicationController
"paper_title"
]
end
if params[:selectbox] !=nil
journal_papers_temp = JournalPaper.where(:is_hidden=>false).sort_by{ |tp| [-tp[:year].to_i,-tp[:publication_date].to_i] }
case params[:selectbox]
when "paper_title","default"
if page.custom_string_field == "table"
journal_papers_show = journal_papers_temp.select {|value| search_all_words(value.paper_title, params[:keywords])}
else
journal_papers_show = journal_papers_temp.select {|value| search_all_words(value.create_link, params[:keywords])}
end
when "level_type"
journal_papers_show = journal_papers_temp.select {|value| search_all_words(value.journal_levels.collect{|x| x.title}.join(', ').to_s, params[:keywords])}
when "publication_date"
journal_papers_show = journal_papers_temp.select {|value| search_all_words((value.send("publication_date").strftime("%Y/%m/%d") rescue ""), params[:keywords])}
when "author_type"
journal_papers_show = journal_papers_temp.select {|value| search_all_words(value.journal_paper_author_types.collect{|jat| jat.title}.join(", "), params[:keywords])}
when "language"
journal_papers_show = journal_papers_temp.select {|value| search_all_words((!value.language.nil? ? t("#{value.language}") : ""), params[:keywords])}
else
journal_papers_show = journal_papers_temp.select {|value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords])}
end
if params[:page_no].nil?
page_to_show = 1
else
page_to_show = params[:page_no].to_i
end
journal_papers = journal_papers_show[(page_to_show-1)*OrbitHelper.page_data_count...page_to_show*OrbitHelper.page_data_count]
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|
t = []
@ -37,14 +72,16 @@ class PersonalJournalsController < ApplicationController
t << {"value" => (journal_paper.send(fs).strftime("%Y/%m") rescue "")}
when "author_type"
t << {"value" => (journal_paper.journal_paper_author_types.collect{|jat| jat.title}.join(", ") rescue "")}
when "language"
t << {"value" => (!journal_paper.language.nil? ? t("#{journal_paper.language}") : "")}
else
t << {"value" => journal_paper.send(fs)}
end
end
journal_paper_list << {"jps" => t}
end
headers = []
choice_show = []
fields_to_show.each do |fs|
col = 2
col = 3 if fs == "paper_title"
@ -52,13 +89,30 @@ class PersonalJournalsController < ApplicationController
"head-title" => t("personal_journal.#{fs}"),
"col" => col
}
choice_show << t("personal_journal.#{fs}")
end
choice_value = fields_to_show
choice_value.unshift("default")
choice_select=choice_value.map{|iter| iter==params[:selectbox] ? "selected" : ""}
choice_select=choice_select.map{|value| {"choice_select" => value}}
choice_value=choice_value.map{|value| {"choice_value" => value}}
choice_default = params[:locale]!='en' ? "——選取分類——" : "——select class——"
choice_show.unshift(choice_default)
choice_show=choice_show.map{|value| {"choice_show" => value}}
choice=choice_value.zip(choice_show,choice_select)
choice=choice.map{|value| value.inject:merge}
select_text = params[:locale]!='en' ? "搜尋類別:" : "search class:"
search_text = params[:locale]!='en' ? "關鍵字搜尋:" : "word to search:"
{
"journal_papers" => journal_paper_list,
"headers" => headers,
"extras" => {"widget-title" => t("module_name.journal_paper")},
"total_pages" => journal_papers.total_pages
"extras" => {"widget-title" => t("module_name.journal_paper"),
"url" => "/"+params[:locale]+params[:url],
"select_text" => select_text,
"search_text" => search_text,
"search_value" => params[:keywords]},
"total_pages" => journal_papers_total_pages,
"choice" => choice
}
end