Add type filtering to frontend and backend
This commit is contained in:
parent
f588643ae8
commit
a2c6657b74
|
@ -34,26 +34,6 @@ class TableOfContentsController extends AbstractController
|
|||
*/
|
||||
protected $activeEntries = [];
|
||||
|
||||
/**
|
||||
* @var array $this->filterParams: The current filter parameter
|
||||
* @access protected
|
||||
*/
|
||||
protected $filterParams;
|
||||
|
||||
/**
|
||||
* Filter Action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function filterAction()
|
||||
{
|
||||
// if filter was triggered, get filter parameters from POST variables
|
||||
$this->filterParams = $this->getParametersSafely('filterParameter');
|
||||
|
||||
// output is done by main action
|
||||
$this->forward('main', null, null, ['filterParameter' => $this->filterParams]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The main method of the plugin
|
||||
*
|
||||
|
@ -76,7 +56,9 @@ class TableOfContentsController extends AbstractController
|
|||
unset($this->requestData['logicalPage']);
|
||||
}
|
||||
if ($this->document->getDoc()->tableOfContents[0]['type'] == 'collection') {
|
||||
$this->view->assign('currentList', $this->requestData['id']);
|
||||
$this->view->assign('type', 'collection');
|
||||
$this->view->assign('types', $this->getTypes($this->document->getDoc()->tableOfContents));
|
||||
$this->view->assign('toc', $this->makeMenuFor3DObjects());
|
||||
} else {
|
||||
$this->view->assign('type', 'other');
|
||||
|
@ -174,10 +156,7 @@ class TableOfContentsController extends AbstractController
|
|||
|
||||
// Go through table of contents and create all menu entries.
|
||||
foreach ($this->document->getDoc()->tableOfContents as $entry) {
|
||||
$menuEntry = $this->getMenuEntryWithImage($entry, true);
|
||||
if (!empty($menuEntry)) {
|
||||
$menuArray[] = $menuEntry;
|
||||
}
|
||||
$menuArray[] = $this->getMenuEntryWithImage($entry, true);
|
||||
}
|
||||
return $menuArray;
|
||||
}
|
||||
|
@ -309,11 +288,24 @@ class TableOfContentsController extends AbstractController
|
|||
$entryArray = [];
|
||||
|
||||
// don't filter if the entry type is collection or search params are empty
|
||||
if ($entry['type'] !== 'collection' && is_array($this->filterParams) && !empty($this->filterParams)) {
|
||||
if ($entry['type'] != 'collection') {
|
||||
// currently only title filtering is defined
|
||||
// TODO: add more logic here after another fields are defined
|
||||
if (!str_contains($entry['label'], $this->filterParams[0])) {
|
||||
return $entryArray;
|
||||
if (!empty($this->requestData['title']) && !empty($this->requestData['types'])) {
|
||||
$label = strtolower($entry['label']);
|
||||
$title = strtolower($this->requestData['title']);
|
||||
if (!str_contains($label, $title) && !str_contains($entry['identifier'], $this->requestData['types'])) {
|
||||
return $entryArray;
|
||||
}
|
||||
} else if (!empty($this->requestData['title'])) {
|
||||
$label = strtolower($entry['label']);
|
||||
$title = strtolower($this->requestData['title']);
|
||||
if (!str_contains($label, $title)) {
|
||||
return $entryArray;
|
||||
}
|
||||
} else if (!empty($this->requestData['types'])) {
|
||||
if (!str_contains($entry['identifier'], $this->requestData['types'])) {
|
||||
return $entryArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,10 +342,38 @@ class TableOfContentsController extends AbstractController
|
|||
) {
|
||||
$entryArray['_SUB_MENU'] = [];
|
||||
foreach ($entry['children'] as $child) {
|
||||
$entryArray['_SUB_MENU'][] = $this->getMenuEntryWithImage($child);
|
||||
$menuEntry = $this->getMenuEntryWithImage($child);
|
||||
if (!empty($menuEntry)) {
|
||||
$entryArray['_SUB_MENU'][] = $menuEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $entryArray;
|
||||
}
|
||||
|
||||
private function getTypes($entry) {
|
||||
$types = [];
|
||||
$index = 0;
|
||||
|
||||
if (!empty($entry[0]['children'])) {
|
||||
foreach ($entry[0]['children'] as $child) {
|
||||
$type = $this->getType($child);
|
||||
if (!(in_array($type, $types)) && $type != NULL) {
|
||||
$types[$index] = $type;
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
private function getType($entry) {
|
||||
$type = $entry['identifier'];
|
||||
if (!empty($type)) {
|
||||
return strtok($type, ',');
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,10 @@
|
|||
<source><![CDATA[Download whole work]]></source>
|
||||
<target><![CDATA[Ganzes Werk herunterladen]]></target>
|
||||
</trans-unit>
|
||||
<trans-unit id="filter.submit">
|
||||
<source><![CDATA[Filter]]></source>
|
||||
<target><![CDATA[Filtern]]></target>
|
||||
</trans-unit>
|
||||
<trans-unit id="firstPage" approved="yes">
|
||||
<source><![CDATA[First Page]]></source>
|
||||
<target><![CDATA[Erste Seite]]></target>
|
||||
|
@ -453,6 +457,10 @@
|
|||
<source><![CDATA[Search in document]]></source>
|
||||
<target><![CDATA[Im Dokument suchen]]></target>
|
||||
</trans-unit>
|
||||
<trans-unit id="type" approved="yes">
|
||||
<source><![CDATA[type]]></source>
|
||||
<target><![CDATA[Typ]]></target>
|
||||
</trans-unit>
|
||||
<trans-unit id="volume" approved="yes">
|
||||
<source><![CDATA[volume]]></source>
|
||||
<target><![CDATA[Band]]></target>
|
||||
|
|
|
@ -122,6 +122,9 @@
|
|||
<trans-unit id="downloadWork">
|
||||
<source><![CDATA[Download whole work]]></source>
|
||||
</trans-unit>
|
||||
<trans-unit id="filter.submit">
|
||||
<source><![CDATA[Filter]]></source>
|
||||
</trans-unit>
|
||||
<trans-unit id="firstPage">
|
||||
<source><![CDATA[First Page]]></source>
|
||||
</trans-unit>
|
||||
|
@ -257,6 +260,9 @@
|
|||
<trans-unit id="search.submit">
|
||||
<source><![CDATA[Search]]></source>
|
||||
</trans-unit>
|
||||
<trans-unit id="type" approved="yes">
|
||||
<source><![CDATA[type]]></source>
|
||||
</trans-unit>
|
||||
<trans-unit id="volume">
|
||||
<source><![CDATA[volume]]></source>
|
||||
</trans-unit>
|
||||
|
|
|
@ -9,9 +9,20 @@
|
|||
* LICENSE.txt file that was distributed with this source code.
|
||||
-->
|
||||
</f:comment>
|
||||
<f:form action="filter" controller="TableOfContents" name="filterParameter" method="get" class="tx-dlf-filter-form">
|
||||
<form action="{f:uri.page(pageUid='{viewData.requestData.pageUid}')}" name="filterParameter" method="get" class="tx-dlf-filter-form">
|
||||
<input type="hidden" id="tx-dlf-filter-id" name="tx_dlf[id]" value="{currentList}" />
|
||||
<label for="tx-dlf-filter-title">
|
||||
{f:translate(key: 'title')}
|
||||
</label>
|
||||
<f:form.textfield id="tx-dlf-filter-title" name="tx_dlf[title]" />
|
||||
</f:form>
|
||||
<input id="tx-dlf-filter-title" name="tx_dlf[title]" />
|
||||
<label for="tx-dlf-filter-type">
|
||||
{f:translate(key: 'type')}
|
||||
</label>
|
||||
<select id="tx-dlf-filter-type" name="tx_dlf[types]" >
|
||||
<option value=""></option>
|
||||
<f:for each="{types}" as="type">
|
||||
<option value="{type}">{type}</option>
|
||||
</f:for>
|
||||
</select>
|
||||
<f:form.submit value="{f:translate(key: 'filter.submit')}" />
|
||||
</form>
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
title="{f:if(condition:'{model.title}', then: '{model.title}', else: '{model.type}')}">
|
||||
<span class="tx-dlf-toc-title">{model.title}</span>
|
||||
<br>
|
||||
<span class="tx-dlf-toc-type">{model.identifier}</span>
|
||||
<br>
|
||||
<img class="tx-dlf-toc-preview-image" src="{model.image}" alt="{model.title}">
|
||||
<span class="tx-dlf-toc-description">{model.description}</span>
|
||||
<br>
|
||||
<span class="tx-dlf-toc-preview-type">{model.identifier}</span>
|
||||
<br>
|
||||
<span class="tx-dlf-toc-preview-description"><f:format.crop maxCharacters="115" append=" ...">{model.description}</f:format.crop></span>
|
||||
</f:link.page>
|
||||
</div>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<h2>
|
||||
<f:render partial="TableOfContents/Title" arguments="{child: model}"/>
|
||||
</h2>
|
||||
<f:render partial="TableOfContents/Filter"/>
|
||||
<f:render partial="TableOfContents/Filter" arguments="{currentList: currentList, types: types}"/>
|
||||
<div class="tx-dlf-toc-preview-items">
|
||||
<f:render partial="TableOfContents/Models" arguments="{models: model._SUB_MENU}"/>
|
||||
</div>
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
<f:if condition="{type} == 'collection'">
|
||||
<f:then>
|
||||
<div class="tx-dlf-toc-preview">
|
||||
<f:render partial="TableOfContents/Filter"/>
|
||||
<f:render partial="TableOfContents/Models" arguments="{models: toc}"/>
|
||||
<f:render partial="TableOfContents/Models" arguments="{currentList: currentList, models: toc, types: types}"/>
|
||||
</div>
|
||||
</f:then>
|
||||
<f:else>
|
||||
|
|
|
@ -166,7 +166,7 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\Kitodo\Dlf\U
|
|||
],
|
||||
// non-cacheable actions
|
||||
[
|
||||
TableOfContents::class => '',
|
||||
TableOfContents::class => 'main',
|
||||
]
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue