Skip to content

Commit 573e7e6

Browse files
committed
Create local models so we can avoid cocina edits
1 parent 168823b commit 573e7e6

File tree

132 files changed

+1304
-1274
lines changed

Some content is hidden

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

132 files changed

+1304
-1274
lines changed

app/components/contents/file_component.html.erb

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

app/components/contents/file_component.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ def image?
1919
@image
2020
end
2121

22-
delegate :access, :administrative, :filename, :hasMimeType, :size, :externalIdentifier, :use, :presentation, to: :file
23-
delegate :publish, :shelve, :sdrPreserve, to: :administrative
22+
delegate :filename, :mime_type, :size, :use, :publish, :shelve, :preserve, to: :file
2423

2524
def view_access
26-
access.view.capitalize
25+
file.view_access.capitalize
2726
end
2827

2928
def download_access
30-
access.download.capitalize
29+
file.download_access.capitalize
3130
end
3231

3332
def role
@@ -41,15 +40,11 @@ def link_attrs
4140
end
4241

4342
def height
44-
return '' if presentation&.height.blank?
45-
46-
"#{presentation.height} px"
43+
"#{file.height} px" if file.height
4744
end
4845

4946
def width
50-
return '' if presentation&.width.blank?
51-
52-
"#{presentation.width} px"
47+
"#{file.width} px" if file.width
5348
end
5449
end
5550
end

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
@@ -23,10 +24,6 @@ def type
2324
resource.type.delete_prefix('https://cocina.sul.stanford.edu/models/resources/')
2425
end
2526

26-
delegate :label, to: :resource
27-
28-
def files
29-
resource.structural.contains
30-
end
27+
delegate :label, :files, to: :resource
3128
end
3229
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, :view_token, to: :presenter
11+
delegate :document, :item, :view_token, to: :presenter
1212
end
1313
end

0 commit comments

Comments
 (0)