Revision 1072:872db7098cb9 vendor
| vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb | ||
|---|---|---|
| 5 | 5 |
unloadable |
| 6 | 6 |
|
| 7 | 7 |
model_object Publication |
| 8 |
before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
|
|
| 8 |
before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ] |
|
| 9 | 9 |
before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ] |
| 10 | 10 |
|
| 11 | 11 |
def new |
| ... | ... | |
| 16 | 16 |
@publication.build_bibtex_entry |
| 17 | 17 |
|
| 18 | 18 |
# and at least one author |
| 19 |
# @publication.authorships.build.build_author
|
|
| 19 |
# @publication.authorships.build.build_author |
|
| 20 | 20 |
@author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
|
| 21 |
|
|
| 22 |
|
|
| 23 | 21 |
end |
| 24 | 22 |
|
| 25 |
def create
|
|
| 23 |
def create |
|
| 26 | 24 |
@project = Project.find(params[:project_id]) |
| 27 | 25 |
|
| 28 | 26 |
@author_options = [] |
| ... | ... | |
| 30 | 28 |
@publication = Publication.new(params[:publication]) |
| 31 | 29 |
@publication.projects << @project unless @project.nil? |
| 32 | 30 |
|
| 33 |
if @publication.save
|
|
| 31 |
if @publication.save |
|
| 34 | 32 |
@publication.notify_authors_publication_added(@project) |
| 35 | 33 |
|
| 36 | 34 |
flash[:notice] = "Successfully created publication." |
| ... | ... | |
| 58 | 56 |
|
| 59 | 57 |
# method for creating "pasted" bibtex entries |
| 60 | 58 |
if bibtex_entry |
| 61 |
parse_bibtex_list bibtex_entry
|
|
| 59 |
parse_bibtex_list bibtex_entry |
|
| 62 | 60 |
end |
| 63 | 61 |
end |
| 64 | 62 |
|
| 65 | 63 |
def get_bibtex_required_fields |
| 66 | 64 |
|
| 67 | 65 |
unless params[:value].empty? |
| 68 |
fields = BibtexEntryType.fields(params[:value])
|
|
| 66 |
fields = BibtexEntryType.fields(params[:value]) |
|
| 69 | 67 |
end |
| 70 | 68 |
|
| 71 | 69 |
respond_to do |format| |
| 72 | 70 |
format.js {
|
| 73 |
render(:update) {|page|
|
|
| 71 |
render(:update) {|page|
|
|
| 74 | 72 |
if params[:value].empty? |
| 75 | 73 |
page << "hideOnLoad();" |
| 76 | 74 |
else |
| ... | ... | |
| 92 | 90 |
end |
| 93 | 91 |
end |
| 94 | 92 |
|
| 95 |
def edit
|
|
| 93 |
def edit |
|
| 96 | 94 |
find_project_by_project_id unless params[:project_id].nil? |
| 97 | 95 |
|
| 98 | 96 |
@edit_view = true; |
| 99 | 97 |
@publication = Publication.find(params[:id]) |
| 100 | 98 |
@selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type |
| 101 | 99 |
|
| 102 |
@author_options = []
|
|
| 100 |
@author_options = [] |
|
| 103 | 101 |
|
| 104 |
@bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)
|
|
| 102 |
@bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id) |
|
| 105 | 103 |
end |
| 106 | 104 |
|
| 107 |
def update |
|
| 108 |
@publication = Publication.find(params[:id]) |
|
| 109 |
|
|
| 105 |
def update |
|
| 106 |
@publication = Publication.find(params[:id]) |
|
| 110 | 107 |
@author_options = [] |
| 111 | 108 |
|
| 112 |
logger.error { "INSIDE THE UPDATE ACTION IN THE PUBLICATION CONTROLLER" }
|
|
| 113 |
|
|
| 114 | 109 |
if @publication.update_attributes(params[:publication]) |
| 115 | 110 |
flash[:notice] = "Successfully updated Publication." |
| 116 | 111 |
|
| 112 |
# expires the previosly cached entries |
|
| 113 |
Rails.cache.delete "publication-#{@publication.id}-ieee"
|
|
| 114 |
Rails.cache.delete "publication-#{@publication.id}-bibtex"
|
|
| 115 |
|
|
| 117 | 116 |
if !params[:project_id].nil? |
| 118 | 117 |
redirect_to :action => :show, :id => @publication, :project_id => params[:project_id] |
| 119 | 118 |
else |
| ... | ... | |
| 121 | 120 |
end |
| 122 | 121 |
else |
| 123 | 122 |
render :action => 'edit' |
| 124 |
end
|
|
| 123 |
end |
|
| 125 | 124 |
end |
| 126 | 125 |
|
| 127 | 126 |
|
| ... | ... | |
| 143 | 142 |
return authors_entry.split(" and ")
|
| 144 | 143 |
end |
| 145 | 144 |
|
| 146 |
# parses a list of bibtex
|
|
| 145 |
# parses a list of bibtex |
|
| 147 | 146 |
def parse_bibtex_list(bibtex_list) |
| 148 | 147 |
bibliography = BibTeX.parse bibtex_list |
| 149 | 148 |
|
| ... | ... | |
| 156 | 155 |
create_bibtex_entry d |
| 157 | 156 |
end |
| 158 | 157 |
end |
| 159 |
end
|
|
| 158 |
end |
|
| 160 | 159 |
|
| 161 |
def create_bibtex_entry(d)
|
|
| 160 |
def create_bibtex_entry(d) |
|
| 162 | 161 |
@publication = Publication.new |
| 163 |
@bentry = BibtexEntry.new
|
|
| 162 |
@bentry = BibtexEntry.new |
|
| 164 | 163 |
authors = [] |
| 165 | 164 |
institution = "" |
| 166 | 165 |
email = "" |
| ... | ... | |
| 178 | 177 |
else |
| 179 | 178 |
@bentry[field] = d[field] |
| 180 | 179 |
end |
| 181 |
end
|
|
| 180 |
end |
|
| 182 | 181 |
|
| 183 | 182 |
@publication.bibtex_entry = @bentry |
| 184 | 183 |
@publication.save |
| 185 | 184 |
|
| 186 |
# what is this for???
|
|
| 185 |
# what is this for??? |
|
| 187 | 186 |
# @created_publications << @publication.id |
| 188 | 187 |
|
| 189 | 188 |
# need to save all authors |
| 190 |
# and establish the author-publication association
|
|
| 191 |
# via the authorships table
|
|
| 189 |
# and establish the author-publication association |
|
| 190 |
# via the authorships table |
|
| 192 | 191 |
authors.each_with_index.map do |authorname, idx| |
| 193 | 192 |
author = Author.new(:name => authorname) |
| 194 | 193 |
if author.save! |
| ... | ... | |
| 220 | 219 |
def autocomplete_for_project |
| 221 | 220 |
@publication = Publication.find(params[:id]) |
| 222 | 221 |
|
| 223 |
@projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects
|
|
| 222 |
@projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects |
|
| 224 | 223 |
logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
|
| 225 | 224 |
render :layout => false |
| 226 | 225 |
end |
| 227 | 226 |
|
| 228 |
def autocomplete_for_author
|
|
| 227 |
def autocomplete_for_author |
|
| 229 | 228 |
@results = [] |
| 230 | 229 |
|
| 231 | 230 |
object_id = params[:object_id] |
| ... | ... | |
| 239 | 238 |
|
| 240 | 239 |
@results = users_list |
| 241 | 240 |
|
| 242 |
# TODO: can be optimized…
|
|
| 243 |
authorships_list.each do |authorship|
|
|
| 241 |
# TODO: can be optimized… |
|
| 242 |
authorships_list.each do |authorship| |
|
| 244 | 243 |
flag = true |
| 245 | 244 |
|
| 246 | 245 |
users_list.each do |user| |
| ... | ... | |
| 254 | 253 |
@results << authorship if flag |
| 255 | 254 |
end |
| 256 | 255 |
|
| 257 |
render :layout => false
|
|
| 256 |
render :layout => false |
|
| 258 | 257 |
end |
| 259 | 258 |
|
| 260 | 259 |
def get_user_info |
| ... | ... | |
| 272 | 271 |
|
| 273 | 272 |
respond_to do |format| |
| 274 | 273 |
format.js {
|
| 275 |
render(:update) {|page|
|
|
| 274 |
render(:update) {|page|
|
|
| 276 | 275 |
page[name_field].value = item.name |
| 277 | 276 |
page[email_field].value = item.mail |
| 278 | 277 |
page[institution_field].value = item.institution |
| ... | ... | |
| 294 | 293 |
end |
| 295 | 294 |
|
| 296 | 295 |
def add_project |
| 297 |
@projects = Project.find(params[:publication][:project_ids])
|
|
| 296 |
@projects = Project.find(params[:publication][:project_ids]) |
|
| 298 | 297 |
@publication.projects << @projects |
| 299 |
@project = Project.find(params[:project_id])
|
|
| 298 |
@project = Project.find(params[:project_id]) |
|
| 300 | 299 |
|
| 301 |
# TODO luisf should also respond to HTML???
|
|
| 300 |
# TODO luisf should also respond to HTML??? |
|
| 302 | 301 |
respond_to do |format| |
| 303 | 302 |
format.html { redirect_to :back }
|
| 304 |
format.js {
|
|
| 305 |
render(:update) {|page|
|
|
| 306 |
page[:add_project_form].reset
|
|
| 303 |
format.js {
|
|
| 304 |
render(:update) {|page|
|
|
| 305 |
page[:add_project_form].reset |
|
| 307 | 306 |
page.replace_html :list_projects, :partial => 'list_projects' |
| 308 | 307 |
} |
| 309 | 308 |
} |
| ... | ... | |
| 320 | 319 |
@publication.projects.delete proj if request.post? |
| 321 | 320 |
end |
| 322 | 321 |
else |
| 323 |
logger.error { "Cannot remove project from publication list" }
|
|
| 322 |
logger.error { "Cannot remove project from publication list" }
|
|
| 324 | 323 |
end |
| 325 | 324 |
|
| 326 | 325 |
logger.error { "CURRENT project name#{proj.name} and wanna delete #{@project.name}" }
|
| 327 | 326 |
|
| 328 |
render(:update) {|page|
|
|
| 327 |
render(:update) {|page|
|
|
| 329 | 328 |
page.replace_html "list_projects", :partial => 'list_projects', :id => @publication |
| 330 |
}
|
|
| 329 |
} |
|
| 331 | 330 |
end |
| 332 | 331 |
|
| 333 | 332 |
def destroy |
| 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 | ||
|---|---|---|
| 4 | 4 |
require 'bibtex' |
| 5 | 5 |
require 'citeproc' |
| 6 | 6 |
|
| 7 |
|
|
| 8 |
RAILS_DEFAULT_LOGGER.info 'Starting Bibliography Plugin for RedMine' |
|
| 9 |
|
|
| 10 | 7 |
# Patches to the Redmine core. |
| 11 | 8 |
Dispatcher.to_prepare :redmine_model_dependencies do |
| 12 | 9 |
require_dependency 'project' |
| ... | ... | |
| 25 | 22 |
Mailer.send(:include, Bibliography::MailerPatch) |
| 26 | 23 |
end |
| 27 | 24 |
|
| 28 |
|
|
| 25 |
unless ProjectsHelper.included_modules.include?(Bibliography::ProjectsHelperPatch) |
|
| 26 |
ProjectsHelper.send(:include, Bibliography::ProjectsHelperPatch) |
|
| 27 |
end |
|
| 29 | 28 |
end |
| 30 | 29 |
|
| 31 | 30 |
|
| ... | ... | |
| 51 | 50 |
# extending the Project Menu |
| 52 | 51 |
menu :project_menu, :publications, { :controller => 'publications', :action => 'index', :path => nil }, :after => :activity, :param => :project_id, :caption => Proc.new { Setting.plugin_redmine_bibliography['menu'] },
|
| 53 | 52 |
:if => Proc.new { !Setting.plugin_redmine_bibliography['menu'].blank? }
|
| 54 |
|
|
| 53 |
|
|
| 55 | 54 |
end |
| vendor/plugins/redmine_bibliography/lib/bibliography/projects_helper_patch.rb | ||
|---|---|---|
| 1 |
module Bibliography |
|
| 2 |
module ProjectsHelperPatch |
|
| 3 |
|
|
| 4 |
def self.included(base) # :nodoc: |
|
| 5 |
base.send(:include, InstanceMethods) |
|
| 6 |
base.send(:include, PublicationsHelper) |
|
| 7 |
|
|
| 8 |
base.class_eval do |
|
| 9 |
unloadable |
|
| 10 |
end |
|
| 11 |
end |
|
| 12 |
|
|
| 13 |
module InstanceMethods |
|
| 14 |
end |
|
| 15 |
end |
|
| 16 |
end |
|
| 17 |
|
|
| vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb | ||
|---|---|---|
| 1 | 1 |
require_dependency 'user' |
| 2 | 2 |
|
| 3 | 3 |
module Bibliography |
| 4 |
module UserAuthorPatch
|
|
| 4 |
module UserAuthorPatch |
|
| 5 | 5 |
def self.included(base) |
| 6 |
base.send(:include, InstanceMethods)
|
|
| 7 |
extend ClassMethods
|
|
| 8 |
|
|
| 6 |
base.send(:include, InstanceMethods) |
|
| 7 |
extend ClassMethods |
|
| 8 |
|
|
| 9 | 9 |
end #self.included |
| 10 |
|
|
| 10 |
|
|
| 11 | 11 |
module ClassMethods |
| 12 |
end
|
|
| 13 |
|
|
| 12 |
end |
|
| 13 |
|
|
| 14 | 14 |
module InstanceMethods |
| 15 | 15 |
|
| 16 | 16 |
def institution |
| ... | ... | |
| 18 | 18 |
institution_name = self.ssamr_user_detail.institution_name |
| 19 | 19 |
else |
| 20 | 20 |
institution_name = "No Institution Set" |
| 21 |
end
|
|
| 22 |
return institution_name
|
|
| 21 |
end |
|
| 22 |
return institution_name |
|
| 23 | 23 |
end |
| 24 | 24 |
|
| 25 | 25 |
def get_author_info |
| 26 | 26 |
# TODO: DELETE THIS METHOD?? |
| 27 |
info = {
|
|
| 27 |
info = {
|
|
| 28 | 28 |
:name_on_paper => self.name, |
| 29 | 29 |
:email => self.mail, |
| 30 | 30 |
:institution => "", |
| 31 | 31 |
:author_user_id => self.id, |
| 32 |
:is_user => "1"
|
|
| 32 |
:is_user => "1" |
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
if not self.ssamr_user_detail.nil? |
| 36 | 36 |
info[:institution] = self.ssamr_user_detail.institution_name |
| 37 | 37 |
end |
| 38 | 38 |
|
| 39 |
return info
|
|
| 39 |
return info |
|
| 40 | 40 |
end |
| 41 |
|
|
| 41 |
|
|
| 42 | 42 |
end #InstanceMethods |
| 43 |
|
|
| 43 |
|
|
| 44 | 44 |
end #UserPublicationsPatch |
| 45 | 45 |
end #RedmineBibliography |
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_controller_patch.rb | ||
|---|---|---|
| 3 | 3 |
|
| 4 | 4 |
module RedmineTags |
| 5 | 5 |
module Patches |
| 6 |
module ProjectsControllerPatch
|
|
| 6 |
module ProjectsControllerPatch |
|
| 7 | 7 |
def self.included(base) |
| 8 | 8 |
base.send(:include, InstanceMethods) |
| 9 |
base.class_eval do
|
|
| 10 |
unloadable
|
|
| 9 |
base.class_eval do |
|
| 10 |
unloadable |
|
| 11 | 11 |
skip_before_filter :authorize, :only => [:set_fieldset_status] |
| 12 | 12 |
skip_before_filter :find_project, :only => [:set_fieldset_status] |
| 13 | 13 |
before_filter :add_tags_to_project, :only => [:save, :update] |
| 14 | 14 |
|
| 15 |
helper :tags |
|
| 16 |
include TagsHelper |
|
| 17 |
|
|
| 15 | 18 |
alias :index filtered_index |
| 16 | 19 |
end |
| 17 | 20 |
end |
| 18 | 21 |
|
| 19 | 22 |
module InstanceMethods |
| 20 |
|
|
| 23 |
|
|
| 21 | 24 |
def add_tags_to_project |
| 22 | 25 |
|
| 23 | 26 |
if params && params[:project] && !params[:project][:tag_list].nil? |
| ... | ... | |
| 57 | 60 |
else |
| 58 | 61 |
@myproj_status = session[:my_projects_fieldset_status] |
| 59 | 62 |
end |
| 60 |
|
|
| 63 |
|
|
| 61 | 64 |
if session[:filters_fieldset_status].nil? |
| 62 | 65 |
@filter_status = "false" |
| 63 | 66 |
else |
| 64 | 67 |
@filter_status = session[:filters_fieldset_status] |
| 65 | 68 |
end |
| 66 |
|
|
| 69 |
|
|
| 67 | 70 |
if params && params[:project] && !params[:project][:tag_list].nil? |
| 68 | 71 |
@filter_status = "true" |
| 69 | 72 |
end |
| 70 |
|
|
| 73 |
|
|
| 71 | 74 |
end |
| 72 | 75 |
|
| 73 | 76 |
# Lists visible projects. Paginator is for top-level projects only |
| ... | ... | |
| 78 | 81 |
get_fieldset_statuses |
| 79 | 82 |
|
| 80 | 83 |
respond_to do |format| |
| 81 |
format.html {
|
|
| 84 |
format.html {
|
|
| 82 | 85 |
paginate_projects |
| 83 |
|
|
| 84 |
@projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause)
|
|
| 86 |
|
|
| 87 |
@projects = Project.visible_roots.find(@projects, :offset => @offset, :limit => @limit, :order => sort_clause) |
|
| 85 | 88 |
|
| 86 | 89 |
if User.current.logged? |
| 87 | 90 |
# seems sort_by gives us case-sensitive ordering, which we don't want |
| 88 | 91 |
# @user_projects = User.current.projects.sort_by(&:name) |
| 89 | 92 |
@user_projects = User.current.projects.all(:order => :name) |
| 90 | 93 |
end |
| 91 |
|
|
| 94 |
|
|
| 92 | 95 |
render :template => 'projects/index.html.erb', :layout => !request.xhr? |
| 93 | 96 |
} |
| 94 | 97 |
format.api {
|
| ... | ... | |
| 112 | 115 |
|
| 113 | 116 |
private |
| 114 | 117 |
|
| 115 |
def filter_projects
|
|
| 116 |
@question = (params[:q] || "").strip
|
|
| 118 |
def filter_projects |
|
| 119 |
@question = (params[:q] || "").strip |
|
| 117 | 120 |
|
| 118 | 121 |
if params.has_key?(:project) |
| 119 | 122 |
@tag_list = (params[:project][:tag_list] || "").strip.split(",")
|
| ... | ... | |
| 126 | 129 |
else |
| 127 | 130 |
@projects = Project.visible_roots.find(Project.visible.search_by_question(@question)) |
| 128 | 131 |
end |
| 129 |
|
|
| 132 |
|
|
| 130 | 133 |
unless @tag_list.empty? |
| 131 | 134 |
@tagged_projects_ids = Project.visible.tagged_with(@tag_list).collect{ |project| Project.find(project.id).root }
|
| 132 | 135 |
@projects = @projects & @tagged_projects_ids |
| vendor/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb | ||
|---|---|---|
| 4 | 4 |
|
| 5 | 5 |
def self.included(base) # :nodoc: |
| 6 | 6 |
base.send(:include, InstanceMethods) |
| 7 |
base.send(:include, TagsHelper) |
|
| 7 |
# base.send(:include, TagsHelper)
|
|
| 8 | 8 |
base.class_eval do |
| 9 | 9 |
unloadable |
| 10 | 10 |
end |
| 11 | 11 |
end |
| 12 | 12 |
|
| 13 |
module InstanceMethods
|
|
| 13 |
module InstanceMethods |
|
| 14 | 14 |
# Renders a tree of projects that the current user does not belong |
| 15 | 15 |
# to, or of all projects if the current user is not logged in. The |
| 16 | 16 |
# given collection may be a subset of the whole project tree |
| ... | ... | |
| 19 | 19 |
# description, manager(s), creation date, last activity date, |
| 20 | 20 |
# general activity level, whether there is anything actually hosted |
| 21 | 21 |
# here for the project, etc. |
| 22 |
def render_project_table_with_filtering(projects, question)
|
|
| 22 |
def render_project_table_with_filtering(projects, question) |
|
| 23 | 23 |
custom_fields = "" |
| 24 | 24 |
s = "" |
| 25 | 25 |
if projects.any? |
| 26 | 26 |
tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) |
| 27 |
|
|
| 27 |
|
|
| 28 | 28 |
s << "<div class='autoscroll'>" |
| 29 | 29 |
s << "<table class='list projects'>" |
| 30 | 30 |
s << "<thead><tr>" |
| 31 |
|
|
| 31 |
|
|
| 32 | 32 |
s << sort_header_tag('name', :caption => l("field_name"))
|
| 33 | 33 |
s << "<th class='tags'>" << l("tags") << "</th>"
|
| 34 | 34 |
s << "<th class='managers'>" << l("label_managers") << "</th>"
|
| 35 | 35 |
s << sort_header_tag('created_on', :default_order => 'desc')
|
| 36 | 36 |
s << sort_header_tag('updated_on', :default_order => 'desc')
|
| 37 |
|
|
| 37 |
|
|
| 38 | 38 |
s << "</tr></thead><tbody>" |
| 39 |
|
|
| 39 |
|
|
| 40 | 40 |
original_project = @project |
| 41 |
|
|
| 41 |
|
|
| 42 | 42 |
projects.each do |project| |
| 43 | 43 |
s << render_project_in_table_with_filtering(project, cycle('odd', 'even'), 0, tokens)
|
| 44 | 44 |
end |
| 45 |
|
|
| 45 |
|
|
| 46 | 46 |
s << "</table>" |
| 47 | 47 |
else |
| 48 | 48 |
s << "\n" |
| ... | ... | |
| 52 | 52 |
s |
| 53 | 53 |
end |
| 54 | 54 |
|
| 55 |
def render_project_in_table_with_filtering(project, oddeven, level, tokens)
|
|
| 55 |
def render_project_in_table_with_filtering(project, oddeven, level, tokens) |
|
| 56 | 56 |
# set the project environment to please macros. |
| 57 | 57 |
@project = project |
| 58 | 58 |
|
| ... | ... | |
| 72 | 72 |
s << "<td class='tags' align=top>" << project.tag_counts.collect{ |t| render_project_tag_link(t) }.join(', ') << "</td>"
|
| 73 | 73 |
|
| 74 | 74 |
s << "<td class='managers' align=top>" |
| 75 |
|
|
| 75 |
|
|
| 76 | 76 |
u = project.users_by_role |
| 77 | 77 |
if u |
| 78 | 78 |
u.keys.each do |r| |
| ... | ... | |
| 91 | 91 |
end |
| 92 | 92 |
|
| 93 | 93 |
s << "</td>" |
| 94 |
|
|
| 94 |
|
|
| 95 | 95 |
s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" |
| 96 | 96 |
s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" |
| 97 | 97 |
|
| ... | ... | |
| 105 | 105 |
|
| 106 | 106 |
s |
| 107 | 107 |
end |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 | 111 |
# Renders a tree of projects as a nested set of unordered lists |
| 112 | 112 |
# The given collection may be a subset of the whole project tree |
| 113 | 113 |
# (eg. some intermediate nodes are private and can not be seen) |
| ... | ... | |
| 116 | 116 |
if projects.any? |
| 117 | 117 |
tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) |
| 118 | 118 |
debugger |
| 119 |
|
|
| 119 |
|
|
| 120 | 120 |
|
| 121 | 121 |
ancestors = [] |
| 122 | 122 |
original_project = @project |
| ... | ... | |
| 128 | 128 |
else |
| 129 | 129 |
ancestors.pop |
| 130 | 130 |
s << "</li>" |
| 131 |
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
|
| 131 |
while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
|
| 132 | 132 |
ancestors.pop |
| 133 | 133 |
s << "</ul></li>" |
| 134 | 134 |
end |
| 135 | 135 |
end |
| 136 | 136 |
classes = (ancestors.empty? ? 'root' : 'child') |
| 137 | 137 |
s << "<li class='#{classes}'><div class='#{classes}'>" +
|
| 138 |
link_to( highlight_tokens(project.name, tokens),
|
|
| 138 |
link_to( highlight_tokens(project.name, tokens), |
|
| 139 | 139 |
{:controller => 'projects', :action => 'show', :id => project},
|
| 140 | 140 |
:class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"
|
| 141 | 141 |
) |
| ... | ... | |
| 146 | 146 |
# value = value_model.present? ? value_model.value : nil |
| 147 | 147 |
# s << "<li><b>#{field.name.humanize}:</b> #{highlight_tokens(value, tokens)}</li>" if value.present?
|
| 148 | 148 |
# end |
| 149 |
|
|
| 149 |
|
|
| 150 | 150 |
s << "</ul>" |
| 151 | 151 |
s << "<div class='clear'></div>" |
| 152 | 152 |
unless project.description.blank? |
| ... | ... | |
| 163 | 163 |
end |
| 164 | 164 |
s.join "\n" |
| 165 | 165 |
end |
| 166 |
|
|
| 166 |
|
|
| 167 | 167 |
# Renders a tree of projects where the current user belongs |
| 168 | 168 |
# as a nested set of unordered lists |
| 169 | 169 |
# The given collection may be a subset of the whole project tree |
| ... | ... | |
| 193 | 193 |
s |
| 194 | 194 |
|
| 195 | 195 |
end |
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 | 199 |
|
| 200 | 200 |
def render_my_project_in_hierarchy_with_tags(project) |
| 201 | 201 |
|
| ... | ... | |
| 215 | 215 |
else |
| 216 | 216 |
s << " <span class='private'>" << l(:field_is_private) << "</span>" |
| 217 | 217 |
end |
| 218 |
|
|
| 218 |
|
|
| 219 | 219 |
tc = project.tag_counts |
| 220 | 220 |
if tc.empty? |
| 221 | 221 |
s << " <span class='no-tags'>" << l(:field_no_tags) << "</span>" |
| ... | ... | |
| 242 | 242 |
|
| 243 | 243 |
end |
| 244 | 244 |
|
| 245 |
|
|
| 246 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 | 247 |
private |
| 248 |
|
|
| 248 |
|
|
| 249 | 249 |
# copied from search_helper. This one doesn't escape html or limit the text length |
| 250 | 250 |
def highlight_tokens(text, tokens) |
| 251 | 251 |
return text unless text && tokens && !tokens.empty? |
| 252 | 252 |
re_tokens = tokens.collect {|t| Regexp.escape(t)}
|
| 253 |
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
|
|
| 253 |
regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE
|
|
| 254 | 254 |
result = '' |
| 255 | 255 |
text.split(regexp).each_with_index do |words, i| |
| 256 | 256 |
words = words.mb_chars |
| ... | ... | |
| 263 | 263 |
end |
| 264 | 264 |
result |
| 265 | 265 |
end |
| 266 |
|
|
| 266 |
|
|
| 267 | 267 |
end |
| 268 | 268 |
end |
| 269 | 269 |
end |
Also available in: Unified diff