Revision 1425:cd304b50908c plugins/redmine_bibliography/app/controllers

View differences:

plugins/redmine_bibliography/app/controllers/publications_controller.rb
15 15
    # we'll always want a new publication to have its bibtex entry
16 16
    @publication.build_bibtex_entry
17 17

  
18
    # and at least one author
19
    # @publication.authorships.build.build_author
20
    @author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
21 18
  end
22 19

  
23 20
  def create
24 21
    @project = Project.find(params[:project_id])
25 22

  
26
    @author_options = []
27

  
28 23
    @publication = Publication.new(params[:publication])
29 24
    @publication.projects << @project unless @project.nil?
30 25

  
......
91 86
    @publication = Publication.find(params[:id])
92 87
    @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type
93 88

  
94
    @author_options = []
95

  
96 89
    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)
97 90
  end
98 91

  
99 92
  def update
100 93
    @publication = Publication.find(params[:id])
101
    @author_options = []
102 94

  
103 95
    if @publication.update_attributes(params[:publication])
104 96
      flash[:notice] = "Successfully updated Publication."
......
176 168
    @publication.bibtex_entry = @bentry
177 169
    @publication.save
178 170

  
179
    # what is this for???
180
    # @created_publications << @publication.id
181

  
182 171
    # need to save all authors
183 172
    #   and establish the author-publication association
184 173
    #   via the authorships table
......
199 188
    end
200 189
  end
201 190

  
202
  # parses the bibtex file
203
  def parse_bibtex_file
204

  
205
  end
206

  
207
  def import
208
    @publication = Publication.new
209

  
210

  
211
  end
212

  
213 191
  def autocomplete_for_project
214 192
    @publication = Publication.find(params[:id])
215 193

  
......
225 203
    @object_name = "publications[authorships_attributes][#{object_id}][search_results]"
226 204

  
227 205
    # cc 20110909 -- revert to like instead of like_unique -- see #289
228
    authorships_list = Authorship.like(params[:term]).find(:all, :limit => 100)
206
    authorships_list = Authorship.like(params[:term]).group('author_id').find(:all, :limit => 100)
207

  
208
    authors_list = authorships_list.collect do |x| x.author end
209

  
229 210
    users_list = User.active.like(params[:term]).find(:all, :limit => 100)
230 211

  
231
    logger.debug "Query for \"#{params[:term]}\" returned \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users"
212
    logger.debug "Query for \"#{params[:term]}\" returned \"#{authors_list.size}\" authors and \"#{users_list.size}\" users"
232 213

  
233
    @results = users_list
214
    # will check if any of the members of the users list
215
    #  doesn't belong to the authors list
234 216

  
235
    # TODO: can be optimized…
236
    authorships_list.each do |authorship|
237
      flag = true
217
    @results = authors_list
238 218

  
239
      users_list.each do |user|
240
        if authorship.name == user.name && authorship.email == user.mail && authorship.institution == user.institution
241
          Rails.logger.debug { "Rejecting Authorship #{authorship.id}" }
242
          flag = false
243
          break
244
        end
245
      end
246

  
247
      @results << authorship if flag
219
    users_list.each do |user|
220
      @results << user unless authors_list.include?(user.author)
248 221
    end
249 222

  
223
    logger.debug { "Autocomplete_for_author results --> #{@results}" }
224

  
250 225
    render :layout => false
251 226
  end
252 227

  
253
  def get_user_info
254
    object_id = params[:object_id]
255
    value = params[:value]
256
    classname = Kernel.const_get(value.split('_')[0])
257

  
258
    item = classname.find(value.split('_')[1])
259

  
260
    name_field = "publication_authorships_attributes_#{object_id}_name_on_paper".to_sym
261
    email_field = "publication_authorships_attributes_#{object_id}_email".to_sym
262
    institution_field = "publication_authorships_attributes_#{object_id}_institution".to_sym
263

  
264
    yes_radio = "publication_authorships_attributes_#{object_id}_identify_author_yes".to_sym
265

  
266
    respond_to do |format|
267
      format.js {
268
        render(:update) {|page|
269
          page[name_field].value = item.name
270
          page[email_field].value = item.mail
271
          page[institution_field].value = item.institution
272

  
273
          page[yes_radio].checked = true
274
          page[name_field].readOnly = true
275
          page[email_field].readOnly = true
276
          page[institution_field].readOnly = true
277
        }
278
      }
279
    end
280
  end
281

  
282 228
  def sort_author_order
283 229
    params[:authorships].each_with_index do |id, index|
284 230
      Authorship.update_all(['auth_order=?', index+1], ['id=?', id])
......
303 249
    end
304 250
  end
305 251

  
306

  
307 252
  def remove_project
308 253
    @project = Project.find(params[:project_id])
309 254
    proj = Project.find(params[:remove_project_id])
......
324 269
  end
325 270

  
326 271
  def destroy
327
    find_project_by_project_id
272
    find_project_by_project_id unless params[:project_id].nil?
273
    @publication = Publication.find(params[:id])
328 274

  
329 275
    @publication.destroy
330 276

  

Also available in: Unified diff