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

1 provide search slot #29

Merged
merged 58 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6df21ae
move ElasticSearchService from liszt_bibliography to liszt_common
Oct 9, 2024
a9cb072
get Query Param text in Searchbar todo (caching Problem)
Oct 9, 2024
bb7e349
test of two variants for searchbar, standalone and with f:form helper
Oct 16, 2024
35855fd
Create search bar plugin
Oct 16, 2024
ee65485
change css classes for searchbar
Oct 16, 2024
73bc0d2
Add search bar plugin
Oct 16, 2024
ab0d89c
Fix indexAction
Oct 16, 2024
bd7c587
Styling Searchbar Part 2
Oct 16, 2024
8cfe539
disable page caching for searchbar plugin
Oct 21, 2024
21c67b6
style search results
Oct 21, 2024
c47217d
first simple text search
Oct 22, 2024
78d68ce
function createElasticParams outsourced from SearchService Class to C…
Oct 23, 2024
7e52fb2
Searchresults Filter position sticky
Oct 23, 2024
18ee178
Style SearchResults like designers template
Oct 28, 2024
05fe191
Add string optimized collection
Oct 29, 2024
313b848
Merge branch 'dev' into test
Oct 29, 2024
dead641
move iconpack with itemtype icons from search results to liszt_common…
Oct 30, 2024
d79d332
add modal window icons to iconpack, style mobile search results item …
Nov 4, 2024
866f013
style mobile filter menu as slide over
Nov 4, 2024
7ae84d5
select icons in searchresults from avaliable icons in iconpack
Nov 5, 2024
2ff295f
add iconpack dependency in composer.json
Nov 6, 2024
b2411fa
first facette filters work, View helper for search parameter operations
Nov 6, 2024
a3e258d
Merge branch 'test' into dev
dikastes Nov 7, 2024
7f76e86
Merge pull request #20 from slub/dev
dikastes Nov 7, 2024
ff510d2
Fix elastic client builder for connecting to elastic vm
Nov 8, 2024
32dcb00
Fix elastic client builder for connecting to elastic vm
Nov 8, 2024
5dac889
Fix cert path
Nov 11, 2024
21d4a79
create filter tabs on search results and make multiple filter possible
Nov 11, 2024
99a018d
Add facets
Nov 11, 2024
9371f8d
Merge branch 'test' into dev
dikastes Nov 12, 2024
e893b9d
Merge pull request #25 from slub/dev
dikastes Nov 12, 2024
2caca05
Add Paginator
Nov 19, 2024
ba8934d
custom mappings, facettes for creator names, full text search with bo…
Nov 19, 2024
d827e81
Merge pull request #26 from slub/32-optimize-elasticsearch-mapping-1
dikastes Nov 19, 2024
bfce0fb
Merge branch 'test' into 21-build-pagination-for-the-search-results-p…
Nov 19, 2024
234f0b1
Add current page label
Nov 21, 2024
f39f60f
Harmonize pagination with filters
Nov 21, 2024
f101163
small changes for pager styling
Nov 25, 2024
28b59a3
Add recursive collection
Nov 25, 2024
098c5c1
Dewire search config from QueryParamsBuilder
Nov 25, 2024
a4a8819
Add first automatic QueryParamsBuilder tests
Nov 25, 2024
fd35e2c
Fix
Nov 25, 2024
9c14042
Fix tests
Nov 26, 2024
4847ee4
add ... to pagination gap
Nov 26, 2024
c702422
Add abstract IndexProcessor
Nov 26, 2024
5dd4bbd
remove page from searchParams array for filter tags
Nov 26, 2024
a906fa6
Introduce classes in paginator
Nov 26, 2024
e4a1bdd
update styling and aria attributes to refactored pagination, smaller …
Nov 27, 2024
722a955
Refine tests
Nov 27, 2024
dc9bc06
Config and translation fixes
Nov 27, 2024
f9d6d6a
Merge pull request #27 from slub/21-build-pagination-for-the-search-r…
dikastes Nov 27, 2024
ab87274
Use IndexProcessor constants
Nov 27, 2024
5de2392
Add script treatment
Nov 27, 2024
6ce9e4f
Enhance search all properties
Nov 28, 2024
da13bf2
Merge branch 'test' into 1-provide-search-slot
Nov 28, 2024
c36ba03
Fixes
Nov 28, 2024
27e9cd6
Merge branch 'main' into 1-provide-search-slot
dikastes Nov 28, 2024
14f6e1f
Fix
Nov 28, 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
10 changes: 10 additions & 0 deletions Classes/Common/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ public function implode($value, $glue = null)
{
return Str::of(parent::implode($value, $glue));
}

public function recursive(): Collection
{
return $this->map( function($item) {
if (is_array($item)) {
return Collection::wrap($item)->recursive();
}
return $item;
});
}
}
11 changes: 7 additions & 4 deletions Classes/Common/ElasticClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,22 @@ protected function autoconfig (): ElasticClientBuilder {
$this->setBasicAuthentication('elastic', $this->password);
}
if ($this->caFilePath) {
$this->setSSLVerification($this->caFilePath);
$this->setCABundle($this->caFilePath);
}

return $this;
}

private function setCaFilePath(): void
{
if ($this->extConf->get('elasticCaFileName') == '') {
if ($this->extConf->get('elasticCaFileFilePath') == '') {
$this->caFilePath = '';
return;
}

$this->caFilePath = $this->extConf->
only('elastcCredentialsFilePath', 'elasticCaFileName')->
sortKeysDesc()->
only('elasticCredentialsFilePath', 'elasticCaFileFilePath')->
implode('/');
}

Expand All @@ -77,11 +78,13 @@ private function setPassword(): void
}

$passwordFilePath = $this->extConf->
sortKeys()->
only('elasticCredentialsFilePath', 'elasticPwdFileName')->
implode('/');
$passwordFile = fopen($passwordFilePath, 'r') or
die($passwordFilePath . ' not found. Check your extension\'s configuration');
$size = filesize($passwordFilePath);

$this->password = $passwordFile->getContents();
$this->password = trim(fread($passwordFile, $size));
}
}
191 changes: 191 additions & 0 deletions Classes/Common/Paginator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liszt Catalog Raisonne project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
*/

namespace Slub\LisztCommon\Common;

use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;

class Paginator
{
const CURRENT_PAGE = 'current';
const DOTS = '...';

const SHOW_CLASS = 'show';
const HIDE_CLASS = 'hide-mobile';
const DOTS_CLASS = 'dots';
const CURRENT_CLASS = 'current';

protected int $itemsPerPage = -1;
protected int $totalItems = -1;
protected int $currentPage = -1;
protected ?Collection $paginationRange = null;

final public function __construct()
{ }

public static function createPagination(
int $page,
int $totalItems,
ExtensionConfiguration $extConf
): array
{
return (new static($page, $totalItems, $extConf))->
setPage($page)->
setTotalItems($totalItems)->
setExtensionConfiguration($extConf)->
getPagination();
}

public function setTotalItems(int $totalItems): Paginator
{
$this->totalItems = $totalItems;

return $this;
}

public function setExtensionConfiguration(ExtensionConfiguration $extensionConfiguration): Paginator
{
$extConf = $extensionConfiguration->get('liszt_common');
$this->itemsPerPage = (int) $extConf['itemsPerPage'];
$paginationRangeString = Str::of($extConf['paginationRange']);

if(!$paginationRangeString->isMatch('/^\d* *(, *\d+)*$/')) {
throw new \Exception('Check the configuration of liszt common. The pagination range needs to be specified in the form "1,2,3..."');
}

$this->paginationRange = $paginationRangeString->explode(',')->
map(function($rangeItem) { return self::getRangeItem($rangeItem); })->
// we always want the neighboring pages of the current page
push(1)->
unique()->
sort();

return $this;
}

public function setPage(int $page): Paginator
{
$this->currentPage = $page;

return $this;
}

public function getPagination(): array
{
if (
$this->totalItems < 0 ||
$this->currentPage < 0 ||
$this->itemsPerPage < 0
) {
throw new \Exception('Please specify total items, items per page and current page before retrieving the pagination.');
}

$pagination = new Collection();
$totalPages = (int) ceil($this->totalItems / $this->itemsPerPage);
$currentPage = $this->currentPage;

$pagesBefore = $this->paginationRange->
filter()->
reverse()->
map(function($page) use ($currentPage) { return self::getPageBefore($page, $currentPage); });
$pagesAfter = $this->paginationRange->
filter()->
map(function($page) use ($currentPage, $totalPages) { return self::getPageAfter($page, $currentPage, $totalPages); });

return Collection::wrap([])->
// we include the first page if it is not the current one
when($this->currentPage != 1,
function ($collection) { return $collection->push([ 'page' => 1, 'class' => self::SHOW_CLASS ]); }
)->
// we include the range pages before the current page (which may be empty)
concat($pagesBefore)->
// we include the current page
push(['page' => $this->currentPage, 'class' => self::CURRENT_CLASS])->
// we include the range pages after the current page (which may be empty)
concat($pagesAfter)->
// we include the last page if it is not the current one
when($this->currentPage != $totalPages,
function($collection) use ($totalPages) { return $collection->push([ 'page' => $totalPages, 'class' => self::SHOW_CLASS ]);}
)->
// we filter out empty results from the pagesBefore or pagesAfter arrays
filter()->
// we introduce dots wherever the distance between two pages is greater than one, so we prepare by adding a dummy
push(null)->
// sliding through pairs of pages
sliding(2)->
// returning page 1 if the distance is 1 and page 1 and dots elsewise (here we need the dummy)
mapSpread( function ($page1, $page2) { return self::insertDots($page1, $page2); })->
// and flatten out everything
flatten(1)->
values()->
all();
}

private static function insertDots(?array $page1, ?array $page2): array
{
if ($page2 == null) return [ $page1 ];

if ($page2['page'] - $page1['page'] == 1) {
return [ $page1 ];
}

$dots = [ 'page' => self::DOTS, 'class' => self::DOTS_CLASS ];
return [ $page1, $dots ];
}

private static function getPageBefore(?int $page, int $currentPage): ?array
{
$result = $currentPage - $page;

if ($result < 2) return null;

if ($page == 1) {
return [
'page' => $result,
'class' => self::SHOW_CLASS
];
}

return [
'page' => $result,
'class' => self::HIDE_CLASS
];
}

private static function getPageAfter(?int $page, int $currentPage, int $totalPages): ?array
{
$result = $currentPage + $page;

if ($result >= $totalPages) return null;

if ($page == 1) {
return [
'page' => $result,
'class' => self::SHOW_CLASS
];
}

return [
'page' => $result,
'class' => self::HIDE_CLASS
];
}

private static function getRangeItem(string $rangeItem): ?int
{
if ($rangeItem == '') return null;
return (int) trim($rangeItem);
}
}
Loading