-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #906 from pulibrary/datatables_source
Load folder data asynchronously.
- Loading branch information
Showing
15 changed files
with
188 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
class FolderDataSource | ||
attr_reader :resource, :helper | ||
delegate :folders, to: :resource | ||
def initialize(resource:, helper:) | ||
@resource = resource | ||
@helper = helper | ||
end | ||
|
||
def data | ||
@data ||= folders.map do |folder| | ||
{ | ||
folder_number: folder.folder_number, | ||
workflow_state: folder.rendered_state, | ||
title: folder.title, | ||
barcode: folder.barcode, | ||
genre: folder.genre.try(:label) || folder.genre, | ||
actions: helper.render_to_string(partial: "catalog/folder_actions", locals: { resource: resource, folder: folder }, formats: [:html]) | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
class CountMembers | ||
def self.queries | ||
[:count_members] | ||
end | ||
|
||
attr_reader :query_service | ||
delegate :orm_class, to: :resource_factory | ||
delegate :resource_factory, to: :query_service | ||
def initialize(query_service:) | ||
@query_service = query_service | ||
end | ||
|
||
def count_members(resource:, model: nil) | ||
if model | ||
orm_class.connection.execute(find_members_with_resource_query(resource, model)).first["count"] | ||
else | ||
orm_class.connection.execute(find_members_query(resource)).first["count"] | ||
end | ||
end | ||
|
||
def find_members_query(resource) | ||
<<-SQL | ||
SELECT COUNT(*) FROM orm_resources a, | ||
jsonb_array_elements(a.metadata->'member_ids') AS b(member) | ||
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = '#{resource.id}' | ||
SQL | ||
end | ||
|
||
def find_members_with_resource_query(resource, model) | ||
<<-SQL | ||
SELECT COUNT(*) FROM orm_resources a, | ||
jsonb_array_elements(a.metadata->'member_ids') AS b(member) | ||
JOIN orm_resources member ON (b.member->>'id')::#{id_type} = member.id WHERE a.id = '#{resource.id}' | ||
AND member.internal_resource = '#{model}' | ||
SQL | ||
end | ||
|
||
def id_type | ||
@id_type ||= orm_class.columns_hash["id"].type | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<td> | ||
<% folder_url = parent_solr_document_path("#{resource.id}", "#{folder.id}") %> | ||
<%= link_to 'View', folder_url, class: 'btn btn-default' %> | ||
<%= link_to 'Edit', main_app.polymorphic_path([:edit, folder]), class: 'btn btn-default' %> | ||
</td> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe CountMembers do | ||
subject(:query) { described_class.new(query_service: query_service) } | ||
let(:box) { FactoryBot.create_for_repository(:ephemera_box, member_ids: folder.id) } | ||
let(:folder) { FactoryBot.create_for_repository(:ephemera_folder) } | ||
let(:query_service) { Valkyrie.config.metadata_adapter.query_service } | ||
|
||
describe "#count_members" do | ||
it "can give a count of all members" do | ||
expect(query.count_members(resource: box)).to eq 1 | ||
end | ||
it "can give a count of all members of a specific type" do | ||
expect(query.count_members(resource: box, model: EphemeraFolder)).to eq 1 | ||
expect(query.count_members(resource: box, model: ScannedResource)).to eq 0 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters