Skip to content

Commit f42a171

Browse files
committed
Moves the loading of Aspace repositories to the controller action (#2168).
1 parent 58dc646 commit f42a171

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

app/controllers/hyrax/dashboard/collections_controller_override.rb

+26-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,39 @@ def add_new_banner(uploaded_file_ids)
1818
banner_info.save f.collection_banner_url
1919
end
2020

21-
# [Hyrax-overwrite-v3.0.0.pre.rc1] Restrict deletion to admins only
21+
# [Hyrax-overwrite-v3.4.2] Restrict deletion to admins only
2222
def destroy
2323
if current_user.admin? && @collection.destroy
2424
after_destroy(params[:id])
2525
else
2626
after_destroy_error(params[:id])
2727
end
2828
end
29+
30+
def new
31+
# Coming from the UI, a collection type id should always be present. Coming from the API, if a collection type id is not specified,
32+
# use the default collection type (provides backward compatibility with versions < Hyrax 2.1.0)
33+
@aspace_repositories = retrieve_aspace_repositories
34+
collection_type_id = params[:collection_type_id].presence || default_collection_type.id
35+
@collection.collection_type_gid = CollectionType.find(collection_type_id).to_global_id
36+
add_breadcrumb t(:'hyrax.controls.home'), root_path
37+
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
38+
add_breadcrumb t('.header', type_title: collection_type.title), request.path
39+
@collection.try(:apply_depositor_metadata, current_user.user_key)
40+
form
41+
end
42+
43+
private
44+
45+
def retrieve_aspace_repositories
46+
service = Aspace::ApiService.new
47+
formatter = Aspace::FormattingService.new
48+
49+
service.authenticate!
50+
51+
data = service.fetch_repositories
52+
data.map { |r| formatter.format_repository(r) } || []
53+
end
2954
end
3055
end
3156
end

app/views/hyrax/dashboard/collections/new.html.erb

+4-17
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
<p>Select an ArchivesSpace Repository.</p>
2121
<div class="form-group">
2222
<label for="sel1">Select list:</label>
23-
<select class="form-control" id="sel1"></select>
23+
<% repositories = @aspace_repositories.presence || [] %>
24+
<%= select_tag('sel1',
25+
options_for_select(repositories.collect{ |ar| [ar[:name], ar[:repository_id]] }),
26+
class: 'form-control') %>
2427
</div>
2528
<div class="call-number-field">
2629
<label for="aspace-call-number">Call Number: (must be exact)</label>
@@ -71,22 +74,6 @@
7174
var result_success;
7275
var result_error;
7376

74-
$.ajax({
75-
url: '/aspace/repositories',
76-
type: 'GET',
77-
dataType: 'json',
78-
async: false,
79-
success: function(repositories) {
80-
jQuery.each( repositories, function(i, val) {
81-
var o = new Option(val.name, val.repository_id);
82-
/// jquerify the DOM object 'o' so we can use the html method
83-
$(o).html(val.name);
84-
$("#sel1").append(o);
85-
repository_id = val.repository_id;
86-
});
87-
}
88-
});
89-
9077
$("#aspace-loader").click(function (e) {
9178
$("#aspace-error").hide();
9279
$(".aspace-result-empty").empty();

0 commit comments

Comments
 (0)