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 @ 444:b461f84ed41a

History | View | Annotate | Download (3.75 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 407:96910efbd45e luis
10 404:216a61338322 luis
    # the step we're at in the form
11
    @publication.current_step = session[:publication_step]
12 409:50474139cad4 luis
13
    @new_publications = []
14
    session[:publications] ||= {}
15 393:9595ab4cac6b luis
  end
16 384:4be6b16bc6f9 luis
17 404:216a61338322 luis
  def create
18 390:5562a95edbf7 luis
    @publication = Publication.new(params[:publication])
19 391:fecd4b2f4b77 luis
    @publication.current_step = session[:publication_step]
20 409:50474139cad4 luis
21 404:216a61338322 luis
    # contents of the paste text area
22
    bibtex_entry = params[:bibtex_entry]
23 384:4be6b16bc6f9 luis
24 404:216a61338322 luis
    # method for creating "pasted" bibtex entries
25 424:b601a9e472f3 luis
    if bibtex_entry
26
      logger.error "ANTES PARSE"
27 409:50474139cad4 luis
      parse_bibtex_list bibtex_entry
28 424:b601a9e472f3 luis
      logger.error "DEPOIS PARSE"
29 404:216a61338322 luis
    end
30 393:9595ab4cac6b luis
31 404:216a61338322 luis
    # form's flow control
32 390:5562a95edbf7 luis
    if params[:back_button]
33
      @publication.previous_step
34
    else
35
      @publication.next_step
36
    end
37 393:9595ab4cac6b luis
38 390:5562a95edbf7 luis
    session[:publication_step] = @publication.current_step
39 393:9595ab4cac6b luis
40 409:50474139cad4 luis
    if @publication.new_record?
41
      render "new"
42
    else
43
      session[:publication_step] = session[:publication_params] = nil
44
      flash[:notice] = "New publication saved!"
45
      redirect_to @publication
46
    end
47 329:4575b631f6ce luis
  end
48
49
  def index
50
    @publications = Publication.find(:all)
51 328:aed18b463206 luis
  end
52
53
  def edit
54 444:b461f84ed41a luis
55 428:9cfd7a1d848e luis
    @publication = Publication.find(params[:id])
56 429:27930c9b424d luis
57 328:aed18b463206 luis
  end
58
59
  def update
60 429:27930c9b424d luis
    @publication = Publication.find(params[:id])
61
    if @publication.update_attributes(params[:publication])
62
      flash[:notice] = "Successfully updated Publication."
63
      redirect_to @publication
64
    else
65
      render :action => 'edit'
66
    end
67 328:aed18b463206 luis
  end
68 329:4575b631f6ce luis
69 425:4ecbc22579e2 luis
  def show
70 428:9cfd7a1d848e luis
    @publication = Publication.find(params[:id])
71 425:4ecbc22579e2 luis
72
    if @publication.nil?
73
        @publications = Publication.all
74
        render "index", :alert => 'Your Publications was not found!'
75
    else
76
      @authors = @publication.authors
77
      @bibtext_entry = @publication.bibtex_entry
78
79
      respond_to do |format|
80
        format.html
81
        format.xml {render :xml => @publication}
82
      end
83
    end
84 329:4575b631f6ce luis
  end
85
86 406:40144aa9dfe7 luis
  # parse string with bibtex authors
87
  def parse_authors(authors_entry)
88
    # in bibtex the authors are always seperated by "and"
89 407:96910efbd45e luis
    return authors_entry.split(" and ")
90 406:40144aa9dfe7 luis
  end
91
92
  # parses a list of bibtex
93
  def parse_bibtex_list(bibtex_list)
94
    bibliography = BibTeX.parse bibtex_list
95
96
    no_entries = bibliography.data.length
97
98
    # parses the bibtex entries
99
    bibliography.data.map do |d|
100 407:96910efbd45e luis
101
      if d.class == BibTeX::Entry
102
        create_bibtex_entry d
103
      end
104 406:40144aa9dfe7 luis
    end
105 407:96910efbd45e luis
  end
106
107 409:50474139cad4 luis
  def create_bibtex_entry(d)
108 407:96910efbd45e luis
    @publication = Publication.new
109
    @bentry = BibtexEntry.new
110
    authors = []
111
    institution = ""
112
    email = ""
113 409:50474139cad4 luis
114 407:96910efbd45e luis
    d.fields.keys.map do |field|
115
      case field.to_s
116
      when "author"
117
        authors = parse_authors d[field]
118
      when "title"
119
        @publication.title = d[field]
120
      when "institution"
121
        institution = d[field]
122
      when "email"
123
        email = d[field]
124
      else
125
        @bentry[field] = d[field]
126
      end
127
    end
128 406:40144aa9dfe7 luis
129
    @publication.bibtex_entry = @bentry
130 407:96910efbd45e luis
    @publication.save
131 409:50474139cad4 luis
132 424:b601a9e472f3 luis
    # what is this for???
133
    # @created_publications << @publication.id
134 409:50474139cad4 luis
135 407:96910efbd45e luis
    # need to save all authors
136
    #   and establish the author-publication association
137
    #   via the authorships table
138
    authors.each_with_index.map do |authorname, idx|
139
      author = Author.new(:name => authorname)
140
      if author.save!
141
        puts "SAVED"
142
      else
143
        puts "NOT SAVED"
144 406:40144aa9dfe7 luis
      end
145
146 407:96910efbd45e luis
      author.authorships.create!(
147 444:b461f84ed41a luis
        :publication => @publication,
148
        :institution => institution,
149
        :email => email,
150
        :order => idx)
151 409:50474139cad4 luis
152 407:96910efbd45e luis
    end
153
  end
154 409:50474139cad4 luis
155 407:96910efbd45e luis
  # parses the bibtex file
156
  def parse_bibtex_file
157
158 406:40144aa9dfe7 luis
  end
159
160 444:b461f84ed41a luis
  def import
161
    @publication = Publication.new
162
163
164
  end
165 409:50474139cad4 luis
166
  def review_new_entries
167
168
  end
169
170
171 328:aed18b463206 luis
end