Revision 1068:e11d8d13ebc5 vendor/plugins
| vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb | ||
|---|---|---|
| 12 | 12 |
def projects_check_box_tags(name, projects) |
| 13 | 13 |
s = '' |
| 14 | 14 |
projects.sort.each do |project| |
| 15 |
if User.current.allowed_to?(:edit_publication, project)
|
|
| 15 |
if User.current.allowed_to?(:edit_publication, project) |
|
| 16 | 16 |
s << "<label>#{ check_box_tag name, project.id, false } #{link_to_project project}</label>\n"
|
| 17 | 17 |
s << '<br />' |
| 18 | 18 |
end |
| 19 | 19 |
end |
| 20 | 20 |
|
| 21 |
s
|
|
| 21 |
s |
|
| 22 | 22 |
end |
| 23 |
|
|
| 23 |
|
|
| 24 | 24 |
def choose_author_link(object_name, items) |
| 25 | 25 |
# called by autocomplete_for_author (publications' action/view) |
| 26 | 26 |
# creates the select list based on the results array |
| 27 | 27 |
# results is an array with both Users and Authorships objects |
| 28 |
|
|
| 28 |
|
|
| 29 | 29 |
@author_options = [] |
| 30 | 30 |
@results.each do |result| |
| 31 | 31 |
email_bit = result.mail.partition('@')[2]
|
| ... | ... | |
| 34 | 34 |
end |
| 35 | 35 |
@author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"]
|
| 36 | 36 |
end |
| 37 |
|
|
| 37 |
|
|
| 38 | 38 |
if @results.size > 0 |
| 39 | 39 |
s = select_tag( form_tag_name(object_name, :author_search_results), options_for_select(@author_options), { :id => form_tag_id(object_name, :author_search_results), :size => 3} )
|
| 40 | 40 |
s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q')
|
| 41 | 41 |
else |
| 42 | 42 |
s = "<em>No Authors found that match your search… sorry!</em>" |
| 43 |
end
|
|
| 43 |
end |
|
| 44 | 44 |
end |
| 45 | 45 |
|
| 46 | 46 |
def link_to_remove_fields(name, f) |
| 47 | 47 |
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del') |
| 48 | 48 |
end |
| 49 |
|
|
| 49 |
|
|
| 50 | 50 |
def link_to_add_author_fields(name, f, association, action) |
| 51 | 51 |
new_object = f.object.class.reflect_on_association(association).klass.new |
| 52 | 52 |
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
|
| 53 | 53 |
render(association.to_s.singularize + "_fields", :f => builder) |
| 54 |
end
|
|
| 54 |
end |
|
| 55 | 55 |
link_to_function(name, h("add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')"), { :class => 'icon icon-add', :id => "add_another_author" })
|
| 56 |
end
|
|
| 56 |
end |
|
| 57 | 57 |
|
| 58 | 58 |
def sanitized_object_name(object_name) |
| 59 | 59 |
object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") |
| ... | ... | |
| 62 | 62 |
def sanitized_method_name(method_name) |
| 63 | 63 |
method_name.sub(/\?$/, "") |
| 64 | 64 |
end |
| 65 |
|
|
| 65 |
|
|
| 66 | 66 |
def form_tag_name(object_name, method_name) |
| 67 | 67 |
str = "#{object_name.to_s}[#{sanitized_method_name(method_name.to_s)}]"
|
| 68 |
str.to_sym
|
|
| 68 |
str.to_sym |
|
| 69 | 69 |
end |
| 70 |
|
|
| 71 |
def form_tag_id(object_name, method_name)
|
|
| 70 |
|
|
| 71 |
def form_tag_id(object_name, method_name) |
|
| 72 | 72 |
str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}"
|
| 73 | 73 |
str.to_sym |
| 74 | 74 |
end |
| 75 |
|
|
| 75 |
|
|
| 76 | 76 |
def form_object_id(object_name) |
| 77 | 77 |
str = object_name.split("\[").last().gsub("\]","")
|
| 78 | 78 |
str.to_sym |
| 79 | 79 |
end |
| 80 | 80 |
|
| 81 |
def render_authorships_list(publication)
|
|
| 81 |
def render_authorships_list(publication) |
|
| 82 | 82 |
s = '<p>' |
| 83 |
|
|
| 83 |
|
|
| 84 | 84 |
publication.authorships.each do |authorship| |
| 85 | 85 |
s << link_to_authorship(authorship) |
| 86 | 86 |
s << "<br /><em>#{authorship.institution}</em></p>"
|
| 87 |
end
|
|
| 87 |
end |
|
| 88 | 88 |
|
| 89 |
s
|
|
| 89 |
s |
|
| 90 | 90 |
end |
| 91 |
|
|
| 92 |
def render_projects_list(publication, show_delete_icon)
|
|
| 91 |
|
|
| 92 |
def render_projects_list(publication, show_delete_icon) |
|
| 93 | 93 |
s= "" |
| 94 |
|
|
| 94 |
|
|
| 95 | 95 |
publication.projects.visible.each do |proj| |
| 96 | 96 |
s << link_to_project(proj, {}, :class => 'publication_project')
|
| 97 |
|
|
| 98 |
if show_delete_icon
|
|
| 97 |
|
|
| 98 |
if show_delete_icon |
|
| 99 | 99 |
if User.current.allowed_to?(:edit_publication, @project) |
| 100 | 100 |
if @project == proj |
| 101 | 101 |
# todo: move this message to yml file |
| 102 | 102 |
confirm_msg = 'Are you sure you want to remove the current project from this publication\'s projects list?' |
| 103 | 103 |
else |
| 104 | 104 |
confirm_msg = false |
| 105 |
end
|
|
| 106 |
|
|
| 107 |
s << link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_project', :id => publication, :remove_project_id => proj, :project_id => @project }, :method => :post, :confirm => confirm_msg }, :class => 'icon icon-del')
|
|
| 105 |
end |
|
| 106 |
|
|
| 107 |
s << link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_project', :id => publication, :remove_project_id => proj, :project_id => @project }, :method => :post, :confirm => confirm_msg }, :class => 'icon icon-del')
|
|
| 108 | 108 |
end |
| 109 | 109 |
end |
| 110 |
|
|
| 111 |
s << "<br />" |
|
| 112 |
end |
|
| 113 | 110 |
|
| 114 |
s |
|
| 111 |
s << "<br />" |
|
| 112 |
end |
|
| 113 |
|
|
| 114 |
s |
|
| 115 | 115 |
end |
| 116 |
|
|
| 117 |
def show_cite_proc_entry(publication)
|
|
| 118 |
# code that should be moved either to the model or to the controller?
|
|
| 119 |
|
|
| 120 |
publication.print_entry(:ieee)
|
|
| 116 |
|
|
| 117 |
def print_ieee_format(publication)
|
|
| 118 |
Rails.cache.fetch("publication-#{publication.id}-ieee") do
|
|
| 119 |
publication.print_entry(:ieee) |
|
| 120 |
end
|
|
| 121 | 121 |
end |
| 122 |
|
|
| 123 |
def print_bibtex_entry(publication) |
|
| 124 |
publication.print_entry(:bibtex) |
|
| 122 |
|
|
| 123 |
def print_bibtex_format(publication) |
|
| 124 |
Rails.cache.fetch("publication-#{publication.id}-bibtex") do
|
|
| 125 |
publication.print_entry(:bibtex) |
|
| 126 |
end |
|
| 125 | 127 |
end |
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 128 | 130 |
def show_bibtex_fields(bibtex_entry) |
| 129 | 131 |
s = "" |
| 130 | 132 |
bibtex_entry.attributes.keys.sort.each do |key| |
| 131 | 133 |
value = bibtex_entry.attributes[key].to_s |
| 132 | 134 |
next if key == 'id' or key == 'publication_id' or value == "" |
| 133 |
s << "<h4>" + l("field_#{key}") + "</h4>"
|
|
| 135 |
s << "<h4>" + l("field_#{key}") + "</h4>"
|
|
| 134 | 136 |
s << "<p>" |
| 135 | 137 |
if key == "entry_type" |
| 136 | 138 |
s << bibtex_entry.entry_type_label |
| ... | ... | |
| 140 | 142 |
s << "</p>" |
| 141 | 143 |
end |
| 142 | 144 |
s |
| 143 |
end
|
|
| 145 |
end |
|
| 144 | 146 |
end |
| 145 | 147 |
|
| vendor/plugins/redmine_bibliography/app/models/publication.rb | ||
|---|---|---|
| 2 | 2 |
|
| 3 | 3 |
class Publication < ActiveRecord::Base |
| 4 | 4 |
unloadable |
| 5 |
|
|
| 5 |
|
|
| 6 | 6 |
has_many :authorships, :dependent => :destroy, :order => "auth_order ASC" |
| 7 | 7 |
has_many :authors, :through => :authorships, :uniq => true |
| 8 |
|
|
| 8 |
|
|
| 9 | 9 |
has_one :bibtex_entry, :dependent => :destroy |
| 10 | 10 |
|
| 11 | 11 |
validates_presence_of :title |
| ... | ... | |
| 14 | 14 |
accepts_nested_attributes_for :authorships |
| 15 | 15 |
accepts_nested_attributes_for :authors, :allow_destroy => true |
| 16 | 16 |
accepts_nested_attributes_for :bibtex_entry, :allow_destroy => true |
| 17 |
|
|
| 17 |
|
|
| 18 | 18 |
has_and_belongs_to_many :projects, :uniq => true |
| 19 |
|
|
| 19 |
|
|
| 20 | 20 |
before_save :set_initial_author_order |
| 21 | 21 |
|
| 22 | 22 |
# Ensure error message uses proper text instead of |
| ... | ... | |
| 30 | 30 |
end |
| 31 | 31 |
end |
| 32 | 32 |
|
| 33 |
def notify_authors_publication_added(project)
|
|
| 33 |
def notify_authors_publication_added(project) |
|
| 34 | 34 |
self.authors.each do |author| |
| 35 | 35 |
Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
|
| 36 | 36 |
Mailer.deliver_publication_added(author.user, self, project) unless author.user.nil? |
| 37 | 37 |
end |
| 38 | 38 |
end |
| 39 |
|
|
| 40 |
def notify_authors_publication_updated(project)
|
|
| 39 |
|
|
| 40 |
def notify_authors_publication_updated(project) |
|
| 41 | 41 |
self.authors.each do |author| |
| 42 | 42 |
Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
|
| 43 | 43 |
Mailer.deliver_publication_updated(author.user, self, project) unless author.user.nil? |
| 44 | 44 |
end |
| 45 | 45 |
end |
| 46 |
|
|
| 47 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 | 48 |
def set_initial_author_order |
| 49 | 49 |
authorships = self.authorships |
| 50 |
|
|
| 50 |
|
|
| 51 | 51 |
logger.debug { "Publication \"#{self.title}\" has #{authorships.size} authors." }
|
| 52 |
|
|
| 52 |
|
|
| 53 | 53 |
authorships.each_with_index do |authorship, index| |
| 54 | 54 |
if authorship.auth_order.nil? |
| 55 | 55 |
authorship.auth_order = index |
| 56 | 56 |
end |
| 57 |
end
|
|
| 57 |
end |
|
| 58 | 58 |
end |
| 59 |
|
|
| 59 |
|
|
| 60 | 60 |
def print_bibtex_author_names |
| 61 |
# this authors are correctly sorted because the authorships model
|
|
| 61 |
# this authors are correctly sorted because the authorships model |
|
| 62 | 62 |
# already outputs the author names ASC by auth_order |
| 63 | 63 |
self.authorships.map{|a| a.name_on_paper}.join(' and ')
|
| 64 |
end
|
|
| 65 |
|
|
| 64 |
end |
|
| 65 |
|
|
| 66 | 66 |
def print_entry(style) |
| 67 | 67 |
bib = BibTeX::Entry.new |
| 68 | 68 |
|
| 69 | 69 |
bib.author = self.print_bibtex_author_names |
| 70 | 70 |
bib.title = self.title |
| 71 | 71 |
|
| 72 |
self.bibtex_entry.attributes.keys.sort.each do |key|
|
|
| 72 |
self.bibtex_entry.attributes.keys.sort.each do |key| |
|
| 73 | 73 |
value = self.bibtex_entry.attributes[key].to_s |
| 74 | 74 |
next if key == 'id' or key == 'publication_id' or value == "" |
| 75 | 75 |
|
| 76 |
if key == "entry_type"
|
|
| 76 |
if key == "entry_type" |
|
| 77 | 77 |
bib.type = BibtexEntryType.find(self.bibtex_entry.entry_type).name |
| 78 | 78 |
else |
| 79 | 79 |
bib[key.to_sym] = value |
| 80 |
end
|
|
| 80 |
end |
|
| 81 | 81 |
end |
| 82 |
|
|
| 82 |
|
|
| 83 | 83 |
if style == :ieee |
| 84 |
CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html
|
|
| 85 |
else
|
|
| 84 |
CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html |
|
| 85 |
else |
|
| 86 | 86 |
bibtex = bib.to_s :include => :meta_content |
| 87 | 87 |
bibtex.strip! |
| 88 | 88 |
logger.error { bibtex }
|
| 89 |
end
|
|
| 89 |
end |
|
| 90 | 90 |
end |
| 91 | 91 |
end |
| vendor/plugins/redmine_bibliography/app/views/projects/_bibliography_box.html.erb | ||
|---|---|---|
| 9 | 9 |
<div class="box"> |
| 10 | 10 |
<h3><%=l(:label_related_publication_plural)%></h3> |
| 11 | 11 |
|
| 12 |
<dl>
|
|
| 13 |
<% @project.publications.each do |publication| %>
|
|
| 12 |
<dl> |
|
| 13 |
<% @project.publications.each do |publication| %> |
|
| 14 | 14 |
<dt> |
| 15 |
<%= publication.print_entry(:ieee) -%>
|
|
| 15 |
<%= print_ieee_format(publication) %>
|
|
| 16 | 16 |
</dt> |
| 17 | 17 |
<dd> |
| 18 |
<%= link_to("[More Details]", {:controller => :publications, :action => :show, :id => publication.id, :project_id => @project.id}) -%>
|
|
| 19 |
|
|
| 20 |
<%= link_to_function "[B<small>IB</small>T<sub>E</sub>X]", onclick="toggleBibtex(this)" -%>
|
|
| 18 |
<%= link_to("[More Details]", {:controller => :publications, :action => :show, :id => publication.id, :project_id => @project.id}) -%>
|
|
| 19 |
|
|
| 20 |
<%= link_to_function "[B<small>IB</small>T<sub>E</sub>X]", onclick="toggleBibtex(this)" -%> |
|
| 21 | 21 |
</dd> |
| 22 | 22 |
<dd class="bibtex-textarea collapsed" style="display: none;"> |
| 23 |
<textarea readonly><%= publication.print_entry(:bibtex) -%></textarea>
|
|
| 23 |
<textarea readonly> <%= print_bibtex_format(publication) %> </textarea>
|
|
| 24 | 24 |
</dd> |
| 25 | 25 |
<% end -%> |
| 26 | 26 |
</dl> |
| vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb | ||
|---|---|---|
| 2 | 2 |
|
| 3 | 3 |
<div class="box"> |
| 4 | 4 |
<h3>Publication Info</h3> |
| 5 |
<p><%= show_cite_proc_entry(@publication)%></p>
|
|
| 5 |
<p><%= print_ieee_format(@publication)%></p>
|
|
| 6 | 6 |
|
| 7 | 7 |
<h3>B<small>IB</small>T<sub>E</sub>X Format</h3> |
| 8 |
<pre><%=h print_bibtex_entry(@publication) %></pre>
|
|
| 8 |
<pre><%=h print_bibtex_format(@publication) %></pre>
|
|
| 9 | 9 |
</div> |
| 10 | 10 |
|
| 11 | 11 |
<div class="box"> |
| vendor/plugins/redmine_bibliography/init.rb | ||
|---|---|---|
| 5 | 5 |
require 'citeproc' |
| 6 | 6 |
|
| 7 | 7 |
|
| 8 |
RAILS_DEFAULT_LOGGER.info 'Starting Bibliography Plugin for RedMine'
|
|
| 8 |
RAILS_DEFAULT_LOGGER.info 'Starting Bibliography Plugin for Redmine'
|
|
| 9 | 9 |
|
| 10 | 10 |
# Patches to the Redmine core. |
| 11 | 11 |
Dispatcher.to_prepare :redmine_model_dependencies do |
| ... | ... | |
| 25 | 25 |
Mailer.send(:include, Bibliography::MailerPatch) |
| 26 | 26 |
end |
| 27 | 27 |
|
| 28 |
unless ProjectsController.included_modules.include?(Bibliography::ProjectsControllerPatch) |
|
| 29 |
ProjectsController.send(:include, Bibliography::ProjectsControllerPatch) |
|
| 30 |
end |
|
| 28 | 31 |
|
| 29 | 32 |
end |
| 30 | 33 |
|
| ... | ... | |
| 51 | 54 |
# extending the Project Menu |
| 52 | 55 |
menu :project_menu, :publications, { :controller => 'publications', :action => 'index', :path => nil }, :after => :activity, :param => :project_id, :caption => Proc.new { Setting.plugin_redmine_bibliography['menu'] },
|
| 53 | 56 |
:if => Proc.new { !Setting.plugin_redmine_bibliography['menu'].blank? }
|
| 54 |
|
|
| 57 |
|
|
| 55 | 58 |
end |
Also available in: Unified diff