From 681501b77bd84af0b45319f230c5804e8d4dc3ef Mon Sep 17 00:00:00 2001 From: Eric O Date: Tue, 13 Feb 2024 20:57:17 -0500 Subject: [PATCH] Add view_limitation dynamic field type --- .../digital_objects_app/models/digital_object/base.js | 2 +- .../models/digital_object_search_result.js | 4 ++-- .../widgets/digital_object_editor/_dynamic_field.ejs | 9 +++++++++ app/controllers/application_controller.rb | 2 -- app/jobs/update_image_service_job.rb | 3 +++ app/models/dynamic_field.rb | 10 +++++++++- app/views/digital_objects/media_view.html.erb | 2 +- lib/tasks/hyacinth/setup.rake | 5 +++++ lib/tasks/hyacinth/test.rake | 5 +++++ 9 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/digital_objects_app/models/digital_object/base.js b/app/assets/javascripts/digital_objects_app/models/digital_object/base.js index 5aea1a173..8c94364d8 100644 --- a/app/assets/javascripts/digital_objects_app/models/digital_object/base.js +++ b/app/assets/javascripts/digital_objects_app/models/digital_object/base.js @@ -24,7 +24,7 @@ Hyacinth.DigitalObjectsApp.DigitalObject.Base.getImageUrl = function (pid, type, if (type == 'scaled') { type = 'full'; } if (type == 'square') { type = 'featured'; } - return Hyacinth.imageServerUrl + '/iiif/2/' + pid + '/' + type + '/!' + size + ',' + size + '/0/default.jpg'; + return Hyacinth.imageServerUrl + '/iiif/2/standard/' + pid + '/' + type + '/!' + size + ',' + size + '/0/default.jpg'; }; Hyacinth.DigitalObjectsApp.DigitalObject.Base.showMediaViewModal = function (pid) { diff --git a/app/assets/javascripts/digital_objects_app/models/digital_object_search_result.js b/app/assets/javascripts/digital_objects_app/models/digital_object_search_result.js index 534029fa2..73fdb5ea0 100644 --- a/app/assets/javascripts/digital_objects_app/models/digital_object_search_result.js +++ b/app/assets/javascripts/digital_objects_app/models/digital_object_search_result.js @@ -57,9 +57,9 @@ Hyacinth.DigitalObjectsApp.DigitalObjectSearchResult.prototype.getImageUrl = fun if(type == 'square') { type = 'featured'; } if(this.getHyacinthType() == 'asset') { - return Hyacinth.imageServerUrl + '/iiif/2/' + this.getPid() + '/' + type + '/!' + size + ',' + size + '/0/default.jpg'; + return Hyacinth.imageServerUrl + '/iiif/2/standard/' + this.getPid() + '/' + type + '/!' + size + ',' + size + '/0/default.jpg'; } else if (this.getHyacinthType() == 'item' && this.getOrderedChildDigitalObjectPids().length > 0) { - return Hyacinth.imageServerUrl + '/iiif/2/' + this.getOrderedChildDigitalObjectPids()[0] + '/' + type + '/!' + size + ',' + size + '/0/default.jpg'; + return Hyacinth.imageServerUrl + '/iiif/2/standard/' + this.getOrderedChildDigitalObjectPids()[0] + '/' + type + '/!' + size + ',' + size + '/0/default.jpg'; } else { return null; } diff --git a/app/assets/templates/digital_objects_app/widgets/digital_object_editor/_dynamic_field.ejs b/app/assets/templates/digital_objects_app/widgets/digital_object_editor/_dynamic_field.ejs index f02d78323..6c9df5d2f 100644 --- a/app/assets/templates/digital_objects_app/widgets/digital_object_editor/_dynamic_field.ejs +++ b/app/assets/templates/digital_objects_app/widgets/digital_object_editor/_dynamic_field.ejs @@ -64,6 +64,15 @@ var fieldsetIds = associatedEnabledDynamicField ? associatedEnabledDynamicField[ case 'string': %><% break; + case 'view_limitation': + %> + + <% + break; default: %>Unknown field type: <%= dynamic_field['dynamic_field_type'] %><% } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1fe71599c..4003e58a7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -58,7 +58,6 @@ def render_forbidden! format.html { render 'pages/forbidden', status: :forbidden } format.all { render json: { error: 'Forbidden' }, status: :forbidden } end - throw(:abort) end def render_unauthorized! @@ -66,7 +65,6 @@ def render_unauthorized! format.html { render 'pages/unauthorized', status: :unauthorized } format.all { render json: { error: 'Unauthorized' }, status: :unauthorized } end - throw(:abort) end def require_hyacinth_admin! diff --git a/app/jobs/update_image_service_job.rb b/app/jobs/update_image_service_job.rb index 1318810eb..8e14f43a1 100644 --- a/app/jobs/update_image_service_job.rb +++ b/app/jobs/update_image_service_job.rb @@ -14,6 +14,9 @@ def perform(digital_object_pid) Rails.logger.error('Received Bad Request response from the image server: ' + JSON.parse(e.http_body)['errors'].inspect) rescue Errno::ECONNREFUSED # Silently fail because the image server is currently unavailable and there is nothing we can do. + rescue RestClient::InternalServerError => e + # Silently fail because the image server is currently unavailable and there is nothing we can do. + Rails.logger.error "Received 500 response from the image server when making a request for #{asset.pid}." end def payload_for_image_service_update_request(asset) diff --git a/app/models/dynamic_field.rb b/app/models/dynamic_field.rb index fc985f15f..a63b033b8 100644 --- a/app/models/dynamic_field.rb +++ b/app/models/dynamic_field.rb @@ -9,6 +9,7 @@ module Type SELECT = 'select' DATE = 'date' CONTROLLED_TERM = 'controlled_term' + VIEW_LIMITATION = 'view_limitation' end TYPES_TO_LABELS = { @@ -18,7 +19,8 @@ module Type DynamicField::Type::BOOLEAN => 'Boolean', DynamicField::Type::SELECT => 'Select', DynamicField::Type::DATE => 'Date', - DynamicField::Type::CONTROLLED_TERM => 'Controlled Term' + DynamicField::Type::CONTROLLED_TERM => 'Controlled Term', + DynamicField::Type::VIEW_LIMITATION => 'View Limitation' } belongs_to :parent_dynamic_field_group, class_name: 'DynamicFieldGroup' @@ -45,6 +47,12 @@ def as_json(_options = {}) if dynamic_field_type == self.class::Type::SELECT additional_data = self.additional_data hash_to_return[:select_options] = additional_data['select_options'].present? ? additional_data['select_options'] : {} + elsif dynamic_field_type == self.class::Type::VIEW_LIMITATION + hash_to_return[:view_limitation_options] = [ + {value: '', display_label: '- Default (none specified) -'}, + {value: 'full', display_label: 'Full Quality'}, + {value: 'reduced', display_label: 'Reduced Quality'} + ] elsif dynamic_field_type == self.class::Type::CONTROLLED_TERM hash_to_return[:controlled_vocabulary] = {} controlled_vocabulary = ControlledVocabulary.find_by(string_key: controlled_vocabulary_string_key) diff --git a/app/views/digital_objects/media_view.html.erb b/app/views/digital_objects/media_view.html.erb index 012c09af9..f8bc8c1a5 100644 --- a/app/views/digital_objects/media_view.html.erb +++ b/app/views/digital_objects/media_view.html.erb @@ -2,7 +2,7 @@