Skip to content

Commit 5cfc58f

Browse files
committed
Create local models so we can avoid cocina edits
1 parent a0dead4 commit 5cfc58f

File tree

137 files changed

+1319
-1219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1319
-1219
lines changed

app/components/contents/file_component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<%= filename %>
77
<% end %>
88
</td>
9-
<td><%= hasMimeType %></td>
9+
<td><%= mime_type %></td>
1010
<td><%= number_to_human_size(size) %></td>
1111
<td><%= role %></td>
1212
<td class="ps-4"><%= tag :span, class: 'bi-check' if publish %></td>
1313
<td class="ps-4"><%= tag :span, class: 'bi-check' if shelve %></td>
14-
<td class="ps-4"><%= tag :span, class: 'bi-check' if sdrPreserve %></td>
14+
<td class="ps-4"><%= tag :span, class: 'bi-check' if preserve %></td>
1515
<td><%= view_access %></td>
1616
<td><%= download_access %></td>
1717
</tr>

app/components/contents/file_component.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ def viewable?
1414
@viewable
1515
end
1616

17-
delegate :access, :administrative, :filename, :hasMimeType, :size, :externalIdentifier, :use, to: :file
18-
delegate :publish, :shelve, :sdrPreserve, to: :administrative
17+
delegate :filename, :mime_type, :size, :use, :publish, :shelve, :preserve, to: :file
1918

2019
def view_access
21-
access.view.capitalize
20+
file.view_access.capitalize
2221
end
2322

2423
def download_access
25-
access.download.capitalize
24+
file.download_access.capitalize
2625
end
2726

2827
def role

app/components/contents/resource_component.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module Contents
44
class ResourceComponent < ViewComponent::Base
5+
# @param [FileSet] resource
56
def initialize(resource:, resource_counter:, object_id:, viewable:)
67
@resource = resource
78
@resource_counter = resource_counter
@@ -19,10 +20,6 @@ def type
1920
resource.type.delete_prefix('https://cocina.sul.stanford.edu/models/resources/')
2021
end
2122

22-
delegate :label, to: :resource
23-
24-
def files
25-
resource.structural.contains
26-
end
23+
delegate :label, :files, to: :resource
2724
end
2825
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<ul class="resource-list">
2-
<%= render Contents::ResourceComponent.with_collection(structural&.contains, object_id: object_id, viewable: viewable?) %>
3-
<%= render Contents::ExternalFileComponent.with_collection(structural&.hasMemberOrders&.first&.members) %>
2+
<%= render Contents::ResourceComponent.with_collection(item.file_sets, object_id: object_id, viewable: viewable?) %>
3+
<%= render Contents::ExternalFileComponent.with_collection(item.members) %>
44
</ul>

app/components/contents/structural_component.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
module Contents
44
class StructuralComponent < ViewComponent::Base
5-
def initialize(structural:, object_id:, viewable:)
6-
@structural = structural
5+
def initialize(item:, viewable:)
6+
@item = item
77
@viewable = viewable
8-
@object_id = object_id
8+
@object_id = item.id
99
end
1010

11-
attr_reader :structural, :object_id
11+
attr_reader :item, :object_id
1212

1313
def viewable?
1414
@viewable

app/components/contents_component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="accordion-item">
22
<h2 class="accordion-header" id="document-contents-heading">
33
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#document-contents-section" aria-expanded="true" aria-controls="document-contents-section">
4-
Content (<%= pluralize Array(@cocina.structural&.contains).size, 'Resource' %>)
4+
Content (<%= pluralize @item.file_sets.size, 'Resource' %>)
55
</button>
66
</h2>
77
<div id="document-contents-section" class="accordion-collapse collapse show" aria-labelledby="document-contents-heading">
@@ -28,7 +28,7 @@
2828
<% end %>
2929
</div>
3030

31-
<%= render Contents::StructuralComponent.new(structural: @cocina.structural, object_id: @cocina.externalIdentifier, viewable: can?(:view_content, @cocina)) %>
31+
<%= render Contents::StructuralComponent.new(item: @item, viewable: can?(:view_content, @item)) %>
3232
</div>
3333
</div>
3434
</div>

app/components/contents_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
class ContentsComponent < ApplicationComponent
44
def initialize(presenter:)
5+
@item = presenter.item
56
@document = presenter.document
6-
@cocina = presenter.cocina
77
@state_service = presenter.state_service
88
end
99

1010
def render?
11-
@cocina.respond_to?(:structural)
11+
@item.is_a? Item
1212
end
1313

1414
delegate :allows_modification?, to: :@state_service

app/components/document_title_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<header class="document-header row mb-5 pb-3">
2-
<%= render OpenCloseComponent.new(id: @document.id) if helpers.can?(:manage_item, @presenter.cocina) %>
2+
<%= render OpenCloseComponent.new(id: @document.id) if helpers.can?(:manage_item, @presenter.item) %>
33

44
<%= content_tag @as, class: @classes do %>
55
<%= title -%>

app/components/show/admin_policy_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="row">
44
<div class="col">
55
<%= render Show::ExternalLinksComponent.new(document: document) %>
6-
<%= render Show::ControlsComponent.new(solr_document: document, manager: helpers.can?(:manage_item, cocina)) %>
6+
<%= render Show::ControlsComponent.new(solr_document: document, manager: helpers.can?(:manage_item, item)) %>
77
</div>
88
</div>
99

app/components/show/admin_policy_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ def initialize(presenter:)
88

99
attr_reader :presenter
1010

11-
delegate :document, :cocina, to: :presenter
11+
delegate :document, :item, to: :presenter
1212
end
1313
end

0 commit comments

Comments
 (0)