Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimistically lock the file_manager
- Loading branch information
Showing
16 changed files
with
188 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module CurationConcerns | ||
module Forms | ||
class FileManagerForm | ||
include HydraEditor::Form | ||
self.terms = [] | ||
delegate :id, :thumbnail_id, :representative_id, :to_s, to: :model | ||
attr_reader :current_ability, :request | ||
def initialize(work, ability) | ||
super(work) | ||
@current_ability = ability | ||
@request = nil | ||
end | ||
|
||
def version | ||
model.etag | ||
end | ||
|
||
delegate :member_presenters, to: :member_presenter_factory | ||
|
||
private | ||
|
||
def member_presenter_factory | ||
MemberPresenterFactory.new(work, ability) | ||
end | ||
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
70 changes: 70 additions & 0 deletions
70
app/presenters/curation_concerns/member_presenter_factory.rb
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,70 @@ | ||
module CurationConcerns | ||
# Creates the presenters of the members (member works and file sets) of a specific object | ||
class MemberPresenterFactory | ||
class_attribute :file_presenter_class, :work_presenter_class | ||
# modify this attribute to use an alternate presenter class for the files | ||
self.file_presenter_class = FileSetPresenter | ||
|
||
# modify this attribute to use an alternate presenter class for the child works | ||
self.work_presenter_class = WorkShowPresenter | ||
|
||
def initialize(work, ability, request = nil) | ||
@work = work | ||
@current_ability = ability | ||
@request = request | ||
end | ||
|
||
delegate :id, to: :@work | ||
attr_reader :current_ability, :request | ||
|
||
# @param [Array<String>] ids a list of ids to build presenters for | ||
# @param [Class] presenter_class the type of presenter to build | ||
# @return [Array<presenter_class>] presenters for the ordered_members (not filtered by class) | ||
def member_presenters(ids = ordered_ids, presenter_class = composite_presenter_class) | ||
PresenterFactory.build_presenters(ids, presenter_class, *presenter_factory_arguments) | ||
end | ||
|
||
# @return [Array<FileSetPresenter>] presenters for the orderd_members that are FileSets | ||
def file_set_presenters | ||
@file_set_presenters ||= member_presenters(ordered_ids & file_set_ids) | ||
end | ||
|
||
# @return [Array<WorkShowPresenter>] presenters for the ordered_members that are not FileSets | ||
def work_presenters | ||
@work_presenters ||= member_presenters(ordered_ids - file_set_ids, work_presenter_class) | ||
end | ||
|
||
private | ||
|
||
# TODO: Extract this to ActiveFedora::Aggregations::ListSource | ||
def ordered_ids | ||
@ordered_ids ||= begin | ||
ActiveFedora::SolrService.query("proxy_in_ssi:#{id}", | ||
rows: 10_000, | ||
fl: "ordered_targets_ssim") | ||
.flat_map { |x| x.fetch("ordered_targets_ssim", []) } | ||
end | ||
end | ||
|
||
# These are the file sets that belong to this work, but not necessarily | ||
# in order. | ||
# Arbitrarily maxed at 10 thousand; had to specify rows due to solr's default of 10 | ||
def file_set_ids | ||
@file_set_ids ||= begin | ||
ActiveFedora::SolrService.query("{!field f=has_model_ssim}FileSet", | ||
rows: 10_000, | ||
fl: ActiveFedora.id_field, | ||
fq: "{!join from=ordered_targets_ssim to=id}id:\"#{id}/list_source\"") | ||
.flat_map { |x| x.fetch(ActiveFedora.id_field, []) } | ||
end | ||
end | ||
|
||
def presenter_factory_arguments | ||
[current_ability, request] | ||
end | ||
|
||
def composite_presenter_class | ||
CompositePresenterFactory.new(file_presenter_class, work_presenter_class, ordered_ids & file_set_ids) | ||
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
4 changes: 2 additions & 2 deletions
4
app/views/curation_concerns/base/_file_manager_member_resource_options.html.erb
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<div class="form-group radio_buttons member_resource_options"> | ||
<span class="radio"> | ||
<%= radio_button_tag "thumbnail_id", node.id, @presenter.thumbnail_id == node.id, id: "thumbnail_id_#{node.id}", class: "radio_buttons" %> | ||
<%= radio_button_tag "thumbnail_id", node.id, @form.thumbnail_id == node.id, id: "thumbnail_id_#{node.id}", class: "radio_buttons" %> | ||
<%= label_tag "thumbnail_id_#{node.id}", "Thumbnail" %> | ||
</span> | ||
<span class="radio"> | ||
<%= radio_button_tag "representative_id", node.id, @presenter.representative_id == node.id, id: "representative_id_#{node.id}", class: "radio_buttons" %> | ||
<%= radio_button_tag "representative_id", node.id, @form.representative_id == node.id, id: "representative_id_#{node.id}", class: "radio_buttons" %> | ||
<%= label_tag "representative_id_#{node.id}", "Representative Media" %> | ||
</span> | ||
</div> |
18 changes: 13 additions & 5 deletions
18
app/views/curation_concerns/base/_file_manager_members.html.erb
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
<ul id="sortable" data-id="<%= @presenter.id %>" data-class-name="<%= @presenter.model_name.plural %>" data-singular-class-name="<%= @presenter.model_name.singular %>" class="list-unstyled grid clearfix"> | ||
<% @presenter.member_presenters.each do |member| %> | ||
<%= render "file_manager_member", node: member %> | ||
<% end %> | ||
</ul> | ||
<%= content_tag :ul, | ||
id: "sortable", | ||
class: "list-unstyled grid clearfix", | ||
data: { | ||
id: @form.id, | ||
"class-name" => @form.model_name.plural, | ||
"singular-class-name" => @form.model_name.singular, | ||
version: @form.version | ||
} do %> | ||
<% @form.member_presenters.each do |member| %> | ||
<%= render "file_manager_member", node: member %> | ||
<% end %> | ||
<% end %> |
2 changes: 1 addition & 1 deletion
2
app/views/curation_concerns/base/_file_manager_resource_form.html.erb
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
json.extract! @curation_concern, *[:id] + @curation_concern.class.fields.select {|f| ![:has_model].include? f} | ||
json.extract! @curation_concern, *[:id] + @curation_concern.class.fields.select {|f| ![:has_model].include? f} | ||
json.version @curation_concern.etag |
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
25 changes: 25 additions & 0 deletions
25
spec/presenters/curation_concerns/member_presenter_factory_spec.rb
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,25 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe CurationConcerns::MemberPresenterFactory do | ||
describe "#file_set_presenters" do | ||
describe "getting presenters from factory" do | ||
let(:solr_document) { SolrDocument.new(attributes) } | ||
let(:attributes) { {} } | ||
let(:ability) { double } | ||
let(:request) { double } | ||
let(:factory) { described_class.new(solr_document, ability, request) } | ||
let(:presenter_class) { double } | ||
before do | ||
allow(factory).to receive(:composite_presenter_class).and_return(presenter_class) | ||
allow(factory).to receive(:ordered_ids).and_return(['12', '33']) | ||
allow(factory).to receive(:file_set_ids).and_return(['33', '12']) | ||
end | ||
|
||
it "uses the set class" do | ||
expect(CurationConcerns::PresenterFactory).to receive(:build_presenters) | ||
.with(['12', '33'], presenter_class, ability, request) | ||
factory.file_set_presenters | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.