Revision 1040:ff783f2cc500 vendor

View differences:

vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
3 3

  
4 4
class PublicationsController < ApplicationController
5 5
  unloadable
6
  
6

  
7 7
  model_object Publication
8 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
12 12
    find_project_by_project_id
13 13
    @publication = Publication.new
14
    
14

  
15 15
    # we'll always want a new publication to have its bibtex entry
16 16
    @publication.build_bibtex_entry
17
    
17

  
18 18
    # and at least one author
19 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}"]]
......
29 29

  
30 30
    @publication = Publication.new(params[:publication])
31 31
    @publication.projects << @project unless @project.nil?
32
        
32

  
33 33
    if @publication.save 
34 34
      @publication.notify_authors_publication_added(@project)
35
      
35

  
36 36
      flash[:notice] = "Successfully created publication."
37 37
      redirect_to :action => :show, :id => @publication, :project_id => @project
38 38
    else
......
52 52

  
53 53
  def new_from_bibfile
54 54
    @publication.current_step = session[:publication_step]
55
    
55

  
56 56
    # contents of the paste text area
57 57
    bibtex_entry = params[:bibtex_entry]
58 58

  
......
78 78
          end
79 79
        }
80 80
      }
81
    
81

  
82 82
    end
83 83
  end
84 84

  
......
94 94

  
95 95
  def edit   
96 96
    find_project_by_project_id unless params[:project_id].nil?
97
    
97

  
98 98
    @edit_view = true;
99 99
    @publication = Publication.find(params[:id])
100 100
    @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type
101 101

  
102 102
    @author_options = []  
103
    
103

  
104 104
    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)    
105 105
  end
106 106

  
......
124 124
    end   
125 125
  end
126 126

  
127

  
127 128
  def show
128 129
    find_project_by_project_id unless params[:project_id].nil?
129
        
130

  
130 131
    if @publication.nil?
131 132
      @publications = Publication.all
132 133
      render "index", :alert => 'The publication was not found!'
......
191 192
    authors.each_with_index.map do |authorname, idx|
192 193
      author = Author.new(:name => authorname)
193 194
      if author.save!
195
        # todo: catch the errors...
194 196
        puts "SAVED"
195 197
      else
196 198
        puts "NOT SAVED"
197 199
      end
198 200

  
199 201
      author.authorships.create!(
200
        :publication => @publication,
201
        :institution => institution,
202
        :email => email,
203
        :order => idx)
202
      :publication => @publication,
203
      :institution => institution,
204
      :email => email,
205
      :order => idx)
204 206
    end
205 207
  end
206 208

  
......
211 213

  
212 214
  def import
213 215
    @publication = Publication.new
214
    
215
    
216

  
217

  
216 218
  end
217
  
219

  
218 220
  def autocomplete_for_project
219 221
    @publication = Publication.find(params[:id])
220
        
222

  
221 223
    @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects            
222 224
    logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
223 225
    render :layout => false
......
225 227

  
226 228
  def autocomplete_for_author    
227 229
    @results = []
228
    
230

  
229 231
    object_id = params[:object_id]
230 232
    @object_name = "publications[authorships_attributes][#{object_id}][search_results]"
231
        
233

  
232 234
    # cc 20110909 -- revert to like instead of like_unique -- see #289
233 235
    authorships_list = Authorship.like(params[:q]).find(:all, :limit => 100)
234 236
    users_list = User.active.like(params[:q]).find(:all, :limit => 100)
235 237

  
236 238
    logger.debug "Query for \"#{params[:q]}\" returned \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users"
237
    
239

  
238 240
    @results = users_list
239 241

  
240 242
    # TODO: can be optimized…    
241 243
    authorships_list.each do |authorship|      
242 244
      flag = true
243
      
245

  
244 246
      users_list.each do |user|
245 247
        if authorship.name == user.name && authorship.email == user.mail && authorship.institution == user.institution
246 248
          Rails.logger.debug { "Rejecting Authorship #{authorship.id}" }
......
254 256

  
255 257
    render :layout => false    
256 258
  end
257
  
258
  
259

  
259 260
  def get_user_info
260 261
    object_id = params[:object_id]
261 262
    value = params[:value]
......
266 267
    name_field = "publication_authorships_attributes_#{object_id}_name_on_paper".to_sym
267 268
    email_field = "publication_authorships_attributes_#{object_id}_email".to_sym
268 269
    institution_field = "publication_authorships_attributes_#{object_id}_institution".to_sym
269
    
270

  
270 271
    yes_radio = "publication_authorships_attributes_#{object_id}_identify_author_yes".to_sym
271
    
272

  
272 273
    respond_to do |format|
273 274
      format.js {
274 275
        render(:update) {|page| 
......
296 297
    @projects = Project.find(params[:publication][:project_ids])    
297 298
    @publication.projects << @projects
298 299
    @project = Project.find(params[:project_id])    
299
    
300

  
300 301
    # TODO luisf should also respond to HTML??? 
301 302
    respond_to do |format|
302 303
      format.html { redirect_to :back }
......
308 309
      }
309 310
    end
310 311
  end
311
  
312
  
312

  
313

  
313 314
  def remove_project
314 315
    @project = Project.find(params[:project_id])
315 316
    proj = Project.find(params[:remove_project_id])
......
321 322
    else
322 323
      logger.error { "Cannot remove project from publication list" }      
323 324
    end
324
    
325

  
325 326
    logger.error { "CURRENT project name#{proj.name} and wanna delete #{@project.name}" }
326
        
327

  
327 328
    render(:update) {|page| 
328 329
      page.replace_html "list_projects", :partial => 'list_projects', :id  => @publication
329 330
    }    
330 331
  end
331
    
332

  
332 333
  def destroy
333 334
    find_project_by_project_id
334
    
335

  
335 336
    @publication.destroy
336
        
337

  
337 338
    flash[:notice] = "Successfully deleted Publication."
338 339
    redirect_to :controller => :publications, :action => 'index', :project_id => @project
339 340
  end
vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb
89 89
    s   
90 90
  end
91 91
  
92
    
93 92
  def render_projects_list(publication, show_delete_icon)    
94 93
    s= ""
95 94
    
......
99 98
      if show_delete_icon  
100 99
        if User.current.allowed_to?(:edit_publication, @project)
101 100
          if @project == proj
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
......
114 114
    s  
115 115
  end
116 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)
121
  end
122
  
123
  def print_bibtex_entry(publication)
124
    publication.print_entry(:bibtex)
125
  end
126
    
127
  
117 128
  def show_bibtex_fields(bibtex_entry)
118 129
    s = ""
119 130
    bibtex_entry.attributes.keys.sort.each do |key|
vendor/plugins/redmine_bibliography/app/models/author.rb
1 1
class Author < ActiveRecord::Base
2
  unloadable
3
  
2 4
  has_many :authorships, :dependent => :destroy
3 5
  has_many :publications, :through => :authorships
4 6

  
vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb
1 1
class BibtexEntryType < ActiveRecord::Base
2
  unloadable
2 3

  
3 4
  @@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ], 
4 5
                  'book' , [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ],
vendor/plugins/redmine_bibliography/app/models/publication.rb
57 57
    end    
58 58
  end
59 59
  
60
  def print_bibtex_author_names
61
    # this authors are correctly sorted because the authorships model 
62
    # already outputs the author names ASC by auth_order
63
    self.authorships.map{|a| a.name_on_paper}.join(' and ')
64
  end  
60 65
  
61
  
62
  
66
  def print_entry(style)
67
    bib = BibTeX::Entry.new
68

  
69
    bib.author = self.print_bibtex_author_names
70
    bib.title = self.title
71

  
72
    self.bibtex_entry.attributes.keys.sort.each do |key|      
73
      value = self.bibtex_entry.attributes[key].to_s
74
      next if key == 'id' or key == 'publication_id' or value == ""
75

  
76
      if key == "entry_type"        
77
        bib.type = BibtexEntryType.find(self.bibtex_entry.entry_type).name
78
      else
79
        bib[key.to_sym] = value
80
      end               
81
    end
82
    
83
    if style == :ieee
84
      CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html      
85
    else 
86
      bibtex = bib.to_s :include => :meta_content
87
      bibtex.strip!
88
      logger.error { bibtex }
89
    end  
90
  end
63 91
end
vendor/plugins/redmine_bibliography/app/views/projects/_bibliography_box.html.erb
1
<% content_for :header_tags do %>
2
    <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
3
    <%= javascript_include_tag 'bibtex', :plugin => 'redmine_bibliography' -%>
4
<% end %>
5

  
1 6
<% if @project.publications.any? %>
2 7
<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
3 8
  <div id="bibliography">
4 9
    <div class="box">
5 10
    <h3><%=l(:label_related_publication_plural)%></h3>
6 11

  
7
   <dl>
8
     <% @project.publications.each do |publication| %>
9
     <dt>
10
     <span class="authors">
11
       <%= publication.authorships.map { |a| h a.name_on_paper }.join(', ') %><% if !publication.authorships.empty? %>.<% end %>
12
     </span>
13
     <span class="title"><%= link_to publication.title, :controller => 'publications', :action => 'show', :id => publication, :project_id => @project %></span>
14
     <% if publication.bibtex_entry.year.to_s != "" %>
15
     <span class="year">
16
       &nbsp;(<%= publication.bibtex_entry.year %>)
17
     </span>
18
     <% end %>
19
     </dt><dd></dd>
12
     <dl>       
13
     <% @project.publications.each do |publication| %>       
14
       <dt>
15
          <%= publication.print_entry(:ieee) -%>
16
       </dt>
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)" -%> 
21
       </dd>
22
       <dd class="bibtex-textarea collapsed" style="display: none;">
23
         <textarea readonly><%= publication.print_entry(:bibtex) -%></textarea>         
24
       </dd>
20 25
   <% end -%>
21
   </dl>
26
     </dl>
22 27
  </div>
23 28
</div>
24
<% end %>
29
<% end -%>
vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb
1
<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
2

  
3 1
<h2><%=l(:label_publication_show)%></h2>
4 2

  
5 3
<div class="box">
6
<h3>
7
  <%= h @publication.title %>
8
</h3>
4
  <h3>Publication Info</h3>
5
  <p><%= show_cite_proc_entry(@publication)%></p>
6
  
7
  <h3>B<small>IB</small>T<sub>E</sub>X Format</h3>
8
  <pre><%=h print_bibtex_entry(@publication) %></pre>
9
</div>
10

  
11
<div class="box">
9 12

  
10 13
<h4><%= l(:authors) %></h4>
11 14
<ul id="authorships">
......
18 21
    <%- end -%>
19 22
  <%- end -%>
20 23
</ul>
24

  
21 25
<%- if User.current.allowed_to?(:edit_publication, @project) && @publication.authorships.length > 1 -%>
22 26
  <%= sortable_element("authorships", :url => { :controller => :publications, :action => :sort_author_order }, :handle => "handle") %>
23 27
<%- end -%>
......
26 30
  <%= show_bibtex_fields(@publication.bibtex_entry) %>
27 31
<%- end -%>
28 32

  
29

  
30 33
<% unless @publication.external_url.blank? %>
31 34
  <h4>
32 35
    <%= l(:field_external_url) %>
......
46 49
</div>
47 50

  
48 51
<% projects = Project.active.find(:all, :limit => 100, :order => 'name ASC') - @publication.projects %>
49

  
52
  
50 53
<% content_for :sidebar do %>
51 54
  <h3><%=l(:label_publication_project_index)%></h3>
52 55

  
vendor/plugins/redmine_bibliography/assets/javascripts/bibtex.js
1
function toggleBibtex(el) {
2
  var dd = Element.up(el).next('dd')
3

  
4
  dd.toggleClassName('collapsed');
5
  Effect.toggle(dd, 'slide', {duration:0.2});
6
}
vendor/plugins/redmine_bibliography/assets/stylesheets/bibliography.css
32 32
    min-width: 150px;
33 33
}
34 34

  
35
div#bibliography dl { margin-left: 2em; }
36
div#bibliography .box dl { margin-left: 0; }
37
div#bibliography dt { margin-bottom: 0px; padding-left: 20px }
38
div#bibliography .box dt { margin-bottom: 0px; padding-left: 10px }
39
div#bibliography dd { margin-bottom: 1em; padding-left: 18px; font-size: 0.9em; }
40
div#bibliography .box dd { margin-bottom: 0.6em; padding-left: 0; }
35

  
36
div#bibliography dd { margin-bottom: 1em; font-size: 0.9em; }
37

  
41 38
div#bibliography dd .authors { font-style: italic; }
42
div#bibliography dt .title { font-style: italic; }
43 39
div#bibliography dd span.authors { color: #808080; }
44 40
div#bibliography dd span.year { padding-left: 0.6em; }
45 41

  
46
div#bibliography h3 { background: url(../../../images/table_multiple.png) no-repeat 0% 50%; padding-left: 20px; }
42
div#bibliography .box dt { 
43
  background: url(../../../images/document.png) no-repeat 0% 4px;
44
  padding-left: 20px;
45
  margin-left: 0;
46
}
47
div#bibliography .box dd { 
48
  padding-left: 20px;
49
  margin-left: 0;
50
}
51

  
52
div#bibliography h3 { 
53
  background: url(../../../images/table_multiple.png) no-repeat 0% 50%; 
54
  padding-left: 20px;
55
}
56

  
57
div#bibliography textarea {
58
  width: 90%;
59
  height: 200px;
60
  font: normal 8px;
61
  padding: 2px 10px;
62
  border: solid 1px #ddd;  
63
}
vendor/plugins/redmine_bibliography/init.rb
1 1
require 'redmine'
2 2
require 'dispatcher'
3 3

  
4
require 'bibtex'
5
require 'citeproc'
6

  
7

  
4 8
RAILS_DEFAULT_LOGGER.info 'Starting Bibliography Plugin for RedMine'
5 9

  
6 10
# Patches to the Redmine core.
vendor/plugins/redmine_tags/app/controllers/tags_controller.rb
1
class TagsController < ApplicationController
2
  
3
  def index
4
    respond_to do |format|
5
      format.html {
6
        render :template => 'tags/index.html.erb', :layout => !request.xhr?
7
      }
8
      format.api  {
9
      }
10
      format.atom {
11
      }
12
    end
13
  end
14

  
15
end
vendor/plugins/redmine_tags/app/views/tags/index.html.erb
1
<% content_for :header_tags do %>
2
    <%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %>
3
    <%= stylesheet_link_tag 'redmine_tags', :plugin => 'redmine_tags' %>
4
<% end %>
5

  
6

  
7
<div style="clear:both;"></div>
8
<h2>
9
  <%= l("label_project_tags_all") %>
10
</h2>
11

  
12
<%= render_tags_list(Project.available_tags, :style => :cloud) %>
13

  

Also available in: Unified diff