Skip to content
Snippets Groups Projects
Commit 9b317282 authored by Robert Lange's avatar Robert Lange Committed by Dorian Merz
Browse files

refs #19268 [finc] cover loader performance boost

* avoid redirect after list action in layout context
** override Vufind CartController::redirectToSource for bulk export and mail
** override Vufind CartController::deleteAction for bulk delete
** override Vufind RecordController::saveAction for saving favorites on result list
* use empty template for rendering messages in lightbox
** override Vufind RecordController::processSave instead of saveAction
** render messages in new message.phtml
parent 7dd7bda8
No related merge requests found
...@@ -41,6 +41,7 @@ $config = [ ...@@ -41,6 +41,7 @@ $config = [
'finc\Controller\DocumentDeliveryServiceController' => 'finc\Controller\DocumentDeliveryServiceControllerFactory', 'finc\Controller\DocumentDeliveryServiceController' => 'finc\Controller\DocumentDeliveryServiceControllerFactory',
'finc\Controller\Admin\I18nController' => 'finc\Controller\Admin\I18nControllerFactory', 'finc\Controller\Admin\I18nController' => 'finc\Controller\Admin\I18nControllerFactory',
'finc\Controller\RecordsController' => 'VuFind\Controller\AbstractBaseFactory', 'finc\Controller\RecordsController' => 'VuFind\Controller\AbstractBaseFactory',
'finc\Controller\CartController' => 'VuFind\Controller\CartControllerFactory',
], ],
'aliases' => [ 'aliases' => [
'AdminI18n' => 'finc\Controller\Admin\I18nController', 'AdminI18n' => 'finc\Controller\Admin\I18nController',
...@@ -50,6 +51,8 @@ $config = [ ...@@ -50,6 +51,8 @@ $config = [
'VuFind\Controller\MyResearchController' => 'finc\Controller\MyResearchController', 'VuFind\Controller\MyResearchController' => 'finc\Controller\MyResearchController',
'VuFind\Controller\RecordController' => 'finc\Controller\RecordController', 'VuFind\Controller\RecordController' => 'finc\Controller\RecordController',
'VuFind\Controller\RecordsController' => 'finc\Controller\RecordsController', 'VuFind\Controller\RecordsController' => 'finc\Controller\RecordsController',
'Cart' => 'finc\Controller\CartController',
'cart' => 'finc\Controller\CartController'
], ],
], ],
'controller_plugins' => [ 'controller_plugins' => [
......
<?php
/**
* Book Bag / Bulk Action Controller
*
* PHP version 7
*
* Copyright (C) Leipzig University Library 2021.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Controller
* @author Robert Lange <lange@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
namespace finc\Controller;
/**
* Book Bag / Bulk Action Controller
*
* @category VuFind
* @package Controller
* @author Robert Lange <lange@ub.uni-leipzig.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
class CartController extends \VuFind\Controller\CartController
{
/**
* Delete group of records from favorites.
*
* @return mixed
*/
public function deleteAction()
{
// Force login:
$user = $this->getUser();
if (!$user) {
return $this->forceLogin();
}
// Get target URL for after deletion:
$listID = $this->params()->fromPost('listID');
$newUrl = empty($listID)
? $this->url()->fromRoute('myresearch-favorites')
: $this->url()->fromRoute('userList', ['id' => $listID]);
// Fail if we have nothing to delete:
$ids = null === $this->params()->fromPost('selectAll')
? $this->params()->fromPost('ids')
: $this->params()->fromPost('idsAll');
if (!is_array($ids) || empty($ids)) {
$this->flashMessenger()->addMessage('bulk_noitems_advice', 'error');
// finc specific: dont redirect in layout context for performance reasons - page reloads after closing of lighbox anyway
if ($this->params()->fromPost('layout', $this->params()->fromQuery('layout')) === 'lightbox') {
return;
}
// finc specific - END
return $this->redirect()->toUrl($newUrl);
}
// Process the deletes if necessary:
if ($this->formWasSubmitted('submit')) {
$this->favorites()->delete($ids, $listID, $user);
$this->flashMessenger()->addMessage('fav_delete_success', 'success');
// finc specific: dont redirect in layout context for performance reasons - page reloads after closing of lighbox anyway
if ($this->params()->fromPost('layout', $this->params()->fromQuery('layout')) === 'lightbox') {
return;
}
// finc specific - END
return $this->redirect()->toUrl($newUrl);
}
// If we got this far, the operation has not been confirmed yet; show
// the necessary dialog box:
if (empty($listID)) {
$list = false;
} else {
$table = $this->getTable('UserList');
$list = $table->getExisting($listID);
}
return $this->createViewModel(
[
'list' => $list, 'deleteIDS' => $ids,
'records' => $this->getRecordLoader()->loadBatch($ids)
]
);
}
/**
* Support method: redirect to the page we were on when the bulk action was
* initiated.
*
* @param string $flashNamespace Namespace for flash message (null for none)
* @param string $flashMsg Flash message to set (ignored if namespace null)
*
* @return mixed
*/
public function redirectToSource($flashNamespace = null, $flashMsg = null)
{
// Set flash message if requested:
if (null !== $flashNamespace && !empty($flashMsg)) {
$this->flashMessenger()->addMessage($flashMsg, $flashNamespace);
}
// finc specific: dont redirect in layout context for performance reasons - page reloads after closing of lighbox anyway
if ($this->params()->fromPost('layout', $this->params()->fromQuery('layout')) === 'lightbox') {
$view = $this->createViewModel($this->params()->fromPost());
$view->setTemplate('default/flash-message');
return $view;
}
// finc specific - END
// If we entered the controller in the expected way (i.e. via the
// myresearchbulk action), we should have a source set in the followup
// memory. If that's missing for some reason, just forward to MyResearch.
if (isset($this->session->url)) {
$target = $this->session->url;
unset($this->session->url);
} else {
$target = $this->url()->fromRoute('myresearch-home');
}
return $this->redirect()->toUrl($target);
}
}
...@@ -31,6 +31,7 @@ namespace finc\Controller; ...@@ -31,6 +31,7 @@ namespace finc\Controller;
use finc\Rewrite\EblRewrite; use finc\Rewrite\EblRewrite;
use Zend\Log\LoggerAwareInterface as LoggerAwareInterface; use Zend\Log\LoggerAwareInterface as LoggerAwareInterface;
use Zend\View\View;
/** /**
* Record Controller * Record Controller
...@@ -61,4 +62,54 @@ class RecordController extends \VuFind\Controller\RecordController implements ...@@ -61,4 +62,54 @@ class RecordController extends \VuFind\Controller\RecordController implements
{ {
return $this->serviceLocator->get(EblRewrite::class); return $this->serviceLocator->get(EblRewrite::class);
} }
/**
* ProcessSave -- store the results of the Save action.
*
* @return mixed
*/
protected function processSave()
{
// Retrieve user object and force login if necessary:
if (!($user = $this->getUser())) {
return $this->forceLogin();
}
// Perform the save operation:
$driver = $this->loadRecord();
$post = $this->getRequest()->getPost()->toArray();
$tagParser = $this->serviceLocator->get('VuFind\Tags');
$post['mytags']
= $tagParser->parse($post['mytags'] ?? '');
$favorites = $this->serviceLocator
->get('VuFind\Favorites\FavoritesService');
$results = $favorites->save($post, $user, $driver);
// Display a success status message:
$listUrl = $this->url()->fromRoute('userList', ['id' => $results['listId']]);
$message = [
'html' => true,
'msg' => $this->translate('bulk_save_success') . '. '
. '<a href="' . $listUrl . '" class="gotolist">'
. $this->translate('go_to_list') . '</a>.'
];
$this->flashMessenger()->addMessage($message, 'success');
// finc specific: dont redirect in layout context for performance reasons
if ($this->params()->fromPost('layout', $this->params()->fromQuery('layout')) === 'lightbox') {
$view = $this->createViewModel($this->params()->fromPost());
$view->setTemplate('default/flash-message');
return $view;
}
// finc specific - END
// redirect to followup url saved in saveAction
if ($url = $this->getFollowupUrl()) {
$this->clearFollowupUrl();
return $this->redirect()->toUrl($url);
}
// No followup info found? Send back to record view:
return $this->redirectToRecord();
}
} }
<?=$this->flashmessages();?>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment