diff --git a/Classes/Controller/RecommenderController.php b/Classes/Controller/RecommenderController.php index 98c31008df43fff3acfe01196a45d0d3675ebac9..123e98c336de616408a54707d4fd4d00bc8c0269 100644 --- a/Classes/Controller/RecommenderController.php +++ b/Classes/Controller/RecommenderController.php @@ -37,7 +37,7 @@ class RecommenderController extends AbstractController * * @return void */ - public function mainAction() + public function searchAction() { $this->results = []; @@ -46,42 +46,56 @@ class RecommenderController extends AbstractController $this->abstract = !empty($this->requestData['abstract']) ? $this->requestData['abstract'] : ''; $this->references = !empty($this->requestData['references']) ? $this->requestData['references'] : ''; - try { - $response = $this->client->request( - 'POST', - 'search', - [ - 'json' => [ - 'title' => $this->requestData['title'], - 'abstract' => $this->requestData['abstract'], - 'references' => $this->requestData['references'], + // query results if there are search parameters delivered from the client + if (!empty($this->title) || !empty($this->abstract) || !empty($this->references)) { + try { + $response = $this->client->request( + 'POST', + 'search', + [ + 'json' => [ + 'title' => $this->requestData['title'], + 'abstract' => $this->requestData['abstract'], + 'references' => $this->requestData['references'], + ] ] - ] - ); + ); - if ($response->getStatusCode() === 200) { - $content = $response->getBody()->getContents(); - $result = json_decode($content); - foreach ($result->journals as $journal) { - $this->results[] = new Journal($journal); - } + if ($response->getStatusCode() === 200) { + $content = $response->getBody()->getContents(); + $result = json_decode($content); + foreach ($result->journals as $journal) { + $this->results[] = new Journal($journal); + } - $this->processResults(); + $this->processResults(); - $this->assignViewVariables($result); - } else { - $this->logger->error('Server response error: '.$response->getStatusCode()); - $this->view->assign('error','Server response error: '.$response->getStatusCode()); + $this->assignViewVariables($result); + } else { + $this->logger->error('Server response error: '.$response->getStatusCode()); + $this->view->assign('error','Server response error: '.$response->getStatusCode()); + } + } catch (\Exception $e) { + $this->logger->error('Request error: '.$e->getMessage()); + $this->view->assign('error', $e->getMessage()); } - } catch (\Exception $e) { - $this->logger->error('Request error: '.$e->getMessage()); - $this->view->assign('error', $e->getMessage()); } $this->view->assign('contact', $this->getContactPerson()); $this->view->assign('viewData', $this->viewData); } + /** + * The recommender function returning journals based on title etc. + * + * @return void + */ + public function mainAction() + { + $this->view->assign('contact', $this->getContactPerson()); + $this->view->assign('viewData', $this->viewData); + } + /** * Assign view variables. * diff --git a/Resources/Private/Partials/Recommender/Content.html b/Resources/Private/Partials/Recommender/Content.html index 0dc6a4552262b48cfe46e73f036f20d5c43b1a15..3b1682ed64388e2e0a13768a6f5859186d4c8236 100644 --- a/Resources/Private/Partials/Recommender/Content.html +++ b/Resources/Private/Partials/Recommender/Content.html @@ -26,7 +26,7 @@ </f:if> <f:if condition="{error}"> <h2><f:translate key="message.error.header"/></h2> - <p><f:translate key="message.error.content" arguments="{count: '{error'}"/></p> + <p><f:translate key="message.error.content" arguments="{count: '{error}'}"/></p> </f:if> </div> </div> diff --git a/Resources/Private/Partials/Recommender/Form.html b/Resources/Private/Partials/Recommender/Form.html index cda5d6ac568abb249fc7cd8308840b65da263e00..bdf91ba3be4968544ccb4f969dd154d34b8fc13c 100644 --- a/Resources/Private/Partials/Recommender/Form.html +++ b/Resources/Private/Partials/Recommender/Form.html @@ -1,6 +1,6 @@ <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> -<f:form action="main" controller="Recommender" name="filterParameter" method="post" class="mt-5"> +<f:form action="search" controller="Recommender" name="filterParameter" method="post" class="mt-5"> <div> <label for="input-title"><f:translate key="label.title" default="Title"/></label> <div> diff --git a/Resources/Private/Templates/Recommender/Search.html b/Resources/Private/Templates/Recommender/Search.html new file mode 100644 index 0000000000000000000000000000000000000000..ecb12b1693656db533b26407211c7cc4e83f4631 --- /dev/null +++ b/Resources/Private/Templates/Recommender/Search.html @@ -0,0 +1,15 @@ +<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" + data-namespace-typo3-fluid="true"> + +<f:layout name="Standard" /> + +<f:section name="Content"> + <f:render partial="Recommender/Content" arguments="{_all}"/> +</f:section> + +<f:section name="FooterAssets"> + <script src="/typo3conf/ext/bison/Resources/Public/JavaScript/Recommender/main.js" type="text/javascript"></script> +</f:section> + +</html> + diff --git a/ext_localconf.php b/ext_localconf.php index f1375a0c39e301cea3c5eb89fcd1324bcec1cf8b..08b84c74ab131ab2cb3e0476f9f20dace4d2d13a 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -22,11 +22,11 @@ defined('TYPO3') || die(); 'Bison', 'Recommender', [ - \Slub\Bison\Controller\RecommenderController::class => 'main' + \Slub\Bison\Controller\RecommenderController::class => 'main, search' ], // non-cacheable actions [ - \Slub\Bison\Controller\RecommenderController::class => 'main' + \Slub\Bison\Controller\RecommenderController::class => 'search' ] );