From c99aea82ca714cce8397aa7b4f874e544f12fae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Sat, 19 Dec 2020 21:54:30 +0800 Subject: [PATCH] fix double show name problem for authors that are not blank --- app/helpers/admin/journal_papers_helper.rb | 40 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/app/helpers/admin/journal_papers_helper.rb b/app/helpers/admin/journal_papers_helper.rb index cfe0bb6..fc889ef 100644 --- a/app/helpers/admin/journal_papers_helper.rb +++ b/app/helpers/admin/journal_papers_helper.rb @@ -3,14 +3,48 @@ module Admin::JournalPapersHelper (journal.authors.to_s.blank? ? get_member(journal).collect(&:name).join('/') : Nokogiri::HTML(journal.authors.to_s).text rescue "") end def get_authors_show(journal) - member_names = get_member_show(journal) - (journal.authors.to_s.blank? ? get_member_show(journal) : (member_names.blank? ? journal.authors.to_s : (member_names + "、" + journal.authors.to_s.gsub(",","、").gsub(",","、")) ) rescue "") + begin + if journal.authors.to_s.blank? + get_member_show(journal) + else + members = get_member(journal) + if members.blank? + journal.authors.to_s + else + authors = journal.authors.to_s.split(/,|,/).collect{|v| v.strip} + authors_tp = authors.clone + locales = Site.first.enable_locales rescue I18n.available_locales + members_tp = members.select do |member| + flag = true + locales.each do |locale| + name_tp = I18n.with_locale(locale) do + member.name.strip + end + author_index = authors.index(name_tp) + if !author_index.nil? + author = authors[author_index] + authors_tp[author_index] = "#{author}" + flag = false + break + end + end + flag + end + (get_a_tag_from_members(members_tp) + authors_tp).join('、') + end + end + rescue => e + "" + end end def get_member(journal) Array(MemberProfile.find(Array(journal).collect(&:member_profile_id))) rescue [] end + def get_a_tag_from_members(members) + members.collect{|member| "#{member.name}"} + end def get_member_show(journal) - get_member(journal).collect{|member| "#{member.name}"}.join('、') + get_a_tag_from_members(get_member(journal)).join('、') end def get_level_type(journal) !journal.journal_levels.blank? ? "(#{journal.journal_levels.collect(&:title).join(', ')})" : nil