Skip to content

Commit

Permalink
♻️ Move common code into a shared partial
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaLMoore committed Oct 28, 2024
1 parent b84f692 commit 93d99d7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 111 deletions.
43 changes: 6 additions & 37 deletions app/views/bulkrax/importers/_bagit_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,13 @@
<p>File upload and Cloud File upload must be a Zip file containing a single BagIt Bag, or a folder containing multiple BagIt Bags.</p>
<p>The Server Path can point to a BagIt Bag, a folder containing BagIt Bags, or a zip file containing either.</p>

<%= fi.input :file_style, collection: ['Upload a File', 'Specify a Path on the Server', 'Add Cloud File'], as: :radio_buttons, label: false %>
<%= fi.input :file_style,
collection: ['Upload a File', 'Specify a Path on the Server'] +
(defined?(::Hyrax) && Hyrax.config.browse_everything? ? ['Add Cloud File'] : []),
as: :radio_buttons, label: false %>
<div id='file_upload'>
<% if defined?(::Hyrax) %>
<div id="fileupload-bulkrax">
<noscript><input type="hidden" name="redirect" value="<%= main_app.root_path %>" /></noscript>
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
<div class="fileupload-buttonbar">
<div class="row">
<div class="col-12">
<div class="fileinput-button" id="add-files">
<input id="addfiles" type="file" style="display:none;" name="files[]" accept="text/csv,application/zip,application/gzip" />
<button type="button" class="btn btn-success" onclick="document.getElementById('addfiles').click();">
<span class="fa fa-plus"></span>
<span>Add Files</span>
</button>
</div>
<button type="reset" id="file-upload-cancel-btn" class="btn btn-warning cancel">
<span class="fa fa-ban"></span>
<span>Cancel Upload</span>
</button>
<span class="fileupload-process"></span>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="fileupload-progress fade">
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-striped progress-bar-animated bg-success" style="width:0%;"></div>
</div>
<div class="progress-extended">&nbsp;</div>
</div>
</div>
</div>
</div>
<div class="dropzone">
Drop files here to upload
</div>
</div>
<%= render 'hyrax/uploads/js_templates' %>
<%= render 'bulkrax/importers/file_uploader', accepted_file_types: 'application/zip' %>
<% else %>
<%= fi.input 'file', as: :file, input_html: {accept: 'application/zip'} %><br />
<% end %>
Expand All @@ -94,6 +62,7 @@
</div>
</div>

<!-- Uploader initialization script -->
<script type="text/javascript">
$(function() {
if ($('#fileupload-bulkrax').length) {
Expand Down
37 changes: 1 addition & 36 deletions app/views/bulkrax/importers/_csv_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,7 @@

<div id='file_upload'>
<% if defined?(::Hyrax) %>
<div id="fileupload-bulkrax">
<noscript><input type="hidden" name="redirect" value="<%= main_app.root_path %>" /></noscript>
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
<div class="fileupload-buttonbar">
<div class="row">
<div class="col-12">
<div class="fileinput-button" id="add-files">
<input id="addfiles" type="file" style="display:none;" name="files[]" accept="text/csv,application/zip,application/gzip" />
<button type="button" class="btn btn-success" onclick="document.getElementById('addfiles').click();">
<span class="fa fa-plus"></span>
<span>Add Files</span>
</button>
</div>
<button type="reset" id="file-upload-cancel-btn" class="btn btn-warning cancel">
<span class="fa fa-ban"></span>
<span>Cancel Upload</span>
</button>
<span class="fileupload-process"></span>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="fileupload-progress fade">
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-striped progress-bar-animated bg-success" style="width:0%;"></div>
</div>
<div class="progress-extended">&nbsp;</div>
</div>
</div>
</div>
</div>
<div class="dropzone">
Drop files here to upload
</div>
</div>
<%= render 'hyrax/uploads/js_templates' %>
<%= render 'bulkrax/importers/file_uploader', accepted_file_types: 'text/csv,application/zip,application/gzip' %>
<% else %>
<%= fi.input 'file', as: :file, input_html: { accept: 'text/csv,application/zip,application/gzip' } %><br />
<% end %>
Expand Down
37 changes: 37 additions & 0 deletions app/views/bulkrax/importers/_file_uploader.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div id="fileupload-bulkrax">
<noscript><input type="hidden" name="redirect" value="<%= main_app.root_path %>" /></noscript>
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
<div class="fileupload-buttonbar">
<div class="row">
<div class="col-12">
<div class="fileinput-button" id="add-files">
<input id="addfiles" type="file" style="display:none;" name="files[]"
accept="<%= accepted_file_types || 'text/csv,application/zip,application/gzip' %>" />
<button type="button" class="btn btn-success" onclick="document.getElementById('addfiles').click();">
<span class="fa fa-plus"></span>
<span>Add Files</span>
</button>
</div>
<button type="reset" id="file-upload-cancel-btn" class="btn btn-warning cancel">
<span class="fa fa-ban"></span>
<span>Cancel Upload</span>
</button>
<span class="fileupload-process"></span>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="fileupload-progress fade">
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-striped progress-bar-animated bg-success" style="width:0%;"></div>
</div>
<div class="progress-extended">&nbsp;</div>
</div>
</div>
</div>
</div>
<div class="dropzone">
Drop files here to upload
</div>
<%= render 'hyrax/uploads/js_templates' %>
</div>
69 changes: 31 additions & 38 deletions app/views/bulkrax/importers/_xml_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,13 @@
<p>File upload and Cloud File upload MUST be a either a single XML file (for metadata only import) OR a Zip file containing the XML files and data files, each in a separate folder.</p>
<p>The Server Path can point to a folder containing XML files and data files to import, or direct to the XML file itself.</p>

<%= fi.input :file_style, collection: ['Upload a File', 'Specify a Path on the Server', 'Add Cloud File'], as: :radio_buttons, label: false %>
<%= fi.input :file_style,
collection: ['Upload a File', 'Specify a Path on the Server'] +
(defined?(::Hyrax) && Hyrax.config.browse_everything? ? ['Add Cloud File'] : []),
as: :radio_buttons, label: false %>
<div id='file_upload'>
<% if defined?(::Hyrax) %>
<div id="fileupload-bulkrax">
<noscript><input type="hidden" name="redirect" value="<%= main_app.root_path %>" /></noscript>
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
<div class="fileupload-buttonbar">
<div class="row">
<div class="col-12">
<div class="fileinput-button" id="add-files">
<input id="addfiles" type="file" style="display:none;" name="files[]" accept="text/csv,application/zip,application/gzip" />
<button type="button" class="btn btn-success" onclick="document.getElementById('addfiles').click();">
<span class="fa fa-plus"></span>
<span>Add Files</span>
</button>
</div>
<button type="reset" id="file-upload-cancel-btn" class="btn btn-warning cancel">
<span class="fa fa-ban"></span>
<span>Cancel Upload</span>
</button>
<span class="fileupload-process"></span>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="fileupload-progress fade">
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-striped progress-bar-animated bg-success" style="width:0%;"></div>
</div>
<div class="progress-extended">&nbsp;</div>
</div>
</div>
</div>
</div>
<div class="dropzone">
Drop files here to upload
</div>
</div>
<%= render 'hyrax/uploads/js_templates' %>
<%= render 'bulkrax/importers/file_uploader', accepted_file_types: 'application/zip,application/xml' %>
<% else %>
<%= fi.input 'file', as: :file, input_html: {accept: ['application/zip', 'application/xml']} %><br />
<% end%>
Expand All @@ -95,7 +63,32 @@
</div>
<div id='cloud'>
<% if defined?(::Hyrax) && Hyrax.config.browse_everything? %>
<%= render 'browse_everything', form: form %>
<% end %>
</div>
</div>

<!-- Uploader initialization script -->
<script type="text/javascript">
$(function() {
console.log('Running uploader initialization in XML partial'); // Add this line
if ($('#fileupload-bulkrax').length) {
console.log('Initializing uploader on #fileupload-bulkrax in XML view');
$('#fileupload-bulkrax').hyraxUploader({
maxNumberOfFiles: 1,
add: function (e, data) {
console.log('Add event triggered with data:', data);
var that = this;
$.post('/uploads/', { files: [data.files[0].name] }, function (result) {
console.log('File post successful:', result);
data.formData = { id: result.files[0].id };
$.blueimp.fileupload.prototype.options.add.call(that, e, data);
}).fail(function() {
console.log('Error posting file');
});
}
}).on('fileuploadadded', function (e, data) {
console.log('File upload added event triggered with data:', data);
});
}
});
</script>

0 comments on commit 93d99d7

Please sign in to comment.