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