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 @ 430:948400933de8

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