Revision 1431:303b9be118d4 plugins/redmine_bibliography/app/models
| plugins/redmine_bibliography/app/models/author.rb | ||
|---|---|---|
| 18 | 18 |
} |
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 |
def institution |
|
| 22 |
if self.authorships.first.nil? |
|
| 23 |
"" |
|
| 24 |
else |
|
| 25 |
self.authorships.first.institution |
|
| 26 |
end |
|
| 27 |
end |
|
| 28 |
|
|
| 29 |
def mail |
|
| 30 |
if self.authorships.first.nil? |
|
| 31 |
"" |
|
| 32 |
else |
|
| 33 |
self.authorships.first.mail |
|
| 34 |
end |
|
| 35 |
end |
|
| 36 |
|
|
| 37 |
# todo: need to fix the name getter |
|
| 38 |
def name |
|
| 39 |
if self.authorships.first.nil? |
|
| 40 |
"" |
|
| 41 |
else |
|
| 42 |
self.authorships.first.name |
|
| 43 |
end |
|
| 44 |
end |
|
| 45 |
|
|
| 21 | 46 |
end |
| plugins/redmine_bibliography/app/models/authorship.rb | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
validates_presence_of :name_on_paper |
| 11 | 11 |
|
| 12 |
attr_accessor :search_author_class, :search_author_id, :search_name, :search_results, :identify_author |
|
| 12 |
attr_writer :search_author_id , :search_author_class |
|
| 13 |
attr_writer :search_author_tie |
|
| 13 | 14 |
|
| 14 |
before_create :associate_author_user |
|
| 15 |
### attr_accessor :search_results, :identify_author |
|
| 16 |
## attr_writer :search_author_class |
|
| 17 |
|
|
| 18 |
before_save :set_author |
|
| 15 | 19 |
before_update :delete_publication_cache |
| 16 | 20 |
|
| 17 | 21 |
# tod: review scope of ordering |
| ... | ... | |
| 34 | 38 |
} |
| 35 | 39 |
} |
| 36 | 40 |
|
| 41 |
def search_author_class |
|
| 42 |
# Authorship must always have an Author |
|
| 43 |
# unless it hasn't been saved yet |
|
| 44 |
# using default setter (attr_writer) |
|
| 45 |
|
|
| 46 |
if self.author.nil? |
|
| 47 |
aclass = "" |
|
| 48 |
else |
|
| 49 |
aclass = "Author" |
|
| 50 |
end |
|
| 51 |
|
|
| 52 |
@search_author_class || aclass |
|
| 53 |
end |
|
| 54 |
|
|
| 55 |
def search_author_id |
|
| 56 |
if self.author.nil? |
|
| 57 |
authid = "" |
|
| 58 |
else |
|
| 59 |
authid = author_id |
|
| 60 |
end |
|
| 61 |
|
|
| 62 |
@search_author_id || authid |
|
| 63 |
end |
|
| 64 |
|
|
| 65 |
def search_author_tie |
|
| 66 |
if self.author.nil? |
|
| 67 |
auth_tie = false |
|
| 68 |
else |
|
| 69 |
auth_tie = true |
|
| 70 |
end |
|
| 71 |
|
|
| 72 |
@search_author_tie || auth_tie |
|
| 73 |
end |
|
| 74 |
|
|
| 37 | 75 |
def name |
| 38 | 76 |
return self.name_on_paper |
| 39 | 77 |
end |
| ... | ... | |
| 54 | 92 |
Rails.cache.delete "publication-#{publication.id}-bibtex"
|
| 55 | 93 |
end |
| 56 | 94 |
|
| 57 |
def associate_author_user |
|
| 58 |
case self.search_author_class |
|
| 59 |
when "" |
|
| 60 |
logger.debug { "Unknown Author to be added..." }
|
|
| 61 |
when "User" |
|
| 95 |
private |
|
| 96 |
|
|
| 97 |
def set_author |
|
| 98 |
# do we want to associate the authorship |
|
| 99 |
# with an existing author/user? |
|
| 100 |
if @search_author_tie |
|
| 101 |
# if an author, simply associates with it |
|
| 102 |
# if an user, checks if it has already an author associated with it |
|
| 103 |
# if so, associates with that author |
|
| 104 |
# otherwise, creates a new author |
|
| 105 |
|
|
| 106 |
case @search_author_class |
|
| 107 |
when "" |
|
| 108 |
author = Author.new |
|
| 109 |
author.save |
|
| 110 |
|
|
| 111 |
when "User" |
|
| 112 |
user = User.find(@search_author_id) |
|
| 113 |
|
|
| 114 |
if user.author.nil? |
|
| 115 |
# User w/o author: |
|
| 116 |
# create new author and update user |
|
| 117 |
author = Author.new |
|
| 118 |
author.save |
|
| 119 |
user.author = author |
|
| 120 |
user.save |
|
| 121 |
else |
|
| 122 |
author = user.author |
|
| 123 |
end |
|
| 124 |
|
|
| 125 |
when "Author" |
|
| 126 |
author = Author.find(@search_author_id) |
|
| 127 |
end |
|
| 128 |
|
|
| 129 |
# if we don't want to associate with an existing author/user |
|
| 130 |
else |
|
| 131 |
# todo: should we delete any previously existing relationship? |
|
| 62 | 132 |
author = Author.new |
| 63 | 133 |
author.save |
| 64 |
self.author_id = author.id
|
|
| 134 |
end
|
|
| 65 | 135 |
|
| 66 |
when "Author" |
|
| 67 |
selected = self.search_results |
|
| 68 |
selected_classname = Kernel.const_get(self.search_author_class) |
|
| 69 |
selected_id = self.search_author_id |
|
| 70 |
object = selected_classname.find(selected_id) |
|
| 71 |
|
|
| 72 |
if object.respond_to? :name_on_paper |
|
| 73 |
# Authorship |
|
| 74 |
self.author_id = object.author.id |
|
| 75 |
else |
|
| 76 |
# User |
|
| 77 |
unless object.author.nil? |
|
| 78 |
self.author_id = object.author.id |
|
| 79 |
else |
|
| 80 |
author = Author.new |
|
| 81 |
object.author = author |
|
| 82 |
object.save |
|
| 83 |
self.author_id = object.author.id |
|
| 84 |
end |
|
| 85 |
end |
|
| 86 |
end |
|
| 136 |
self.author = author |
|
| 87 | 137 |
end |
| 88 | 138 |
end |
| plugins/redmine_bibliography/app/models/bibtex_entry_type.rb | ||
|---|---|---|
| 1 | 1 |
class BibtexEntryType < ActiveRecord::Base |
| 2 | 2 |
unloadable |
| 3 | 3 |
|
| 4 |
@@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ],
|
|
| 4 |
@@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ], |
|
| 5 | 5 |
'book' , [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ], |
| 6 | 6 |
'booklet' , [ 'howpublished', 'address', 'year', 'month', 'note', 'key' ], |
| 7 | 7 |
'conference', [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ], |
| ... | ... | |
| 25 | 25 |
end |
| 26 | 26 |
|
| 27 | 27 |
def self.fields (type) |
| 28 |
@@fields[ self.find(type).name ]
|
|
| 28 |
@@fields[ self.find(type).name ] |
|
| 29 | 29 |
end |
| 30 | 30 |
end |
| plugins/redmine_bibliography/app/models/publication.rb | ||
|---|---|---|
| 53 | 53 |
def notify_authors_publication_added(project) |
| 54 | 54 |
self.authors.each do |author| |
| 55 | 55 |
Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
|
| 56 |
Mailer.deliver_publication_added(author.user, self, project) unless author.user.nil?
|
|
| 56 |
Mailer.publication_added(author.user, self, project).deliver unless author.user.nil?
|
|
| 57 | 57 |
end |
| 58 | 58 |
end |
| 59 | 59 |
|
| 60 | 60 |
def notify_authors_publication_updated(project) |
| 61 | 61 |
self.authors.each do |author| |
| 62 | 62 |
Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
|
| 63 |
Mailer.deliver_publication_updated(author.user, self, project) unless author.user.nil?
|
|
| 63 |
Mailer.publication_updated(author.user, self, project).deliver unless author.user.nil?
|
|
| 64 | 64 |
end |
| 65 | 65 |
end |
| 66 | 66 |
|
Also available in: Unified diff