Skip to content

Commit

Permalink
Add rocrate download to collections
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Oct 17, 2024
1 parent 0842b00 commit 1b33c24
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
20 changes: 19 additions & 1 deletion app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ def bulk_update
end
end

def private_rocrate
@data = @collection
@is_item = false
@admin_rocrate = true

json_data = render_to_string(template: 'api/v1/oni/object_meta', formats: [:json], handlers: [:jb])
send_data json_data, filename: "#{@collection.identifier}-ro-crate-metadata.json", type: 'application/json', disposition: 'attachment'
end

def public_rocrate
@data = @collection
@is_item = false
@admin_rocrate = false

json_data = render_to_string(template: 'api/v1/oni/object_meta', formats: [:json], handlers: [:jb])
send_data json_data, filename: "#{@collection.identifier}-ro-crate-metadata.json", type: 'application/json', disposition: 'attachment'
end

def new_from_metadata
@collection = Collection.new
end
Expand Down Expand Up @@ -316,7 +334,7 @@ def find_item
:collector,
:countries,
:field_of_research,
{ :grants => %i[funding_body] },
{ grants: %i[funding_body] },
:languages,
:operator,
:university,
Expand Down
7 changes: 0 additions & 7 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,6 @@ def bulk_update
redirect_to bulk_update_items_path + "?#{params[:original_search_params]}"
end

def s3_rocrate
location = Nabu::Catalog.instance.item_admin_url(@item, 'ro-crate-metadata.json')
raise ActionController::RoutingError, 'PDSC file not found' unless location

redirect_to location, allow_other_host: true
end

def private_rocrate
@data = @item
@is_item = true
Expand Down
11 changes: 11 additions & 0 deletions app/views/collections/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@
%th #Essence objects in items of collection
%td= number_to_human @num_essences

%fieldset
%legend Metadata

%table.form.show
%tr
%th RO-Crate Metadata
%td
%ul
%li= link_to 'Download', public_rocrate_collection_path(@collection)
- if admin_user_signed_in?
%li= link_to 'Download (with private metadata)', private_rocrate_collection_path(@collection)

.right
- if can? :destroy, Collection
Expand Down
6 changes: 2 additions & 4 deletions app/views/items/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,9 @@
%th RO-Crate Metadata
%td
%ul
%li= link_to 'Download', public_rocrate_collection_item_path(@collection, @item)
- if admin_user_signed_in?
%li= link_to 'S3', s3_rocrate_collection_item_path(@collection, @item)
%li= link_to 'Live (Public)', public_rocrate_collection_item_path(@collection, @item)
- if admin_user_signed_in?
%li= link_to 'Live (Private)', private_rocrate_collection_item_path(@collection, @item)
%li= link_to 'Download (with private metadata)', private_rocrate_collection_item_path(@collection, @item)

%fieldset
%legend Comments
Expand Down
11 changes: 7 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
get '/up' => 'rails/health#show', as: :rails_health_check

# Render dynamic PWA files from app/views/pwa/*
get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
get 'service-worker' => 'rails/pwa#service_worker', as: :pwa_service_worker
get 'manifest' => 'rails/pwa#manifest', as: :pwa_manifest

# Graphql
get '/paradisec.graphql', to: 'graphql#schema', as: 'graphql_schema'
Expand Down Expand Up @@ -49,9 +49,12 @@
post 'exsite9' => 'collections#create_from_exsite9'
post 'spreadsheet' => 'collections#create_from_spreadsheet'
end
member do
get :private_rocrate
get :public_rocrate
end
resources :items, except: %i[index] do
member do
get :s3_rocrate
get :private_rocrate
get :public_rocrate
get :data
Expand Down Expand Up @@ -104,7 +107,7 @@
end

authenticated :user, ->(user) { user.admin? } do
mount MissionControl::Jobs::Engine, at: "/jobs"
mount MissionControl::Jobs::Engine, at: '/jobs'
mount Searchjoy::Engine, at: '/searchjoy'
match '/_dashboards/*path' => 'opensearch_dashboard#index', via: %i[get post put patch delete]
end
Expand Down

0 comments on commit 1b33c24

Please sign in to comment.