Skip to content

Commit

Permalink
Merge pull request #131 from jweiland-net/bugfix/html-response-not-set
Browse files Browse the repository at this point in the history
Bugfix/html response not set
  • Loading branch information
sfroemkenjw committed May 31, 2024
2 parents ccef596 + 13ea677 commit 246e443
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 33 deletions.
31 changes: 20 additions & 11 deletions Classes/Controller/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use JWeiland\Reserve\Service\DataTablesService;
use JWeiland\Reserve\Utility\CacheUtility;
use JWeiland\Reserve\Utility\OrderSessionUtility;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation as Extbase;
Expand Down Expand Up @@ -74,7 +75,7 @@ public function injectCancellationService(CancellationService $cancellationServi
$this->cancellationService = $cancellationService;
}

public function listAction(): void
public function listAction(): ResponseInterface
{
$facilities = $this->facilityRepository->findByUids(GeneralUtility::trimExplode(',', $this->settings['facility']));
$this->view->assign('facilities', $facilities);
Expand All @@ -89,9 +90,11 @@ public function listAction(): void
]
);
CacheUtility::addFacilityToCurrentPageCacheTags((int)$this->settings['facility']);

return $this->htmlResponse();
}

public function formAction(Period $period): void
public function formAction(Period $period): ResponseInterface
{
if (!$period->isBookable()) {
$this->redirect('list');
Expand All @@ -108,12 +111,14 @@ public function formAction(Period $period): void
$order = GeneralUtility::makeInstance(Order::class);
$order->setBookedPeriod($period);
$this->view->assign('order', $order);

return $this->htmlResponse();
}

/**
* @Extbase\Validate("JWeiland\Reserve\Domain\Validation\OrderValidator", param="order")
*/
public function createAction(Order $order, int $furtherParticipants = 0): void
public function createAction(Order $order, int $furtherParticipants = 0): ResponseInterface
{
if (!(
$order->_isNew()
Expand All @@ -125,13 +130,13 @@ public function createAction(Order $order, int $furtherParticipants = 0): void
'',
ContextualFeedbackSeverity::ERROR
);
$this->redirect('list');
return $this->redirect('list');
}

if ($this->checkoutService->checkout($order, (int)$this->settings['orderPid'], $furtherParticipants)) {
$this->checkoutService->sendConfirmationMail($order);
$this->addFlashMessage(LocalizationUtility::translate('reservation.created', 'reserve'));
$this->redirect('list');
return $this->redirect('list');
}

$this->addFlashMessage(
Expand All @@ -140,10 +145,10 @@ public function createAction(Order $order, int $furtherParticipants = 0): void
ContextualFeedbackSeverity::ERROR
);

$this->redirect('form', null, null, ['period' => $order->getBookedPeriod()]);
return $this->redirect('form', null, null, ['period' => $order->getBookedPeriod()]);
}

public function confirmAction(string $email, string $activationCode): void
public function confirmAction(string $email, string $activationCode): ResponseInterface
{
$order = $this->orderRepository->findByEmailAndActivationCode($email, $activationCode);
if ($order instanceof Order) {
Expand All @@ -153,7 +158,7 @@ public function confirmAction(string $email, string $activationCode): void
'',
ContextualFeedbackSeverity::INFO
);
$this->redirect('list');
return $this->redirect('list');
}
$this->checkoutService->confirm($order);
$this->view->assign('order', $order);
Expand All @@ -164,9 +169,11 @@ public function confirmAction(string $email, string $activationCode): void
ContextualFeedbackSeverity::ERROR
);
}

return $this->htmlResponse();
}

public function cancelAction(string $email, string $activationCode, bool $confirm = false): void
public function cancelAction(string $email, string $activationCode, bool $confirm = false): ResponseInterface
{
$order = $this->orderRepository->findByEmailAndActivationCode($email, $activationCode);

Expand All @@ -177,7 +184,7 @@ public function cancelAction(string $email, string $activationCode, bool $confir
'',
ContextualFeedbackSeverity::ERROR
);
$this->redirect('list');
return $this->redirect('list');
}

$redirect = true;
Expand Down Expand Up @@ -225,8 +232,10 @@ public function cancelAction(string $email, string $activationCode, bool $confir

if ($redirect) {
CacheUtility::clearPageCachesForPagesWithCurrentFacility($order->getBookedPeriod()->getFacility()->getUid());
$this->redirect('list');
return $this->redirect('list');
}

return $this->htmlResponse();
}

private function getAdditionalDefaultConfiguration(int $orderColumnBegin): array
Expand Down
21 changes: 15 additions & 6 deletions Classes/Controller/ManagementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use JWeiland\Reserve\Domain\Repository\PeriodRepository;
use JWeiland\Reserve\Domain\Repository\ReservationRepository;
use JWeiland\Reserve\Service\DataTablesService;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\JsonView;
Expand Down Expand Up @@ -55,27 +56,33 @@ protected function initializeView($view): void
]);
}

public function overviewAction(): void
public function overviewAction(): ResponseInterface
{
$this->view->assign(
'periods',
$this->periodRepository->findUpcomingAndRunningByFacilityUids(
[(int)$this->settings['facility']]
)
);

return $this->htmlResponse();
}

public function scannerAction(Period $period): void
public function scannerAction(Period $period): ResponseInterface
{
$this->view->assign('period', $period);

return $this->htmlResponse();
}

public function periodAction(Period $period): void
public function periodAction(Period $period): ResponseInterface
{
$this->view->assign('period', $period);

return $this->htmlResponse();
}

public function periodsOnSameDayAction(Period $period): void
public function periodsOnSameDayAction(Period $period): ResponseInterface
{
$this->view->assign(
'periods',
Expand All @@ -84,9 +91,11 @@ public function periodsOnSameDayAction(Period $period): void
(int)$this->settings['facility']
)
);

return $this->htmlResponse();
}

public function scanAction(Reservation $reservation, bool $entireOrder = false): string
public function scanAction(Reservation $reservation, bool $entireOrder = false): ResponseInterface
{
$view = $this->getJsonView();
$view->setVariablesToRender(['status']);
Expand Down Expand Up @@ -130,7 +139,7 @@ public function scanAction(Reservation $reservation, bool $entireOrder = false):
]
);

return $view->render();
return $this->jsonResponse($view->render());
}

protected function getJsonView(): JsonView
Expand Down
2 changes: 1 addition & 1 deletion Classes/DataHandler/FacilityClearCacheAfterUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function processDataHandlerResultAfterAllOperations(DataHandler $dataHand
protected function replaceNewWithIds(array $ids): array
{
foreach ($ids as &$id) {
if (is_string($id) && str_starts_with($id, 'NEW')) {
if (is_string($id) && str_starts_with($id, 'NEW') && isset($this->dataHandler->substNEWwithIDs[$id])) {
$id = $this->dataHandler->substNEWwithIDs[$id];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/CancellationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function cancel(

// Remove with DataHandler
$this->dataHandler->start([], []);
$this->dataHandler->deleteRecord('tx_yourext_domain_model_order', $order->getUid());
$this->dataHandler->deleteRecord('tx_reserve_domain_model_order', $order->getUid());
$this->dataHandler->process_datamap();

CacheUtility::clearPageCachesForPagesWithCurrentFacility($order->getBookedPeriod()->getFacility()->getUid());
Expand Down
16 changes: 13 additions & 3 deletions Classes/Service/FluidService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace JWeiland\Reserve\Service;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Fluid\View\StandaloneView;
Expand Down Expand Up @@ -42,6 +43,7 @@ public function configureStandaloneViewForMailing(StandaloneView $standaloneView
$standaloneView->setTemplateRootPaths(
$extbaseFrameworkConfiguration['view']['templateRootPaths'] ?? ['EXT:reserve/Resources/Private/Templates/']
);

$standaloneView->setLayoutRootPaths(
$extbaseFrameworkConfiguration['view']['layoutRootPaths'] ?? ['EXT:reserve/Resources/Private/Layouts/']
);
Expand All @@ -64,8 +66,8 @@ public function replaceMarkerByRenderedTemplate(
string $content,
array $vars = []
): string {
$view = self::getStandaloneView();
static::configureStandaloneViewForMailing($view);
$view = $this->getStandaloneView();
$this->configureStandaloneViewForMailing($view);
$view->assignMultiple($vars);
$view->setTemplate($template);

Expand All @@ -74,6 +76,14 @@ public function replaceMarkerByRenderedTemplate(

private function getStandaloneView(): StandaloneView
{
return GeneralUtility::makeInstance(StandaloneView::class);
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setRequest($this->getRequest());

return $view;
}

public function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
}
16 changes: 14 additions & 2 deletions Classes/Utility/QrCodeUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static function generateQrCode(Reservation $reservation): ResultInterface
sprintf(
'%s %s %s %s',
$bookedPeriod->getFacility()->getShortName() ?: $bookedPeriod->getFacility()->getName(),
strftime(
self::formatTime(
LocalizationUtility::translate('date_format', 'reserve'),
$bookedPeriod->getDate()->getTimestamp()
(int)$bookedPeriod->getDate()->getTimestamp()
),
$begin,
$bookedPeriod->getEnd() ? (' - ' . $bookedPeriod->getEnd()->format('H:i')) : ''
Expand Down Expand Up @@ -73,4 +73,16 @@ protected static function applyQrCodeSettingsFromFacility(BuilderInterface $buil
->logoResizeToWidth($facility->getQrCodeLogoWidth());
}
}

public static function formatTime(string $format, $timestamp = null): string
{
// Ensure the format is compatible with DateTime
$format = strtr($format, [
'%a' => 'D', '%d' => 'd', '%m' => 'm', '%Y' => 'Y',
'%H' => 'H', '%M' => 'i', '%S' => 's', '%B' => 'F',
]);

$dateTime = new \DateTime();
return $dateTime->setTimestamp($timestamp)->format($format);
}
}
3 changes: 3 additions & 0 deletions Configuration/TCA/tx_reserve_domain_model_order.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
'typeicon_classes' => [
'default' => 'tx_reserve_domain_model_order',
],
'security' => [
'ignorePageTypeRestriction' => true,
],
],
'types' => [
0 => [
Expand Down
3 changes: 3 additions & 0 deletions Configuration/TCA/tx_reserve_domain_model_period.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
'typeicon_classes' => [
'default' => 'tx_reserve_domain_model_period',
],
'security' => [
'ignorePageTypeRestriction' => true,
],
],
'types' => [
'1' => [
Expand Down
3 changes: 3 additions & 0 deletions Configuration/TCA/tx_reserve_domain_model_reservation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
'typeicon_classes' => [
'default' => 'tx_reserve_domain_model_reservation',
],
'security' => [
'ignorePageTypeRestriction' => true,
],
],
'types' => [
'1' => [
Expand Down
8 changes: 8 additions & 0 deletions Documentation/Changelog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
Changelog
=========

Version 3.0.1
=============

* [BUGFIX] HTML Response not set properly on controller
* [BUGFIX] StandAloneView initialization issue fixed
* [BUGFIX] Replaced deprecated function `strftime`
* [BUGFIX] Reserve management module broken because of relative path 'typo3conf' usage in javascript

Version 3.0.0
=============

Expand Down
2 changes: 1 addition & 1 deletion Documentation/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[general]

project = Reserve
version = 3.0.0
version = 3.0.1
release = 3.0
copyright = by jweiland.net

Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Partials/Scanner.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<f:translate key="scanner_unavailable"/>
</div>

<canvas id="canvas" hidden></canvas>
<canvas id="canvas" data-base-path="{f:uri.resource(path: 'JavaScript', extensionName: 'reserve')}" hidden></canvas>

<f:render partial="Reservations" arguments="{datatable: 1, reservations: reservations, showAdditionalInformation: 1}"/>
</html>
18 changes: 14 additions & 4 deletions Resources/Public/JavaScript/qrReader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
self.importScripts('/typo3conf/ext/reserve/Resources/Public/JavaScript/jsQR.js');
self.addEventListener("message", message => {
const { width, height, data } = message.data;
self.postMessage(jsQR(data, width, height));
});
if (message.data.basePath) {
// Import jsQR dynamically using the base path
self.importScripts(message.data.basePath + '/jsQR.js');

// Setup the message handler to process QR code data
self.addEventListener("message", function(message) {
const { width, height, data } = message.data;
self.postMessage(jsQR(data, width, height));
});

// Once the base path is set and script is imported, remove this listener
self.removeEventListener('message', message.callee);
}
});
4 changes: 3 additions & 1 deletion Resources/Public/JavaScript/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $(() => {
});

let canvasElement = document.getElementById('canvas');
let basePath = canvasElement.getAttribute('data-base-path');
let activeScan = false;
let video = null;
let codeInImage = null;
Expand Down Expand Up @@ -125,7 +126,8 @@ $(() => {
requestAnimationFrame(tick);
});

let qrReader = new Worker(`/typo3conf/ext/reserve/Resources/Public/JavaScript/qrReader.js`);
let qrReader = new Worker(basePath + '/qrReader.js');
qrReader.postMessage({basePath: basePath});
let qrReaderReady = true;

function tick(timestamp) {
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
{
"name": "Stefan Frömken",
"email": "projects@jweiland.net",
"role": "Lead Developer"
},
{
"name": "Hoja Mustaffa Abdul Latheef",
"email": "projects@jweiland.net",
"role": "Developer"
}
],
Expand Down
Loading

0 comments on commit 246e443

Please sign in to comment.