Skip to content

Commit

Permalink
Merge pull request #20 from slub/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dikastes authored Nov 7, 2024
2 parents 313b848 + a3e258d commit 7f76e86
Show file tree
Hide file tree
Showing 29 changed files with 558 additions and 23 deletions.
26 changes: 20 additions & 6 deletions Classes/Common/QueryParamsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static function createElasticParams(string $bibIndex, array $searchParams
'index' => $bibIndex,
'body' => [
'size' => 10,
'_source' => ['itemType', 'title', 'creators', 'pages', 'date', 'language', 'localizedCitations', 'publicationTitle', 'archiveLocation'],
'_source' => ['itemType', 'tx_lisztcommon_header', 'tx_lisztcommon_body', 'tx_lisztcommon_footer'],
'aggs' => [
'itemType' => [
'terms' => [
Expand All @@ -23,6 +23,11 @@ public static function createElasticParams(string $bibIndex, array $searchParams
'terms' => [
'field' => 'place.keyword',
]
],
'date' => [
'terms' => [
'field' => 'date.keyword',
]
]
]
]
Expand All @@ -38,14 +43,23 @@ public static function createElasticParams(string $bibIndex, array $searchParams
} else {
$params['body']['query'] = [
'bool' => [
'must' => [[
'query_string' => [
'query' => $searchParams['searchText']
]
]]
'must' => [
['query_string' => ['query' => $searchParams['searchText']]],
]
]
];
}

// Todo: automate the creation of parameters
if (isset($searchParams['f_itemType']) && $searchParams['f_itemType'] !== "") {
$params['body']['query']['bool']['filter']['term']['itemType.keyword'] = $searchParams['f_itemType'];
}
if (isset($searchParams['f_place']) && $searchParams['f_place'] !== "") {
$params['body']['query']['bool']['filter']['term']['place.keyword'] = $searchParams['f_place'];
}
if (isset($searchParams['f_date']) && $searchParams['f_date'] !== "") {
$params['body']['query']['bool']['filter']['term']['date.keyword'] = $searchParams['f_date'];
}
return $params;
}

Expand Down
42 changes: 42 additions & 0 deletions Classes/ViewHelpers/ItemTypeIconNameViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

namespace Slub\LisztCommon\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

use Quellenform\Iconpack\IconpackFactory;


final class ItemTypeIconNameViewHelper extends AbstractViewHelper
{
public function initializeArguments(): void
{
$this->registerArgument('iconPackKey', 'string', 'Name of the key for the IconPack (from Iconpack.yaml)', true);
$this->registerArgument('itemType', 'string', 'Name of the itemType (from Zotero)', true);
}

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext)
: ?string
{
// get installed icon names from the t3x Iconpack Extension with Key 'lziconsr' as Array
$iconpackFactory = GeneralUtility::makeInstance(IconpackFactory::class);
$iconPackKey = $arguments['iconPackKey'];
$availableIconsArray = $iconpackFactory->queryConfig($iconPackKey, 'icons');

// Check if itemType exists as a key in the array
$itemType = $arguments['itemType'];
if (array_key_exists($itemType, $availableIconsArray)) {
return $iconPackKey.','.$itemType;
}

// else Return default icon
return 'lziconsr,lisztDocument';

}
}
44 changes: 44 additions & 0 deletions Classes/ViewHelpers/SearchParamsViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Slub\LisztCommon\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

final class SearchParamsViewHelper extends AbstractViewHelper
{
public function initializeArguments(): void
{
$this->registerArgument('action', 'string', 'the operation to be performed with the search parameters', true);
$this->registerArgument('key', 'string', 'the key wich has to be operated (added oder removed) ', true);
$this->registerArgument('value', 'string', 'the value if is a add operation', false);
$this->registerArgument('searchParamsArray', 'array', 'the Array with SearchParams from Controller', true);
}
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext)
: ?array
{
$action = $arguments['action'];
$key = $arguments['key'];
$value = $arguments['value'] ?? null;
$searchParamsArray = $arguments['searchParamsArray'];

if ($action === 'add') {
$searchParamsArray[$key] = $value;
} elseif ($action === 'remove') {
unset($searchParamsArray[$key]);
}

// Convert the array to a string formatted as {key: 'value', key2: 'value2'}
$formattedParams = [];
foreach ($searchParamsArray as $paramKey => $paramValue) {
$formattedParams[] = "{$paramKey}: '" . $paramValue . "'";
}

// return '{' . implode(', ', $formattedParams) . '}';
return ['searchParams' => $searchParamsArray];

}
}
49 changes: 49 additions & 0 deletions Configuration/Iconpack/LisztSearchResultsIconpack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
iconpack:
title: "Liszt Custom Icons for Search Results in LQWV"
# The key of the iconpack (!)
key: "lziconsr"
version: 1.0.0

renderTypes:
svg:
# Source folder of the SVG files, which are rendered as <img> tag:
source: "EXT:liszt_common/Resources/Public/Icons/IconPackSearchResults/"
attributes:
class: "lzicon"

svgInline:
# Source folder of the SVG files that are rendered as <svg> tag (inline SVG):
source: "EXT:liszt_common/Resources/Public/Icons/IconPackSearchResults/"
attributes:
class: "lzicon-inline"
fill: "currentColor"


svgSprite:
source: "EXT:liszt_common/Resources/Public/Icons/IconPackSearchResults/IconSpritesSearchResults.svg"
attributes:
class: "lzicon-sprite"
fill: "currentColor"

# Define here which icons are provided by this iconpack
# In this case, the values here correspond to the file names (without file name extension)
icons:
- auctionCatalog
- lisztDocument
- book
- attachment
- encyclopediaArticle
- essay
- journalArticle
- lisztDocument
- musicSheet
- thesis
- performance
- profession
- birth
- corporation
- open-access
- place
- person
- death
- work
9 changes: 7 additions & 2 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ tt_content {
}
}

// same namespace for both plugins on searchresults page
plugin.tx_lisztcommon_searchbar.view.pluginNamespace = tx_liszt_common_searchlisting
plugin.tx_lisztcommon_searchlisting.view.pluginNamespace = tx_liszt_common_searchlisting
// while two plugins are on searchresults page, the searchbar plugin brings "action index is not allowed by this plugin" by non searchbar actions
// set use default action to avoid this error
plugin.tx_lisztcommon_searchbar.mvc.callDefaultActionIfActionCantBeResolved = 1;


# get the selected frontend layout from page table for show/hide SearchBar, because bootstrap package not use this param
Expand Down Expand Up @@ -78,5 +84,4 @@ tt_content {
}*/


plugin.tx_lisztcommon_searchbar.view.pluginNamespace = tx_liszt_common_searchlisting
plugin.tx_lisztcommon_searchlisting.view.pluginNamespace = tx_liszt_common_searchlisting

6 changes: 6 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<trans-unit id="searchButtonLabel">
<source>Suchen</source>
</trans-unit>
<trans-unit id="filter_container_label">
<source>Suchfilter</source>
</trans-unit>
<trans-unit id="filter_container_close">
<source>Filtermenü schließen</source>
</trans-unit>
</body>
</file>
</xliff>
6 changes: 6 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<trans-unit id="searchButtonLabel">
<source>Suchen</source>
</trans-unit>
<trans-unit id="filter_container_label">
<source>Suchfilter</source>
</trans-unit>
<trans-unit id="filter_container_close">
<source>Filtermenü schließen</source>
</trans-unit>

</body>
</file>
Expand Down
67 changes: 54 additions & 13 deletions Resources/Private/Templates/Search/Index.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,86 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
{namespace lc=Slub\LisztCommon\ViewHelpers}
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:i="http://typo3.org/ns/Quellenform/Iconpack/ViewHelpers"
data-namespace-typo3-fluid="true">




<output class="searchresults-total-items frame">{totalItems} Treffer</output>
<f:debug>{_all}</f:debug>
<div class="searchresults-info frame">
<output class="searchresults-total-items">{totalItems} Treffer</output>
<button class="filter-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#filter-container" aria-controls="filter-container">
Filter
</button>
</div>

<aside class="sidebar">
<div class="filter-container" >
<nav class="filter-container offcanvas offcanvas-end" id="filter-container" aria-label="{f:translate(key: 'filter_container_label', extensionName: 'liszt_common')}" >
<div class="offcanvas-header">
<h5 class="offcanvas-title">{f:translate(key: 'filter_container_label', extensionName: 'liszt_common')}</h5>
<button type="button" class="btn-close " data-bs-dismiss="offcanvas" aria-label="{f:translate(key: 'filter_container_close', extensionName: 'liszt_common')}">
<i:icon iconfig="lzicon,close" preferredRenderTypes="svgSprite" additionalAttributes="{aria-hidden:'true'}" />
</button>
</div>
<div class="offcanvas-body">
<f:for each="{searchResults.aggregations}" key="key" as="filterGroup">
<f:if condition="{filterGroup.buckets}">
<div class="filter-block frame">
<h4 class="">{key}</h4>
<f:variable name="searchParamsFilterKey">f_{key}</f:variable>
<ul>
<f:for each="{filterGroup.buckets}" as="filter">
<li>
<f:if condition="{searchParams.{searchParamsFilterKey}} == {filter.key}">
<f:then>
<f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{lc:searchParams(action: 'remove', searchParamsArray: searchParams, key: searchParamsFilterKey)}" class="filter-item selected">
<span class="filter-item-label">{filter.key}</span>
<span class="filter-item-count">{filter.doc_count}</span>
</f:link.action>
</f:then>
<f:else>
<f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{lc:searchParams(action: 'add', searchParamsArray: searchParams, key: searchParamsFilterKey, value: filter.key)}" class="filter-item">
<span class="filter-item-label">{filter.key}</span>
<span class="filter-item-count">{filter.doc_count}</span>
</f:link.action>
</f:else>
</f:if>
</li>



<f:comment> <!-- old versions of filter (form input), ToDo: remove later if not needed-->
<li><f:link.action action="index" controller="Search" pluginName="SearchListing" arguments="{searchParams: {f_itemType: filter.key}}" class="form-checkbox"><input class="form-check-input" type="checkbox" id="{filter.key}" value="{filter.key}"><label class="form-check-label" for="{filter.key}">{filter.key}</label><span class="count">{filter.doc_count}</span></f:link.action></li>
<li><a href="{f:uri.action(controller: 'Search', action: 'index', extensionName: 'liszt_common', pluginName: 'SearchListing', pageUid: '18')}" class="form-checkbox"><input class="form-check-input" type="checkbox" id="{filter.key}" value="{filter.key}"><label class="form-check-label" for="{filter.key}">{filter.key}</label></a><span class="count">{filter.doc_count}</span></li>
<li><span class="form-checkbox"><input class="form-check-input" type="checkbox" id="{filter.key}" value="{filter.key}"><label class="form-check-label" for="{filter.key}">{filter.key}</label></span><span class="count">{filter.doc_count}</span></li>
</f:comment>

</f:for>
</ul>
</div>
</f:if>
</f:for>
</div>
</div>
</nav>

</aside>
<div class="content grid-colspan-lg-3 grid-colspan-md-2">
<div class="frame">


<f:for each="{searchResults.hits.hits}" as="hit">
<article class="searchresults-item ">
<header>
<div class="searchresults-item-label">
<f:for each="{hit._source.creators}" as="creator">
{creator.firstName} {creator.lastName}
</f:for>
{hit._source.tx_lisztcommon_header}
</div>
<h3 class="searchresults-item-title">
{hit._source.title}, {hit._source.title}
<div class="searchresults-item-title">
<div class="searchresults-item-icon"><i:icon iconfig="{lc:ItemTypeIconName(iconPackKey: 'lziconsr', itemType: hit._source.itemType)}" preferredRenderTypes="svgSprite" additionalAttributes="{aria-hidden:'true'}" /></div>
<h3 >
{hit._source.tx_lisztcommon_body}
</h3>
</div>
</header>
<div class="searchresults-item-details">
{hit._source.date}, {hit._source.pages}, {hit._source.archiveLocation}
{hit._source.tx_lisztcommon_footer}
</div>
</article>
</f:for>
Expand Down
Loading

0 comments on commit 7f76e86

Please sign in to comment.