Skip to content

Commit

Permalink
Merge branch 'main' into flexible_double_combo
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf authored Dec 12, 2024
2 parents 98a7d59 + dd6f355 commit 96c867a
Show file tree
Hide file tree
Showing 93 changed files with 1,086 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .regen
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# When updating CI regen seed, set to current date.
2023-08-09T14:34:59
2024-09-09T14:34:59
187 changes: 187 additions & 0 deletions app/assets/javascripts/hydra-editor/field_manager.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
export class FieldManager {
constructor(element, options) {
this.element = $(element);

this.options = options;

this.options.label = this.getFieldLabel(this.element, options)

this.addSelector = '.add'
this.removeSelector = '.remove'

this.adder = this.createAddHtml(this.options)
this.remover = this.createRemoveHtml(this.options)

this.controls = $(options.controlsHtml);

this.inputTypeClass = options.inputTypeClass;
this.fieldWrapperClass = options.fieldWrapperClass;
this.warningClass = options.warningClass;
this.listClass = options.listClass;

this.init();
}

// call _addInitialID
init() {
this._addInitialClasses();
this._addInitialID();
this._addAriaLiveRegions();
this._appendControls();
this._attachEvents();
this._addCallbacks();
}

_addInitialClasses() {
this.element.addClass("managed");
$(this.fieldWrapperClass, this.element).addClass("input-group input-append");
}

// ensure ID is assigned
_addInitialID() {
let id = this.element.find('.multi_value.form-control').attr('id') + '_' + 'label';
if (id != "undefined_label"){
this.element.find('label').attr('id', id);
}
}

_addAriaLiveRegions() {
$(this.element).find('.listing').attr('aria-live', 'polite')
}

// Add the "Add another" and "Remove" controls to the DOM
_appendControls() {
// We want to make these DOM additions idempotently, so exit if it's
// already set up.
if (!this._hasRemoveControl()) {
this._createRemoveWrapper()
this._createRemoveControl()
}

if (!this._hasAddControl()) {
this._createAddControl()
}
}

_createRemoveWrapper() {
$(this.fieldWrapperClass, this.element).append(this.controls);
}

_createRemoveControl() {
$(this.fieldWrapperClass + ' .field-controls', this.element).append(this.remover)
}

_createAddControl() {
this.element.find(this.listClass).after(this.adder)
}

_hasRemoveControl() {
return this.element.find(this.removeSelector).length > 0
}

_hasAddControl() {
return this.element.find(this.addSelector).length > 0
}

_attachEvents() {
this.element.on('click', this.removeSelector, (e) => this.removeFromList(e))
this.element.on('click', this.addSelector, (e) => this.addToList(e))
}

_addCallbacks() {
this.element.bind('managed_field:add', this.options.add);
this.element.bind('managed_field:remove', this.options.remove);
}

_manageFocus() {
$(this.element).find(this.listClass).children('li').last().find('.form-control').focus();
}

addToList( event ) {
event.preventDefault();
let $listing = $(event.target).closest(this.inputTypeClass).find(this.listClass)
let $activeField = $listing.children('li').last()

if (this.inputIsEmpty($activeField)) {
this.displayEmptyWarning();
} else {
this.clearEmptyWarning();
$listing.append(this._newField($activeField));
}

this._manageFocus()
}

inputIsEmpty($activeField) {
return $activeField.children('input.multi-text-field').val() === '';
}

_newField ($activeField) {
var $newField = this.createNewField($activeField);
return $newField;
}

createNewField($activeField) {
let $newField = $activeField.clone();
let $newChildren = this.createNewChildren($newField);
this.element.trigger("managed_field:add", $newChildren);
return $newField;
}

clearEmptyWarning() {
let $listing = $(this.listClass, this.element)
$listing.children(this.warningClass).remove();
}

displayEmptyWarning() {
let $listing = $(this.listClass, this.element)
var $warningMessage = $("<div class=\'message has-warning\'>cannot add another with empty field</div>");
$listing.children(this.warningClass).remove();
$listing.append($warningMessage);
}

removeFromList( event ) {
event.preventDefault();
var $field = $(event.target).parents(this.fieldWrapperClass).remove();
this.element.trigger("managed_field:remove", $field);

this._manageFocus();
}

destroy() {
$(this.fieldWrapperClass, this.element).removeClass("input-append");
this.element.removeClass("managed");
}

getFieldLabel($element, options) {
var label = '';
var $label = $element.find("label").first();
if ($label.length && options.labelControls) {
var label = $label.data('label') || $.trim($label.contents().filter(function() { return this.nodeType === 3; }).text());
label = ' ' + label;
}

return label;
}

createAddHtml(options) {
var $addHtml = $(options.addHtml);
$addHtml.find('.controls-add-text').html(options.addText + options.label);
return $addHtml;
}

createRemoveHtml(options) {
var $removeHtml = $(options.removeHtml);
$removeHtml.find('.controls-remove-text').html(options.removeText);
$removeHtml.find('.controls-field-name-text').html(options.label);
return $removeHtml;
}

createNewChildren(clone) {
let $newChildren = $(clone).children(this.inputTypeClass);
$newChildren.val('').removeAttr('required');
$newChildren.first().focus();
return $newChildren.first();
}
}

1 change: 1 addition & 0 deletions app/assets/javascripts/hyrax.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
//= require hyrax/collapse
//= require hyrax/skip_to_content
//= require hyrax/reports-buttons
//= require hydra-editor/field_manager

// this needs to be after batch_select so that the form ids get setup correctly
//= require hyrax/batch_edit
8 changes: 4 additions & 4 deletions app/assets/javascripts/hyrax/analytics_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ $(document).on('click', '#file_download', function(e) {
window.trackingTags.analytics().push([trackingTags.trackEvent(), 'work-in-collection', 'work-in-collection-download', collection]);
});
} else {
gtag('event', 'file-set-download', { 'content-type': 'file-set', 'content-id': $(this).data('label')})
gtag('event', 'file-set-in-work-download', { 'content-type': 'file-set-in-work', 'content-id': $(this).data('work-id')})
gtag('event', 'file-set-download', { 'content_type': 'file-set', 'content_id': $(this).data('label')})
gtag('event', 'file-set-in-work-download', { 'content_type': 'file-set-in-work', 'content_id': $(this).data('work-id')})
$(this).data('collection-ids').forEach(function (collection) {
gtag('event', 'file-set-in-collection-download', { 'content-type': 'file-set-in-collection', 'content-id': collection })
gtag('event', 'work-in-collection-download', { 'content-type': 'work-in-collection', 'content-id': collection })
gtag('event', 'file-set-in-collection-download', { 'content_type': 'file-set-in-collection', 'content_id': collection })
gtag('event', 'work-in-collection-download', { 'content_type': 'work-in-collection', 'content_id': collection })
});
}
});
8 changes: 4 additions & 4 deletions app/assets/javascripts/hyrax/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function getStatusActivity(){
}
else if(isCollapsed){
resultDiv.classList.remove("in");
resultDiv.setAttribute("aria-expanded", "false");
// resultDiv.setAttribute("aria-expanded", "false");
}else{
resultDiv.classList.add("in");
resultDiv.setAttribute("aria-expanded", "true");
// resultDiv.setAttribute("aria-expanded", "true");
}
}

Expand All @@ -55,10 +55,10 @@ function getStatusSettings(){
}
else if(isCollapsed){
resultDiv.classList.remove("in");
resultDiv.setAttribute("aria-expanded", "false");
// resultDiv.setAttribute("aria-expanded", "false");
}else{
resultDiv.classList.add("in");
resultDiv.setAttribute("aria-expanded", "true");
// resultDiv.setAttribute("aria-expanded", "true");
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/hyrax/file_manager/save_manager.es6
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export default class SaveManager {
check_button() {
if (this.is_changed) {
this.save_button.removeClass("disabled")
this.save_button.attr("aria-disabled", "false")
} else {
this.save_button.addClass("disabled")
this.save_button.attr("aria-disabled", "true")
}
}

Expand Down
38 changes: 20 additions & 18 deletions app/assets/javascripts/hyrax/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
Expand All @@ -21,45 +20,48 @@

$.fn.extend({
hyraxUploader: function( options ) {
// Initialize our jQuery File Upload widget.
this.fileupload($.extend({
// xhrFields: {withCredentials: true}, // to send cross-domain cookies
// acceptFileTypes: /(\.|\/)(png|mov|jpe?g|pdf)$/i, // not a strong check, just a regex on the filename
// limitMultiFileUploadSize: 500000000, // bytes
maxChunkSize: 10000000, // 10 MB chunk size
autoUpload: true,
url: '/uploads/',
type: 'POST',
dropZone: $(this).find('.dropzone')
dropZone: $(this).find('.dropzone'),
add: function (e, data) {
var that = this;
$.post('/uploads/', { files: [data.files[0].name] }, function (result) {
data.formData = {id: result.files[0].id};
$.blueimp.fileupload.prototype.options.add.call(that, e, data);
});
}
}, Hyrax.config.uploader, options))
.on('fileuploadadded', function (e, data) {
$(e.currentTarget).find('button.cancel').removeAttr("hidden");
});

$(document).on('dragover', function(e) {
var dropZone = $('.dropzone'),
timeout = window.dropZoneTimeout;
if (!timeout) {
dropZone.addClass('in');
dropZone.addClass('in');
} else {
clearTimeout(timeout);
clearTimeout(timeout);
}
var found = false,
node = e.target;
do {
if (node === dropZone[0]) {
found = true;
break;
}
node = node.parentNode;
if (node === dropZone[0]) {
found = true;
break;
}
node = node.parentNode;
} while (node !== null);
if (found) {
dropZone.addClass('hover');
dropZone.addClass('hover');
} else {
dropZone.removeClass('hover');
dropZone.removeClass('hover');
}
window.dropZoneTimeout = setTimeout(function () {
window.dropZoneTimeout = null;
dropZone.removeClass('in hover');
window.dropZoneTimeout = null;
dropZone.removeClass('in hover');
}, 100);
});
}
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/_bootstrap-default-overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ $warning: #565653 !default;
// * Darkens the text for disabled pagination buttons on every page.
$breadcrumb-active-color: #4c4c4c;
$pagination-disabled-color: #4c4c4c;
$blue: #0056B3 !default;
// Adjusts link text to show as underlined and then not underlined on hover
$link-decoration: underline !default;
$link-hover-decoration: none !default;

// Date picker on safari placeholder text was misaligned
@media screen {
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/hyrax/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ legend small {

.select2-container .select2-choice > .select2-chosen {
max-width: 26em;
overflow: auto;
}

form {
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/hyrax/_styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ label.disabled {
margin-bottom: 1rem;
}
}

#content_block_page {
display: block;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/hyrax/_work-show.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
margin-left: auto;
}
}
.dropdown-item {
font-size: 125%;
}
}

.no-preview,
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/concerns/hyrax/works_controller_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def hash_key_for_curation_concern

def contextual_path(presenter, parent_presenter)
::Hyrax::ContextualPath.new(presenter, parent_presenter).show
rescue NoMethodError
''
end

##
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/hyrax/dashboard/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def update_valkyrie_collection
banner_unchanged_indicator: params["banner_unchanged"] },
'collection_resource.save_collection_logo' => { update_logo_file_ids: params["logo_files"],
alttext_values: params["alttext"],
linkurl_values: params["linkurl"] }
linkurl_values: params["linkurl"],
logo_unchanged_indicator: false }
)
.call(form)
@collection = result.value_or { return after_update_errors(result.failure.first) }
Expand Down
Loading

0 comments on commit 96c867a

Please sign in to comment.