To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / plugins / redmine_bibliography / app / controllers / publications_controller.rb @ 407:96910efbd45e

History | View | Annotate | Download (2.7 KB)

1 385:a6f8c0584a92 luis
# vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
2
3 328:aed18b463206 luis
class PublicationsController < ApplicationController
4
5 404:216a61338322 luis
  def new
6
    # we always try to create at least one publication
7
    @publication = Publication.new
8 407:96910efbd45e luis
9 404:216a61338322 luis
    # the step we're at in the form
10
    @publication.current_step = session[:publication_step]
11 393:9595ab4cac6b luis
  end
12 384:4be6b16bc6f9 luis
13 404:216a61338322 luis
  def create
14 390:5562a95edbf7 luis
    @publication = Publication.new(params[:publication])
15 391:fecd4b2f4b77 luis
    @publication.current_step = session[:publication_step]
16 384:4be6b16bc6f9 luis
17 404:216a61338322 luis
    # contents of the paste text area
18
    bibtex_entry = params[:bibtex_entry]
19 384:4be6b16bc6f9 luis
20 404:216a61338322 luis
    # method for creating "pasted" bibtex entries
21
    if bibtex_entry
22 407:96910efbd45e luis
      parse_bibtex_list bibtex_entry
23 404:216a61338322 luis
    end
24 393:9595ab4cac6b luis
25 404:216a61338322 luis
    # form's flow control
26 390:5562a95edbf7 luis
    if params[:back_button]
27
      @publication.previous_step
28
    else
29
      @publication.next_step
30
    end
31 393:9595ab4cac6b luis
32 390:5562a95edbf7 luis
    session[:publication_step] = @publication.current_step
33 393:9595ab4cac6b luis
34 390:5562a95edbf7 luis
    render "new"
35 329:4575b631f6ce luis
  end
36
37 405:8a105a53b8f4 luis
38 329:4575b631f6ce luis
  def index
39
    @publications = Publication.find(:all)
40 328:aed18b463206 luis
  end
41
42
  def edit
43 384:4be6b16bc6f9 luis
    logger.error "AAAA edit"
44 376:ad71d0604ac2 luis
45 328:aed18b463206 luis
  end
46
47
  def update
48 384:4be6b16bc6f9 luis
49
    logger.error "AAAA update"
50 376:ad71d0604ac2 luis
51 328:aed18b463206 luis
  end
52 329:4575b631f6ce luis
53
  def show
54
    @publication = Publication.find(params[id])
55
    @authors = @publication.authors
56
  end
57
58 406:40144aa9dfe7 luis
  # parse string with bibtex authors
59
  def parse_authors(authors_entry)
60
    # in bibtex the authors are always seperated by "and"
61 407:96910efbd45e luis
    return authors_entry.split(" and ")
62 406:40144aa9dfe7 luis
  end
63
64
  # parses a list of bibtex
65
  def parse_bibtex_list(bibtex_list)
66
    bibliography = BibTeX.parse bibtex_list
67
68
    no_entries = bibliography.data.length
69
70
    # parses the bibtex entries
71
    bibliography.data.map do |d|
72 407:96910efbd45e luis
73
      if d.class == BibTeX::Entry
74
        create_bibtex_entry d
75
      end
76 406:40144aa9dfe7 luis
    end
77 407:96910efbd45e luis
  end
78
79
  def create_bibtex_entry(d)
80
    @publication = Publication.new
81
    @bentry = BibtexEntry.new
82
    authors = []
83
    institution = ""
84
    email = ""
85
86
    d.fields.keys.map do |field|
87
      case field.to_s
88
      when "author"
89
        authors = parse_authors d[field]
90
      when "title"
91
        @publication.title = d[field]
92
      when "institution"
93
        institution = d[field]
94
      when "email"
95
        email = d[field]
96
      else
97
        @bentry[field] = d[field]
98
      end
99
    end
100 406:40144aa9dfe7 luis
101
    @publication.bibtex_entry = @bentry
102 407:96910efbd45e luis
    @publication.save
103
104
    # need to save all authors
105
    #   and establish the author-publication association
106
    #   via the authorships table
107
    authors.each_with_index.map do |authorname, idx|
108
      author = Author.new(:name => authorname)
109
      if author.save!
110
        puts "SAVED"
111
      else
112
        puts "NOT SAVED"
113 406:40144aa9dfe7 luis
      end
114
115 407:96910efbd45e luis
      author.authorships.create!(
116
      :publication => @publication,
117
      :institution => institution,
118
      :email => email,
119
      :order => idx)
120
121
    end
122
  end
123
124
125
  # parses the bibtex file
126
  def parse_bibtex_file
127
128 406:40144aa9dfe7 luis
  end
129
130 407:96910efbd45e luis
131 328:aed18b463206 luis
end