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

refs #17712 [master] speed up deleting of single favorite and list items

* dont reload favorites because we use ajax in templates for single items
** early return when layout is lightbox
** for multiple items we still use bulk action in CartController
* dont set flash messages when deleting items
** override method performDeleteFavorite from vufind
** prevent delayed success messages when loading modals
** use VuFind.lightbox.alert with javascript in template instead (see 17711)
parent 19ed0e32
Branches
Tags
No related merge requests found
...@@ -26,9 +26,10 @@ ...@@ -26,9 +26,10 @@
* @link https://vufind.org Main Site * @link https://vufind.org Main Site
*/ */
namespace finc\Controller; namespace finc\Controller;
use Zend\Log\LoggerAwareInterface as LoggerAwareInterface,
Zend\Mvc\MvcEvent as MvcEvent; use Zend\Log\LoggerAwareInterface as LoggerAwareInterface;
use Zend\Mvc\Controller\Plugin\Url; use Zend\Mvc\Controller\Plugin\Url;
use Zend\Mvc\MvcEvent as MvcEvent;
/** /**
* Controller for the user account area. * Controller for the user account area.
...@@ -62,10 +63,131 @@ class MyResearchController extends \VuFind\Controller\MyResearchController imple ...@@ -62,10 +63,131 @@ class MyResearchController extends \VuFind\Controller\MyResearchController imple
//we achieve that by forcing the follow-up url to be the redirect //we achieve that by forcing the follow-up url to be the redirect
//but watch out, the redirect via followup will only work if the redirect url //but watch out, the redirect via followup will only work if the redirect url
//is schemed correctly //is schemed correctly
if (!is_string($redirect)) $this->flashMessenger()->addErrorMessage('Invalid data type for redirect'); if (!is_string($redirect)) {
elseif (!preg_match('/^https?\:\/\//',$redirect)) $this->flashMessenger()->addErrorMessage('Invalid Redirect: '.$redirect); $this->flashMessenger()->addErrorMessage('Invalid data type for redirect');
else $this->followup()->store(['finc-redirect' => $redirect]); } elseif (!preg_match('/^https?\:\/\//', $redirect)) {
$this->flashMessenger()->addErrorMessage('Invalid Redirect: ' . $redirect);
} else {
$this->followup()->store(['finc-redirect' => $redirect]);
}
} }
return parent::onDispatch($e); return parent::onDispatch($e);
} }
/**
* Send user's saved favorites from a particular list to the view
*
* @return mixed
*/
public function mylistAction()
{
// Fail if lists are disabled:
if (!$this->listsEnabled()) {
throw new ForbiddenException('Lists disabled');
}
// Check for "delete item" request; parameter may be in GET or POST depending
// on calling context.
$deleteId = $this->params()->fromPost(
'delete', $this->params()->fromQuery('delete')
);
if ($deleteId) {
$deleteSource = $this->params()->fromPost(
'source',
$this->params()->fromQuery('source', DEFAULT_SEARCH_BACKEND)
);
// If the user already confirmed the operation, perform the delete now;
// otherwise prompt for confirmation:
$confirm = $this->params()->fromPost(
'confirm', $this->params()->fromQuery('confirm')
);
if ($confirm) {
$layout = $this->params()->fromPost(
'layout', $this->params()->fromQuery('layout')
);
/* #17712 not necessary to fetch items after deleting by ajax */
$success = $this->performDeleteFavorite($deleteId, $deleteSource);
if ($layout === 'lightbox' || $success !== true) {
return $success;
}
} else {
return $this->confirmDeleteFavorite($deleteId, $deleteSource);
}
}
// If we got this far, we just need to display the favorites:
try {
$runner = $this->serviceLocator->get('VuFind\Search\SearchRunner');
// We want to merge together GET, POST and route parameters to
// initialize our search object:
$request = $this->getRequest()->getQuery()->toArray()
+ $this->getRequest()->getPost()->toArray()
+ ['id' => $this->params()->fromRoute('id')];
// Set up listener for recommendations:
$rManager = $this->serviceLocator
->get('VuFind\Recommend\PluginManager');
$setupCallback = function ($runner, $params, $searchId) use ($rManager) {
$listener = new RecommendListener($rManager, $searchId);
$listener->setConfig(
$params->getOptions()->getRecommendationSettings()
);
$listener->attach($runner->getEventManager()->getSharedManager());
};
$results = $runner->run($request, 'Favorites', $setupCallback);
return $this->createViewModel(
['params' => $results->getParams(), 'results' => $results]
);
} catch (ListPermissionException $e) {
if (!$this->getUser()) {
return $this->forceLogin();
}
throw $e;
}
}
/**
* Delete record
* Overrides Vufind method without flash messages
*
* @param string $id ID of record to delete
* @param string $source Source of record to delete
*
* @return bool|mixed
*
* @throws \Exception
**/
public function performDeleteFavorite($id, $source)
{
// Force login:
$user = $this->getUser();
if (!$user) {
return $this->forceLogin();
}
// Load/check incoming parameters:
$listID = $this->params()->fromRoute('id');
$listID = empty($listID) ? null : $listID;
if (empty($id)) {
throw new \Exception('Cannot delete empty ID!');
}
// Perform delete #17712 without setting messages
if (null !== $listID) {
// ...Specific List
$table = $this->getTable('UserList');
$list = $table->getExisting($listID);
$list->removeResourcesById($user, [$id], $source);
} else {
// ...My Favorites
$user->removeResourcesById([$id], $source);
}
// All done -- return true to indicate success.
return true;
}
} }
...@@ -208,6 +208,8 @@ if ($cover): ...@@ -208,6 +208,8 @@ if ($cover):
: $this->url('userList', ['id' => $list_id]); : $this->url('userList', ['id' => $list_id]);
$deleteUrlGet = $deleteUrl . '?delete=' . urlencode($id) . '&source=' . urlencode($source); $deleteUrlGet = $deleteUrl . '?delete=' . urlencode($id) . '&source=' . urlencode($source);
/* #17712 not necessary to fetch items after deleting by ajax in controller */
$deleteUrl .= '?layout=lightbox';
$dLabel = 'delete-label-' . preg_replace('[\W]', '-', $id); $dLabel = 'delete-label-' . preg_replace('[\W]', '-', $id);
?> ?>
<div class="dropdown"> <div class="dropdown">
......
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