From 588caa3a1d862f4ce1c2397ee41ac0e4be025e0f Mon Sep 17 00:00:00 2001 From: FrantisekMichalSebestyen Date: Wed, 23 Aug 2023 09:17:34 +0200 Subject: [PATCH 1/4] fix: handle aggregation funct on FE --- .../catalog-new/ItemsFilterController.vue | 6 +++++- .../catalog-new/SearchOptionsController.vue | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/resources/js/components/catalog-new/ItemsFilterController.vue b/resources/js/components/catalog-new/ItemsFilterController.vue index 4315f6e53..8d8a7300f 100644 --- a/resources/js/components/catalog-new/ItemsFilterController.vue +++ b/resources/js/components/catalog-new/ItemsFilterController.vue @@ -23,7 +23,7 @@ function getParsedFilterFromUrl() { } function stringifyUrl({ url, params }) { - const { filter, size, terms, page } = params + const { filter, size, terms, page, min, max } = params const { yearRange, author, @@ -63,6 +63,8 @@ function stringifyUrl({ url, params }) { sort: { [sort]: SORT_DIRECTIONS[sort], }, + min, + max, page, terms, size, @@ -254,6 +256,8 @@ export default { filter: this.query, terms: AGGREGATIONS_TERMS, size: AGGREGATIONS_SIZE, + min: { date_earliest: 'date_earliest' }, + max: { date_latest: 'date_latest' }, }, }), { headers: this.apiHeaders } diff --git a/resources/js/components/catalog-new/SearchOptionsController.vue b/resources/js/components/catalog-new/SearchOptionsController.vue index 0903c17bc..d7107e6b7 100644 --- a/resources/js/components/catalog-new/SearchOptionsController.vue +++ b/resources/js/components/catalog-new/SearchOptionsController.vue @@ -10,12 +10,21 @@ export default { filteredOptions() { // TODO better matching algorithm? const query = this.search.toLowerCase() - return this.options - .filter((option) => option.value.toLowerCase().includes(query)) - .map((option) => ({ + const optionsWithSelected = [ + ...this.options.map((option) => ({ ...option, checked: this.selected.includes(option.value), - })) + })), + ...this.selected + .filter((queryItem) => + this.options.every((option) => option.value !== queryItem) + ) + .map((selected) => ({ value: selected, count: 0, checked: true })), + ] + + return optionsWithSelected.filter((option) => + option.value.toLowerCase().includes(query) + ) }, }, render() { From 8eaecc9ecd3b134537b52ba300dfc5f7b65fce83 Mon Sep 17 00:00:00 2001 From: FrantisekMichalSebestyen Date: Wed, 23 Aug 2023 13:39:03 +0200 Subject: [PATCH 2/4] feat: year slider functionality --- .../frontend/catalog-new/index-new.blade.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/resources/views/frontend/catalog-new/index-new.blade.php b/resources/views/frontend/catalog-new/index-new.blade.php index 8bf72cf7a..9ef7ed8c0 100644 --- a/resources/views/frontend/catalog-new/index-new.blade.php +++ b/resources/views/frontend/catalog-new/index-new.blade.php @@ -228,10 +228,12 @@ class="tw-mb-3"> {{ trans('item.filter.clear') }} - + @@ -389,9 +391,11 @@ class="tw-ml-2" @endslot @slot('body') + v-bind:default-from="Number(query.yearRange?.from)" + v-bind:default-to="Number(query.yearRange?.to)" + v-bind:min="Number(aggregations.date_earliest) - 5" + v-bind:max="Math.min(Number(aggregations.date_latest) + 5, new Date().getFullYear())" + v-on:change="handleYearRangeChange">
From 762bbea1f214b8297e08092e8d8b34be553734b4 Mon Sep 17 00:00:00 2001 From: FrantisekMichalSebestyen Date: Thu, 24 Aug 2023 09:13:46 +0200 Subject: [PATCH 3/4] fix: remove unnecessary code --- app/Http/Controllers/NewCatalogController.php | 10 +------- app/Item.php | 25 ------------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/app/Http/Controllers/NewCatalogController.php b/app/Http/Controllers/NewCatalogController.php index 333890819..a769b7418 100644 --- a/app/Http/Controllers/NewCatalogController.php +++ b/app/Http/Controllers/NewCatalogController.php @@ -15,14 +15,6 @@ class NewCatalogController extends Controller */ public function index() { - $yearLimits = Cache::remember( - 'items.year-limits', - now()->addHours(1), - fn() => Item::getYearLimits() - ); - - return view('frontend.catalog-new.index-new', [ - 'yearLimits' => $yearLimits, - ]); + return view('frontend.catalog-new.index-new'); } } diff --git a/app/Item.php b/app/Item.php index 89d548dcc..abd9467f9 100644 --- a/app/Item.php +++ b/app/Item.php @@ -144,31 +144,6 @@ public function getCitation() return $this->getTitleWithAuthors() . ', ' . $this->getDatingFormated() . ', ' . $this->gallery . ', ' . $this->getUrl(); } - // Get limits from elastic, because date_earliest and date_latest - // are not indexed in DB - public static function getYearLimits() - { - $searchResult = self::searchQuery(Query::matchAll()) - ->size(false) - ->aggregate('min', [ - 'min' => [ - 'field' => 'date_earliest', - ], - ]) - ->aggregate('max', [ - 'max' => [ - 'field' => 'date_latest', - ], - ]) - ->execute() - ->raw(); - - return [ - 'min' => $searchResult['aggregations']['min']['value'], - 'max' => $searchResult['aggregations']['max']['value'], - ]; - } - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addGetterConstraint('images', new Valid()); } From 3c15b2e9ea66e3caf5adb0a8e62c7225bdd97a17 Mon Sep 17 00:00:00 2001 From: FrantisekMichalSebestyen Date: Thu, 24 Aug 2023 09:20:09 +0200 Subject: [PATCH 4/4] fix: rmeove unnecessary type conversion --- .../frontend/catalog-new/index-new.blade.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/resources/views/frontend/catalog-new/index-new.blade.php b/resources/views/frontend/catalog-new/index-new.blade.php index 9ef7ed8c0..8b48d7e58 100644 --- a/resources/views/frontend/catalog-new/index-new.blade.php +++ b/resources/views/frontend/catalog-new/index-new.blade.php @@ -229,10 +229,10 @@ class="tw-mb-3">
@@ -391,10 +391,10 @@ class="tw-ml-2" @endslot @slot('body')