From a5b88ebf471831e782bd1e2310e14db923df8718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Thu, 21 Oct 2021 18:30:35 +0200 Subject: [PATCH] WIP Migrate mobile search --- .../Controller/AjaxFilterPanelController.php | 100 +++ .../Classes/Controller/SearchController.php | 13 - .../Configuration/TypoScript/setup.typoscript | 4 + .../ext/ep_products/ext_localconf.php | 2 + .../TypoScript/Library/SearchBox.typoscript | 18 - .../js/controllers/contactform_controller.js | 12 - .../controllers/mobile_search_controller.js | 89 +++ .../js/controllers/pricetable_controller.js | 4 +- .../Private/Layouts/Page/Frontpage.html | 2 +- .../Private/Layouts/Page/Subpage.html | 1 + .../Layouts/Page/SubpageSidebarLeft.html | 1 + .../Layouts/Page/SubpageSidebarRight.html | 1 + .../Resources/Private/Partials/Mainnav.html | 22 +- .../Private/Partials/Search/FilterPanel.html | 693 +++++++++--------- .../Private/Partials/Search/Main.html | 46 +- .../Private/Partials/Search/MobileSearch.html | 37 + .../Templates/AjaxFilterPanel/Options.html | 24 +- .../Private/Templates/Form/SimpleForm.html | 20 - .../Private/Templates/Search/Searchbox.html | 69 -- .../Templates/Search/Searchresult.html | 2 +- 20 files changed, 654 insertions(+), 506 deletions(-) create mode 100644 public/typo3conf/ext/ep_products/Classes/Controller/AjaxFilterPanelController.php delete mode 100644 public/typo3conf/ext/ep_theme/Configuration/TypoScript/Library/SearchBox.typoscript delete mode 100644 public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/contactform_controller.js create mode 100644 public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/mobile_search_controller.js create mode 100644 public/typo3conf/ext/ep_theme/Resources/Private/Partials/Search/MobileSearch.html delete mode 100644 public/typo3conf/ext/ep_theme/Resources/Private/Templates/Form/SimpleForm.html delete mode 100644 public/typo3conf/ext/ep_theme/Resources/Private/Templates/Search/Searchbox.html diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/AjaxFilterPanelController.php b/public/typo3conf/ext/ep_products/Classes/Controller/AjaxFilterPanelController.php new file mode 100644 index 00000000..e4b79f7a --- /dev/null +++ b/public/typo3conf/ext/ep_products/Classes/Controller/AjaxFilterPanelController.php @@ -0,0 +1,100 @@ +, dreipunktnull + * + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ + +use EP\EpProducts\Service\FilterService; +use EP\EpProducts\Traits\RequestArgumentTypeConversionTrait; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; + +class AjaxFilterPanelController extends ActionController +{ + + use RequestArgumentTypeConversionTrait; + + /** + * @var \EP\EpProducts\Service\FilterService + */ + protected $filterService; + + /** + * @param FilterService $filterService + */ + public function __construct(FilterService $filterService) + { + $this->filterService = $filterService; + } + + public function initializeAction() + { + $forcedConceptUids = GeneralUtility::trimExplode(',', $this->settings['forcedConceptUids'], true); + $this->processFilterSettingsArgument($forcedConceptUids); + } + + /** + * @param array $filterSettings + */ + public function optionsAction(array $filterSettings) + { + $forcedConceptUids = GeneralUtility::trimExplode(',', $this->settings['forcedConceptUids'], true); + $excludedConceptUids = GeneralUtility::trimExplode(',', $this->settings['excludedConceptUids']); + $excludedRegionUids = GeneralUtility::trimExplode(',', $this->settings['excludedRegionUids']); + + $filterOptions = $this->filterService->getFilterOptions( + $filterSettings, + $excludedConceptUids, + $excludedRegionUids, + $forcedConceptUids + ); + + $this->view->assignMultiple([ + 'filterSettings' => $filterSettings, + 'filterOptions' => $filterOptions, + ]); + } + + /** + * @param array $filterSettings + */ + public function searchAction(array $filterSettings) + { + $uri = $this->uriBuilder + ->reset() + ->setCreateAbsoluteUri(true) + ->setTargetPageUid($this->settings['defaultSearchPageUid']) + ->uriFor( + 'searchresult', + ['filterSettings' => $filterSettings], + 'Search', + 'epproducts', + 'searchresult' + ); + + return json_encode($uri, JSON_THROW_ON_ERROR); + } +} diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/SearchController.php b/public/typo3conf/ext/ep_products/Classes/Controller/SearchController.php index 0b93dd51..bb21e4cc 100644 --- a/public/typo3conf/ext/ep_products/Classes/Controller/SearchController.php +++ b/public/typo3conf/ext/ep_products/Classes/Controller/SearchController.php @@ -74,19 +74,6 @@ class SearchController extends ActionController ]); } - public function searchboxAction() - { - $searchParams = $this->searchResultService->getNormalizedSearchParams(); - $filterSettings = $this->filterService->getNormalizedFilterSettings(); - $filterOptions = $this->filterService->getFilterOptions($filterSettings); - - $this->view->assignMultiple([ - 'filterSettings' => $filterSettings, - 'filterOptions' => $filterOptions, - 'searchParams' => $searchParams, - ]); - } - public function initializeProcessSearchAction() { $this->processSearchParamsArgument(); diff --git a/public/typo3conf/ext/ep_products/Configuration/TypoScript/setup.typoscript b/public/typo3conf/ext/ep_products/Configuration/TypoScript/setup.typoscript index 311aec7f..24d31bb4 100644 --- a/public/typo3conf/ext/ep_products/Configuration/TypoScript/setup.typoscript +++ b/public/typo3conf/ext/ep_products/Configuration/TypoScript/setup.typoscript @@ -148,6 +148,10 @@ tx_epproducts_ajax_json { 1 = pricetable 2 = searchresult } + AjaxFilterPanel { + 1 = options + 2 = search + } AjaxDate { 1 = dates } diff --git a/public/typo3conf/ext/ep_products/ext_localconf.php b/public/typo3conf/ext/ep_products/ext_localconf.php index b6c8a36c..351a0bda 100644 --- a/public/typo3conf/ext/ep_products/ext_localconf.php +++ b/public/typo3conf/ext/ep_products/ext_localconf.php @@ -295,6 +295,7 @@ $iconRegistry->registerIcon( 'ajax', [ 'AjaxSearch' => 'searchresult', + 'AjaxFilterPanel' => 'options,search', 'AjaxDate' => 'dates', 'AjaxContingent' => 'list,rooms', 'AjaxTable' => 'datestable,pricetable,pricetableHtml,eventPricetable,daytripRooms', @@ -304,6 +305,7 @@ $iconRegistry->registerIcon( ], [ 'AjaxSearch' => 'searchresult', + 'AjaxFilterPanel' => 'options,search', 'AjaxDate' => 'dates', 'AjaxContingent' => 'list,rooms', 'AjaxTable' => 'datestable,pricetable,pricetableHtml,eventPricetable,daytripRooms', diff --git a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/Library/SearchBox.typoscript b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/Library/SearchBox.typoscript deleted file mode 100644 index e73fe3b6..00000000 --- a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/Library/SearchBox.typoscript +++ /dev/null @@ -1,18 +0,0 @@ -lib.searchBox = USER -lib.searchBox { - userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run - extensionName = EpProducts - pluginName = searchbox - vendorName = EP - controller = Search - action = searchbox - switchableControllerActions { - Search { - 1 = searchbox - } - } - settings =< plugin.tx_epproducts.settings - settings.searchPageUid < plugin.tx_epproducts.settings.defaultSearchPageUid - persistence =< plugin.tx_epproducts.persistence - view =< plugin.tx_epproducts.view -} diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/contactform_controller.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/contactform_controller.js deleted file mode 100644 index c3122595..00000000 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/contactform_controller.js +++ /dev/null @@ -1,12 +0,0 @@ -import { Controller } from 'stimulus' - -export default class extends Controller { - - static targets = [ 'form', 'container' ] - - static values = { loading: Boolean } - - submit(e) { - - } -} diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/mobile_search_controller.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/mobile_search_controller.js new file mode 100644 index 00000000..ceab96be --- /dev/null +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/mobile_search_controller.js @@ -0,0 +1,89 @@ +import { Controller } from 'stimulus' +import { useFetch} from '../mixins/use_fetch' + +export default class extends Controller { + + static targets = [ + 'form', + 'container', + 'loadingIndicator', + 'dateFrom', + 'dateTo', + ] + + static values = { + optionsUri: String, + searchUri: String, + loading: Boolean, + show: Boolean, + } + + initialize() { + useFetch(this) + } + + open(e) { + if (e.detail === 'mobile-search') { + this.showValue = true + this.load() + } + } + + close() { + this.showValue = false + this.containerTarget.innerHTML = '' + } + + filter() { + this.load({ + method: 'POST', + body: new FormData(this.formTarget) + }) + } + + reset() { + this.load({ method: 'POST' }) + } + + load(options) { + this.loadingValue = true + fetch(this.optionsUriValue, options) + .then(this.checkStatus) + .then(this.parseHTML) + .then(html => { + this.containerTarget.innerHTML = html + }) + .finally(() => { + this.loadingValue = false + }) + } + + search() { + const options = { + method: 'POST', + body: new FormData(this.formTarget) + } + this.loadingValue = true + fetch(this.searchUriValue, options) + .then(this.checkStatus) + .then(this.parseJSON) + .then(uri => { + window.location = uri + }) + } + + selectDateRange(e) { + this.dateFromTarget.value = e.detail.from + this.dateToTarget.value = e.detail.to + this.filter() + } + + showValueChanged() { + this.element.classList.toggle('hidden', false === this.showValue) + } + + loadingValueChanged() { + this.containerTarget.classList.toggle('opacity-25', this.loadingValue === true) + this.loadingIndicatorTarget.classList.toggle('hidden', this.loadingValue === false) + } +} diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/pricetable_controller.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/pricetable_controller.js index 1a069b05..23ba02f4 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/pricetable_controller.js +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/pricetable_controller.js @@ -49,7 +49,7 @@ export default class extends Controller { this.busIconTargets.forEach(icon => { let busPrice = parseInt(icon.dataset.busPrice) let busIncluded = !!icon.dataset.busIncluded - icon.classList.toggle('hidden', this.hideBusIcon(busPrice, busIncluded)) + icon.classList.toggle('hidden', this.isHideBusIcon(busPrice, busIncluded)) }) if (this.hasSurchargeToggleLabelTarget) { let labelDefault = this.surchargeToggleLabelTarget.dataset.labelDefault @@ -86,7 +86,7 @@ export default class extends Controller { return minPrice } - hideBusIcon(busPrice, busIncluded) { + isHideBusIcon(busPrice, busIncluded) { return ( busPrice && this.modeValue !== 'surcharge' || busIncluded && this.modeValue === 'discount' diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/Frontpage.html b/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/Frontpage.html index 1bcfa646..4add3b5e 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/Frontpage.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/Frontpage.html @@ -16,7 +16,7 @@ - + diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/Subpage.html b/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/Subpage.html index 002f0f14..c297ebc5 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/Subpage.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/Subpage.html @@ -18,6 +18,7 @@ + diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/SubpageSidebarLeft.html b/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/SubpageSidebarLeft.html index 365249bf..c65cca4b 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/SubpageSidebarLeft.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/SubpageSidebarLeft.html @@ -26,6 +26,7 @@ + diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/SubpageSidebarRight.html b/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/SubpageSidebarRight.html index 332c5507..df6f1e9e 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/SubpageSidebarRight.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Layouts/Page/SubpageSidebarRight.html @@ -26,6 +26,7 @@ + diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Mainnav.html b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Mainnav.html index 957f2939..e3bdd491 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Mainnav.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Mainnav.html @@ -16,19 +16,15 @@
- - - - - + +
+ + -
- -
- - - -
-
- - - - -