forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 44
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
[FINNA-2662] Adjust loan history export to use paging #3076
Open
LuomaJuha
wants to merge
25
commits into
NatLibFi:dev
Choose a base branch
from
LuomaJuha:add-paging-to-history
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9c2bf86
Paging for exporting transaction history until work processor is impl…
LuomaJuha 3c602e0
Adjusted loan history to show form to download
LuomaJuha 9a549d9
Added csrf
LuomaJuha 0d6b1c2
QA
LuomaJuha 4cfe9cc
Adjusted translations
LuomaJuha 33616de
Adjustments to loan history downloading
LuomaJuha 5573fca
Added comments to template
LuomaJuha 2d99afd
Merge branch 'dev' into add-paging-to-history
LuomaJuha a19346e
Adjusted to fetch file from ajax handler
LuomaJuha c78eb63
Removed unused files and translations
LuomaJuha 4497c6d
Adjusted translation, reverted change to demo driver
LuomaJuha 81b6326
Adjusted page numbers
LuomaJuha 42c1d18
Remove useless ilsdefaults
LuomaJuha 00fe1dd
Adjusted comments
LuomaJuha 7ab3039
Removed unused use
LuomaJuha 701d067
Merge branch 'dev' into add-paging-to-history
LuomaJuha e473b62
Changed naming from transactions to checkouts
LuomaJuha 39061ab
Added comments
LuomaJuha 9ba8d20
Removed unused parameter type
LuomaJuha 6ca8bb4
Adjusted js comments
LuomaJuha 6931dbf
Removed test variable..
LuomaJuha 1d742b5
Adjusted to calculate history properly
LuomaJuha 6125ab8
Added test for GetCheckoutHistory
LuomaJuha c6a274c
small tuning to test
LuomaJuha dc5359c
Fix
LuomaJuha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
module/Finna/src/Finna/AjaxHandler/GetCheckoutHistory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
/** | ||
* GetCheckoutHistory AJAX handler | ||
* | ||
* PHP version 8 | ||
* | ||
* Copyright (C) The National Library of Finland 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 AJAX | ||
* @author Juha Luoma <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
|
||
namespace Finna\AjaxHandler; | ||
|
||
use Laminas\Mvc\Controller\Plugin\Params; | ||
use VuFind\Auth\ILSAuthenticator; | ||
use VuFind\Db\Entity\UserEntityInterface; | ||
use VuFind\ILS\Connection; | ||
use VuFind\ILS\PaginationHelper; | ||
use VuFind\Session\Settings as SessionSettings; | ||
|
||
/** | ||
* GetCheckoutHistory AJAX handler | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Juha Luoma <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
class GetCheckoutHistory extends \VuFind\AjaxHandler\AbstractIlsAndUserAction | ||
{ | ||
/** | ||
* Cache for patron | ||
* | ||
* @var array | ||
*/ | ||
protected array $cachedPatron = []; | ||
|
||
/** | ||
* Cache for function config. | ||
* | ||
* @var array | ||
*/ | ||
protected array $cachedFunctionConfig = []; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param SessionSettings $ss Session settings | ||
* @param Connection $ils ILS connection | ||
* @param ILSAuthenticator $ilsAuthenticator ILS authenticator | ||
* @param ?UserEntityInterface $user Logged in user (or null) | ||
* @param \VuFind\Record\Loader $recordLoader Record loader | ||
* @param int $batchLimit Config specified default batch limit | ||
* @param int $defaultPageSize Default page size set in config.ini | ||
*/ | ||
public function __construct( | ||
SessionSettings $ss, | ||
Connection $ils, | ||
ILSAuthenticator $ilsAuthenticator, | ||
?UserEntityInterface $user, | ||
protected \VuFind\Record\Loader $recordLoader, | ||
protected int $batchLimit = 1000, | ||
protected int $defaultPageSize = 50 | ||
) { | ||
parent::__construct($ss, $ils, $ilsAuthenticator, $user); | ||
} | ||
|
||
/** | ||
* Handle a request. | ||
* | ||
* @param Params $params Parameter helper from controller | ||
* | ||
* @return array [response data, HTTP status code] | ||
*/ | ||
public function handleRequest(Params $params) | ||
{ | ||
$this->disableSessionWrites(); // avoid session write timing bug | ||
$result = $this->getCheckoutHistoryResult(); | ||
if ($result['success'] === false) { | ||
return $this->formatResponse($result['message'], $result['status']); | ||
} | ||
return $this->formatResponse(['parts' => ceil(($result['function_result']['count'] ?? 1) / $this->batchLimit)]); | ||
} | ||
|
||
/** | ||
* Get checkout history result for user if available | ||
* | ||
* @param int $page First page to get from ils | ||
* @param ?int $limit Current limit for the page size or null for default | ||
* | ||
* @return array | ||
*/ | ||
public function getCheckoutHistoryResult(int $page = 1, ?int $limit = null): array | ||
{ | ||
$getErrorMessage = function ($message, $status) { | ||
$success = false; | ||
$message = $this->translate($message); | ||
return compact('success', 'message', 'status'); | ||
}; | ||
if (!$this->cachedPatron) { | ||
$this->cachedPatron = $this->ilsAuthenticator->storedCatalogLogin(); | ||
if (!$this->user || !$this->cachedPatron) { | ||
return $getErrorMessage('You must be logged in first', self::STATUS_HTTP_NEED_AUTH); | ||
} | ||
} | ||
// Check function config | ||
if (!$this->cachedFunctionConfig) { | ||
$this->cachedFunctionConfig = $this->ils->checkFunction('getMyTransactionHistory', $this->cachedPatron); | ||
if (false === $this->cachedFunctionConfig) { | ||
return $getErrorMessage('ils_action_unavailable', self::STATUS_HTTP_UNAVAILABLE); | ||
} | ||
} | ||
$paginationHelper = new PaginationHelper(); | ||
$pageOptions = $paginationHelper->getOptions( | ||
$page, | ||
null, | ||
$limit ?? $this->defaultPageSize, | ||
$this->cachedFunctionConfig | ||
); | ||
$result = $this->ils->getMyTransactionHistory($this->cachedPatron, $pageOptions['ilsParams']); | ||
if (isset($result['success']) && !$result['success']) { | ||
return $getErrorMessage('An error has occurred', self::STATUS_HTTP_ERROR); | ||
} | ||
return [ | ||
'success' => true, | ||
'status' => 'wat', | ||
'function_result' => $result, | ||
'pageOptions' => $pageOptions, | ||
]; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
module/Finna/src/Finna/AjaxHandler/GetCheckoutHistoryFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/** | ||
* Factory for GetCheckoutHistory Ajax handler | ||
* | ||
* PHP version 8 | ||
* | ||
* Copyright (C) The National Library of Finland 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 AJAX | ||
* @author Juha Luoma <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
|
||
namespace Finna\AjaxHandler; | ||
|
||
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; | ||
use Laminas\ServiceManager\Exception\ServiceNotFoundException; | ||
use Psr\Container\ContainerExceptionInterface as ContainerException; | ||
use Psr\Container\ContainerInterface; | ||
use VuFind\AjaxHandler\AbstractIlsAndUserActionFactory; | ||
|
||
/** | ||
* Factory for GetCheckoutHistory Ajax handler | ||
* | ||
* @category VuFind | ||
* @package AJAX | ||
* @author Juha Luoma <[email protected]> | ||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License | ||
* @link https://vufind.org/wiki/development Wiki | ||
*/ | ||
class GetCheckoutHistoryFactory extends AbstractIlsAndUserActionFactory | ||
{ | ||
/** | ||
* Create an object | ||
* | ||
* @param ContainerInterface $container Service manager | ||
* @param string $requestedName Service being created | ||
* @param null|array $options Extra options (optional) | ||
* | ||
* @return object | ||
* | ||
* @throws ServiceNotFoundException if unable to resolve the service. | ||
* @throws ServiceNotCreatedException if an exception is raised when | ||
* creating a service. | ||
* @throws ContainerException&\Throwable if any other error occurs | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function __invoke( | ||
ContainerInterface $container, | ||
$requestedName, | ||
array $options = null | ||
) { | ||
$config = $container->get(\VuFind\Config\PluginManager::class)->get('config'); | ||
$options = [ | ||
$container->get(\VuFind\Record\Loader::class), | ||
$config->Catalog->loan_history_download_batch_limit ?? 1000, | ||
$config->Catalog->historic_loan_page_size ?? 50, | ||
]; | ||
return parent::__invoke($container, $requestedName, $options); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tämä ei näytä vaikuttavan dropdownissa näkyvään sivumäärään.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ny pitäis taas vaikuttaa!