Skip to content

Commit

Permalink
File size information for 3d models too and related additions and cha…
Browse files Browse the repository at this point in the history
…nges.
  • Loading branch information
siiriylonen committed Jan 15, 2025
1 parent a14dd13 commit bc9c073
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
20 changes: 16 additions & 4 deletions module/Finna/src/Finna/RecordDriver/SolrLido.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,14 @@ 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;
Expand Down Expand Up @@ -829,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,
): array {
$type = $this->modelTypes[$type];
$format = strtolower($format);
Expand All @@ -849,6 +858,9 @@ protected function getModel(
'url' => $url,
'format' => $format,
'type' => $type,
'data' => $this->formatResourceMeasurements(
$measurements
),
];
}

Expand Down
7 changes: 7 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 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
5 changes: 4 additions & 1 deletion themes/finna2/scss/finna/record.scss
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ a.authority {
font-weight: 600;
text-transform: uppercase;
}
.dropdown-menu li .file-size {
font-size: $font-size-small;
}
}

.image-link {
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
],
]
) : $this->escapeHtmlAttr($model['url']);
if ($fileSize = $model['data']['size'] ?? '') {
$fileSize = !empty($fileSize['value']) && $fileSize['unit'] === 'byte' ? '(' . $this->fileSize(preg_replace('/[^0-9]/', '', $fileSize['value'])) . ')' : '';
}
?>
<a download href="<?=$url?>" rel="nofollow">
<?=$this->transEscWithPrefix('model_type_', $model['type'])?>
<span><?=$this->transEscWithPrefix('model_format_', $model['format'])?></span>
<span><?=$this->transEscWithPrefix('model_format_', $model['format'])?></span> <span class="file-size"><?=$fileSize?></span>
</a>
</li>
<?php endforeach; ?>
Expand All @@ -48,11 +51,14 @@
],
]
) : $this->escapeHtmlAttr($model['url']);
if ($fileSize = $model['data']['size'] ?? '') {
$fileSize = !empty($fileSize['value']) && $fileSize['unit'] === 'byte' ? '(' . $this->fileSize(preg_replace('/[^0-9]/', '', $fileSize['value'])) . ')' : '';
}
?>
<a download href="<?=$url?>" rel="nofollow">
<?=$this->icon('download') ?>
<span><?=$this->transEsc('Download the file')?></span>
</a>
</a> <span class="file-size"><?=$fileSize?></span>
</div>
<?php endif; ?>
</div>
Expand Down

0 comments on commit bc9c073

Please sign in to comment.