Skip to content

Commit

Permalink
Refactored code to pass nil objects to curator worklist if data objec…
Browse files Browse the repository at this point in the history
…ts doesn't exist. Also modified code to show proper common name in curator worklist depending on current user's language. WEB-2134
  • Loading branch information
vitthalkudal committed Apr 12, 2011
1 parent 98f52f4 commit 8cb8e96
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/models/data_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -971,10 +971,10 @@ def self.latest_published_version_of(data_object_id)
return obj[0]
end

def self.latest_published_version_id(data_object_id)
latest_data_object = DataObject.find_by_sql("SELECT do.id FROM data_objects do_old JOIN data_objects do ON (do_old.guid=do.guid) WHERE do_old.id=#{data_object_id} AND do.published=1 ORDER BY id desc LIMIT 1")
return nil if latest_data_object.blank?
return latest_data_object[0].id
def self.latest_published_version_ids_of_do_ids(data_object_ids)
latest_published_version_ids = DataObject.find_by_sql("SELECT do.id FROM data_objects do_old JOIN data_objects do ON (do_old.guid=do.guid) WHERE do.id IN (#{data_object_ids.collect{|doi| doi}.join(', ')}) AND do.published=1")
latest_published_version_ids.collect!{|data_object| (data_object.id)}.uniq!
latest_published_version_ids
end

def self.latest_published_version_of_guid(guid, options={})
Expand Down
8 changes: 8 additions & 0 deletions app/models/taxon_concept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def common_name(hierarchy = nil)
quick_common_name(hierarchy)
end

def preferred_common_name_in_language(language)
common_names = preferred_common_names.select do |preferred_common_name|
preferred_common_name.language_id == language.id
end
return common_names[0].name.string unless common_names.blank?
return nil
end

def self.common_names_for_concepts(taxon_concept_ids, hierarchy = nil)
quick_common_names(taxon_concept_ids, hierarchy)
end
Expand Down
19 changes: 13 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,9 @@ def images_to_curate(options = {})

start = per_page * (page - 1)
last = start + per_page - 1
data_object_ids_to_lookup = data_object_ids[start..last]

# We should not have to do it if the solr index get updated after every content import. Created a ticket WEB-2180 for this.
data_object_ids_to_lookup.collect! {|dato_id| DataObject.latest_published_version_id(dato_id) }.compact!

data_object_ids_to_lookup = data_object_ids[start..last].clone
data_object_ids_to_lookup = DataObject.latest_published_version_ids_of_do_ids(data_object_ids_to_lookup)

add_include = [
:all_comments,
{ :users_data_objects => :user },
Expand All @@ -626,11 +624,20 @@ def images_to_curate(options = {})
{ :taxon_concepts => { :preferred_common_names => :name } } ]
add_select = {
:users => '*',
:names => [ :string ],
:taxon_concept_names => [ :language_id ],
:comments => [ :parent_id, :visible_at, :user_id ],
:untrust_reasons => '*',
:users_data_objects_ratings => [ :user_id, :rating ] }
data_object_ids[start..last] = DataObject.core_relationships(:add_include => add_include,
core_data = DataObject.core_relationships(:add_include => add_include,
:add_select => add_select).find_all_by_id(data_object_ids_to_lookup).sort_by{|d| Invert(d.id)}
core_data.each do |data_object|
if index = data_object_ids[start..last].index(data_object.id)
data_object_ids[index] = data_object
end
end
data_object_ids = data_object_ids.collect{|do_or_id| (do_or_id.class == DataObject) ? do_or_id : nil }

return data_object_ids
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/curators/curate_image.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%h3
= taxon_concept_link(nil, :data_type => "image", :data_object_id => @data_object.id, :name_string => @data_object.first_concept_name, :taxon_concept_id => @data_object.first_hierarchy_entry.taxon_concept_id, :popup => true)
- common_name = @data_object.taxon_concepts[0].subtitle(@session_hierarchy) unless @data_object.taxon_concepts[0].nil?
- common_name = @data_object.taxon_concepts[0].preferred_common_name_in_language(current_user.language) unless @data_object.taxon_concepts[0].nil?
- if common_name
%p
%em
Expand Down
3 changes: 2 additions & 1 deletion app/views/curators/curate_images.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
%th{ :width => 368 }
Actions
- @images_to_curate.each do |data_object|
- next if data_object.nil?
/ %tr{ :id => "undo-move-#{data_object.id}", :class => 'hide ' + data_object.vetted.label.downcase }
/ %td{ :colspan => 2 }
/ You moved the image to
Expand All @@ -34,7 +35,7 @@
.curation-item
%h5
= taxon_concept_link(nil, :data_type => "image", :data_object_id => data_object.id, :name_string => data_object.first_concept_name, :taxon_concept_id => data_object.first_hierarchy_entry.taxon_concept_id, :popup => true)
- common_name = data_object.taxon_concepts[0].subtitle(@session_hierarchy) unless data_object.taxon_concepts[0].nil?
- common_name = data_object.taxon_concepts[0].preferred_common_name_in_language(current_user.language) unless data_object.taxon_concepts[0].nil?
- if common_name
%h6
= common_name.firstcap
Expand Down
2 changes: 1 addition & 1 deletion app/views/curators/ignored_images.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/ - taxon_concept = data_object.get_taxon_concepts(:published => :preferred).first
/ %h5
/ = taxon_concept_link(taxon_concept, :data_type => "image", :data_object_id => data_object.id, :popup => true)
/ - common_name = data_object.taxon_concepts[0].subtitle(@session_hierarchy) unless data_object.taxon_concepts[0].nil?
/ - common_name = data_object.taxon_concepts[0].preferred_common_name_in_language(current_user.language) unless data_object.taxon_concepts[0].nil?
/ - if common_name
/ %h6
/ = common_name.firstcap
Expand Down

0 comments on commit 8cb8e96

Please sign in to comment.