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 @ 424:b601a9e472f3

History | View | Annotate | Download (3.13 KB)

1 385:a6f8c0584a92 luis
# vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
2
3 328:aed18b463206 luis
class PublicationsController < ApplicationController
4
5 404:216a61338322 luis
  def new
6
    # we always try to create at least one publication
7
    @publication = Publication.new
8 407:96910efbd45e luis
9 404:216a61338322 luis
    # the step we're at in the form
10
    @publication.current_step = session[:publication_step]
11 409:50474139cad4 luis
12
    @new_publications = []
13
    session[:publications] ||= {}
14
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 384:4be6b16bc6f9 luis
    logger.error "AAAA edit"
55 376:ad71d0604ac2 luis
56 328:aed18b463206 luis
  end
57
58
  def update
59 384:4be6b16bc6f9 luis
60
    logger.error "AAAA update"
61 376:ad71d0604ac2 luis
62 328:aed18b463206 luis
  end
63 329:4575b631f6ce luis
64
  def show
65
    @publication = Publication.find(params[id])
66
    @authors = @publication.authors
67
  end
68
69 406:40144aa9dfe7 luis
  # parse string with bibtex authors
70
  def parse_authors(authors_entry)
71
    # in bibtex the authors are always seperated by "and"
72 407:96910efbd45e luis
    return authors_entry.split(" and ")
73 406:40144aa9dfe7 luis
  end
74
75
  # parses a list of bibtex
76
  def parse_bibtex_list(bibtex_list)
77
    bibliography = BibTeX.parse bibtex_list
78
79
    no_entries = bibliography.data.length
80
81
    # parses the bibtex entries
82
    bibliography.data.map do |d|
83 407:96910efbd45e luis
84
      if d.class == BibTeX::Entry
85
        create_bibtex_entry d
86
      end
87 406:40144aa9dfe7 luis
    end
88 407:96910efbd45e luis
  end
89
90 409:50474139cad4 luis
  def create_bibtex_entry(d)
91 407:96910efbd45e luis
    @publication = Publication.new
92
    @bentry = BibtexEntry.new
93
    authors = []
94
    institution = ""
95
    email = ""
96 409:50474139cad4 luis
97 407:96910efbd45e luis
    d.fields.keys.map do |field|
98
      case field.to_s
99
      when "author"
100
        authors = parse_authors d[field]
101
      when "title"
102
        @publication.title = d[field]
103
      when "institution"
104
        institution = d[field]
105
      when "email"
106
        email = d[field]
107
      else
108
        @bentry[field] = d[field]
109
      end
110
    end
111 406:40144aa9dfe7 luis
112
    @publication.bibtex_entry = @bentry
113 407:96910efbd45e luis
    @publication.save
114 409:50474139cad4 luis
115 424:b601a9e472f3 luis
    # what is this for???
116
    # @created_publications << @publication.id
117 409:50474139cad4 luis
118 407:96910efbd45e luis
    # need to save all authors
119
    #   and establish the author-publication association
120
    #   via the authorships table
121
    authors.each_with_index.map do |authorname, idx|
122
      author = Author.new(:name => authorname)
123
      if author.save!
124
        puts "SAVED"
125
      else
126
        puts "NOT SAVED"
127 406:40144aa9dfe7 luis
      end
128
129 407:96910efbd45e luis
      author.authorships.create!(
130
      :publication => @publication,
131
      :institution => institution,
132
      :email => email,
133
      :order => idx)
134 409:50474139cad4 luis
135 407:96910efbd45e luis
    end
136
  end
137 409:50474139cad4 luis
138 407:96910efbd45e luis
  # parses the bibtex file
139
  def parse_bibtex_file
140
141 406:40144aa9dfe7 luis
  end
142
143 409:50474139cad4 luis
144
  def review_new_entries
145
146
  end
147
148
149 328:aed18b463206 luis
end