forked from saurabh/personal-journal
Fix authors display.
This commit is contained in:
parent
eedcf7e7f3
commit
2929b87154
|
@ -1,44 +1,33 @@
|
||||||
module Admin::JournalPapersHelper
|
module Admin::JournalPapersHelper
|
||||||
def get_authors_text(journal)
|
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
|
end
|
||||||
def get_authors_show(journal)
|
def get_authors_show(journal)
|
||||||
begin
|
authors_text = Nokogiri::HTML(journal.authors.to_s).text
|
||||||
if journal.authors.to_s.blank?
|
split_text = authors_text.match(/[、,,\/]/)
|
||||||
get_member_show(journal)
|
split_text = split_text.nil? ? '/' : split_text[0]
|
||||||
else
|
full_authors_names = []
|
||||||
members = get_member(journal)
|
full_authors = get_member(journal).collect{|member|
|
||||||
if members.blank?
|
member_name = member.name
|
||||||
journal.authors.to_s
|
full_authors_names << member_name
|
||||||
else
|
"<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member_name}'>#{member_name}</a>"
|
||||||
authors = journal.authors.to_s.split(/,|,/).collect{|v| v.strip}
|
}
|
||||||
authors_tp = authors.clone
|
if authors_text.present?
|
||||||
locales = Site.first.enable_locales rescue I18n.available_locales
|
authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))}
|
||||||
members_tp = members.select do |member|
|
full_authors += authors_names
|
||||||
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
|
||||||
|
full_authors.join(split_text)
|
||||||
end
|
end
|
||||||
def get_member(journal)
|
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
|
end
|
||||||
def get_a_tag_from_members(members)
|
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>"}
|
members.collect{|member| "<a href='#{OrbitHelper.url_to_plugin_show(member.to_param,'member')}' title='#{member.name}'>#{member.name}</a>"}
|
||||||
|
|
Loading…
Reference in New Issue