To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / vendor / plugins / redmine_bibliography / app / controllers / publications_controller.rb @ 459:0f9097245756
History | View | Annotate | Download (4.57 KB)
| 1 | 385:a6f8c0584a92 | luis | # vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
|
|---|---|---|---|
| 2 | |||
| 3 | 328:aed18b463206 | luis | class PublicationsController < ApplicationController |
| 4 | 425:4ecbc22579e2 | luis | unloadable |
| 5 | 457:8aa775cb7c0a | luis | |
| 6 | 458:f2288bb384bb | luis | before_filter :find_project_by_project_id
|
| 7 | 457:8aa775cb7c0a | luis | |
| 8 | 404:216a61338322 | luis | def new |
| 9 | 444:b461f84ed41a | luis | @publication = Publication.new |
| 10 | 445:77f88379115a | luis | |
| 11 | # we'll always want a new publication to have its bibtex entry
|
||
| 12 | @publication.build_bibtex_entry
|
||
| 13 | |||
| 14 | 446:995d4c99843d | luis | # and at least one author
|
| 15 | @publication.authors.build
|
||
| 16 | |||
| 17 | 458:f2288bb384bb | luis | @project_id = params[:project_id] |
| 18 | |||
| 19 | 404:216a61338322 | luis | # the step we're at in the form
|
| 20 | 459:0f9097245756 | luis | # @publication.current_step = session[:publication_step]
|
| 21 | 409:50474139cad4 | luis | |
| 22 | @new_publications = []
|
||
| 23 | session[:publications] ||= {}
|
||
| 24 | 393:9595ab4cac6b | luis | end
|
| 25 | 384:4be6b16bc6f9 | luis | |
| 26 | 404:216a61338322 | luis | def create |
| 27 | 390:5562a95edbf7 | luis | @publication = Publication.new(params[:publication]) |
| 28 | 458:f2288bb384bb | luis | @project = Project.find(params[:project_id]) |
| 29 | 445:77f88379115a | luis | |
| 30 | 458:f2288bb384bb | luis | logger.error { "FIGUEIRA" }
|
| 31 | Rails.logger.debug { @project } |
||
| 32 | |||
| 33 | @publication.projects << @project |
||
| 34 | |||
| 35 | 448:0a5d997578da | luis | if @publication.save |
| 36 | 445:77f88379115a | luis | flash[:notice] = "Successfully created publication." |
| 37 | 459:0f9097245756 | luis | redirect_to :action => :show, :id => @publication, :project_id => @project.id |
| 38 | 445:77f88379115a | luis | else
|
| 39 | render :action => 'new' |
||
| 40 | end
|
||
| 41 | end
|
||
| 42 | |||
| 43 | def index |
||
| 44 | 458:f2288bb384bb | luis | @project = Project.find(params[:project_id]) |
| 45 | @publications = Publication.find :all, :joins => :projects, :conditions => ["project_id = ?", @project.id] |
||
| 46 | 445:77f88379115a | luis | end
|
| 47 | |||
| 48 | def new_from_bibfile |
||
| 49 | 391:fecd4b2f4b77 | luis | @publication.current_step = session[:publication_step] |
| 50 | 409:50474139cad4 | luis | |
| 51 | 404:216a61338322 | luis | # contents of the paste text area
|
| 52 | bibtex_entry = params[:bibtex_entry]
|
||
| 53 | 384:4be6b16bc6f9 | luis | |
| 54 | 404:216a61338322 | luis | # method for creating "pasted" bibtex entries
|
| 55 | 424:b601a9e472f3 | luis | if bibtex_entry
|
| 56 | 409:50474139cad4 | luis | parse_bibtex_list bibtex_entry |
| 57 | 404:216a61338322 | luis | end
|
| 58 | 393:9595ab4cac6b | luis | |
| 59 | 404:216a61338322 | luis | # form's flow control
|
| 60 | 390:5562a95edbf7 | luis | if params[:back_button] |
| 61 | @publication.previous_step
|
||
| 62 | else
|
||
| 63 | @publication.next_step
|
||
| 64 | end
|
||
| 65 | 393:9595ab4cac6b | luis | |
| 66 | 390:5562a95edbf7 | luis | session[:publication_step] = @publication.current_step |
| 67 | 429:27930c9b424d | luis | |
| 68 | 329:4575b631f6ce | luis | end
|
| 69 | |||
| 70 | 328:aed18b463206 | luis | |
| 71 | 445:77f88379115a | luis | def edit |
| 72 | 428:9cfd7a1d848e | luis | @publication = Publication.find(params[:id]) |
| 73 | 430:948400933de8 | luis | end
|
| 74 | |||
| 75 | 445:77f88379115a | luis | def update |
| 76 | 448:0a5d997578da | luis | @publication = Publication.find(params[:id]) |
| 77 | 430:948400933de8 | luis | if @publication.update_attributes(params[:publication]) |
| 78 | flash[:notice] = "Successfully updated Publication." |
||
| 79 | 448:0a5d997578da | luis | redirect_to @publication
|
| 80 | 430:948400933de8 | luis | else
|
| 81 | 448:0a5d997578da | luis | render :action => 'edit' |
| 82 | end
|
||
| 83 | 328:aed18b463206 | luis | end
|
| 84 | |||
| 85 | 425:4ecbc22579e2 | luis | def show |
| 86 | 430:948400933de8 | luis | logger.error "-------> No Show"
|
| 87 | |||
| 88 | 428:9cfd7a1d848e | luis | @publication = Publication.find(params[:id]) |
| 89 | 425:4ecbc22579e2 | luis | |
| 90 | if @publication.nil? |
||
| 91 | @publications = Publication.all |
||
| 92 | render "index", :alert => 'Your Publications was not found!' |
||
| 93 | else
|
||
| 94 | @authors = @publication.authors |
||
| 95 | @bibtext_entry = @publication.bibtex_entry |
||
| 96 | |||
| 97 | respond_to do |format|
|
||
| 98 | format.html |
||
| 99 | format.xml {render :xml => @publication}
|
||
| 100 | end
|
||
| 101 | end
|
||
| 102 | 329:4575b631f6ce | luis | end
|
| 103 | |||
| 104 | 406:40144aa9dfe7 | luis | # parse string with bibtex authors
|
| 105 | def parse_authors(authors_entry) |
||
| 106 | # in bibtex the authors are always seperated by "and"
|
||
| 107 | 407:96910efbd45e | luis | return authors_entry.split(" and ") |
| 108 | 406:40144aa9dfe7 | luis | end
|
| 109 | |||
| 110 | # parses a list of bibtex
|
||
| 111 | def parse_bibtex_list(bibtex_list) |
||
| 112 | bibliography = BibTeX.parse bibtex_list
|
||
| 113 | |||
| 114 | no_entries = bibliography.data.length |
||
| 115 | |||
| 116 | # parses the bibtex entries
|
||
| 117 | bibliography.data.map do |d|
|
||
| 118 | 407:96910efbd45e | luis | |
| 119 | if d.class == BibTeX::Entry |
||
| 120 | create_bibtex_entry d |
||
| 121 | end
|
||
| 122 | 406:40144aa9dfe7 | luis | end
|
| 123 | 407:96910efbd45e | luis | end
|
| 124 | |||
| 125 | 409:50474139cad4 | luis | def create_bibtex_entry(d) |
| 126 | 407:96910efbd45e | luis | @publication = Publication.new |
| 127 | @bentry = BibtexEntry.new |
||
| 128 | authors = [] |
||
| 129 | institution = ""
|
||
| 130 | email = ""
|
||
| 131 | 409:50474139cad4 | luis | |
| 132 | 407:96910efbd45e | luis | d.fields.keys.map do |field|
|
| 133 | case field.to_s
|
||
| 134 | when "author" |
||
| 135 | authors = parse_authors d[field] |
||
| 136 | when "title" |
||
| 137 | @publication.title = d[field]
|
||
| 138 | when "institution" |
||
| 139 | institution = d[field] |
||
| 140 | when "email" |
||
| 141 | email = d[field] |
||
| 142 | else
|
||
| 143 | @bentry[field] = d[field]
|
||
| 144 | end
|
||
| 145 | end
|
||
| 146 | 406:40144aa9dfe7 | luis | |
| 147 | @publication.bibtex_entry = @bentry |
||
| 148 | 407:96910efbd45e | luis | @publication.save
|
| 149 | 409:50474139cad4 | luis | |
| 150 | 424:b601a9e472f3 | luis | # what is this for???
|
| 151 | # @created_publications << @publication.id
|
||
| 152 | 409:50474139cad4 | luis | |
| 153 | 407:96910efbd45e | luis | # need to save all authors
|
| 154 | # and establish the author-publication association
|
||
| 155 | # via the authorships table
|
||
| 156 | authors.each_with_index.map do |authorname, idx|
|
||
| 157 | author = Author.new(:name => authorname) |
||
| 158 | if author.save!
|
||
| 159 | puts "SAVED"
|
||
| 160 | else
|
||
| 161 | puts "NOT SAVED"
|
||
| 162 | 406:40144aa9dfe7 | luis | end
|
| 163 | |||
| 164 | 407:96910efbd45e | luis | author.authorships.create!( |
| 165 | 444:b461f84ed41a | luis | :publication => @publication, |
| 166 | :institution => institution,
|
||
| 167 | :email => email,
|
||
| 168 | :order => idx)
|
||
| 169 | 407:96910efbd45e | luis | end
|
| 170 | end
|
||
| 171 | 409:50474139cad4 | luis | |
| 172 | 407:96910efbd45e | luis | # parses the bibtex file
|
| 173 | def parse_bibtex_file |
||
| 174 | |||
| 175 | 406:40144aa9dfe7 | luis | end
|
| 176 | |||
| 177 | 444:b461f84ed41a | luis | def import |
| 178 | @publication = Publication.new |
||
| 179 | |||
| 180 | |||
| 181 | end
|
||
| 182 | 409:50474139cad4 | luis | |
| 183 | def review_new_entries |
||
| 184 | |||
| 185 | end
|
||
| 186 | 457:8aa775cb7c0a | luis | |
| 187 | |||
| 188 | private |
||
| 189 | |||
| 190 | 459:0f9097245756 | luis | # TODO: luisf. - only here for debugging purposes
|
| 191 | # Find project of id params[:project_id]
|
||
| 192 | def find_project_by_project_id |
||
| 193 | |||
| 194 | logger.error { "FIND PROJECT BY PROJECT ID" }
|
||
| 195 | |||
| 196 | @project = Project.find(params[:project_id]) |
||
| 197 | rescue ActiveRecord::RecordNotFound |
||
| 198 | render_404 |
||
| 199 | end
|
||
| 200 | 328:aed18b463206 | luis | end |