Skip to content

Commit

Permalink
Merge pull request #447 from cul/2.6.x-pcdm_types
Browse files Browse the repository at this point in the history
permit PCDM dc_type values for Assets if assigned (2.6.x)
  • Loading branch information
barmintor authored Jul 3, 2024
2 parents 78afc71 + 3604eb8 commit 6e424a1
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Hyacinth.DigitalObjectsApp.DigitalObject.Asset.prototype.getOriginalFilePath = f
};

Hyacinth.DigitalObjectsApp.DigitalObject.Asset.prototype.hasImage = function () {
return Hyacinth.imageServerUrl && this.getDcType() == 'StillImage';
return Hyacinth.imageServerUrl && this.isStillImage();
};

Hyacinth.DigitalObjectsApp.DigitalObject.Asset.prototype.isRestrictedSizeImage = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ Hyacinth.DigitalObjectsApp.DigitalObject.Base.prototype.getStateAsDisplayLabel =
return statesToDisplayLabels[this.getState()];
};

Hyacinth.DigitalObjectsApp.DigitalObject.Base.prototype.isAudioMovingImage = function () {
return ['Audio','MovingImage', 'Sound', 'Video'].includes(this.dc_type);
};

Hyacinth.DigitalObjectsApp.DigitalObject.Base.prototype.isStillImage = function () {
return ['Image','StillImage'].includes(this.dc_type);
};

Hyacinth.DigitalObjectsApp.DigitalObject.Base.prototype.isNewRecord = function () {
return (this.getPid() == null);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Hyacinth.DigitalObjectsApp.DigitalObjectSearchResult.prototype.getDcType = funct
return this.dcType;
};

Hyacinth.DigitalObjectsApp.DigitalObjectSearchResult.prototype.isAudioMovingImage = function(){
return ['Audio','MovingImage', 'Sound', 'Video'].includes(this.dcType);
};

Hyacinth.DigitalObjectsApp.DigitalObjectSearchResult.prototype.isStillImage = function(){
return ['Image', 'StillImage'].includes(this.dcType);
};

Hyacinth.DigitalObjectsApp.DigitalObjectSearchResult.prototype.getPid = function(){
return this.pid;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Hyacinth.DigitalObjectsApp.DigitalObjectAnnotationEditor.prototype.init = functi
this.$containerElement.addClass(Hyacinth.DigitalObjectsApp.DigitalObjectAnnotationEditor.ANNOTATION_EDITOR_ELEMENT_CLASS); //Add class to container element
this.$containerElement.data(Hyacinth.DigitalObjectsApp.DigitalObjectAnnotationEditor.ANNOTATION_EDITOR_DATA_KEY, this); //Assign this editor object as data to the container element so that we can access it later

if(['MovingImage', 'Sound'].indexOf(this.digitalObject.getDcType()) > -1) {
if(this.digitalObject.isAudioMovingImage()) {
this.$containerElement.html(
Hyacinth.DigitalObjectsApp.renderTemplate('digital_objects_app/widgets/digital_object_annotation_editor/oh_synchronizer_index_mode.ejs', {
digitalObject: this.digitalObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Hyacinth.DigitalObjectsApp.DigitalObjectSynchronizedTranscriptEditor.prototype.i
this.$containerElement.addClass(Hyacinth.DigitalObjectsApp.DigitalObjectSynchronizedTranscriptEditor.SYNCHRONIZED_TRANSCRIPT_EDITOR_ELEMENT_CLASS); //Add class to container element
this.$containerElement.data(Hyacinth.DigitalObjectsApp.DigitalObjectSynchronizedTranscriptEditor.SYNCHRONIZED_TRANSCRIPT_EDITOR_DATA_KEY, this); //Assign this editor object as data to the container element so that we can access it later

if (['MovingImage', 'Sound'].indexOf(this.digitalObject.getDcType()) > -1) {
if(this.digitalObject.isAudioMovingImage()) {
this.$containerElement.html(
Hyacinth.DigitalObjectsApp.renderTemplate('digital_objects_app/widgets/digital_object_synchronized_transcript_editor/oh_synchronizer_transcript_mode.ejs', {
digitalObject: this.digitalObject,
Expand Down
29 changes: 14 additions & 15 deletions app/assets/templates/digital_objects_app/digital_objects/show.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ if (digitalObject.digital_object_type.string_key == 'asset') {
Hyacinth.DigitalObjectsApp.paramsToHashValue({controller: 'digital_objects',
action: 'manage_transcript',
pid: Hyacinth.DigitalObjectsApp.params['pid']})});
}
if (digitalObject.digital_object_type.string_key == 'asset' && (digitalObject.getDcType() == 'MovingImage' || digitalObject.getDcType() == 'Sound')) {
navItems.push({label: '<span class="glyphicon glyphicon-edit"></span> Annotation', url: '#' +
Hyacinth.DigitalObjectsApp.paramsToHashValue({controller: 'digital_objects',
action: 'manage_annotation',
pid: Hyacinth.DigitalObjectsApp.params['pid']})});
if (digitalObject.isAudioMovingImage()) {
navItems.push({label: '<span class="glyphicon glyphicon-edit"></span> Annotation', url: '#' +
Hyacinth.DigitalObjectsApp.paramsToHashValue({controller: 'digital_objects',
action: 'manage_annotation',
pid: Hyacinth.DigitalObjectsApp.params['pid']})});
navItems.push({label: '<span class="glyphicon glyphicon-edit"></span> Synchronized Transcript', url: '#' +
Hyacinth.DigitalObjectsApp.paramsToHashValue({controller: 'digital_objects',
action: 'manage_synchronized_transcript',
pid: Hyacinth.DigitalObjectsApp.params['pid']})});
navItems.push({label: '<span class="glyphicon glyphicon-edit"></span> Captions', url: '#' +
Hyacinth.DigitalObjectsApp.paramsToHashValue({controller: 'digital_objects',
action: 'manage_captions',
pid: Hyacinth.DigitalObjectsApp.params['pid']})});
navItems.push({label: '<span class="glyphicon glyphicon-edit"></span> Synchronized Transcript', url: '#' +
Hyacinth.DigitalObjectsApp.paramsToHashValue({controller: 'digital_objects',
action: 'manage_synchronized_transcript',
pid: Hyacinth.DigitalObjectsApp.params['pid']})});
navItems.push({label: '<span class="glyphicon glyphicon-edit"></span> Captions', url: '#' +
Hyacinth.DigitalObjectsApp.paramsToHashValue({controller: 'digital_objects',
action: 'manage_captions',
pid: Hyacinth.DigitalObjectsApp.params['pid']})});
}
}
if (hasUpdatePermission) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
<h4 class="preview-heading">Asset</h4>
<img class="img-responsive thumbnail" src="<%= Hyacinth.DigitalObjectsApp.DigitalObject.Base.getImageUrl(digitalObject.getPid(), 'scaled', 256) %>" title="<%= digitalObject.getPid() %>" />
<div class="caption">
<% if (digitalObject.getDcType() == 'StillImage') { %>
<% if (digitalObject.isStillImage()) { %>
<a href="#" class="btn btn-block btn-primary btn-xs" onclick="Hyacinth.DigitalObjectsApp.DigitalObject.Base.showMediaViewModal('<%= digitalObject.getPid() %>'); return false;">View Zoomable Image</a>
<% if (mode == 'show') { %>
<br />
Expand All @@ -314,7 +314,7 @@
</ul>
</div>
<% } %>
<% } else if (['Sound','MovingImage'].includes(digitalObject.getDcType())) { %>
<% } else if (digitalObject.isAudioMovingImage()) { %>
<a href="#" class="btn btn-block btn-primary btn-xs" onclick="Hyacinth.DigitalObjectsApp.DigitalObject.Base.showMediaViewModal('<%= digitalObject.getPid() %>'); return false;">View Media</a>
<% } %>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/assignments/changesets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def update
end
when 'annotate_object'
if index_document_params[:index_document_text]
if ['MovingImage', 'Sound'].include?(digital_object.dc_type)
if digital_object.audio_moving_image?
create_or_update_annotate_changeset(@assignment, digital_object, index_document_params[:index_document_text])
@assignment.save
else
Expand All @@ -45,7 +45,7 @@ def update
end
when 'synchronize'
if synchronized_transcript_params[:synchronized_transcript_text]
if ['MovingImage', 'Sound'].include?(digital_object.dc_type)
if digital_object.audio_moving_image?
create_or_update_synchronize_changeset(@assignment, digital_object, synchronized_transcript_params[:synchronized_transcript_text])
@assignment.save
else
Expand Down Expand Up @@ -86,7 +86,7 @@ def create_or_update_transcribe_changeset(assignment, digital_object, new_conten
end

def create_or_update_annotate_changeset(assignment, digital_object, new_content)
if ['MovingImage', 'Sound'].include?(digital_object.dc_type)
if digital_object.audio_moving_image?
assignment.original = digital_object.index_document if assignment.original.nil?
else
raise 'Not implemented yet'
Expand All @@ -95,7 +95,7 @@ def create_or_update_annotate_changeset(assignment, digital_object, new_content)
end

def create_or_update_synchronize_changeset(assignment, digital_object, new_content)
if ['MovingImage', 'Sound'].include?(digital_object.dc_type)
if digital_object.audio_moving_image?
assignment.original = digital_object.synchronized_transcript if assignment.original.nil?
else
raise 'Not implemented yet'
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create
@assignment.proposed = @assignment.original
when 'annotate_object'
# store current state of transcript in *original* field
if ['MovingImage', 'Sound'].include?(@digital_object.dc_type)
if @digital_object.audio_moving_image?
@assignment.original = @digital_object.index_document
else
raise 'Not implemented yet'
Expand All @@ -43,7 +43,7 @@ def create
@assignment.proposed = @assignment.original
when 'synchronize'
# store current state of transcript in *original* field
if ['MovingImage', 'Sound'].include?(@digital_object.dc_type)
if @digital_object.audio_moving_image?
@assignment.original = @digital_object.synchronized_transcript
else
raise 'Not implemented yet'
Expand Down Expand Up @@ -124,13 +124,13 @@ def commit
digital_object.transcript = @assignment.proposed
when 'annotate_object'
# TODO: Probably change index_document to annotation
if ['MovingImage', 'Sound'].include?(digital_object.dc_type)
if digital_object.audio_moving_image?
digital_object.index_document = @assignment.proposed
else
raise 'Not implemented yet'
end
when 'synchronize'
if ['MovingImage', 'Sound'].include?(digital_object.dc_type)
if digital_object.audio_moving_image?
digital_object.synchronized_transcript = @assignment.proposed
else
raise "Cannot commit synchronized transcript for non-audiovisual resource (pid: #{digital_object.pid}, dc_type: #{digital_object.dc_type})"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/digital_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def saveable?(errors = nil)
end

def rotate_image
unless @digital_object.is_a?(DigitalObject::Asset) && @digital_object.dc_type == 'StillImage'
unless @digital_object.is_a?(DigitalObject::Asset) && @digital_object.still_image?
render json: { errors: ["Only Assets of type StillImage can be rotated. This is a #{@digital_object.digital_object_type.display_label} of type #{@digital_object.dc_type}"] }
return
end
Expand Down
16 changes: 14 additions & 2 deletions app/models/digital_object/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class DigitalObject::Asset < DigitalObject::Base
include DigitalObject::Assets::Captions
include Hyacinth::Utils::StringUtils

UNKNOWN_DC_TYPE = 'Unknown'
VALID_DC_TYPES = [UNKNOWN_DC_TYPE, 'Dataset', 'MovingImage', 'Software', 'Sound', 'StillImage', 'Text']
UNKNOWN_DC_TYPE = BestType::PcdmTypeLookup::UNKNOWN
ASSET_DC_TYPES = ['Dataset', 'MovingImage', 'Software', 'Sound', 'StillImage', 'Text']
VALID_DC_TYPES = (BestType::PcdmTypeLookup::VALID_TYPES + ASSET_DC_TYPES).uniq
AMI_DC_TYPES = ['Audio', 'MovingImage', 'Sound', 'Video']
IMAGE_DC_TYPES = ['Image', 'StillImage']

DIGITAL_OBJECT_TYPE_STRING_KEY = 'asset'

DEFAULT_ASSET_NAME = 'Asset' # For when a title is not supplied and we're not doing with a filesystem upload
Expand Down Expand Up @@ -405,6 +409,14 @@ def write_update_synchronized_transcript_file_if_changed!
end
end

def audio_moving_image?
AMI_DC_TYPES.include?(self.dc_type || BestType.dc_type.for_file_name(self.original_filename))
end

def still_image?
IMAGE_DC_TYPES.include?(self.dc_type || BestType.dc_type.for_file_name(self.original_filename))
end

def player_mime_type
if HYACINTH.fetch(:media_streaming, {})['wowza'].present?
'application/x-mpegURL'
Expand Down
8 changes: 8 additions & 0 deletions app/models/digital_object/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ def self.valid_dc_types
self::VALID_DC_TYPES
end

def audio_moving_image?
false
end

def still_image?
false
end

def allowed_publish_targets
DigitalObject::PublishTarget.basic_publish_target_data_from_solr(project.enabled_publish_target_pids)
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/digital_objects/media_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if @digital_object.dc_type == 'StillImage' %>
<% if @digital_object.still_image? %>

<script>
$(document).ready(function(){
Expand Down Expand Up @@ -154,7 +154,7 @@
</span>
</div>
</div>
<% elsif ['Sound','MovingImage'].include? @digital_object.dc_type %>
<% elsif @digital_object.audio_moving_image? %>
<% media_url = @digital_object.player_url(request.remote_ip) %>
<% media_mime_type = @digital_object.player_mime_type %>
<div id="media-content" style="width: 800px; height: 600px;">
Expand Down
42 changes: 42 additions & 0 deletions spec/models/digital_object/asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,46 @@
expect(asset.perform_derivative_processing).to eq(false)
end
end
describe 'audio_moving_image?' do
let(:asset) { DigitalObject::Asset.new }
it "is true when appropriate dc_type value from DC" do
asset.instance_variable_set(:@dc_type, 'MovingImage')
expect(asset.audio_moving_image?).to be true
asset.instance_variable_set(:@dc_type, 'Sound')
expect(asset.audio_moving_image?).to be true
end
it "is false when inappropriate dc_type value from DC" do
asset.instance_variable_set(:@dc_type, 'Dataset')
expect(asset.audio_moving_image?).to be false
end
it "is true when appropriate dc_type value from PCDM" do
asset.instance_variable_set(:@dc_type, 'Audio')
expect(asset.audio_moving_image?).to be true
asset.instance_variable_set(:@dc_type, 'Video')
expect(asset.audio_moving_image?).to be true
end
it "is false when inappropriate dc_type value from PCDM" do
asset.instance_variable_set(:@dc_type, 'Spreadsheet')
expect(asset.audio_moving_image?).to be false
end
end
describe 'still_image?' do
let(:asset) { DigitalObject::Asset.new }
it "is true when appropriate dc_type value from DC" do
asset.instance_variable_set(:@dc_type, 'StillImage')
expect(asset.still_image?).to be true
end
it "is false when inappropriate dc_type value from DC" do
asset.instance_variable_set(:@dc_type, 'MovingImage')
expect(asset.still_image?).to be false
end
it "is true when appropriate dc_type value from PCDM" do
asset.instance_variable_set(:@dc_type, 'Image')
expect(asset.still_image?).to be true
end
it "is false when inappropriate dc_type value from PCDM" do
asset.instance_variable_set(:@dc_type, 'Video')
expect(asset.still_image?).to be false
end
end
end

0 comments on commit 6e424a1

Please sign in to comment.