fix double show name problem for authors that are not blank

This commit is contained in:
邱博亞 2020-12-19 21:54:30 +08:00
parent 0b91cf4086
commit c99aea82ca
1 changed files with 37 additions and 3 deletions

View File

@ -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 "") (journal.authors.to_s.blank? ? get_member(journal).collect(&:name).join('/') : Nokogiri::HTML(journal.authors.to_s).text rescue "")
end end
def get_authors_show(journal) def get_authors_show(journal)
member_names = get_member_show(journal) begin
(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 "") 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] = "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{author}'>#{author}</a>"
flag = false
break
end
end
flag
end
(get_a_tag_from_members(members_tp) + authors_tp).join('、')
end
end
rescue => e
""
end
end end
def get_member(journal) def get_member(journal)
Array(MemberProfile.find(Array(journal).collect(&:member_profile_id))) rescue [] Array(MemberProfile.find(Array(journal).collect(&:member_profile_id))) rescue []
end end
def get_a_tag_from_members(members)
members.collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}
end
def get_member_show(journal) def get_member_show(journal)
get_member(journal).collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}.join('、') get_a_tag_from_members(get_member(journal)).join('、')
end end
def get_level_type(journal) def get_level_type(journal)
!journal.journal_levels.blank? ? "(#{journal.journal_levels.collect(&:title).join(', ')})" : nil !journal.journal_levels.blank? ? "(#{journal.journal_levels.collect(&:title).join(', ')})" : nil