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 @ 428:9cfd7a1d848e

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