Skip to content

Commit

Permalink
Revert "Moves the loading of Aspace repositories to the controller ac…
Browse files Browse the repository at this point in the history
…tion (#2168). (#2230)" (#2253)

This reverts commit c57dfd0.
  • Loading branch information
bwatson78 authored Feb 15, 2024
1 parent 9adcad2 commit 7171130
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
33 changes: 0 additions & 33 deletions app/controllers/hyrax/dashboard/collections_controller_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,6 @@ def destroy
after_destroy_error(params[:id])
end
end

# [Hyrax-overwrite-v3.4.2] Creates instance variable for aspace repositories.
def new
# Coming from the UI, a collection type id should always be present. Coming from the API, if a collection type id is not specified,
# use the default collection type (provides backward compatibility with versions < Hyrax 2.1.0)
@aspace_repositories = retrieve_aspace_repositories
collection_type_id = params[:collection_type_id].presence || default_collection_type.id
@collection.collection_type_gid = CollectionType.find(collection_type_id).to_global_id
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
add_breadcrumb t('.header', type_title: collection_type.title), request.path
@collection.try(:apply_depositor_metadata, current_user.user_key)
form
end

private

def retrieve_aspace_repositories
service = Aspace::ApiService.new
formatter = Aspace::FormattingService.new

repositories =
begin
service.authenticate!

data = service.fetch_repositories
data.map { |r| formatter.format_repository(r) } || []
rescue
Rails.logger.error "Curate failed to authenticate with ArchivesSpace."
[]
end
repositories
end
end
end
end
21 changes: 17 additions & 4 deletions app/views/hyrax/dashboard/collections/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
<p>Select an ArchivesSpace Repository.</p>
<div class="form-group">
<label for="sel1">Select list:</label>
<% repositories = @aspace_repositories.presence || [] %>
<%= select_tag('sel1',
options_for_select(repositories.collect{ |ar| [ar[:name], ar[:repository_id]] }),
class: 'form-control') %>
<select class="form-control" id="sel1"></select>
</div>
<div class="call-number-field">
<label for="aspace-call-number">Call Number: (must be exact)</label>
Expand Down Expand Up @@ -74,6 +71,22 @@
var result_success;
var result_error;

$.ajax({
url: '/aspace/repositories',
type: 'GET',
dataType: 'json',
async: false,
success: function(repositories) {
jQuery.each( repositories, function(i, val) {
var o = new Option(val.name, val.repository_id);
/// jquerify the DOM object 'o' so we can use the html method
$(o).html(val.name);
$("#sel1").append(o);
repository_id = val.repository_id;
});
}
});

$("#aspace-loader").click(function (e) {
$("#aspace-error").hide();
$(".aspace-result-empty").empty();
Expand Down

0 comments on commit 7171130

Please sign in to comment.