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 @ 409:50474139cad4

History | View | Annotate | Download (3.04 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 409:50474139cad4 luis
    if bibtex_entry
26
      parse_bibtex_list 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 409:50474139cad4 luis
    if @publication.new_record?
39
      render "new"
40
    else
41
      session[:publication_step] = session[:publication_params] = nil
42
      flash[:notice] = "New publication saved!"
43
      redirect_to @publication
44
    end
45 329:4575b631f6ce luis
  end
46
47
  def index
48
    @publications = Publication.find(:all)
49 328:aed18b463206 luis
  end
50
51
  def edit
52 384:4be6b16bc6f9 luis
    logger.error "AAAA edit"
53 376:ad71d0604ac2 luis
54 328:aed18b463206 luis
  end
55
56
  def update
57 384:4be6b16bc6f9 luis
58
    logger.error "AAAA update"
59 376:ad71d0604ac2 luis
60 328:aed18b463206 luis
  end
61 329:4575b631f6ce luis
62
  def show
63
    @publication = Publication.find(params[id])
64
    @authors = @publication.authors
65
  end
66
67 406:40144aa9dfe7 luis
  # parse string with bibtex authors
68
  def parse_authors(authors_entry)
69
    # in bibtex the authors are always seperated by "and"
70 407:96910efbd45e luis
    return authors_entry.split(" and ")
71 406:40144aa9dfe7 luis
  end
72
73
  # parses a list of bibtex
74
  def parse_bibtex_list(bibtex_list)
75
    bibliography = BibTeX.parse bibtex_list
76
77
    no_entries = bibliography.data.length
78
79
    # parses the bibtex entries
80
    bibliography.data.map do |d|
81 407:96910efbd45e luis
82
      if d.class == BibTeX::Entry
83
        create_bibtex_entry d
84
      end
85 406:40144aa9dfe7 luis
    end
86 407:96910efbd45e luis
  end
87
88 409:50474139cad4 luis
  def create_bibtex_entry(d)
89 407:96910efbd45e luis
    @publication = Publication.new
90
    @bentry = BibtexEntry.new
91
    authors = []
92
    institution = ""
93
    email = ""
94 409:50474139cad4 luis
95 407:96910efbd45e luis
    d.fields.keys.map do |field|
96
      case field.to_s
97
      when "author"
98
        authors = parse_authors d[field]
99
      when "title"
100
        @publication.title = d[field]
101
      when "institution"
102
        institution = d[field]
103
      when "email"
104
        email = d[field]
105
      else
106
        @bentry[field] = d[field]
107
      end
108
    end
109 406:40144aa9dfe7 luis
110
    @publication.bibtex_entry = @bentry
111 407:96910efbd45e luis
    @publication.save
112 409:50474139cad4 luis
113
    @created_publications << @publication.id
114
115 407:96910efbd45e luis
    # need to save all authors
116
    #   and establish the author-publication association
117
    #   via the authorships table
118
    authors.each_with_index.map do |authorname, idx|
119
      author = Author.new(:name => authorname)
120
      if author.save!
121
        puts "SAVED"
122
      else
123
        puts "NOT SAVED"
124 406:40144aa9dfe7 luis
      end
125
126 407:96910efbd45e luis
      author.authorships.create!(
127
      :publication => @publication,
128
      :institution => institution,
129
      :email => email,
130
      :order => idx)
131 409:50474139cad4 luis
132 407:96910efbd45e luis
    end
133
  end
134 409:50474139cad4 luis
135 407:96910efbd45e luis
  # parses the bibtex file
136
  def parse_bibtex_file
137
138 406:40144aa9dfe7 luis
  end
139
140 409:50474139cad4 luis
141
  def review_new_entries
142
143
  end
144
145
146 328:aed18b463206 luis
end