Revision 1052:6674e52e20bf vendor/plugins
| vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb | ||
|---|---|---|
| 24 | 24 |
|
| 25 | 25 |
def parse_bibtex |
| 26 | 26 |
find_project_by_project_id |
| 27 |
@bibtex_parse_success = true |
|
| 27 | 28 |
|
| 28 |
bibtex_paste = params[:bibtex_paste] |
|
| 29 |
bib = BibTeX.parse(bibtex_paste) |
|
| 29 |
begin |
|
| 30 |
bibtex_paste = params[:bibtex_paste] |
|
| 31 |
bib = BibTeX.parse(bibtex_paste) |
|
| 32 |
rescue |
|
| 33 |
# todo: output errors to user |
|
| 34 |
# bib.errors.present? |
|
| 35 |
@bibtex_parse_success = false |
|
| 36 |
# @bibtex_parsing_error = bib.errors[0].trace[4] |
|
| 37 |
# logger.error { "BibTex Parsing Error: #{@bibtex_parsing_error}" }
|
|
| 38 |
logger.error { "BibTex Parsing Error" }
|
|
| 39 |
end |
|
| 30 | 40 |
|
| 31 | 41 |
respond_to do |format| |
| 32 |
if bib.errors.present? or bib[0].class == NilClass |
|
| 33 |
|
|
| 34 | 42 |
# todo: response for HTML |
| 35 | 43 |
format.html{}
|
| 36 | 44 |
|
| 37 |
# todo: better error handling |
|
| 38 |
biberror = bib.errors[0].trace[4] |
|
| 39 |
logger.error { "BibTex Parsing Error: #{biberror}" }
|
|
| 40 |
flash[:error] = "BibTex Parsing Error: #{biberror}"
|
|
| 41 |
#raise BibtexParsingError, "Bibtex Parsing Error: biberror}" |
|
| 45 |
if @bibtex_parse_success |
|
| 46 |
@ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html |
|
| 47 |
end |
|
| 48 |
|
|
| 42 | 49 |
format.js |
| 43 |
else |
|
| 44 |
@ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html |
|
| 45 |
flash['notice'] = "OK!" |
|
| 46 |
format.js |
|
| 47 |
end |
|
| 50 |
|
|
| 51 |
|
|
| 48 | 52 |
end |
| 49 | 53 |
end |
| 50 | 54 |
|
| vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb | ||
|---|---|---|
| 8 | 8 |
<%= link_to_remote "Parse BiBTeX", :url => { :project_id => @project, :action => :parse_bibtex}, :with => "'bibtex_paste=' + $('bibtex_paste').value" -%>
|
| 9 | 9 |
</div> |
| 10 | 10 |
|
| 11 |
<div class="box" id="ieee_prev"></div> |
|
| 11 |
<div class="box" id="ieee_prev"><h3>Preview</h3></div>
|
|
| 12 | 12 |
|
| vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs | ||
|---|---|---|
| 1 |
page.replace_html :ieee_prev, @ieee_prev |
|
| 1 |
if @bibtex_parse_success |
|
| 2 |
page.insert_html :bottom, :ieee_prev, @ieee_prev |
|
| 3 |
page.insert_html :top, :content, '<div class="flash notice">Successfully Parsed BibTeX</div>' |
|
| 4 |
else |
|
| 5 |
page.insert_html :top, :content, '<div class="flash error">Error parsing BibTeX.</div>' |
|
| 6 |
end |
|
| 2 | 7 |
|
| 3 |
page.replace_html :error, flash[:error] |
|
| 4 | 8 |
flash.discard |
Also available in: Unified diff