Skip to content

Commit

Permalink
Fix file manager sorting for Koppie (#6217)
Browse files Browse the repository at this point in the history
* Use the presenter, not a form.

* Remove unused file.

* Fix test, small refactor.
  • Loading branch information
tpendragon authored Aug 25, 2023
1 parent f27f71c commit 04b6ecd
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 166 deletions.
5 changes: 3 additions & 2 deletions app/assets/javascripts/hyrax/file_manager/sorting.es6
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default class SortManager {
this.sorting_info = {}
this.initialize_sort()
this.element.data("current-order", this.order)
this.sort_property = this.element.data("sort-property")
this.save_manager = save_manager
this.initialize_alpha_sort_button()
}
Expand Down Expand Up @@ -38,9 +39,9 @@ export default class SortManager {
params() {
let params = {}
params[this.singular_class_name] = {
"version": this.version,
"ordered_member_ids": this.order
"version": this.version
}
params[this.singular_class_name][this.sort_property] = this.order
params["_method"] = "PATCH"
return params
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def destroy
end

def file_manager
@form = Forms::FileManagerForm.new(curation_concern, current_ability)
@form = presenter
end

def inspect_work
Expand Down
35 changes: 0 additions & 35 deletions app/forms/hyrax/forms/file_manager_form.rb

This file was deleted.

7 changes: 6 additions & 1 deletion app/presenters/hyrax/work_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ def valid_child_concerns
Hyrax::ChildTypes.for(parent: solr_document.hydra_model).to_a
end

# @return [Boolean]
def valkyrie_presenter?
solr_document.hydra_model < Valkyrie::Resource
end

private

# list of item ids to display is based on ordered_ids
Expand Down Expand Up @@ -298,7 +303,7 @@ def presenter_factory_arguments

def member_presenter_factory
@member_presenter_factory ||=
if solr_document.hydra_model < Valkyrie::Resource
if valkyrie_presenter?
PcdmMemberPresenterFactory.new(solr_document, current_ability)
else
self.class
Expand Down
4 changes: 2 additions & 2 deletions app/views/hyrax/base/_file_manager_members.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
id: "sortable",
class: "list-unstyled grid d-flex flex-wrap clearfix",
data: {
id: @form.id,
id: @form.id.to_s,
"class-name" => @form.model_name.plural,
"singular-class-name" => @form.model_name.singular,
version: @form.version
"sort_property" => @form.valkyrie_presenter? ? "member_ids" : "ordered_member_ids"
} do %>
<% @form.member_presenters.each do |member| %>
<%= render "file_manager_member", node: member %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/base/file_manager.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</li>
</ul>

<% if !@form.member_presenters.empty? %>
<% if !@form.member_presenters.blank? %>
<div class="row" data-action="file-manager">
<div class="col-lg-3" id="file-manager-tools">
<h2><%= t('.toolbar') %></h2>
Expand Down
4 changes: 2 additions & 2 deletions app/views/hyrax/base/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true
@curation_concern = Wings::ActiveFedoraConverter.convert(resource: @curation_concern) if
@curation_concern.is_a? Hyrax::Resource
@curation_concern = ::Wings::ActiveFedoraConverter.convert(resource: @curation_concern) if
@curation_concern.is_a?(Hyrax::Resource) && Object.const_defined?("Wings")

json.extract! @curation_concern, *[:id] + @curation_concern.class.fields.reject { |f| [:has_model].include? f }
json.version @curation_concern.try(:etag)
53 changes: 53 additions & 0 deletions spec/features/file_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true
RSpec.describe "file manager" do
let(:user) { FactoryBot.create(:admin) }
let!(:work) do
FactoryBot.valkyrie_create(:monograph, :with_member_file_sets, :public,
title: ["Toothbrush"])
end
let(:file_set) do
Hyrax.query_service.find_members(resource: work).first
end
before do
sign_in user
visit "/concern/monographs/#{work.id}/file_manager"
end

it "looks like a file manager" do
# has a bulk edit header
expect(page.html).to include "<h1>#{I18n.t('hyrax.file_manager.link_text')}</h1>"

# displays each file set's label
expect(page).to have_selector "input[name='file_set[title][]'][type='text'][value='#{file_set.title.first}']"

# has a link to edit each file set
expect(page).to have_selector("a[href='/concern/parent/#{work.id}/file_sets/#{file_set.id}']")

# has a link back to parent
expect(page).to have_link work.title.first, href: hyrax_monograph_path(id: work.id, locale: :en)

# renders a form for each member
expect(page).to have_selector("#sortable form", count: work.member_ids.length)

# Defines the order property
expect(page).to have_selector("#sortable[data-sort-property='member_ids']")

# renders an input for titles
expect(page).to have_selector("input[name='file_set[title][]']")

# renders a resource form for the entire resource
expect(page).to have_selector("form#resource-form")

# renders a hidden field for the resource form thumbnail id
expect(page).to have_selector("#resource-form input[type=hidden][name='monograph[thumbnail_id]']", visible: false)

# renders a thumbnail field for each member
expect(page).to have_selector("input[name='thumbnail_id']", count: work.member_ids.length)

# renders a hidden field for the resource form representative id
expect(page).to have_selector("#resource-form input[type=hidden][name='monograph[representative_id]']", visible: false)

# renders a representative field for each member
expect(page).to have_selector("input[name='representative_id']", count: work.member_ids.length)
end
end
34 changes: 0 additions & 34 deletions spec/forms/hyrax/forms/file_manager_form_spec.rb

This file was deleted.

88 changes: 0 additions & 88 deletions spec/views/hyrax/base/file_manager.html.erb_spec.rb

This file was deleted.

0 comments on commit 04b6ecd

Please sign in to comment.