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