Fix authors display.

This commit is contained in:
BoHung Chiu 2021-12-16 15:23:24 +08:00
parent eedcf7e7f3
commit 2929b87154
1 changed files with 23 additions and 34 deletions

View File

@ -1,44 +1,33 @@
module Admin::JournalPapersHelper
def get_authors_text(journal)
(journal.authors.to_s.blank? ? get_member(journal).collect(&:name).join('/') : Nokogiri::HTML(journal.authors.to_s).text rescue "")
authors_text = Nokogiri::HTML(journal.authors.to_s).text
split_text = authors_text.match(/[、,,\/]/)
split_text = split_text.nil? ? '/' : split_text[0]
full_authors_names = get_member(journal).collect(&:name)
if authors_text.present?
authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))}
full_authors_names += authors_names
end
full_authors_names.join(split_text)
end
def get_authors_show(journal)
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] = "<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
""
authors_text = Nokogiri::HTML(journal.authors.to_s).text
split_text = authors_text.match(/[、,,\/]/)
split_text = split_text.nil? ? '/' : split_text[0]
full_authors_names = []
full_authors = get_member(journal).collect{|member|
member_name = member.name
full_authors_names << member_name
"<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member_name}'>#{member_name}</a>"
}
if authors_text.present?
authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))}
full_authors += authors_names
end
full_authors.join(split_text)
end
def get_member(journal)
Array(MemberProfile.find(Array(journal).collect(&:member_profile_id))) rescue []
Array(MemberProfile.where(:id.in=>Array(journal).collect(&:member_profile_id).flatten))
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>"}