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 @ 446:995d4c99843d

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