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

[IMPROVEMENT] Improvements 3d viewer implementation #1283

Merged
merged 49 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
cb04a34
Initial commit of embedded 3d viewer implementation
markusweigelt May 31, 2024
18fe909
Merge branch 'kitodo:master' into 3d-viewer-integration
markusweigelt May 31, 2024
2ec8fee
Fix unnecessary change
markusweigelt May 31, 2024
cc6188e
Fix loading of METS/MODS
markusweigelt Jun 5, 2024
151ae7d
Improve embedded 3d viewer
markusweigelt Jun 5, 2024
7df1935
Remove unused files and add logging to embedded 3d viewer
markusweigelt Jun 7, 2024
22c1f1b
Add error handling
markusweigelt Jun 7, 2024
beeacbd
Merge branch 'kitodo:master' into 3d-viewer-integration
markusweigelt Jun 10, 2024
d2754fe
Adjust documentation and improve implemenation
markusweigelt Jun 11, 2024
34047a3
Minor changes
markusweigelt Jun 11, 2024
2a58f0b
Add extension viewer configuration and select viewer by model format
markusweigelt Jun 11, 2024
851772f
Update documentation
markusweigelt Jun 11, 2024
51a67e9
Remove converted model cause currently no example exist
markusweigelt Jun 12, 2024
c265eb3
Controller improvements and error handling of embedded 3d viewer
markusweigelt Jun 12, 2024
2612969
Update documentation
markusweigelt Jun 12, 2024
e6fb3f9
Improve documentation
markusweigelt Jun 12, 2024
1ed92fc
Codacy fixes
markusweigelt Jun 12, 2024
56b2155
Codacy fixes
markusweigelt Jun 12, 2024
3d3dcaf
Merge branch 'master' into 3d-viewer-integration
markusweigelt Jun 26, 2024
76779d9
Update Embedded3DViewer.php
markusweigelt Jun 26, 2024
15fe6bf
Merge branch 'kitodo:master' into 3d-viewer-integration
markusweigelt Jul 16, 2024
7f16533
Add model-viewer as default viewer
markusweigelt Jul 16, 2024
37a0186
Merge branch 'kitodo:master' into 3d-viewer-integration
markusweigelt Jul 16, 2024
0ccdd99
Mode default viewer implementation to separate method and fix phpstan…
markusweigelt Jul 16, 2024
8c6b662
Fixes of Codacy errors
markusweigelt Jul 16, 2024
bc31f94
Fix Codacy issues and improve wording of Html title
markusweigelt Jul 16, 2024
63b149a
Adjust parameter type in comment
markusweigelt Jul 16, 2024
b45d8c6
Adjust parameter type in comment
markusweigelt Jul 16, 2024
ceae089
Improve wording in extension config documentation
markusweigelt Jul 16, 2024
6cdd9ed
Update documentation
markusweigelt Jul 16, 2024
46608c7
Replace tags with HTML entities
markusweigelt Jul 16, 2024
6e222fb
Renaming to embedded 3d viewer, adjust documentation, change behaviou…
markusweigelt Jul 22, 2024
e40a87e
Resolve conflicts
markusweigelt Jul 22, 2024
c02fe13
Improve renaming to embedded 3d viewer
markusweigelt Jul 22, 2024
0bf7233
Fix merging problems
markusweigelt Jul 22, 2024
f5b4305
Improvements regarding renaming to embedded 3d viewer
markusweigelt Jul 22, 2024
2622268
Fix detection of 3d object
markusweigelt Jul 22, 2024
3ad394e
Implementation for adding embedded 3d viewer as component
markusweigelt Jul 22, 2024
2814c42
Fix codacy
markusweigelt Jul 22, 2024
0a6bceb
Fix documentation
markusweigelt Jul 22, 2024
c605ffd
Merge branch 'master' into 3d-viewer-integration
sebastian-meyer Jul 23, 2024
7b4eabf
Changes regarding code review
markusweigelt Jul 24, 2024
849f474
Reduce complexity
markusweigelt Jul 24, 2024
08f59b0
Add visiblity and types to method
markusweigelt Jul 24, 2024
dbddee9
Apply suggestions from code review
markusweigelt Jul 26, 2024
b07e635
Update Classes/ExpressionLanguage/DocumentTypeFunctionProvider.php
markusweigelt Jul 26, 2024
c0b6e33
remove object constant
markusweigelt Jul 26, 2024
376db7d
Bugfix of using correct type in function
markusweigelt Jul 26, 2024
c2e4fe9
Merge branch 'master' into 3d-viewer-integration
sebastian-meyer Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,13 @@ private function getDocumentByUid(int $documentId)
/**
* Get document by URL.
*
* @access private
* @access protected
*
* @param string $documentId The document's URL
*
* @return AbstractDocument
*/
private function getDocumentByUrl(string $documentId)
protected function getDocumentByUrl(string $documentId)
markusweigelt marked this conversation as resolved.
Show resolved Hide resolved
{
$doc = AbstractDocument::getInstance($documentId, $this->settings, true);

Expand Down
97 changes: 97 additions & 0 deletions Classes/Controller/Embedded3dViewerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* (c) Kitodo. Key to digital objects e.V. <[email protected]>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Controller;

use Kitodo\Dlf\Common\AbstractDocument;

/**
* Plugin 'Embedded3dViewer' for the 'dlf' extension
*
* @package TYPO3
* @subpackage dlf
*
* @access public
*/
class Embedded3dViewerController extends AbstractController
{

const MIDDLEWARE_DLF_EMBEDDED_3D_VIEWER_PREFIX = '/?middleware=dlf/embedded3dviewer';

/**
* @access public
*
* @return void
*/
public function mainAction(): void
{
if (!empty($this->requestData['model']) || !empty($this->settings['model'])) {
$this->view->assign('embedded3dViewerUrl', $this->buildEmbedded3dViewerUrl());
return;
}

if (!empty($this->settings['document'])) {
$this->assignModelFromDocument($this->getDocumentByUrl($this->settings['document']));
} else {
$this->loadDocument();
if (!$this->isDocMissingOrEmpty()) {
$this->assignModelFromDocument($this->document->getCurrentDocument());
}
}

}

/**
* Builds the embedded 3D viewer url.
*
* @param string $model The model url
* @return string The embedded 3D viewer url
*/
public function buildEmbedded3dViewerUrl(string $model = ""): string
markusweigelt marked this conversation as resolved.
Show resolved Hide resolved
{
$viewer = "";
$embedded3dViewerUrl = self::MIDDLEWARE_DLF_EMBEDDED_3D_VIEWER_PREFIX;

if (!empty($this->requestData['model'])) {
$model = $this->requestData['model'];
} elseif (!empty($this->settings['model'])) {
$model = $this->settings['model'];
}

if (!empty($model)) {
$embedded3dViewerUrl .= '&model=' . $model;
}

if (!empty($this->requestData['viewer'])) {
$viewer = $this->requestData['viewer'];
} elseif (!empty($this->settings['viewer'])) {
$viewer = $this->settings['viewer'];
}

if (!empty($viewer)) {
$embedded3dViewerUrl .= '&viewer=' . $viewer;
}
return $embedded3dViewerUrl;
}

/**
* Assign the model from document to view.
*
* @param AbstractDocument $document The document containing the model
*/
public function assignModelFromDocument(AbstractDocument $document): void
{
if ($document->getToplevelMetadata()['type'][0] == 'object') {
markusweigelt marked this conversation as resolved.
Show resolved Hide resolved
$model = trim($document->getFileLocation($document->physicalStructureInfo[$document->physicalStructure[1]]['files']['DEFAULT']));
sebastian-meyer marked this conversation as resolved.
Show resolved Hide resolved
$this->view->assign('embedded3dViewerUrl', $this->buildEmbedded3dViewerUrl($model));
}
}
}
79 changes: 0 additions & 79 deletions Classes/Controller/View3DController.php

This file was deleted.

35 changes: 27 additions & 8 deletions Classes/ExpressionLanguage/DocumentTypeFunctionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;

const TYPE_OBJECT = "object";

markusweigelt marked this conversation as resolved.
Show resolved Hide resolved
/**
* Provider class for additional "getDocumentType" function to the ExpressionLanguage.
*
Expand Down Expand Up @@ -132,25 +134,26 @@ function($arguments, $cPid)
return $type;
}

// 3d object type if model parameter is not empty
if (!empty($queryParams['tx_dlf']['model'])) {
return TYPE_OBJECT;
}

// Load document with current plugin parameters.
$this->loadDocument($queryParams['tx_dlf'], $cPid);
if (!isset($this->document) || $this->document->getCurrentDocument() === null) {
return $type;
}

// Set PID for metadata definitions.
$this->document->getCurrentDocument()->cPid = $cPid;

$metadata = $this->document->getCurrentDocument()->getToplevelMetadata($cPid);
if (!empty($metadata['type'][0])) {
// Calendar plugin does not support IIIF (yet). Abort for all newspaper related types.
if (
$this->document->getCurrentDocument() instanceof IiifManifest
&& array_search($metadata['type'][0], ['newspaper', 'ephemera', 'year', 'issue']) !== false
) {
return $type;
}
if (!empty($metadata['type'][0])
&& (!$this->isIiifManifestWithNewspaperRelatedType($metadata['type'][0]) || $metadata['type'][0] == TYPE_OBJECT)) {
markusweigelt marked this conversation as resolved.
Show resolved Hide resolved
$type = $metadata['type'][0];
}

return $type;
});
}
Expand Down Expand Up @@ -211,4 +214,20 @@ protected function loadDocument(array $requestData, int $pid): void
$this->logger->error('Empty UID or invalid PID "' . $pid . '" for document loading');
}
}

/**
* Check if is IIIF Manifest with newspaper related type.
*
* Calendar plugin does not support IIIF (yet). Abort for all newspaper related types.
*
* @access private
*
* @param array $metadata The metadata
* @return bool
*/
private function isIiifManifestWithNewspaperRelatedType(array $metadata): bool
{
return ($this->document->getCurrentDocument() instanceof IiifManifest
&& in_array($metadata, ['newspaper', 'ephemera', 'year', 'issue']));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @subpackage dlf
* @access public
*/
class Embedded3DViewer implements MiddlewareInterface
class Embedded3dViewer implements MiddlewareInterface
{
use LoggerAwareTrait;

Expand All @@ -58,7 +58,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
// parameters are sent by POST --> use getParsedBody() instead of getQueryParams()
$parameters = $request->getQueryParams();
// Return if not this middleware
if (!isset($parameters['middleware']) || ($parameters['middleware'] != 'dlf/embedded3DViewer')) {
if (!isset($parameters['middleware']) || ($parameters['middleware'] != 'dlf/embedded3dviewer')) {
return $response;
}

Expand Down Expand Up @@ -202,8 +202,8 @@ public function renderDefaultViewer($model): HtmlResponse
{
/** @var ResourceFactory $resourceFactory */
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$html = $resourceFactory->retrieveFileOrFolderObject('EXT:dlf/Resources/Private/Templates/View3D/Standalone.html')->getContents();
$file = $resourceFactory->retrieveFileOrFolderObject('EXT:dlf/Resources/Public/JavaScript/3DViewer/model-viewer-3.5.0.min.js');
$html = $resourceFactory->retrieveFileOrFolderObject('EXT:dlf/Resources/Private/Templates/Embedded3dViewer/Standalone.html')->getContents();
$file = $resourceFactory->retrieveFileOrFolderObject('EXT:dlf/Resources/Public/JavaScript/Embedded3dViewer/model-viewer-3.5.0.min.js');
$html = str_replace('{{modelViewerJS}}', $file->getPublicUrl(), $html);
$html = str_replace("{{modelUrl}}", $model, $html);
return new HtmlResponse($html);
Expand Down
57 changes: 57 additions & 0 deletions Configuration/FlexForms/Embedded3dViewer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!--
* (c) Kitodo. Key to digital objects e.V. <[email protected]>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
-->
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:flexform.sheet_general</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.document>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.embedded3dviewer.flexform.document</label>
<config>
<type>input</type>
<eval>trim</eval>
</config>
</TCEforms>
</settings.document>
<settings.model>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.embedded3dviewer.flexform.model</label>
<config>
<type>input</type>
<eval>trim</eval>
</config>
</TCEforms>
</settings.model>
<settings.viewer>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.embedded3dviewer.flexform.viewer</label>
<config>
<type>input</type>
<eval>trim</eval>
</config>
</TCEforms>
</settings.viewer>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
37 changes: 0 additions & 37 deletions Configuration/FlexForms/View3D.xml

This file was deleted.

2 changes: 1 addition & 1 deletion Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
],
'dlf/embedded3DViewer' => [
'target' => \Kitodo\Dlf\Middleware\Embedded3DViewer::class,
'target' => \Kitodo\Dlf\Middleware\Embedded3dViewer::class,
'after' => [
'typo3/cms-frontend/prepare-tsfe-rendering'
]
Expand Down
Loading