Skip to content

Commit

Permalink
🎁 Generate GenericWorkResource and ImageResource
Browse files Browse the repository at this point in the history
This commit runs the following commands:

```sh
bundle exec rails g hyrax:work_resource GenericWorkResource
bundle exec rails g hyrax:work_resource ImageResource
```

Also we update IIIF Print to allow it to boot.
See:
  - scientist-softserv/iiif_print@cc105d0
Ref:
  - scientist-softserv/hykuup_knapsack#80
  • Loading branch information
kirkkwang committed Jan 4, 2024
1 parent 1797a6a commit ad44840
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ GIT

GIT
remote: https://github.com/scientist-softserv/iiif_print.git
revision: cad2cf33fc07ec2abb5b6834a858b5ed74903c12
revision: cc105d061727988e016c32235459f4cb82bd3ad6
branch: rails_hyrax_upgrade
specs:
iiif_print (1.0.0)
Expand Down
17 changes: 17 additions & 0 deletions app/controllers/hyrax/generic_work_resources_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource GenericWorkResource`
module Hyrax
# Generated controller for GenericWorkResource
class GenericWorkResourcesController < ApplicationController
# Adds Hyrax behaviors to the controller.
include Hyrax::WorksControllerBehavior
include Hyrax::BreadcrumbsForWorks
self.curation_concern_type = ::GenericWorkResource

# Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style
# forms.
self.work_form_service = Hyrax::FormFactory.new
end
end
17 changes: 17 additions & 0 deletions app/controllers/hyrax/image_resources_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource ImageResource`
module Hyrax
# Generated controller for ImageResource
class ImageResourcesController < ApplicationController
# Adds Hyrax behaviors to the controller.
include Hyrax::WorksControllerBehavior
include Hyrax::BreadcrumbsForWorks
self.curation_concern_type = ::ImageResource

# Use a Valkyrie aware form service to generate Valkyrie::ChangeSet style
# forms.
self.work_form_service = Hyrax::FormFactory.new
end
end
20 changes: 20 additions & 0 deletions app/forms/generic_work_resource_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource GenericWorkResource`
#
# @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms
# @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking
class GenericWorkResourceForm < Hyrax::Forms::PcdmObjectForm(GenericWorkResource)
include Hyrax::FormFields(:basic_metadata)
include Hyrax::FormFields(:generic_work_resource)

# Define custom form fields using the Valkyrie::ChangeSet interface
#
# property :my_custom_form_field

# if you want a field in the form, but it doesn't have a directly corresponding
# model attribute, make it virtual
#
# property :user_input_not_destined_for_the_model, virtual: true
end
20 changes: 20 additions & 0 deletions app/forms/image_resource_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource ImageResource`
#
# @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms
# @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking
class ImageResourceForm < Hyrax::Forms::PcdmObjectForm(ImageResource)
include Hyrax::FormFields(:basic_metadata)
include Hyrax::FormFields(:image_resource)

# Define custom form fields using the Valkyrie::ChangeSet interface
#
# property :my_custom_form_field

# if you want a field in the form, but it doesn't have a directly corresponding
# model attribute, make it virtual
#
# property :user_input_not_destined_for_the_model, virtual: true
end
16 changes: 16 additions & 0 deletions app/indexers/generic_work_resource_indexer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource GenericWorkResource`
class GenericWorkResourceIndexer < Hyrax::ValkyrieWorkIndexer
include Hyrax::Indexer(:basic_metadata)
include Hyrax::Indexer(:generic_work_resource)

# Uncomment this block if you want to add custom indexing behavior:
# def to_solr
# super.tap do |index_document|
# index_document[:my_field_tesim] = resource.my_field.map(&:to_s)
# index_document[:other_field_ssim] = resource.other_field
# end
# end
end
16 changes: 16 additions & 0 deletions app/indexers/image_resource_indexer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource ImageResource`
class ImageResourceIndexer < Hyrax::ValkyrieWorkIndexer
include Hyrax::Indexer(:basic_metadata)
include Hyrax::Indexer(:image_resource)

# Uncomment this block if you want to add custom indexing behavior:
# def to_solr
# super.tap do |index_document|
# index_document[:my_field_tesim] = resource.my_field.map(&:to_s)
# index_document[:other_field_ssim] = resource.other_field
# end
# end
end
8 changes: 8 additions & 0 deletions app/models/generic_work_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource GenericWorkResource`
class GenericWorkResource < Hyrax::Work
include Hyrax::Schema(:basic_metadata)
include Hyrax::Schema(:generic_work_resource)
end
8 changes: 8 additions & 0 deletions app/models/image_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource ImageResource`
class ImageResource < Hyrax::Work
include Hyrax::Schema(:basic_metadata)
include Hyrax::Schema(:image_resource)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%# This is a search result view %>
<%= render 'catalog/document', document: generic_work_resource, document_counter: generic_work_resource_counter %>
2 changes: 2 additions & 0 deletions app/views/hyrax/image_resources/_image_resource.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%# This is a search result view %>
<%= render 'catalog/document', document: image_resource, document_counter: image_resource_counter %>
4 changes: 4 additions & 0 deletions config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
config.register_curation_concern :generic_work
# Injected via `rails g hyrax:work Image`
config.register_curation_concern :image
# Injected via `rails g hyrax:work_resource GenericWorkResource`
config.register_curation_concern :generic_work_resource
# Injected via `rails g hyrax:work_resource ImageResource`
config.register_curation_concern :image_resource

# The email address that messages submitted via the contact page are sent to
# This is set by account settings
Expand Down
24 changes: 24 additions & 0 deletions config/metadata/generic_work_resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Simple yaml config-driven schema which is used to define model attributes,
# index key names, and form properties.
#
# Attributes must have a type but all other configuration options are optional.
# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes
# must be placed here.
#
# attributes:
# attribute_name:
# type: string
# multiple: false
# index_keys:
# - "attribute_name_sim"
# form:
# required: true
# primary: true
# multiple: false
#
# @see config/metadata/basic_metadata.yaml for an example configuration
#
# Generated via
# `rails generate hyrax:work_resource GenericWorkResource`

attributes: {}
24 changes: 24 additions & 0 deletions config/metadata/image_resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Simple yaml config-driven schema which is used to define model attributes,
# index key names, and form properties.
#
# Attributes must have a type but all other configuration options are optional.
# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes
# must be placed here.
#
# attributes:
# attribute_name:
# type: string
# multiple: false
# index_keys:
# - "attribute_name_sim"
# form:
# required: true
# primary: true
# multiple: false
#
# @see config/metadata/basic_metadata.yaml for an example configuration
#
# Generated via
# `rails generate hyrax:work_resource ImageResource`

attributes: {}
13 changes: 13 additions & 0 deletions spec/indexers/generic_work_resource_indexer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource GenericWorkResource`
require 'rails_helper'
require 'hyrax/specs/shared_specs/indexers'

RSpec.describe GenericWorkResourceIndexer do
let(:indexer_class) { described_class }
let(:resource) { GenericWorkResource.new }

it_behaves_like 'a Hyrax::Resource indexer'
end
13 changes: 13 additions & 0 deletions spec/indexers/image_resource_indexer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource ImageResource`
require 'rails_helper'
require 'hyrax/specs/shared_specs/indexers'

RSpec.describe ImageResourceIndexer do
let(:indexer_class) { described_class }
let(:resource) { ImageResource.new }

it_behaves_like 'a Hyrax::Resource indexer'
end
12 changes: 12 additions & 0 deletions spec/models/generic_work_resource_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource GenericWorkResource`
require 'rails_helper'
require 'hyrax/specs/shared_specs/hydra_works'

RSpec.describe GenericWorkResource do
subject(:work) { described_class.new }

it_behaves_like 'a Hyrax::Work'
end
12 changes: 12 additions & 0 deletions spec/models/image_resource_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource ImageResource`
require 'rails_helper'
require 'hyrax/specs/shared_specs/hydra_works'

RSpec.describe ImageResource do
subject(:work) { described_class.new }

it_behaves_like 'a Hyrax::Work'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource GenericWorkResource`
RSpec.describe 'generic_work_resources/generic_work_resource.html.erb', type: :view do # rubocop:disable RSpec/EmptyExampleGroup
# add generic_work_resource view specs
end
7 changes: 7 additions & 0 deletions spec/views/image_resources/_image_resource.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

# Generated via
# `rails generate hyrax:work_resource ImageResource`
RSpec.describe 'image_resources/image_resource.html.erb', type: :view do # rubocop:disable RSpec/EmptyExampleGroup
# add image_resource view specs
end

0 comments on commit ad44840

Please sign in to comment.