Skip to content

Commit

Permalink
Generic resource for MODS HTML preview from raw xml
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcliff committed Feb 2, 2024
1 parent 2429e3c commit 5c3309d
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.144
0.0.145
19 changes: 19 additions & 0 deletions app/controllers/resources_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

class ResourcesController < ApplicationController
def show
@resource = Resource.find(params[:id]).decorate
redirect_to(@resource)
end

def preview
# An action to facilitate temporary resources - given raw xml give back html
# Loader preview, XML editor, etc.
@resource = Work.new(alternate_ids: [Time.now.to_f.to_s.gsub!('.', '').to_s])
file = params[:binary]
path = file.tempfile.path.presence || file.path
@resource.mods_json = File.read(path)
@resource.decorate
# Need to figure out how to clean up any residual objects
end
end
2 changes: 0 additions & 2 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

class Collection < Resource
include Modsable

attribute :a_member_of, Valkyrie::Types::Set.of(Valkyrie::Types::ID).meta(ordered: true)
end
2 changes: 0 additions & 2 deletions app/models/community.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

class Community < Resource
include Modsable

attribute :a_member_of, Valkyrie::Types::Set.of(Valkyrie::Types::ID).meta(ordered: true)
end
1 change: 1 addition & 0 deletions app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class Resource < Valkyrie::Resource
include Relationships
include Modsable

attribute :alternate_ids,
Valkyrie::Types::Set.of(Valkyrie::Types::ID).meta(ordered: true).default {
Expand Down
2 changes: 0 additions & 2 deletions app/models/work.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

class Work < Resource
include Modsable

attribute :a_member_of, Valkyrie::Types::Set.of(Valkyrie::Types::ID).meta(ordered: true)
end
1 change: 1 addition & 0 deletions app/views/collections/mods.xml.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= @collection.mods_xml.html_safe
1 change: 1 addition & 0 deletions app/views/communities/mods.xml.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= @community.mods_xml.html_safe
14 changes: 14 additions & 0 deletions app/views/resources/preview.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#mods
%dl
= @resource.title
= @resource.names
= @resource.languages
= @resource.date_created
= @resource.resource_type
= @resource.genres
= @resource.digital_origin
= @resource.abstract
= @resource.related_series
= @resource.subjects
= @resource.permanent_url
= @resource.access_condition
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
resources :file_sets
resources :files, :controller => :blobs

# Generics
get '/resources/:id', to: 'resources#show'
post '/resources/preview', to: 'resources#preview', defaults: { format: 'html' }

# Metadata
get '/communities/:id/mods', to: 'communities#mods', as: 'community_mods'
get '/communities/:id/children', to: 'communities#children', as: 'community_children'
Expand Down

0 comments on commit 5c3309d

Please sign in to comment.