Update personal_journals_controller.rb

fix coding style
This commit is contained in:
chiu 2019-08-20 12:05:04 +08:00
parent 71f37eeba3
commit a3bcb1e06a
1 changed files with 11 additions and 59 deletions

View File

@ -3,17 +3,9 @@ class PersonalJournalsController < ApplicationController
params = OrbitHelper.params params = OrbitHelper.params
page_data_count = OrbitHelper.page_data_count page_data_count = OrbitHelper.page_data_count
journal_papers = JournalPaper.where(is_hidden: false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count) journal_papers = JournalPaper.where(is_hidden: false).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(page_data_count)
page = begin page = Page.where(page_id: params[:page_id]).first rescue nil
Page.where(page_id: params[:page_id]).first
rescue StandardError
nil
end
if page.custom_string_field == 'table' if page.custom_string_field == 'table'
fields_to_show = begin fields_to_show = page.custom_array_field rescue []
page.custom_array_field
rescue StandardError
[]
end
if fields_to_show.blank? if fields_to_show.blank?
fields_to_show = %w[ fields_to_show = %w[
paper_title paper_title
@ -43,33 +35,17 @@ class PersonalJournalsController < ApplicationController
when 'level_type' when 'level_type'
journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.journal_levels.collect(&:title).join(', ').to_s, params[:keywords]) } journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.journal_levels.collect(&:title).join(', ').to_s, params[:keywords]) }
when 'publication_date' when 'publication_date'
journal_papers_show = journal_papers_temp.select do |value| journal_papers_show = journal_papers_temp.select { |value| search_all_words((value.send('publication_date').strftime('%Y/%m/%d') rescue ''), params[:keywords]) }
search_all_words((begin
value.send('publication_date').strftime('%Y/%m/%d')
rescue StandardError
''
end), params[:keywords])
end
when 'author_type' when 'author_type'
journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.journal_paper_author_types.collect(&:title).join(', '), params[:keywords]) } journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.journal_paper_author_types.collect(&:title).join(', '), params[:keywords]) }
when 'paper_type' when 'paper_type'
journal_papers_show = journal_papers_temp.select do |value| journal_papers_show = journal_papers_temp.select { |value| search_all_words((value.journal_paper_type.title rescue ''), params[:keywords]) }
search_all_words((begin
value.journal_paper_type.title
rescue StandardError
''
end), params[:keywords])
end
when 'language' when 'language'
journal_papers_show = journal_papers_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) } journal_papers_show = journal_papers_temp.select { |value| search_all_words((!value.language.nil? ? t(value.language.to_s) : ''), params[:keywords]) }
else else
journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) } journal_papers_show = journal_papers_temp.select { |value| search_all_words(value.send(params[:selectbox]).to_s, params[:keywords]) }
end end
page_to_show = if params[:page_no].nil? page_to_show = params[:page_no].nil? ? 1 : params[:page_no].to_i
1
else
params[:page_no].to_i
end
journal_papers = journal_papers_show[(page_to_show - 1) * page_data_count...page_to_show * page_data_count] journal_papers = journal_papers_show[(page_to_show - 1) * page_data_count...page_to_show * page_data_count]
journal_papers_total_pages = (journal_papers_show.length / page_data_count.to_f).ceil journal_papers_total_pages = (journal_papers_show.length / page_data_count.to_f).ceil
else else
@ -89,31 +65,15 @@ class PersonalJournalsController < ApplicationController
when 'level_type' when 'level_type'
t << { 'value' => (!journal_paper.journal_levels.blank? ? "(#{journal_paper.journal_levels.collect(&:title).join(', ')})" : nil) } t << { 'value' => (!journal_paper.journal_levels.blank? ? "(#{journal_paper.journal_levels.collect(&:title).join(', ')})" : nil) }
when 'publication_date' when 'publication_date'
t << { 'value' => (begin t << { 'value' => (journal_paper.send(fs).strftime('%Y/%m') rescue '') }
journal_paper.send(fs).strftime('%Y/%m')
rescue StandardError
''
end) }
when 'author_type' when 'author_type'
t << { 'value' => (begin t << { 'value' => (journal_paper.journal_paper_author_types.collect(&:title).join(', ') rescue '') }
journal_paper.journal_paper_author_types.collect(&:title).join(', ')
rescue StandardError
''
end) }
when 'paper_type' when 'paper_type'
t << { 'value' => (begin t << { 'value' => (journal_paper.journal_paper_type.title rescue '') }
journal_paper.journal_paper_type.title
rescue StandardError
''
end) }
when 'language' when 'language'
t << { 'value' => (!journal_paper.language.nil? ? t(journal_paper.language.to_s) : '') } t << { 'value' => (!journal_paper.language.nil? ? t(journal_paper.language.to_s) : '') }
else else
t << { 'value' => (begin t << { 'value' => (journal_paper.send(fs) rescue '') }
journal_paper.send(fs)
rescue StandardError
''
end) }
end end
end end
journal_paper_list << { 'jps' => t } journal_paper_list << { 'jps' => t }
@ -182,11 +142,7 @@ class PersonalJournalsController < ApplicationController
end end
def get_fields_for_index def get_fields_for_index
@page = begin @page = Page.find(params[:page_id]) rescue nil
Page.find(params[:page_id])
rescue StandardError
nil
end
@fields_to_show = %w[ @fields_to_show = %w[
year year
authors authors
@ -220,11 +176,7 @@ class PersonalJournalsController < ApplicationController
end end
def save_index_fields def save_index_fields
page = begin page = Page.find(params[:page_id]) rescue nil
Page.find(params[:page_id])
rescue StandardError
nil
end
page.custom_array_field = params[:keys] page.custom_array_field = params[:keys]
page.save page.save
render json: { 'success' => true }.to_json render json: { 'success' => true }.to_json