| 7 |
7 |
unloadable
|
| 8 |
8 |
|
| 9 |
9 |
model_object Publication
|
| 10 |
|
before_filter :find_model_object, :except => [:parse_bibtex, :new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
|
|
10 |
before_filter :find_model_object, :except => [:parse_bibtex, :new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
|
| 11 |
11 |
before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ]
|
| 12 |
12 |
|
| 13 |
13 |
def new
|
| ... | ... | |
| 18 |
18 |
@publication.build_bibtex_entry
|
| 19 |
19 |
|
| 20 |
20 |
# and at least one author
|
| 21 |
|
# @publication.authorships.build.build_author
|
|
21 |
# @publication.authorships.build.build_author
|
| 22 |
22 |
@author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
|
| 23 |
23 |
end
|
| 24 |
24 |
|
| 25 |
|
|
| 26 |
25 |
def parse_bibtex
|
| 27 |
26 |
find_project_by_project_id
|
| 28 |
27 |
|
| 29 |
|
@bibtex_paste = params[:bibtex_paste]
|
|
28 |
bibtex_paste = params[:bibtex_paste]
|
|
29 |
bib = BibTeX.parse(bibtex_paste)
|
| 30 |
30 |
|
| 31 |
|
begin
|
| 32 |
|
bib = BibTeX.parse(@bibtex_paste)
|
|
31 |
respond_to do |format|
|
|
32 |
if bib.errors.present? or bib[0].class == NilClass
|
| 33 |
33 |
|
| 34 |
|
if bib.errors.present? or bib[0].class == NilClass
|
| 35 |
|
raise BibtexParsingError, "Bibtex Parsing Error"
|
|
34 |
# todo: response for HTML
|
|
35 |
format.html{}
|
|
36 |
|
|
37 |
# todo: better error handling
|
|
38 |
biberror = bib.errors[0].trace[4]
|
|
39 |
logger.error { "BibTex Parsing Error: #{biberror}" }
|
|
40 |
flash[:error] = "BibTex Parsing Error: #{biberror}"
|
|
41 |
#raise BibtexParsingError, "Bibtex Parsing Error: biberror}"
|
|
42 |
format.js
|
|
43 |
else
|
|
44 |
@ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html
|
|
45 |
flash['notice'] = "OK!"
|
|
46 |
format.js
|
| 36 |
47 |
end
|
|
48 |
end
|
|
49 |
end
|
| 37 |
50 |
|
| 38 |
|
respond_to do |format|
|
| 39 |
|
format.js {
|
| 40 |
|
render(:update) {|page|
|
| 41 |
|
flash[:notice] = "Correctly parsed BibTeX entry"
|
| 42 |
51 |
|
| 43 |
|
bibtex_entry_no = BibtexEntryType.find_by_name(bib[0].type.to_s).id
|
| 44 |
|
page["publication_title"].value = bib[0][:title]
|
| 45 |
|
page["publication_bibtex_entry_attributes_entry_type"].value = bibtex_entry_no
|
| 46 |
|
|
| 47 |
|
BibtexEntryType.fields(bibtex_entry_no).each do |field|
|
| 48 |
|
page["publication_bibtex_entry_attributes_#{field}"].value = bib[0][field]
|
| 49 |
|
end
|
|
52 |
# respond_to do |format|
|
|
53 |
# format.js {
|
|
54 |
# render(:update) {|page|
|
|
55 |
# flash.now[:notice] = "Correctly parsed BibTeX entry"
|
|
56 |
#
|
|
57 |
# bibtex_entry_no = BibtexEntryType.find_by_name(bib[0].type.to_s).id
|
|
58 |
# page["publication_title"].value = bib[0][:title]
|
|
59 |
# page["publication_bibtex_entry_attributes_entry_type"].value = #bibtex_entry_no
|
|
60 |
#
|
|
61 |
# BibtexEntryType.fields(bibtex_entry_no).each do |field|
|
|
62 |
# page["publication_bibtex_entry_attributes_#{field}"].value = bib[0][field#]
|
|
63 |
# end
|
|
64 |
#
|
|
65 |
# # for each author simulates a click and fills the author info
|
|
66 |
## bib[0].authors.each do |author|
|
|
67 |
## page["add_another_author"].click
|
|
68 |
## page.alert(bib[0].authors.length)
|
|
69 |
## page.alert(page["authors"].first.id)
|
|
70 |
## end
|
|
71 |
#
|
|
72 |
#
|
|
73 |
#
|
|
74 |
# }
|
|
75 |
# }
|
|
76 |
# end
|
| 50 |
77 |
|
| 51 |
|
# for each author simulates a click and fills the author info
|
| 52 |
|
bib[0].authors.each do |author|
|
| 53 |
|
page["add_another_author"].click
|
| 54 |
|
# page.alert(bib[0].authors.length)
|
| 55 |
|
# page.alert(page["authors"].first.id)
|
| 56 |
|
|
| 57 |
|
end
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
}
|
| 62 |
|
}
|
| 63 |
|
end
|
| 64 |
|
|
| 65 |
|
rescue BibtexParsingError => e
|
| 66 |
|
logger.error { "Bibtex Parsing Error #{bib.errors}" }
|
|
78 |
# rescue BibtexParsingError => e
|
|
79 |
# logger.error { "Bibtex Parsing Error #{bib.errors}" }
|
| 67 |
80 |
|
| 68 |
81 |
# todo: not showing... should be inside render?
|
| 69 |
|
flash[:error] = e.message
|
| 70 |
|
|
| 71 |
|
respond_to do |format|
|
| 72 |
|
format.js{
|
| 73 |
|
render(:update) {|page|
|
| 74 |
|
}
|
| 75 |
|
}
|
| 76 |
|
end
|
|
82 |
# flash[:error] = e.message
|
| 77 |
83 |
|
| 78 |
|
end
|
|
84 |
# respond_to do |format|
|
|
85 |
# format.js{
|
|
86 |
# render(:update) {|page|
|
|
87 |
# }
|
|
88 |
# }
|
|
89 |
# end
|
| 79 |
90 |
|
| 80 |
|
end
|
|
91 |
# end
|
| 81 |
92 |
|
| 82 |
93 |
|
| 83 |
|
def create
|
|
94 |
|
|
95 |
def create
|
| 84 |
96 |
@project = Project.find(params[:project_id])
|
| 85 |
97 |
|
| 86 |
98 |
@author_options = []
|
| ... | ... | |
| 88 |
100 |
@publication = Publication.new(params[:publication])
|
| 89 |
101 |
@publication.projects << @project unless @project.nil?
|
| 90 |
102 |
|
| 91 |
|
if @publication.save
|
|
103 |
if @publication.save
|
| 92 |
104 |
@publication.notify_authors_publication_added(@project)
|
| 93 |
105 |
|
| 94 |
106 |
flash[:notice] = "Successfully created publication."
|
| ... | ... | |
| 116 |
128 |
|
| 117 |
129 |
# method for creating "pasted" bibtex entries
|
| 118 |
130 |
if bibtex_entry
|
| 119 |
|
parse_bibtex_list bibtex_entry
|
|
131 |
parse_bibtex_list bibtex_entry
|
| 120 |
132 |
end
|
| 121 |
133 |
end
|
| 122 |
134 |
|
| 123 |
135 |
def get_bibtex_required_fields
|
| 124 |
136 |
|
| 125 |
|
fields = BibtexEntryType.fields(params[:q])
|
|
137 |
fields = BibtexEntryType.fields(params[:q])
|
| 126 |
138 |
|
| 127 |
139 |
respond_to do |format|
|
| 128 |
140 |
format.js {
|
| 129 |
|
render(:update) {|page|
|
|
141 |
render(:update) {|page|
|
| 130 |
142 |
if params[:q].empty?
|
| 131 |
143 |
page << "hideOnLoad();"
|
| 132 |
144 |
else
|
| ... | ... | |
| 148 |
160 |
end
|
| 149 |
161 |
end
|
| 150 |
162 |
|
| 151 |
|
def edit
|
|
163 |
def edit
|
| 152 |
164 |
find_project_by_project_id unless params[:project_id].nil?
|
| 153 |
165 |
|
| 154 |
166 |
@edit_view = true;
|
| 155 |
167 |
@publication = Publication.find(params[:id])
|
| 156 |
168 |
@selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type
|
| 157 |
169 |
|
| 158 |
|
@author_options = []
|
|
170 |
@author_options = []
|
| 159 |
171 |
|
| 160 |
|
@bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)
|
|
172 |
@bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)
|
| 161 |
173 |
end
|
| 162 |
174 |
|
| 163 |
|
def update
|
| 164 |
|
@publication = Publication.find(params[:id])
|
|
175 |
def update
|
|
176 |
@publication = Publication.find(params[:id])
|
| 165 |
177 |
|
| 166 |
178 |
@author_options = []
|
| 167 |
179 |
|
| ... | ... | |
| 175 |
187 |
end
|
| 176 |
188 |
else
|
| 177 |
189 |
render :action => 'edit'
|
| 178 |
|
end
|
|
190 |
end
|
| 179 |
191 |
end
|
| 180 |
192 |
|
| 181 |
193 |
|
| ... | ... | |
| 197 |
209 |
return authors_entry.split(" and ")
|
| 198 |
210 |
end
|
| 199 |
211 |
|
| 200 |
|
# parses a list of bibtex
|
|
212 |
# parses a list of bibtex
|
| 201 |
213 |
def parse_bibtex_list(bibtex_list)
|
| 202 |
214 |
bibliography = BibTeX.parse bibtex_list
|
| 203 |
215 |
|
| ... | ... | |
| 210 |
222 |
create_bibtex_entry d
|
| 211 |
223 |
end
|
| 212 |
224 |
end
|
| 213 |
|
end
|
|
225 |
end
|
| 214 |
226 |
|
| 215 |
|
def create_bibtex_entry(d)
|
|
227 |
def create_bibtex_entry(d)
|
| 216 |
228 |
@publication = Publication.new
|
| 217 |
|
@bentry = BibtexEntry.new
|
|
229 |
@bentry = BibtexEntry.new
|
| 218 |
230 |
authors = []
|
| 219 |
231 |
institution = ""
|
| 220 |
232 |
email = ""
|
| ... | ... | |
| 232 |
244 |
else
|
| 233 |
245 |
@bentry[field] = d[field]
|
| 234 |
246 |
end
|
| 235 |
|
end
|
|
247 |
end
|
| 236 |
248 |
|
| 237 |
249 |
@publication.bibtex_entry = @bentry
|
| 238 |
250 |
@publication.save
|
| 239 |
251 |
|
| 240 |
|
# what is this for???
|
|
252 |
# what is this for???
|
| 241 |
253 |
# @created_publications << @publication.id
|
| 242 |
254 |
|
| 243 |
255 |
# need to save all authors
|
| 244 |
|
# and establish the author-publication association
|
| 245 |
|
# via the authorships table
|
|
256 |
# and establish the author-publication association
|
|
257 |
# via the authorships table
|
| 246 |
258 |
authors.each_with_index.map do |authorname, idx|
|
| 247 |
259 |
author = Author.new(:name => authorname)
|
| 248 |
260 |
if author.save!
|
| ... | ... | |
| 274 |
286 |
def autocomplete_for_project
|
| 275 |
287 |
@publication = Publication.find(params[:id])
|
| 276 |
288 |
|
| 277 |
|
@projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects
|
|
289 |
@projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects
|
| 278 |
290 |
logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
|
| 279 |
291 |
render :layout => false
|
| 280 |
292 |
end
|
| 281 |
|
|
| 282 |
293 |
|
| 283 |
|
def autocomplete_for_author
|
|
294 |
|
|
295 |
def autocomplete_for_author
|
| 284 |
296 |
@results = []
|
| 285 |
297 |
|
| 286 |
298 |
object_id = params[:object_id]
|
| ... | ... | |
| 294 |
306 |
|
| 295 |
307 |
@results = users_list
|
| 296 |
308 |
|
| 297 |
|
# TODO: can be optimized…
|
| 298 |
|
authorships_list.each do |authorship|
|
|
309 |
# TODO: can be optimized…
|
|
310 |
authorships_list.each do |authorship|
|
| 299 |
311 |
flag = true
|
| 300 |
312 |
|
| 301 |
313 |
users_list.each do |user|
|
| ... | ... | |
| 309 |
321 |
@results << authorship if flag
|
| 310 |
322 |
end
|
| 311 |
323 |
|
| 312 |
|
render :layout => false
|
|
324 |
render :layout => false
|
| 313 |
325 |
end
|
| 314 |
326 |
|
| 315 |
327 |
def get_user_info
|
| ... | ... | |
| 327 |
339 |
|
| 328 |
340 |
respond_to do |format|
|
| 329 |
341 |
format.js {
|
| 330 |
|
render(:update) {|page|
|
|
342 |
render(:update) {|page|
|
| 331 |
343 |
page[name_field].value = item.name
|
| 332 |
344 |
page[email_field].value = item.mail
|
| 333 |
345 |
page[institution_field].value = item.institution
|
| ... | ... | |
| 349 |
361 |
end
|
| 350 |
362 |
|
| 351 |
363 |
def add_project
|
| 352 |
|
@projects = Project.find(params[:publication][:project_ids])
|
|
364 |
@projects = Project.find(params[:publication][:project_ids])
|
| 353 |
365 |
@publication.projects << @projects
|
| 354 |
|
@project = Project.find(params[:project_id])
|
|
366 |
@project = Project.find(params[:project_id])
|
| 355 |
367 |
|
| 356 |
|
# TODO luisf should also respond to HTML???
|
|
368 |
# TODO luisf should also respond to HTML???
|
| 357 |
369 |
respond_to do |format|
|
| 358 |
370 |
format.html { redirect_to :back }
|
| 359 |
|
format.js {
|
| 360 |
|
render(:update) {|page|
|
| 361 |
|
page[:add_project_form].reset
|
|
371 |
format.js {
|
|
372 |
render(:update) {|page|
|
|
373 |
page[:add_project_form].reset
|
| 362 |
374 |
page.replace_html :list_projects, :partial => 'list_projects'
|
| 363 |
375 |
}
|
| 364 |
376 |
}
|
| ... | ... | |
| 375 |
387 |
@publication.projects.delete proj if request.post?
|
| 376 |
388 |
end
|
| 377 |
389 |
else
|
| 378 |
|
logger.error { "Cannot remove project from publication list" }
|
|
390 |
logger.error { "Cannot remove project from publication list" }
|
| 379 |
391 |
end
|
| 380 |
392 |
|
| 381 |
393 |
logger.error { "CURRENT project name#{proj.name} and wanna delete #{@project.name}" }
|
| 382 |
394 |
|
| 383 |
|
render(:update) {|page|
|
|
395 |
render(:update) {|page|
|
| 384 |
396 |
page.replace_html "list_projects", :partial => 'list_projects', :id => @publication
|
| 385 |
|
}
|
|
397 |
}
|
| 386 |
398 |
end
|
| 387 |
399 |
|
| 388 |
400 |
def destroy
|