Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi page selection in favorite list #3142

Merged
merged 29 commits into from Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eca5ca8
multi page selection in favorite list
ThoWagen Oct 4, 2023
b603f40
Merge branch 'dev' into pull-request/multi-page-selection
ThoWagen Oct 10, 2023
fccc3c9
select all on page and multi page selection parallel
ThoWagen Oct 10, 2023
93ef62e
made multi page selection configurable
ThoWagen Oct 10, 2023
389a763
created mink tests, fixed bugs and refactored
ThoWagen Oct 11, 2023
008f6ac
fixed cs
ThoWagen Oct 11, 2023
d42b2ce
Merge branch 'dev' into pull-request/multi-page-selection
ThoWagen Jan 22, 2024
dc1f699
small fixes
ThoWagen Jan 22, 2024
a800090
Fix typo.
demiankatz Jan 22, 2024
5102db7
refactored js
ThoWagen Feb 5, 2024
eea4678
Merge branch 'dev' into pull-request/multi-page-selection
ThoWagen Feb 5, 2024
85d1f4a
renamed configs and simplifed setupTest method
ThoWagen Feb 5, 2024
8114c1d
Merge branch 'pull-request/multi-page-selection' of github.com:ThoWag…
ThoWagen Feb 5, 2024
5a5dd64
clean up
ThoWagen Feb 12, 2024
db3fd8d
Merge branch 'dev' into pull-request/multi-page-selection
ThoWagen Feb 12, 2024
74c9f73
small fixes
ThoWagen Feb 12, 2024
8e5247f
updated copyright year
ThoWagen Feb 12, 2024
8f59064
hide checked_default checkbox
ThoWagen Feb 19, 2024
6773c8d
Merge branch 'dev' into pull-request/multi-page-selection
ThoWagen Feb 19, 2024
69686a4
Merge branch 'dev' into pull-request/multi-page-selection
ThoWagen Feb 27, 2024
b7394ef
added documentation and small fixes
ThoWagen Feb 27, 2024
9a2be33
hide select-all-global when js deactivated
ThoWagen Feb 27, 2024
eaa156e
added clear selection button
ThoWagen Feb 27, 2024
840af7e
Merge branch 'dev' into pull-request/multi-page-selection
demiankatz Feb 27, 2024
8792830
translate clear_selection in js
ThoWagen Feb 28, 2024
8eda649
fixed design problems
ThoWagen Feb 28, 2024
cc67d91
checking clear selection button in mink tests
ThoWagen Feb 28, 2024
e47bceb
Merge branch 'pull-request/multi-page-selection' of github.com:ThoWag…
ThoWagen Feb 28, 2024
9330354
changed default to match config.ini
ThoWagen Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/vufind/config.ini
Expand Up @@ -2441,6 +2441,15 @@ lists = enabled
; searches.ini, but used to control the page sizes of lists of favorites:
lists_default_limit = 20
;lists_limit_options = 10,20,40,60,80,100
; If multi page selection is activated one can select elements on one page in the favorite list
; and the elements will stay selected when switching to another page.
multi_page_favorites_selection = true
; Choose which type of select_all checkbox should be shown in the favorite list.
; on_page - selects all elements on the current page
; global - selects all elements of the current list (only works if multi page selection is enabled)
; both - shows on_page and global (only works if multi page selection is enabled)
; none - disable select_all checkboxes
checkbox_select_all_favorites_type = both
; This section controls what happens when a record title in a favorites list
; is clicked. VuFind can either embed the full result directly in the list using
; AJAX or can display it at its own separate URL as a full HTML page.
Expand Down
1 change: 1 addition & 0 deletions languages/de.ini
Expand Up @@ -1221,6 +1221,7 @@ See also = "Siehe auch"
see_all_ellipsis = "Alle anzeigen …"
Select this record = "Datensatz auswählen"
Select your carrier = "Wählen Sie Ihren Telefonanbieter aus"
select_all = "Alle Einträge auswählen"
select_all_on_page = "Alle Einträge der Seite auswählen"
select_item = "Titel für weitere Aktion auswählen"
select_item_checked_out_renew = "Titel zum Verlängern auswählen"
Expand Down
1 change: 1 addition & 0 deletions languages/en.ini
Expand Up @@ -1241,6 +1241,7 @@ See also = "See also"
see_all_ellipsis = "see all…"
Select this record = "Select this record"
Select your carrier = "Select your carrier"
select_all = "Select all entries"
select_all_on_page = "Select all entries on the page"
select_item = "Select item for further action"
select_item_checked_out_renew = "Select item for renewing"
Expand Down
22 changes: 7 additions & 15 deletions module/VuFind/src/VuFind/Controller/CartController.php
Expand Up @@ -31,6 +31,7 @@

use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\Session\Container;
use VuFind\Controller\Feature\ListItemSelectionTrait;
use VuFind\Exception\Forbidden as ForbiddenException;
use VuFind\Exception\Mail as MailException;

Expand All @@ -50,6 +51,7 @@
class CartController extends AbstractBase
{
use Feature\BulkActionControllerTrait;
use ListItemSelectionTrait;

/**
* Session container
Expand Down Expand Up @@ -179,9 +181,7 @@ public function homeAction()
$this->followup()->retrieveAndClear('cartAction');
$this->followup()->retrieveAndClear('cartIds');

$ids = null === $this->params()->fromPost('selectAll')
? $this->params()->fromPost('ids')
: $this->params()->fromPost('idsAll');
$ids = $this->getSelectedIds();

// Add items if necessary:
if (strlen($this->params()->fromPost('empty', '')) > 0) {
Expand Down Expand Up @@ -259,9 +259,7 @@ public function myresearchbulkAction()
public function emailAction()
{
// Retrieve ID list:
$ids = null === $this->params()->fromPost('selectAll')
? $this->params()->fromPost('ids', [])
: $this->params()->fromPost('idsAll', []);
$ids = $this->getSelectedIds();

// Retrieve follow-up information if necessary:
if (!is_array($ids) || empty($ids)) {
Expand Down Expand Up @@ -345,9 +343,7 @@ public function emailAction()
*/
public function printcartAction()
{
$ids = null === $this->params()->fromPost('selectAll')
? $this->params()->fromPost('ids')
: $this->params()->fromPost('idsAll');
$ids = $this->getSelectedIds();
if (!is_array($ids) || empty($ids)) {
return $this->redirectToSource('error', 'bulk_noitems_advice');
}
Expand Down Expand Up @@ -378,9 +374,7 @@ public function printcartAction()
public function exportAction()
{
// Get the desired ID list:
$ids = null === $this->params()->fromPost('selectAll')
? $this->params()->fromPost('ids', [])
: $this->params()->fromPost('idsAll', []);
$ids = $this->getSelectedIds();

// Get export tools:
$export = $this->export;
Expand Down Expand Up @@ -506,9 +500,7 @@ public function saveAction()

// Load record information first (no need to prompt for login if we just
// need to display a "no records" error message):
$ids = null === $this->params()->fromPost('selectAll')
? $this->params()->fromPost('ids', $this->params()->fromQuery('ids', []))
: $this->params()->fromPost('idsAll', []);
$ids = $this->getSelectedIds();
if (!is_array($ids) || empty($ids)) {
$ids = $this->followup()->retrieveAndClear('cartIds') ?? [];
}
Expand Down
@@ -0,0 +1,75 @@
<?php

/**
* List Item Selection
*
* PHP version 8
*
* Copyright (C) Hebis Verbundzentrale 2024.
*
* 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_Plugins
* @author David Lahm <lahm@uni-frankfurt.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/

namespace VuFind\Controller\Feature;

use function in_array;

/**
* List Item Selection
*
* @category VuFind
* @package Controller_Plugins
* @author David Lahm <lahm@uni-frankfurt.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/
trait ListItemSelectionTrait
{
/**
* Get selected ids
*
* @return array
*/
protected function getSelectedIds()
{
// Values may be stored as a default state (checked_default), a list of IDs that do not
// match the default state (non_default_ids), and a list of all IDs (all_ids_global). If these
// values are found, we need to calculate the selected list from them.
$checkedDefault = $this->params()->fromPost('checked_default') !== null;
demiankatz marked this conversation as resolved.
Show resolved Hide resolved
$nonDefaultIds = $this->params()->fromPost('non_default_ids');
$allIdsGlobal = $this->params()->fromPost('all_ids_global', '[]');
if ($nonDefaultIds !== null) {
$nonDefaultIds = json_decode($nonDefaultIds);
return array_values(array_filter(
json_decode($allIdsGlobal),
function ($id) use ($checkedDefault, $nonDefaultIds) {
$nonDefaultId = in_array($id, $nonDefaultIds);
return $checkedDefault xor $nonDefaultId;
}
));
}
// If we got this far, values were passed in a simpler format: a list of checked IDs (ids),
// a list of all IDs on the current page (idsAll), and whether the whole page is
// selected (selectAll):
return null === $this->params()->fromPost('selectAll')
? $this->params()->fromPost('ids', [])
: $this->params()->fromPost('idsAll', []);
}
}
6 changes: 3 additions & 3 deletions module/VuFind/src/VuFind/Controller/MyResearchController.php
Expand Up @@ -34,6 +34,7 @@
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\Session\Container;
use Laminas\View\Model\ViewModel;
use VuFind\Controller\Feature\ListItemSelectionTrait;
use VuFind\Exception\Auth as AuthException;
use VuFind\Exception\AuthEmailNotVerified as AuthEmailNotVerifiedException;
use VuFind\Exception\AuthInProgress as AuthInProgressException;
Expand Down Expand Up @@ -69,6 +70,7 @@ class MyResearchController extends AbstractBase
use Feature\BulkActionControllerTrait;
use Feature\CatchIlsExceptionsTrait;
use \VuFind\ILS\Logic\SummaryTrait;
use ListItemSelectionTrait;

/**
* Configuration loader
Expand Down Expand Up @@ -853,9 +855,7 @@ public function deleteAction()
: $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', []);
$ids = $this->getSelectedIds();

$actionLimit = $this->getBulkActionLimit('delete');
if (!is_array($ids) || empty($ids)) {
Expand Down
20 changes: 20 additions & 0 deletions module/VuFind/src/VuFind/Search/Favorites/Results.php
Expand Up @@ -89,6 +89,13 @@ class Results extends BaseResults implements AuthorizationServiceAwareInterface
*/
protected $facets;

/**
* All ids
*
* @var array
*/
protected $allIds;

/**
* Constructor
*
Expand Down Expand Up @@ -207,6 +214,9 @@ protected function performSearch()
$this->getParams()->getSort()
);
$this->resultTotal = count($rawResults);
$this->allIds = array_map(function ($result) {
return $result['source'] . '|' . $result['record_id'];
}, $rawResults->toArray());

// Apply offset and limit if necessary!
$limit = $this->getParams()->getLimit();
Expand Down Expand Up @@ -266,4 +276,14 @@ public function getListObject()
}
return $this->list;
}

/**
* Get all ids.
*
* @return array
*/
public function getAllIds()
{
return $this->allIds;
}
}