Skip to content

Commit

Permalink
Add view_limitation dynamic field type
Browse files Browse the repository at this point in the history
  • Loading branch information
elohanlon committed Feb 14, 2024
1 parent a413423 commit 681501b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ var fieldsetIds = associatedEnabledDynamicField ? associatedEnabledDynamicField[
case 'string':
%><input type="text" name="<%= dynamic_field['string_key'] %>" class="form-field-element <%= dynamic_field['dynamic_field_type'] %>_field form-control input-sm clearable tabable <%= mode == 'show' || fieldIsLocked ? 'hidden' : '' %>"/><%
break;
case 'view_limitation':
%>
<select name="<%= dynamic_field['string_key'] %>" class="form-field-element form-control input-sm clearable tabable <%= mode == 'show' || fieldIsLocked ? 'hidden' : '' %>">
<% for(var i = 0; i < dynamic_field['view_limitation_options'].length; i++) { %>
<option value="<%= dynamic_field['view_limitation_options'][i]['value'] %>"><%= dynamic_field['view_limitation_options'][i]['display_label'] %></option>
<% } %>
</select>
<%
break;
default:
%>Unknown field type: <%= dynamic_field['dynamic_field_type'] %><%
}
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ 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!
respond_to do |format|
format.html { render 'pages/unauthorized', status: :unauthorized }
format.all { render json: { error: 'Unauthorized' }, status: :unauthorized }
end
throw(:abort)
end

def require_hyacinth_admin!
Expand Down
3 changes: 3 additions & 0 deletions app/jobs/update_image_service_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion app/models/dynamic_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Type
SELECT = 'select'
DATE = 'date'
CONTROLLED_TERM = 'controlled_term'
VIEW_LIMITATION = 'view_limitation'
end

TYPES_TO_LABELS = {
Expand All @@ -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'
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/views/digital_objects/media_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<script>
$(document).ready(function(){
var tileSources = [Hyacinth.imageServerUrl + "/iiif/2/<%= @digital_object.pid %>/info.json"];
var tileSources = [Hyacinth.imageServerUrl + "/iiif/2/standard/<%= @digital_object.pid %>/info.json"];

var initialPage = 0;

Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/hyacinth/setup.rake
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace :hyacinth do
dfc_record_info = DynamicFieldGroupCategory.create!(display_label: 'Record Information')
dfc_other = DynamicFieldGroupCategory.create!(display_label: 'Other')
dfc_asset_data = DynamicFieldGroupCategory.create!(display_label: 'Asset Data')
dfc_published_access_control = DynamicFieldGroupCategory.create!(display_label: 'Published Access Control')

puts 'Creating default DynamicFieldGroups, DynamicFields and controlled vocabularies...'
# Create core DynamicFieldGroups and DynamicFields
Expand Down Expand Up @@ -179,6 +180,10 @@ namespace :hyacinth do
)
name_role.dynamic_fields.create!(string_key: 'name_role_term', display_label: 'Value', dynamic_field_type: DynamicField::Type::CONTROLLED_TERM, controlled_vocabulary_string_key: 'name_role')

#restriction_on_access -> authorization_limit -> view_authorization_limit_value
restriction_on_access = DynamicFieldGroup.create!(string_key: 'restriction_on_access', display_label: 'Restriction on Access', dynamic_field_group_category: dfc_published_access_control)
authorization_limit = DynamicFieldGroup.create!(parent_dynamic_field_group_id: restriction_on_access.id, string_key: 'authorization_limit', display_label: 'Authorization Limit')
authorization_limit.dynamic_fields.create!(string_key: 'view_authorization_limit_value', display_label: 'View Limitation', dynamic_field_type: DynamicField::Type::VIEW_LIMITATION, is_facet_field: true, is_single_field_searchable: true, standalone_field_label: 'View Limitation')
end

if DigitalObjectType.find_by(string_key: 'publish_target').nil?
Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/hyacinth/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ namespace :hyacinth do
test_project.enabled_dynamic_fields << EnabledDynamicField.new(dynamic_field: dynamic_field, digital_object_type: dot_item)
end

# Only enable authorization_limit fields for the asset type
DynamicFieldGroup.find_by(string_key: 'authorization_limit').dynamic_fields.each do |dynamic_field|
test_project.enabled_dynamic_fields << EnabledDynamicField.new(dynamic_field: dynamic_field, digital_object_type: dot_asset)
end

# Let's create a test fieldset too
fieldset1 = Fieldset.create!(display_label: 'Test Fieldset', project: test_project)

Expand Down

0 comments on commit 681501b

Please sign in to comment.