Skip to content

Commit

Permalink
Merge pull request #5715 from avalonmediasystem/manage_content_quickly
Browse files Browse the repository at this point in the history
Correctly convert count result array into hash
  • Loading branch information
cjcolvar authored Mar 6, 2024
2 parents 1e96a12 + 29f8ef7 commit 9b441cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions app/controllers/admin/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ def load_and_authorize_collections
count_query = "has_model_ssim:MediaObject"
count_response = ActiveFedora::SolrService.get(count_query, { rows: 0, facet: true, 'facet.field': "isMemberOfCollection_ssim", 'facet.limit': -1 })
counts_array = count_response["facet_counts"]["facet_fields"]["isMemberOfCollection_ssim"] rescue []
counts = counts_array.blank? ? {} : [counts_array].to_h
counts = counts_array.each_slice(2).to_h
unpublished_query = count_query + " AND workflow_published_sim:Unpublished"
unpublished_count_response = ActiveFedora::SolrService.get(unpublished_query, { rows: 0, facet: true, 'facet.field': "isMemberOfCollection_ssim", 'facet.limit': -1 })
unpublished_counts_array = unpublished_count_response["facet_counts"]["facet_fields"]["isMemberOfCollection_ssim"] rescue []
unpublished_counts = unpublished_counts_array.blank? ? {} : [unpublished_counts_array].to_h
unpublished_counts = unpublished_counts_array.each_slice(2).to_h

@collections = response.documents.collect { |doc| ::Admin::CollectionPresenter.new(doc, media_object_count: counts[doc.id], unpublished_media_object_count: unpublished_counts[doc.id]) }.sort_by { |c| c.name.downcase }
@collections = response.documents.collect do |doc|
::Admin::CollectionPresenter.new(doc,
media_object_count: (counts[doc.id] || 0),
unpublished_media_object_count: (unpublished_counts[doc.id] || 0))
end.sort_by { |c| c.name.downcase }
end

# GET /collections
Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/admin_collections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@
end

describe "#index" do
let!(:collection) { FactoryBot.create(:collection) }
let!(:collection) { FactoryBot.create(:collection, items: 1) }
let!(:collection2) { FactoryBot.create(:collection, items: 1) }
subject(:json) { JSON.parse(response.body) }

let(:administrator) { FactoryBot.create(:administrator) }
Expand All @@ -165,7 +166,7 @@
end
it "should return list of collections" do
get 'index', params: { format:'json' }
expect(json.count).to eq(1)
expect(json.count).to eq(2)
expect(json.first['id']).to eq(collection.id)
expect(json.first['name']).to eq(collection.name)
expect(json.first['unit']).to eq(collection.unit)
Expand Down

0 comments on commit 9b441cf

Please sign in to comment.