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 @ 406:40144aa9dfe7

History | View | Annotate | Download (2.69 KB)

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