Skip to content

Commit cfa207f

Browse files
committed
Edit project tag from the show page
1 parent 4c9ef6a commit cfa207f

17 files changed

+134
-47
lines changed

app/components/show/agreement/details_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<tr>
1919
<th class="col-3" scope="row">Project</th>
2020
<td>
21-
<%= render Show::ProjectTagComponent.new(document: @presenter.document) %>
21+
<%= render Show::ProjectTagComponent.new(change_set: @presenter.change_set) %>
2222
</td>
2323
</tr>
2424

app/components/show/collection/details_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<tr>
1212
<th class="col-3" scope="row">Project</th>
1313
<td>
14-
<%= render Show::ProjectTagComponent.new(document: @presenter.document) %>
14+
<%= render Show::ProjectTagComponent.new(change_set: @presenter.change_set) %>
1515
</td>
1616
</tr>
1717

app/components/show/item/details_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<tr>
1919
<th class="col-3" scope="row">Project</th>
2020
<td>
21-
<%= render Show::ProjectTagComponent.new(document: @presenter.document) %>
21+
<%= render Show::ProjectTagComponent.new(change_set: @presenter.change_set) %>
2222
</td>
2323
</tr>
2424

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<turbo-frame id="project">
2+
<%= project %>
3+
<%= link_to edit_project_item_path(id: id), aria: { label: 'Edit project' } do %>
4+
<span class="bi-pencil"></span>
5+
<% end %>
6+
</turbo-frame>

app/components/show/project_tag_component.rb

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,10 @@
22

33
module Show
44
class ProjectTagComponent < ApplicationComponent
5-
def initialize(document:)
6-
@document = document
5+
def initialize(change_set:)
6+
@change_set = change_set
77
end
88

9-
def call
10-
render_field 'project_tag_ssim'
11-
end
12-
13-
private
14-
15-
delegate :blacklight_config, :search_state, :search_action_path, to: :helpers
16-
17-
def render_field(field_name)
18-
field_config = fields.fetch(field_name)
19-
Blacklight::FieldPresenter.new(self, @document, field_config).render
20-
end
21-
22-
def fields
23-
@fields ||= blacklight_config.show_fields_for(:show)
24-
end
9+
delegate :id, :project, to: :@change_set
2510
end
2611
end

app/controllers/collections_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ def create
4242
def update
4343
@cocina = maybe_load_cocina(params[:id])
4444
authorize! :manage_item, @cocina
45-
return unless enforce_versioning
45+
46+
attributes = params.require(:collection).permit(:copyright, :use_statement, :license, :project)
47+
48+
# Editing project does not require versioning.
49+
return if attributes.except(:project).present? && !enforce_versioning
4650

4751
change_set = CollectionChangeSet.new(@cocina)
48-
attributes = params.require(:collection).permit(:copyright, :use_statement, :license)
4952
change_set.validate(**attributes)
5053
change_set.save
5154
Argo::Indexer.reindex_pid_remotely(@cocina.externalIdentifier)

app/controllers/items_controller.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ItemsController < ApplicationController
77
add_collection set_collection remove_collection
88
mods
99
purge_object
10-
show_barcode show_copyright show_license show_use_statement
10+
show_barcode show_copyright show_license show_use_statement show_project
1111
source_id
1212
tags_bulk
1313
update
@@ -20,7 +20,6 @@ class ItemsController < ApplicationController
2020
refresh_metadata
2121
set_rights
2222
set_governing_apo
23-
update
2423
]
2524

2625
rescue_from Dor::Services::Client::UnexpectedResponse do |exception|
@@ -279,10 +278,24 @@ def show_license
279278
render Show::LicenseComponent.new(change_set: change_set, state_service: state_service)
280279
end
281280

281+
# Draw form for setting project
282+
def edit_project
283+
@change_set = build_change_set
284+
end
285+
286+
def show_project
287+
change_set = ItemChangeSet.new(@cocina)
288+
render Show::ProjectTagComponent.new(change_set: change_set)
289+
end
290+
282291
# save the form
283292
def update
284293
change_set = ItemChangeSet.new(@cocina)
285-
attributes = params.require(:item).permit(:barcode, :copyright, :use_statement, :license)
294+
attributes = params.require(:item).permit(:barcode, :copyright, :use_statement, :license, :project)
295+
296+
# Editing project does not require versioning.
297+
return if attributes.except(:project).present? && !enforce_versioning
298+
286299
if change_set.validate(**attributes)
287300
change_set.save # may raise Dor::Services::Client::BadRequestError
288301
reindex

app/models/collection_change_set.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CollectionChangeSet < ApplicationChangeSet
77
property :copyright, virtual: true
88
property :license, virtual: true
99
property :use_statement, virtual: true
10+
property :project, virtual: true
1011

1112
def self.model_name
1213
::ActiveModel::Name.new(nil, nil, 'Collection')
@@ -22,6 +23,7 @@ def setup_properties!(_options)
2223
self.copyright = model.access.copyright
2324
self.use_statement = model.access.useAndReproductionStatement
2425
self.license = model.access.license
26+
self.project = model.administrative&.partOfProject
2527
end
2628

2729
def save_model

app/models/item_change_set.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ItemChangeSet < ApplicationChangeSet
1212
property :source_id, virtual: true
1313
property :use_statement, virtual: true
1414
property :barcode, virtual: true
15+
property :project, virtual: true
1516

1617
validates :embargo_access, inclusion: {
1718
in: Constants::REGISTRATION_RIGHTS_OPTIONS.map(&:second),
@@ -36,6 +37,7 @@ def setup_properties!(_options)
3637
self.copyright = model.access.copyright
3738
self.use_statement = model.access.useAndReproductionStatement
3839
self.license = model.access.license
40+
self.project = model.administrative.partOfProject
3941

4042
setup_embargo_properties! if model.access.embargo
4143
end

app/services/collection_change_set_persister.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,24 @@ def update
1818
updated = model
1919
updated = update_identification(updated) if changed?(:source_id) || changed?(:catkey)
2020
updated = updated_access(updated) if access_changed?
21-
updated = updated_administrative(updated) if changed?(:admin_policy_id)
21+
updated = updated_administrative(updated) if administrative_changed?
2222
object_client.update(params: updated)
2323
end
2424

2525
private
2626

2727
attr_reader :model, :change_set
2828

29-
delegate :admin_policy_id, :license, :copyright, :use_statement, :catkey, :changed?, to: :change_set
29+
delegate :admin_policy_id, :project, :license, :copyright, :use_statement, :catkey, :changed?, to: :change_set
3030

3131
def access_changed?
3232
changed?(:copyright) || changed?(:license) || changed?(:use_statement)
3333
end
3434

35+
def administrative_changed?
36+
changed?(:admin_policy_id) || changed?(:project)
37+
end
38+
3539
def updated_access(updated)
3640
access_properties = {
3741
copyright: changed?(:copyright) ? copyright : updated.access.copyright,
@@ -49,7 +53,11 @@ def update_identification(updated)
4953
end
5054

5155
def updated_administrative(updated)
52-
updated_administrative = updated.administrative.new(hasAdminPolicy: admin_policy_id)
56+
properties = {}
57+
properties[:hasAdminPolicy] = admin_policy_id if changed?(:admin_policy_id)
58+
properties[:partOfProject] = project if changed?(:project)
59+
60+
updated_administrative = updated.administrative.new(properties)
5361
updated.new(administrative: updated_administrative)
5462
end
5563

0 commit comments

Comments
 (0)