-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load linked resource interface asynchronously (#2176)
- Loading branch information
Showing
12 changed files
with
163 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace Omeka\Controller; | ||
|
||
use Laminas\Mvc\Controller\AbstractActionController; | ||
use Laminas\View\Model\ViewModel; | ||
|
||
class LinkedResourcesController extends AbstractActionController | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
public function indexAction() | ||
{ | ||
$resource = $this->api()->read('resources', $this->params('resource-id'))->getContent(); | ||
|
||
$view = new ViewModel; | ||
$view->setTerminal(true); | ||
$view->setVariable('resource', $resource); | ||
return $view; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
application/src/Service/Controller/LinkedResourcesControllerFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace Omeka\Service\Controller; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Omeka\Controller\LinkedResourcesController; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
|
||
class LinkedResourcesControllerFactory implements FactoryInterface | ||
{ | ||
public function __invoke(ContainerInterface $services, $requestedName, array $options = null) | ||
{ | ||
return new LinkedResourcesController; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
application/src/Service/ViewHelper/LinkedResourcesFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Omeka\Service\ViewHelper; | ||
|
||
use Omeka\View\Helper\LinkedResources; | ||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Interop\Container\ContainerInterface; | ||
|
||
class LinkedResourcesFactory implements FactoryInterface | ||
{ | ||
public function __invoke(ContainerInterface $services, $requestedName, array $options = null) | ||
{ | ||
return new LinkedResources; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
namespace Omeka\View\Helper; | ||
|
||
use Laminas\View\Helper\AbstractHelper; | ||
use Omeka\Api\Representation\AbstractResourceEntityRepresentation; | ||
|
||
class LinkedResources extends AbstractHelper | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
|
||
public function __invoke(AbstractResourceEntityRepresentation $resource, int $siteId = null) | ||
{ | ||
$view = $this->getView(); | ||
$view->headScript()->appendFile($view->assetUrl('js/linked-resources.js', 'Omeka')); | ||
return sprintf( | ||
'<div id="linked-resources-container" data-url="%s" data-site-id="%s"></div>', | ||
$view->url('linked-resources', ['resource-id' => $resource->id()]), | ||
$view->escapeHtml($siteId) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 4 additions & 12 deletions
16
application/view/common/resource-page-block-layout/linked-resources.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
<?php | ||
$options = [ | ||
'page' => $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); | ||
?> | ||
<?php if ($subjectValues): ?> | ||
<div id="resources-linked"> | ||
<h3><?php echo $this->translate('Linked resources'); ?></h3> | ||
<?php echo $subjectValues; ?> | ||
</div> | ||
<?php if ($resource->subjectValueTotalCount(null, null, $siteId)): ?> | ||
<?php echo $this->linkedResources($resource, $siteId); ?> | ||
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php echo $resource->displaySubjectValues([ | ||
'page' => $this->params()->fromQuery('page', 1), | ||
'perPage' => 25, | ||
'resourceProperty' => $this->params()->fromQuery('resource_property'), | ||
]); ?> |