Skip to content

Commit

Permalink
Moves the loading of Aspace repositories to the controller action (#2168
Browse files Browse the repository at this point in the history
). (#2230)

* Moves the loading of Aspace repositories to the controller action (#2168).

* Adds override comment.
  • Loading branch information
bwatson78 authored Dec 5, 2023
1 parent 58dc646 commit c57dfd0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,40 @@ def add_new_banner(uploaded_file_ids)
banner_info.save f.collection_banner_url
end

# [Hyrax-overwrite-v3.0.0.pre.rc1] Restrict deletion to admins only
# [Hyrax-overwrite-v3.4.2] Restrict deletion to admins only
def destroy
if current_user.admin? && @collection.destroy
after_destroy(params[:id])
else
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

service.authenticate!

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

Please sign in to comment.