2014-06-04 03:55:13 +00:00
|
|
|
class JournalPaper
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
2014-06-12 10:27:26 +00:00
|
|
|
include Mongoid::Attributes::Dynamic
|
2019-11-05 13:39:46 +00:00
|
|
|
include Admin::JournalPapersHelper
|
2014-06-04 03:55:13 +00:00
|
|
|
include OrbitModel::Status
|
2014-06-25 05:26:03 +00:00
|
|
|
include MemberHelper
|
|
|
|
include Slug
|
2023-01-07 02:19:22 +00:00
|
|
|
HideTimeInLinK = (File.exist?("#{Rails.root}/hide_time_fields_for_plugins.txt") rescue false)
|
2014-06-25 05:26:03 +00:00
|
|
|
field :paper_title, as: :slug_title, type: String, localize: true
|
2014-06-04 03:55:13 +00:00
|
|
|
field :journal_title, type: String, localize: true
|
2014-08-11 11:16:52 +00:00
|
|
|
field :authors, type: String, localize: true
|
|
|
|
field :associated_project , type: String, localize: true
|
|
|
|
|
2014-06-04 03:55:13 +00:00
|
|
|
field :year, type: String
|
|
|
|
field :language, type: String
|
|
|
|
field :isbn, type: String
|
|
|
|
field :vol_no, type: String
|
|
|
|
field :issue_no, type: String
|
|
|
|
field :form_to_start, type: String
|
|
|
|
field :form_to_end, type: String
|
|
|
|
field :total_pages, type: String
|
|
|
|
field :keywords, type: String
|
|
|
|
field :abstract, type: String
|
2014-06-12 10:27:26 +00:00
|
|
|
field :publication_date, type: DateTime
|
2014-06-04 03:55:13 +00:00
|
|
|
field :url, type: String
|
|
|
|
field :note, type: String
|
2014-08-11 11:16:52 +00:00
|
|
|
field :number_of_authors
|
2014-07-15 05:52:03 +00:00
|
|
|
field :rss2_id
|
2014-06-04 03:55:13 +00:00
|
|
|
|
2017-01-11 06:23:20 +00:00
|
|
|
# paginates_per 10
|
2014-06-04 03:55:13 +00:00
|
|
|
|
2014-06-12 10:27:26 +00:00
|
|
|
#relations
|
2023-07-01 07:35:21 +00:00
|
|
|
field :member_profile_id, type: Array
|
2023-03-04 03:20:55 +00:00
|
|
|
|
2014-06-12 10:27:26 +00:00
|
|
|
belongs_to :journal_paper_type
|
2023-02-27 15:26:56 +00:00
|
|
|
has_and_belongs_to_many :journal_types
|
2023-02-26 12:57:50 +00:00
|
|
|
|
2014-06-12 10:27:26 +00:00
|
|
|
has_and_belongs_to_many :journal_levels
|
|
|
|
|
|
|
|
has_many :journal_paper_files, autosave: true, dependent: :destroy
|
2019-08-19 07:44:54 +00:00
|
|
|
accepts_nested_attributes_for :journal_paper_files, :allow_destroy => true
|
2014-06-12 10:27:26 +00:00
|
|
|
|
2014-08-11 11:16:52 +00:00
|
|
|
# has_and_belongs_to_many :journal_paper_authors, dependent: :destroy
|
|
|
|
# accepts_nested_attributes_for :journal_paper_authors
|
2014-06-12 10:27:26 +00:00
|
|
|
|
2014-07-03 14:39:01 +00:00
|
|
|
has_and_belongs_to_many :journal_paper_author_types
|
|
|
|
|
2014-08-11 11:16:52 +00:00
|
|
|
# after_save :save_journal_paper_files, :save_journal_paper_authors
|
2014-06-18 04:09:19 +00:00
|
|
|
|
2014-06-12 10:27:26 +00:00
|
|
|
before_validation :add_http
|
2014-07-11 03:09:31 +00:00
|
|
|
# validates :paper_title, presence: true
|
2022-07-26 11:04:00 +00:00
|
|
|
index({year: -1, :publication_date => -1, _id: -1}, { unique: false, background: false })
|
|
|
|
scope :sort_year_date, ->{ order_by(:year => "desc", :publication_date => "desc", :id=>"desc") }
|
|
|
|
scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year => "desc", :publication_date => "desc", :id=>"desc") }
|
2015-12-02 10:34:48 +00:00
|
|
|
|
2023-07-01 07:35:21 +00:00
|
|
|
before_save :fix_member_profile_id
|
|
|
|
after_save :reload_member_profiles
|
|
|
|
|
|
|
|
def fix_member_profile_id
|
|
|
|
org_member_profile_id = self[:member_profile_id]
|
|
|
|
if org_member_profile_id.class == Array
|
|
|
|
self.member_profile_id = self[:member_profile_id].map{|id| BSON::ObjectId(id)}
|
|
|
|
else
|
|
|
|
self.member_profile_id = Array(org_member_profile_id).compact.map{|id| BSON::ObjectId(id)}
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
def reload_member_profiles
|
|
|
|
@member_profiles = MemberProfile.where(:id.in=>self.member_profile_id).to_a
|
|
|
|
@member_profile = @member_profiles.first
|
|
|
|
return @member_profiles
|
|
|
|
end
|
2023-03-04 04:29:48 +00:00
|
|
|
|
2014-06-12 10:27:26 +00:00
|
|
|
def create_link
|
|
|
|
title = []
|
|
|
|
|
2015-10-05 11:28:56 +00:00
|
|
|
title << self.authors if !self.authors.blank?
|
2014-06-12 10:27:26 +00:00
|
|
|
title << self.paper_title if self.paper_title.present?
|
|
|
|
title << self.journal_title if self.journal_title.present?
|
2022-08-23 10:40:15 +00:00
|
|
|
title << "vol. " + self.vol_no.strip if (self.vol_no.present? && self.vol_no != "0")
|
2014-06-12 10:27:26 +00:00
|
|
|
title << self.issue_no if (self.issue_no.present? && self.issue_no != "0")
|
2022-08-23 10:40:15 +00:00
|
|
|
title << "pp. " + self.form_to_start.to_s+"-"+self.form_to_end.to_s if (self.form_to_start.present? && self.form_to_start != "0")
|
2022-08-23 08:23:25 +00:00
|
|
|
# title << ( !self.journal_levels.blank? ? "(#{self.journal_levels.collect{|x| x.title}.join(', ')})" : nil)
|
2023-01-07 02:19:22 +00:00
|
|
|
unless HideTimeInLinK
|
|
|
|
if !self.publication_date.nil?
|
|
|
|
title << (self.publication_date.strftime("%b. %Y") rescue nil)
|
|
|
|
elsif self.year.present?
|
|
|
|
title << self.year
|
|
|
|
end
|
2022-08-23 08:23:25 +00:00
|
|
|
end
|
2015-10-06 07:53:09 +00:00
|
|
|
title.delete(nil)
|
2022-08-23 08:23:25 +00:00
|
|
|
title.join(', ').sub(/^\\s*,/,'').gsub(/,(\s*,)+/,',').strip
|
2014-06-12 10:27:26 +00:00
|
|
|
end
|
2022-08-23 10:40:15 +00:00
|
|
|
def form_to
|
|
|
|
if (self.form_to_start.present? && self.form_to_start != "0")
|
|
|
|
self.form_to_start.to_s+"-"+self.form_to_end.to_s
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
end
|
2016-01-11 12:35:44 +00:00
|
|
|
def self.get_plugin_datas_to_member(datas)
|
2016-03-22 09:58:37 +00:00
|
|
|
page = Page.where(:module => "personal_journal").first rescue nil
|
|
|
|
|
2016-03-24 17:32:20 +00:00
|
|
|
if !page.nil? && page.custom_string_field == "table"
|
2016-04-01 05:57:16 +00:00
|
|
|
if !page.custom_array_field.blank?
|
|
|
|
fields_to_show = page.custom_array_field
|
|
|
|
else
|
|
|
|
fields_to_show = [
|
|
|
|
"paper_title",
|
|
|
|
"journal_title",
|
|
|
|
"authors",
|
|
|
|
"year",
|
|
|
|
"issue_no",
|
|
|
|
"vol_no",
|
|
|
|
"level_type"
|
|
|
|
]
|
|
|
|
end
|
2016-03-22 09:58:37 +00:00
|
|
|
else
|
|
|
|
fields_to_show = [
|
|
|
|
"year",
|
|
|
|
"paper_title"
|
|
|
|
]
|
|
|
|
end
|
2016-01-11 12:35:44 +00:00
|
|
|
|
2016-02-15 10:37:36 +00:00
|
|
|
fields_to_remove = []
|
|
|
|
|
|
|
|
pd_title = []
|
|
|
|
|
|
|
|
fields_to_show.each do |t|
|
|
|
|
if (self.fields[t].type.to_s == "String" rescue false)
|
2016-02-15 10:49:54 +00:00
|
|
|
fields_to_remove << t if (datas.where(t.to_sym.ne => nil).or(t.to_sym.ne => "").count == 0 rescue false)
|
2016-02-15 10:37:36 +00:00
|
|
|
else
|
2022-08-23 10:40:15 +00:00
|
|
|
t2 = t
|
|
|
|
case t
|
|
|
|
when "form_to"
|
|
|
|
t2 = "form_to_start"
|
|
|
|
when "author_type"
|
|
|
|
t2 = "journal_paper_author_types"
|
|
|
|
end
|
|
|
|
fields_to_remove << t if (datas.where(t2.to_sym.ne => nil).count == 0 rescue false)
|
2016-02-15 10:37:36 +00:00
|
|
|
end
|
|
|
|
pd_title << {
|
|
|
|
"plugin_data_title" => I18n.t("personal_journal.#{t}")
|
|
|
|
} if !fields_to_remove.include?(t)
|
2016-01-11 12:35:44 +00:00
|
|
|
end
|
|
|
|
|
2016-02-15 10:37:36 +00:00
|
|
|
fields_to_show = fields_to_show - fields_to_remove
|
|
|
|
|
2016-01-11 12:35:44 +00:00
|
|
|
plugin_datas = datas.sort_for_frontend.collect do |p|
|
|
|
|
|
|
|
|
pd_data = []
|
|
|
|
fields_to_show.collect do |t|
|
2016-03-24 17:36:52 +00:00
|
|
|
if !page.nil? && page.custom_string_field == "table"
|
2016-03-22 09:58:37 +00:00
|
|
|
case t
|
|
|
|
when "paper_title"
|
2021-12-30 07:16:40 +00:00
|
|
|
link = OrbitHelper.url_to_plugin_show(p.to_param,'personal_journal')
|
2022-12-15 09:38:57 +00:00
|
|
|
url_to_plugin_show_blank = OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank)
|
|
|
|
tmp_title = p.paper_title
|
2022-12-15 10:17:51 +00:00
|
|
|
pd_data << { "data_title" => (url_to_plugin_show_blank ? tmp_title : "<a title=\"#{tmp_title}\" href=\"#{link}\" target=\"_blank\">#{tmp_title}</a>") }
|
2016-03-22 09:58:37 +00:00
|
|
|
when "level_type"
|
|
|
|
pd_data << {"data_title" => ( !p.journal_levels.blank? ? "(#{p.journal_levels.collect{|x| x.title}.join(', ')})" : nil)}
|
2016-04-01 05:57:16 +00:00
|
|
|
when "publication_date"
|
2016-04-13 07:28:37 +00:00
|
|
|
pd_data << {"data_title" => (p.send(t).strftime("%Y/%m") rescue "")}
|
2016-04-01 13:04:17 +00:00
|
|
|
when "author_type"
|
2016-04-05 17:59:22 +00:00
|
|
|
pd_data << {"data_title" => (p.journal_paper_author_types.collect{|jat| jat.title}.join(", ") rescue "")}
|
2016-03-22 09:58:37 +00:00
|
|
|
else
|
|
|
|
pd_data << {"data_title" => p.send(t)}
|
|
|
|
end
|
2016-01-11 12:35:44 +00:00
|
|
|
else
|
2016-03-22 09:58:37 +00:00
|
|
|
if t == "paper_title"
|
2023-03-04 04:14:45 +00:00
|
|
|
pd_data << { "data_title" => p.create_link_tag_for_title}
|
2016-03-22 09:58:37 +00:00
|
|
|
else
|
|
|
|
pd_data << { "data_title" => p.send(t) }
|
|
|
|
end
|
2016-01-11 12:35:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
"pd_datas" => pd_data
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
return [pd_title,plugin_datas]
|
|
|
|
end
|
|
|
|
|
2023-03-04 04:14:45 +00:00
|
|
|
def create_link_tag_for_title
|
|
|
|
link = OrbitHelper.url_to_plugin_show(self.to_param,'personal_journal')
|
|
|
|
url_to_plugin_show_blank = OrbitHelper.instance_variable_get(:@url_to_plugin_show_blank)
|
|
|
|
tmp_title = self.create_link
|
|
|
|
(url_to_plugin_show_blank ? tmp_title : "<a title=\"#{tmp_title}\" href=\"#{link}\" target=\"_blank\">#{tmp_title}</a>")
|
|
|
|
end
|
2014-08-11 11:16:52 +00:00
|
|
|
# def self.member_data
|
|
|
|
# members = MemberProfile.all
|
|
|
|
# member_data = []
|
|
|
|
# members.each do |m|
|
|
|
|
# if (m.first_name || m.last_name)
|
|
|
|
# member_data << {"memberId" => m.id.to_s, "memberName" => m.name}
|
|
|
|
# else
|
|
|
|
# member_data << {"memberId" => m.id.to_s, "memberName" => "No Name"}
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# member_data.to_json
|
|
|
|
# end
|
|
|
|
|
2019-08-19 07:15:45 +00:00
|
|
|
# def save_journal_paper_files
|
|
|
|
# self.journal_paper_files.each do |t|
|
|
|
|
# if t.should_destroy
|
|
|
|
# t.destroy
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
2014-08-11 11:16:52 +00:00
|
|
|
|
|
|
|
# def save_journal_paper_authors
|
|
|
|
# self.journal_paper_authors.each do |t|
|
|
|
|
# if t.should_destroy
|
|
|
|
# t.destroy
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
2014-06-18 04:09:19 +00:00
|
|
|
|
2014-08-01 10:56:56 +00:00
|
|
|
def get_plugin_data(fields_to_show)
|
|
|
|
plugin_datas = []
|
|
|
|
fields_to_show.each do |field|
|
2014-10-03 06:15:35 +00:00
|
|
|
plugin_data = self.get_plugin_field_data(field) rescue nil
|
2014-08-01 10:56:56 +00:00
|
|
|
next if plugin_data.blank? or plugin_data['value'].blank?
|
|
|
|
plugin_datas << plugin_data
|
|
|
|
end
|
|
|
|
plugin_datas
|
|
|
|
end
|
|
|
|
|
2023-07-01 07:35:21 +00:00
|
|
|
def member_profiles
|
|
|
|
@member_profiles ||= MemberProfile.where(:id.in=>self.member_profile_id).to_a
|
|
|
|
@member_profiles
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_profiles=(mps)
|
|
|
|
self.member_profile_id = mps.map(&:id)
|
|
|
|
@member_profiles = mps
|
|
|
|
@member_profile = @member_profiles.first
|
|
|
|
@member_profiles
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_profile
|
|
|
|
@member_profile ||= MemberProfile.where(:id.in=>self.member_profile_id).first
|
|
|
|
@member_profile
|
2023-03-04 04:26:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def member_profile=(mp)
|
2023-07-01 07:35:21 +00:00
|
|
|
if mp.class == MemberProfile
|
|
|
|
self.member_profile_id = [mp.id]
|
|
|
|
@member_profiles = [mp]
|
|
|
|
@member_profile = mp
|
|
|
|
else
|
|
|
|
self.member_profile_id = mp.map(&:id)
|
|
|
|
@member_profiles = mp
|
|
|
|
@member_profile = mp.first
|
|
|
|
end
|
2023-03-04 04:26:08 +00:00
|
|
|
end
|
|
|
|
|
2014-08-01 10:56:56 +00:00
|
|
|
def get_plugin_field_data(field)
|
|
|
|
case field
|
|
|
|
when "level_type"
|
|
|
|
value = self.journal_levels.collect{|level| level.title}.join(',') rescue ""
|
|
|
|
when "author_type"
|
|
|
|
value = self.journal_paper_author_types.collect{|type| type.title}.join(',') rescue ""
|
|
|
|
when "paper_type"
|
|
|
|
value = self.journal_paper_type.title rescue ""
|
2014-08-11 11:16:52 +00:00
|
|
|
when "author_name"
|
|
|
|
value = []
|
|
|
|
([I18n.locale]+(Site.first.in_use_locales-[I18n.locale])).each do |locale|
|
|
|
|
if self.member_profile.first_name_translations[locale] || self.member_profile.last_name_translations[locale]
|
|
|
|
value << "#{self.member_profile.first_name_translations[locale]} #{self.member_profile.last_name_translations[locale]}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
value = value.join(" / ")
|
2014-08-01 10:56:56 +00:00
|
|
|
when "publication_date"
|
2016-04-06 06:15:01 +00:00
|
|
|
value = self.publication_date.strftime("%Y-%m-%d") rescue ""
|
2014-08-01 10:56:56 +00:00
|
|
|
when "language"
|
2016-04-06 06:15:01 +00:00
|
|
|
value = I18n.t(self.language) if !self.language.nil? rescue ""
|
2015-01-09 07:30:13 +00:00
|
|
|
when "abstract"
|
|
|
|
value = nl2br(self.abstract)
|
2014-08-01 10:56:56 +00:00
|
|
|
when "file"
|
|
|
|
files = []
|
|
|
|
self.journal_paper_files.each do |file|
|
2019-08-19 07:57:15 +00:00
|
|
|
url = file.journal_file.url
|
2019-08-19 07:55:16 +00:00
|
|
|
title = ((file.title.blank? ? File.basename(file.journal_file.path) : file.title) rescue "")
|
2020-11-27 06:53:44 +00:00
|
|
|
files << (url.nil? ? "" : "<li><a href=\"#{url}\" target=\"_blank\">#{title}</a></li>")
|
2014-08-01 10:56:56 +00:00
|
|
|
end
|
|
|
|
value = files.join("")
|
2019-11-05 13:39:46 +00:00
|
|
|
when "url"
|
|
|
|
value = self.url.to_s.blank? ? "" : "<a href='#{self.url}'>#{self.url}</a>"
|
|
|
|
when "authors"
|
2020-08-14 03:07:30 +00:00
|
|
|
value = get_authors_show(self) rescue ""
|
2014-08-01 10:56:56 +00:00
|
|
|
else
|
|
|
|
value = self.send(field) rescue ""
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
"key"=>field,
|
|
|
|
"title_class"=>"journal-#{field.gsub('_','-')}-field",
|
|
|
|
"value_class"=>"journal-#{field.gsub('_','-')}-value",
|
|
|
|
"title"=>I18n.t('personal_journal.'+field),
|
|
|
|
"value"=>value
|
|
|
|
}
|
2014-06-25 05:26:03 +00:00
|
|
|
end
|
|
|
|
|
2014-06-12 10:27:26 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def add_http
|
|
|
|
unless self.url.blank? || self.url[/^http:\/\//] || self.url[/^https:\/\//]
|
|
|
|
self.url = 'http://' + self.url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-04 03:55:13 +00:00
|
|
|
end
|