Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FINNA-2579] & [FINNA-2875] Add file size to LIDO resource and fix resource play buttons for sr #3118

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions local/languages/finna/en-gb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ place_id_type_mjr = "Ancient Relics Register"
place_id_type_rpr = "Built Heritage Register"
Place of Origin = "Place of Origin"
Place of Storage = "Place of storage"
Play recording = "Play recording"
Playing Time = "Playing Time"
Polytechnic Libraries = "University of applied sciences libraries"
Post Comment = "to post a comment."
Expand Down
1 change: 1 addition & 0 deletions local/languages/finna/fi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ place_id_type_mjr = "muinaisjäännösrekisteri"
place_id_type_rpr = "rakennusperintörekisteri"
Place of Origin = "Luontipaikka"
Place of Storage = "Säilytyspaikka"
Play recording = "Toista äänite"
Playing Time = "Kesto"
Polytechnic Libraries = "AMK-kirjastot"
Post Comment = "lisätäksesi kommentin."
Expand Down
1 change: 1 addition & 0 deletions local/languages/finna/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ place_type_id_mjr = "fornminnesregistret"
place_type_id_rpr = "byggnadsminnesregistret"
Place of Origin = "Tillkomstort"
Place of Storage = "Bevarandeplats"
Play recording = "Spela upp inspelning"
Playing Time = "Speltid"
Polytechnic Libraries = "Yrkeshögskolornas bibliotek"
Post Comment = "att posta kommentar."
Expand Down
71 changes: 55 additions & 16 deletions module/Finna/src/Finna/RecordDriver/SolrLido.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function getAllImages($language = null)
*
* @return array
*/
protected function formatImageMeasurements(
protected function formatResourceMeasurements(
\SimpleXmlElement $measurements
): array {
$results = [];
Expand Down Expand Up @@ -639,14 +639,28 @@ protected function getRepresentations(string $language): array

// Representation is a 3d model
if (in_array($type, $modelTypeKeys)) {
if ($model = $this->getModel($url, $format, $type)) {
if (
$model = $this->getModel(
$url,
$format,
$type,
$representation->resourceMeasurementsSet
)
) {
$modelUrls[] = $model;
}
continue;
}
// Representation is an audio
if (in_array($type, $audioTypeKeys)) {
if ($audio = $this->getAudio($url, $format, $description)) {
if (
$audio = $this->getAudio(
$url,
$format,
$description,
$representation->resourceMeasurementsSet
)
) {
$audioUrls = array_merge($audioUrls, $audio);
if ($extraDetails = $this->getExtraDetails($resourceSet, $language)) {
$audioUrls = array_merge($audioUrls, $extraDetails);
Expand All @@ -656,7 +670,14 @@ protected function getRepresentations(string $language): array
}
// Representation is a video
if (in_array($type, $videoTypeKeys)) {
if ($video = $this->getVideo($url, $format, $description)) {
if (
$video = $this->getVideo(
$url,
$format,
$description,
$representation->resourceMeasurementsSet
)
) {
$videoUrls = array_merge($videoUrls, $video);
if ($extraDetails = $this->getExtraDetails($resourceSet, $language)) {
$videoUrls = array_merge($videoUrls, $extraDetails);
Expand Down Expand Up @@ -815,16 +836,18 @@ protected function getExtraDetails(
* - type Model type preview_3d or provided_3d as key
* url to model as value
*
* @param string $url Model url
* @param string $format Model format
* @param string $type Model type
* @param string $url Model url
* @param string $format Model format
* @param string $type Model type
* @param \SimpleXmlElement $measurements Measurements SimpleXmlElement
*
* @return array
*/
protected function getModel(
string $url,
string $format,
string $type,
\SimpleXmlElement $measurements = null,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tämän tyypin pitäisi olla ?\SimpleXmlElement

): array {
$type = $this->modelTypes[$type];
$format = strtolower($format);
Expand All @@ -835,6 +858,9 @@ protected function getModel(
'url' => $url,
'format' => $format,
'type' => $type,
'data' => $this->formatResourceMeasurements(
$measurements
),
];
}

Expand Down Expand Up @@ -882,7 +908,7 @@ protected function getImage(
$highResolution = [];
if (in_array($size, ['master', 'original'])) {
$currentHiRes = [
'data' => $this->formatImageMeasurements(
'data' => $this->formatResourceMeasurements(
$measurements
),
'url' => $url,
Expand All @@ -905,16 +931,18 @@ protected function getImage(
* - type Type what type is the audio file
* - embed Type of embed is audio
*
* @param string $url Url of the audio
* @param string $format Format of the audio
* @param string $description Description of the audio
* @param string $url Url of the audio
* @param string $format Format of the audio
* @param string $description Description of the audio
* @param \SimpleXmlElement $measurements Measurements SimpleXmlElement
*
* @return array
*/
protected function getAudio(
string $url,
string $format,
string $description
string $description,
\SimpleXmlElement $measurements = null

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tämän tyypin pitäisi olla ?\SimpleXmlElement

): array {
if ($codec = $this->supportedAudioFormats[$format] ?? false) {
return [
Expand All @@ -923,6 +951,9 @@ protected function getAudio(
'codec' => $format,
'type' => 'audio',
'embed' => 'audio',
'data' => $this->formatResourceMeasurements(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ei voi kutsua formatResourceMeasurements-metodia varmistamatta, ettei $measurements ole null.

$measurements
),
];
}
return [];
Expand All @@ -937,16 +968,18 @@ protected function getAudio(
* - src Different sources for the video
* - type Codec type
*
* @param string $url Url of the video
* @param string $format Format of the video
* @param string $description Description of the video
* @param string $url Url of the video
* @param string $format Format of the video
* @param string $description Description of the video
* @param \SimpleXmlElement $measurements Measurements SimpleXmlElement
*
* @return array
*/
protected function getVideo(
string $url,
string $format,
string $description
string $description,
\SimpleXmlElement $measurements = null
): array {
$mediaType = $this->supportedVideoFormats[$format] ?? false;
return match ($mediaType) {
Expand All @@ -955,6 +988,9 @@ protected function getVideo(
'url' => $url,
'embed' => 'iframe',
'format' => $format,
'data' => $this->formatResourceMeasurements(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ei voi kutsua formatResourceMeasurements-metodia varmistamatta, ettei $measurements ole null.

$measurements
),
],
false => [],
default => [
Expand All @@ -966,6 +1002,9 @@ protected function getVideo(
'src' => $url,
'type' => $mediaType,
],
'data' => $this->formatResourceMeasurements(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ei voi kutsua formatResourceMeasurements-metodia varmistamatta, ettei $measurements ole null.

$measurements
),
],
};
}
Expand Down
16 changes: 16 additions & 0 deletions module/Finna/tests/fixtures/lido/lido_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@
<resourceSet>
<resourceRepresentation type="preview_3D">
<linkResource formatResource="glTF">https://gltfmalli.gltf</linkResource>
<resourceMeasurementsSet>
<measurementType lang="fi">koko</measurementType>
<measurementType lang="en">size</measurementType>
<measurementUnit lang="fi">tavua</measurementUnit>
<measurementUnit lang="en">bytes</measurementUnit>
<measurementValue>60840000</measurementValue>
</resourceMeasurementsSet>
</resourceRepresentation>
<resourceRepresentation type="preview_3D">
<linkResource formatResource="glb">https://glbmalli.glb</linkResource>
Expand All @@ -383,6 +390,15 @@
<resourceDescription type="displayLink">VideoTesti.mp4</resourceDescription>
<resourceRepresentation type="preview_video">
<linkResource formatResource="mp4">https://linkkivideoon.fi</linkResource>
<resourceMeasurementsSet>
<measurementType lang="fi">koko</measurementType>
<measurementType lang="en">size</measurementType>
<measurementType lang="sv">storlek</measurementType>
<measurementUnit lang="fi">tavua</measurementUnit>
<measurementUnit lang="en">byte</measurementUnit>
<measurementUnit lang="sv">byte</measurementUnit>
<measurementValue>74576596</measurementValue>
</resourceMeasurementsSet>
</resourceRepresentation>
</resourceSet>
<resourceSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,18 @@ public static function getRepresentationsData(): array
'url' => 'https://gltfmalli.gltf',
'format' => 'gltf',
'type' => 'preview',
'data' => [
'size' => [
'unit' => 'byte',
'value' => '60840000',
],
],
],
[
'url' => 'https://glbmalli.glb',
'format' => 'glb',
'type' => 'preview',
'data' => [],
],
],
'rights' => [
Expand Down Expand Up @@ -202,6 +209,7 @@ public static function getRepresentationsData(): array
'type' => 'audio',
'embed' => 'audio',
'resourceName' => 'AudioTesti.mp3',
'data' => [],
],
[
'desc' => 'VideoTesti.mp4',
Expand All @@ -213,6 +221,12 @@ public static function getRepresentationsData(): array
'type' => 'video/mp4',
],
'resourceName' => 'VideoTesti.mp4',
'data' => [
'size' => [
'unit' => 'byte',
'value' => '74576596',
],
],
],
],
],
Expand Down
13 changes: 13 additions & 0 deletions themes/finna2/js/finna-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,22 @@ finna.layout = (function finnaLayout() {
function onVideoJsInited() {}
);
play.remove();
self.find('.vjs-play-control').focus();
}
);
});
play.on('keydown', function onKeyDown(e) {
if (e.which === 13 || e.which === 32) {
e.preventDefault();
play.trigger('click');
}
});
});
$('finna-video').on('keydown', function onKeyDown(e) {
if (e.which === 13 || e.which === 32) {
e.preventDefault();
$(this).trigger('click');
}
});
}

Expand Down
9 changes: 9 additions & 0 deletions themes/finna2/scss/finna/audio-player.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
.open-link:not(.download-audio) {
font-size: $font-size-small;
}
.open-link a:focus-visible {
outline: 2px solid $action-link-color;
}
}

.audio-accordion {
Expand Down Expand Up @@ -61,6 +64,9 @@
.play {
font-size: 35px;
color: $action-link-color;
&:focus-visible {
outline: 2px solid $action-link-color;
}
}
}

Expand Down Expand Up @@ -119,6 +125,9 @@
height: 3em;
position: absolute;
}
> button:focus-visible {
outline: 2px solid $action-link-color;
}
}

.vjs-play-control {
Expand Down
12 changes: 6 additions & 6 deletions themes/finna2/scss/finna/record.scss
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,13 @@ a.authority {
font-size: 1em;
font-weight: 600;
text-transform: uppercase;
.file-size {
color: $gray-mid-light;
}
}
}

.image-link {
.image-link, .model-link {
display: flex;
align-items: center;
font-size: 1em;
Expand All @@ -230,7 +233,7 @@ a.authority {
.dropdown {
position: initial;
}
.image-dimensions, .image-size {
.image-dimensions, .image-size, .dropdown-menu .file-size {
font-size: 0.8em;
text-transform: initial;
}
Expand Down Expand Up @@ -498,7 +501,7 @@ a.authority {
}
}

.open-link, .save-record-link, .record-link {
.open-link, .save-record-link, .record-link, .model-link .download-link {
text-align: left;
margin-top: 5px;
color: $action-link-color;
Expand All @@ -516,9 +519,6 @@ a.authority {
color: $gray-mid-light;
font-size: .8em;
}
> span.file-size {
color: $gray-slightly-lighter;
}
}

.record .recordcover-holder {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<!-- START of: finna - RecordDriver/DefaultRecord/audio-information.phtml -->
<?php
if ($fileSize = $url['data']['size'] ?? '') {
$fileSize = !empty($fileSize['value']) && $fileSize['unit'] === 'byte' ? '(' . $this->fileSize(preg_replace('/[^0-9]/', '', $fileSize['value'])) . ')' : '';
}
?>
<div class="open-link download-audio">
<a href="<?=$url['url'] ?>" target="_blank" rel="nofollow" download>
<?=$this->icon('download') ?> <?=$this->transEsc('Download recording') ?>
</a>
</a> <span class="file-size"><?=$fileSize?></span>
</div>
<?php if (!empty($url['identifier'])): ?>
<div class="audio-details-container text-left" data-img-index="<?=$ind?>">
Expand Down
Loading
Loading