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
|
2014-06-04 03:55:13 +00:00
|
|
|
|
|
|
|
include OrbitModel::Status
|
2014-06-25 05:26:03 +00:00
|
|
|
include MemberHelper
|
|
|
|
include Slug
|
2014-06-04 03:55:13 +00:00
|
|
|
|
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
|
|
|
|
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-07-15 05:52:03 +00:00
|
|
|
field :rss2_id
|
2014-06-04 03:55:13 +00:00
|
|
|
|
|
|
|
paginates_per 10
|
|
|
|
|
2014-06-12 10:27:26 +00:00
|
|
|
#relations
|
2014-06-04 03:55:13 +00:00
|
|
|
belongs_to :member_profile
|
2014-06-12 10:27:26 +00:00
|
|
|
belongs_to :journal_paper_type
|
|
|
|
has_and_belongs_to_many :journal_levels
|
|
|
|
|
|
|
|
has_many :journal_paper_files, autosave: true, dependent: :destroy
|
|
|
|
accepts_nested_attributes_for :journal_paper_files
|
|
|
|
|
2014-07-10 06:52:06 +00:00
|
|
|
has_and_belongs_to_many :journal_paper_authors, dependent: :destroy
|
2014-06-12 10:27:26 +00:00
|
|
|
accepts_nested_attributes_for :journal_paper_authors
|
|
|
|
|
2014-07-03 14:39:01 +00:00
|
|
|
has_and_belongs_to_many :journal_paper_author_types
|
|
|
|
|
2014-06-18 04:09:19 +00:00
|
|
|
after_save :save_journal_paper_files, :save_journal_paper_authors
|
|
|
|
|
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
|
2014-06-12 10:27:26 +00:00
|
|
|
|
|
|
|
def create_link
|
|
|
|
title = []
|
|
|
|
|
|
|
|
title << self.member_profile.name if self.member_profile_id.present?
|
2014-07-10 09:25:26 +00:00
|
|
|
title << (!self.journal_paper_authors.blank? ? "#{self.journal_paper_authors.collect{|j| j.name}.join(', ')}" : nil)
|
2014-06-12 10:27:26 +00:00
|
|
|
if !self.publication_date.nil?
|
|
|
|
pd = self.publication_date.strftime("%Y-%m-%d").split('-')
|
|
|
|
title << pd[0]
|
|
|
|
end
|
|
|
|
title << self.paper_title if self.paper_title.present?
|
|
|
|
title << self.journal_title if self.journal_title.present?
|
|
|
|
title << self.vol_no if (self.vol_no.present? && self.vol_no != "0")
|
|
|
|
title << self.issue_no if (self.issue_no.present? && self.issue_no != "0")
|
|
|
|
title << "pp"+self.form_to_start+"-"+self.form_to_end if (self.form_to_start.present? && self.form_to_start != "0")
|
|
|
|
title << ( !self.journal_levels.blank? ? "(#{self.journal_levels.collect{|x| x.title}.join(', ')})" : nil)
|
2014-07-30 06:58:17 +00:00
|
|
|
title.join(', ').gsub(', ,',',')
|
2014-06-12 10:27:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def authors
|
|
|
|
authors = []
|
|
|
|
authors << self.member_profile.name if self.member_profile_id.present?
|
2014-07-10 09:25:26 +00:00
|
|
|
authors << (!self.journal_paper_authors.blank? ? "#{self.journal_paper_authors.collect{|j| j.name}.join(', ')}" : nil)
|
2014-06-12 10:27:26 +00:00
|
|
|
authors.join(', ')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.member_data
|
|
|
|
members = MemberProfile.all
|
|
|
|
member_data = []
|
2014-07-09 04:11:18 +00:00
|
|
|
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
|
2014-06-12 10:27:26 +00:00
|
|
|
end
|
|
|
|
member_data.to_json
|
|
|
|
end
|
|
|
|
|
2014-06-18 04:09:19 +00:00
|
|
|
def save_journal_paper_files
|
|
|
|
self.journal_paper_files.each do |t|
|
|
|
|
if t.should_destroy
|
|
|
|
t.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def save_journal_paper_authors
|
|
|
|
self.journal_paper_authors.each do |t|
|
|
|
|
if t.should_destroy
|
|
|
|
t.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-25 05:26:03 +00:00
|
|
|
def values_for_view
|
2014-06-27 03:58:09 +00:00
|
|
|
attribute_values = self.attributes.select{|k,v| v if (k.in?(["year","language","isbn","vol_no","issue_no","form_to_start","form_to_end","total_pages","keywords","abstract","publication_date","url","note"]) && v.present?)}
|
2014-06-25 05:26:03 +00:00
|
|
|
localized_fields = {"paper_title" => self.attributes["paper_title"][I18n.locale], "journal_title" => self.attributes["journal_title"][I18n.locale]}
|
|
|
|
authors = {"authors" => self.authors}
|
2014-07-02 02:29:13 +00:00
|
|
|
files = {}
|
|
|
|
files = self.journal_paper_files.collect do |f| {f.title => url_to_file(f.journal_file.url, f.title)} end
|
|
|
|
values = [attribute_values, localized_fields, authors] + files
|
2014-06-25 05:26:03 +00:00
|
|
|
values.inject(&:merge)
|
|
|
|
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
|