Skip to content

Commit 70504cb

Browse files
committed
Create local models so we can avoid cocina edits
1 parent 9102aac commit 70504cb

File tree

124 files changed

+1269
-902
lines changed

Some content is hidden

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

124 files changed

+1269
-902
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
module Contents
44
class StructuralComponent < ViewComponent::Base
5-
# @param [Cocina::Models::DroStructural] structural
6-
# @param [String] object_id the identifier of the object
5+
# @param [Item] item
76
# @param [Bool] viewable if true the user will be presented with a link to download files
8-
def initialize(structural:, object_id:, viewable:)
9-
@structural = structural
7+
def initialize(item:, viewable:)
8+
@item = item
109
@viewable = viewable
11-
@object_id = object_id
10+
@object_id = item.id
1211
end
1312

14-
attr_reader :structural, :object_id
13+
attr_reader :item, :object_id
1514

1615
def viewable?
1716
@viewable

app/components/contents_component.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
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
@view_token = presenter.view_token
99
end
1010

1111
def render?
12-
@cocina.respond_to?(:structural)
12+
@item.is_a? Item
1313
end
1414

1515
def number_of_file_sets
16-
@cocina.structural.contains.size
16+
@item.file_sets.size
1717
end
1818

1919
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
@@ -4,7 +4,7 @@
44
<div class="col">
55
<%= render Show::ExternalLinksComponent.new(document: document) %>
66
<%= render Show::ControlsComponent.new(presenter: presenter,
7-
manager: helpers.can?(:manage_item, cocina)) %>
7+
manager: helpers.can?(:manage_item, item)) %>
88
</div>
99
</div>
1010

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

app/components/show/agreement_component.html.erb

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

0 commit comments

Comments
 (0)