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 @ 457:8aa775cb7c0a
History | View | Annotate | Download (4.07 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 | before_filter :find_project, :authorize, :only => [:index, :new] |
||
| 7 | |||
| 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 | 404:216a61338322 | luis | # the step we're at in the form
|
| 18 | @publication.current_step = session[:publication_step] |
||
| 19 | 409:50474139cad4 | luis | |
| 20 | @new_publications = []
|
||
| 21 | session[:publications] ||= {}
|
||
| 22 | 393:9595ab4cac6b | luis | end
|
| 23 | 384:4be6b16bc6f9 | luis | |
| 24 | 404:216a61338322 | luis | def create |
| 25 | 390:5562a95edbf7 | luis | @publication = Publication.new(params[:publication]) |
| 26 | 445:77f88379115a | luis | |
| 27 | 448:0a5d997578da | luis | if @publication.save |
| 28 | 445:77f88379115a | luis | flash[:notice] = "Successfully created publication." |
| 29 | redirect_to @publication
|
||
| 30 | else
|
||
| 31 | render :action => 'new' |
||
| 32 | end
|
||
| 33 | end
|
||
| 34 | |||
| 35 | def index |
||
| 36 | @publications = Publication.find(:all) |
||
| 37 | end
|
||
| 38 | |||
| 39 | def new_from_bibfile |
||
| 40 | 391:fecd4b2f4b77 | luis | @publication.current_step = session[:publication_step] |
| 41 | 409:50474139cad4 | luis | |
| 42 | 404:216a61338322 | luis | # contents of the paste text area
|
| 43 | bibtex_entry = params[:bibtex_entry]
|
||
| 44 | 384:4be6b16bc6f9 | luis | |
| 45 | 404:216a61338322 | luis | # method for creating "pasted" bibtex entries
|
| 46 | 424:b601a9e472f3 | luis | if bibtex_entry
|
| 47 | 409:50474139cad4 | luis | parse_bibtex_list bibtex_entry |
| 48 | 404:216a61338322 | luis | end
|
| 49 | 393:9595ab4cac6b | luis | |
| 50 | 404:216a61338322 | luis | # form's flow control
|
| 51 | 390:5562a95edbf7 | luis | if params[:back_button] |
| 52 | @publication.previous_step
|
||
| 53 | else
|
||
| 54 | @publication.next_step
|
||
| 55 | end
|
||
| 56 | 393:9595ab4cac6b | luis | |
| 57 | 390:5562a95edbf7 | luis | session[:publication_step] = @publication.current_step |
| 58 | 429:27930c9b424d | luis | |
| 59 | 329:4575b631f6ce | luis | end
|
| 60 | |||
| 61 | 328:aed18b463206 | luis | |
| 62 | 445:77f88379115a | luis | def edit |
| 63 | 428:9cfd7a1d848e | luis | @publication = Publication.find(params[:id]) |
| 64 | 430:948400933de8 | luis | end
|
| 65 | |||
| 66 | 445:77f88379115a | luis | def update |
| 67 | 448:0a5d997578da | luis | @publication = Publication.find(params[:id]) |
| 68 | 430:948400933de8 | luis | if @publication.update_attributes(params[:publication]) |
| 69 | flash[:notice] = "Successfully updated Publication." |
||
| 70 | 448:0a5d997578da | luis | redirect_to @publication
|
| 71 | 430:948400933de8 | luis | else
|
| 72 | 448:0a5d997578da | luis | render :action => 'edit' |
| 73 | end
|
||
| 74 | 328:aed18b463206 | luis | end
|
| 75 | |||
| 76 | 425:4ecbc22579e2 | luis | def show |
| 77 | 430:948400933de8 | luis | logger.error "-------> No Show"
|
| 78 | |||
| 79 | 428:9cfd7a1d848e | luis | @publication = Publication.find(params[:id]) |
| 80 | 425:4ecbc22579e2 | luis | |
| 81 | if @publication.nil? |
||
| 82 | @publications = Publication.all |
||
| 83 | render "index", :alert => 'Your Publications was not found!' |
||
| 84 | else
|
||
| 85 | @authors = @publication.authors |
||
| 86 | @bibtext_entry = @publication.bibtex_entry |
||
| 87 | |||
| 88 | respond_to do |format|
|
||
| 89 | format.html |
||
| 90 | format.xml {render :xml => @publication}
|
||
| 91 | end
|
||
| 92 | end
|
||
| 93 | 329:4575b631f6ce | luis | end
|
| 94 | |||
| 95 | 406:40144aa9dfe7 | luis | # parse string with bibtex authors
|
| 96 | def parse_authors(authors_entry) |
||
| 97 | # in bibtex the authors are always seperated by "and"
|
||
| 98 | 407:96910efbd45e | luis | return authors_entry.split(" and ") |
| 99 | 406:40144aa9dfe7 | luis | end
|
| 100 | |||
| 101 | # parses a list of bibtex
|
||
| 102 | def parse_bibtex_list(bibtex_list) |
||
| 103 | bibliography = BibTeX.parse bibtex_list
|
||
| 104 | |||
| 105 | no_entries = bibliography.data.length |
||
| 106 | |||
| 107 | # parses the bibtex entries
|
||
| 108 | bibliography.data.map do |d|
|
||
| 109 | 407:96910efbd45e | luis | |
| 110 | if d.class == BibTeX::Entry |
||
| 111 | create_bibtex_entry d |
||
| 112 | end
|
||
| 113 | 406:40144aa9dfe7 | luis | end
|
| 114 | 407:96910efbd45e | luis | end
|
| 115 | |||
| 116 | 409:50474139cad4 | luis | def create_bibtex_entry(d) |
| 117 | 407:96910efbd45e | luis | @publication = Publication.new |
| 118 | @bentry = BibtexEntry.new |
||
| 119 | authors = [] |
||
| 120 | institution = ""
|
||
| 121 | email = ""
|
||
| 122 | 409:50474139cad4 | luis | |
| 123 | 407:96910efbd45e | luis | d.fields.keys.map do |field|
|
| 124 | case field.to_s
|
||
| 125 | when "author" |
||
| 126 | authors = parse_authors d[field] |
||
| 127 | when "title" |
||
| 128 | @publication.title = d[field]
|
||
| 129 | when "institution" |
||
| 130 | institution = d[field] |
||
| 131 | when "email" |
||
| 132 | email = d[field] |
||
| 133 | else
|
||
| 134 | @bentry[field] = d[field]
|
||
| 135 | end
|
||
| 136 | end
|
||
| 137 | 406:40144aa9dfe7 | luis | |
| 138 | @publication.bibtex_entry = @bentry |
||
| 139 | 407:96910efbd45e | luis | @publication.save
|
| 140 | 409:50474139cad4 | luis | |
| 141 | 424:b601a9e472f3 | luis | # what is this for???
|
| 142 | # @created_publications << @publication.id
|
||
| 143 | 409:50474139cad4 | luis | |
| 144 | 407:96910efbd45e | luis | # need to save all authors
|
| 145 | # and establish the author-publication association
|
||
| 146 | # via the authorships table
|
||
| 147 | authors.each_with_index.map do |authorname, idx|
|
||
| 148 | author = Author.new(:name => authorname) |
||
| 149 | if author.save!
|
||
| 150 | puts "SAVED"
|
||
| 151 | else
|
||
| 152 | puts "NOT SAVED"
|
||
| 153 | 406:40144aa9dfe7 | luis | end
|
| 154 | |||
| 155 | 407:96910efbd45e | luis | author.authorships.create!( |
| 156 | 444:b461f84ed41a | luis | :publication => @publication, |
| 157 | :institution => institution,
|
||
| 158 | :email => email,
|
||
| 159 | :order => idx)
|
||
| 160 | 409:50474139cad4 | luis | |
| 161 | 407:96910efbd45e | luis | end
|
| 162 | end
|
||
| 163 | 409:50474139cad4 | luis | |
| 164 | 407:96910efbd45e | luis | # parses the bibtex file
|
| 165 | def parse_bibtex_file |
||
| 166 | |||
| 167 | 406:40144aa9dfe7 | luis | end
|
| 168 | |||
| 169 | 444:b461f84ed41a | luis | def import |
| 170 | @publication = Publication.new |
||
| 171 | |||
| 172 | |||
| 173 | end
|
||
| 174 | 409:50474139cad4 | luis | |
| 175 | def review_new_entries |
||
| 176 | |||
| 177 | end
|
||
| 178 | 457:8aa775cb7c0a | luis | |
| 179 | |||
| 180 | private |
||
| 181 | |||
| 182 | def find_project |
||
| 183 | # @project variable must be set before calling the authorize filter
|
||
| 184 | @project = Project.find(params[:project_id]) |
||
| 185 | end
|
||
| 186 | 409:50474139cad4 | luis | |
| 187 | |||
| 188 | 328:aed18b463206 | luis | end |