diff --git a/application/asset/js/linked-resources.js b/application/asset/js/linked-resources.js new file mode 100644 index 000000000..288d8fced --- /dev/null +++ b/application/asset/js/linked-resources.js @@ -0,0 +1,54 @@ +$(document).ready(function () { + + // Render linked resources. + const renderLinkedResources = function(page, resourceProperty) { + const url = container.data('url'); + const siteId = container.data('siteId'); + const query = {}; + if (siteId) { + query.site_id = siteId; + } + if (page) { + query.page = page; + } + if (resourceProperty) { + query.resource_property = resourceProperty + } + $.get(url, query, function(data) { + container.html(data); + }); + }; + + // Render linked resources on initial load. + const container = $('#linked-resources-container'); + renderLinkedResources(); + + // Handle next and previous clicks. + $(container).on('click', 'a.next, a.previous', function(e) { + e.preventDefault(); + const thisButton = $(this); + // Note that we can use any base URL for this purpose. + const url = new URL(thisButton.attr('href'), 'http://foo'); + renderLinkedResources( + url.searchParams.get('page'), + url.searchParams.get('resource_property') + ); + }); + + // Handle page form submission. + $(container).on('submit', 'form', function(e) { + e.preventDefault(); + const thisForm = $(this); + const searchParams = new URLSearchParams(thisForm.serialize()); + renderLinkedResources( + searchParams.get('page'), + searchParams.get('resource_property') + ); + }); + + // Handle resource property select. + $(container).on('change', '#resource-property-select', function(e) { + const thisSelect = $(this); + renderLinkedResources('1', thisSelect.val()); + }); +}); diff --git a/application/config/module.config.php b/application/config/module.config.php index ff2a42010..eccfe489f 100644 --- a/application/config/module.config.php +++ b/application/config/module.config.php @@ -363,6 +363,7 @@ 'Omeka\Controller\Admin\Item' => Service\Controller\Admin\ItemControllerFactory::class, 'Omeka\Controller\SiteAdmin\Index' => Service\Controller\SiteAdmin\IndexControllerFactory::class, 'Omeka\Controller\Site\Page' => Service\Controller\Site\PageControllerFactory::class, + 'Omeka\Controller\LinkedResources' => Service\Controller\LinkedResourcesControllerFactory::class, ], ], 'controller_plugins' => [ @@ -489,6 +490,7 @@ 'passwordRequirements' => Service\ViewHelper\PasswordRequirementsFactory::class, 'resourcePageBlocks' => Service\ViewHelper\ResourcePageBlocksFactory::class, 'browse' => Service\ViewHelper\BrowseFactory::class, + 'linkedResources' => Service\ViewHelper\LinkedResourcesFactory::class, ], 'shared' => [ 'resourcePageBlocks' => false, diff --git a/application/config/routes.config.php b/application/config/routes.config.php index 0bcf0eeaa..8c74b78ef 100644 --- a/application/config/routes.config.php +++ b/application/config/routes.config.php @@ -377,6 +377,19 @@ ], ], ], + 'linked-resources' => [ + 'type' => \Laminas\Router\Http\Segment::class, + 'options' => [ + 'route' => '/linked-resources/:resource-id', + 'defaults' => [ + 'controller' => 'Omeka\Controller\LinkedResources', + 'action' => 'index', + ], + 'constraints' => [ + 'resource-id' => '\d+', + ], + ], + ], ], ], ]; diff --git a/application/src/Controller/LinkedResourcesController.php b/application/src/Controller/LinkedResourcesController.php new file mode 100644 index 000000000..13c2f9443 --- /dev/null +++ b/application/src/Controller/LinkedResourcesController.php @@ -0,0 +1,22 @@ +api()->read('resources', $this->params('resource-id'))->getContent(); + + $view = new ViewModel; + $view->setTerminal(true); + $view->setVariable('resource', $resource); + return $view; + } +} diff --git a/application/src/Service/Controller/LinkedResourcesControllerFactory.php b/application/src/Service/Controller/LinkedResourcesControllerFactory.php new file mode 100644 index 000000000..dd163e429 --- /dev/null +++ b/application/src/Service/Controller/LinkedResourcesControllerFactory.php @@ -0,0 +1,14 @@ +getView(); + $view->headScript()->appendFile($view->assetUrl('js/linked-resources.js', 'Omeka')); + return sprintf( + '
', + $view->url('linked-resources', ['resource-id' => $resource->id()]), + $view->escapeHtml($siteId) + ); + } +} diff --git a/application/view/common/linked-resources.phtml b/application/view/common/linked-resources.phtml index 2ae8b38dd..a0a648cf5 100644 --- a/application/view/common/linked-resources.phtml +++ b/application/view/common/linked-resources.phtml @@ -98,14 +98,3 @@ $caption = sprintf( $perPage) ? '' : ''; ?> - - diff --git a/application/view/common/resource-page-block-layout/linked-resources.phtml b/application/view/common/resource-page-block-layout/linked-resources.phtml index 5ab48b3b1..018810f1e 100644 --- a/application/view/common/resource-page-block-layout/linked-resources.phtml +++ b/application/view/common/resource-page-block-layout/linked-resources.phtml @@ -1,17 +1,9 @@ $this->params()->fromQuery('page', 1), - 'perPage' => 25, - 'resourceProperty' => $this->params()->fromQuery('resource_property'), -]; +$siteId = null; if ($this->siteSetting('exclude_resources_not_in_site')) { - $options['siteId'] = $this->currentSite()->id(); + $siteId = $this->currentSite()->id(); } -$subjectValues = $resource->displaySubjectValues($options); ?> - -
-

translate('Linked resources'); ?>

- -
+subjectValueTotalCount(null, null, $siteId)): ?> +linkedResources($resource, $siteId); ?> diff --git a/application/view/omeka/admin/item-set/show.phtml b/application/view/omeka/admin/item-set/show.phtml index e580e29ab..332f4afd1 100644 --- a/application/view/omeka/admin/item-set/show.phtml +++ b/application/view/omeka/admin/item-set/show.phtml @@ -49,18 +49,12 @@ $sectionNavs = [
subjectValueTotalCount()): ?> -

- displaySubjectValues([ - 'page' => $this->params()->fromQuery('page', 1), - 'perPage' => 25, - 'resourceProperty' => $this->params()->fromQuery('resource_property'), - ]); ?> + linkedResources($itemSet); ?> -
-

-
- -
+
+

+
+