Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Moves the loading of Aspace repositories to the controller action (#2168). (#2230)" #2253

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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