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

Fix first/last navigation. #3404

Merged
merged 4 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ protected function renderPagination(
string $template = 'search/pagination.phtml',
string $ulClass = ''
): ?string {
$paginationOptions = $results->getOptions()->supportsFirstLastNavigation()
? []
: ['disableFirst' => true, 'disableLast' => true];
$paginationOptions = [];
if ($ulClass) {
$paginationOptions['className'] = $ulClass;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ protected function addData(Results $searchObject): void
$data->limit = $searchObject->getParams()->getLimit();
$data->sort = $searchObject->getParams()->getSort();
$data->total = $searchObject->getResultTotal();
$data->firstlast = $searchObject->getOptions()
->supportsFirstLastNavigation();
$data->firstlast = $searchObject->getOptions()->recordFirstLastNavigationEnabled();

// save the IDs of records on the current page to the session
// so we can "slide" from one record to the next/previous records
Expand Down
37 changes: 33 additions & 4 deletions module/VuFind/src/VuFind/Search/Base/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,18 @@ abstract class Options implements TranslatorAwareInterface
protected $resultLimit = -1;

/**
* Is the first/last navigation scroller enabled?
* Is first/last navigation supported by the backend?
*
* @var bool
*/
protected $firstlastNavigation = false;
protected $firstLastNavigationSupported = true;

/**
* Is the record page first/last navigation scroller enabled?
*
* @var bool
*/
protected $recordPageFirstLastNavigation = false;

/**
* Should hierarchicalFacetFilters and hierarchicalExcludeFilters
Expand Down Expand Up @@ -1209,13 +1216,35 @@ public function getSearchBoxSearchClassId(): string
}

/**
* Should we include first/last options in result scroller navigation?
* Should we include first/last options in record page navigation?
*
* @return bool
*
* @deprecated Use recordFirstLastNavigationEnabled instead
*/
public function supportsFirstLastNavigation()
{
return $this->firstlastNavigation;
return $this->recordFirstLastNavigationEnabled();
}

/**
* Is first/last navigation supported by the backend
*
* @return bool
*/
public function firstLastNavigationSupported()
{
return $this->firstLastNavigationSupported;
}

/**
* Should we include first/last options in record page navigation?
*
* @return bool
*/
public function recordFirstLastNavigationEnabled()
{
return $this->firstLastNavigationSupported() && $this->recordPageFirstLastNavigation;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Search/Blender/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(\VuFind\Config\PluginManager $configLoader)
$this->facetsIni = $this->searchIni = 'Blender';
parent::__construct($configLoader);
// Make sure first-last navigation is never enabled since we cannot support:
$this->firstlastNavigation = false;
$this->firstLastNavigationSupported = false;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions module/VuFind/src/VuFind/Search/EDS/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public function __construct(
$facetConf->Advanced_Facet_Settings->translated_facets->toArray()
);
}
// Make sure first-last navigation is never enabled since we cannot support:
$this->firstLastNavigationSupported = false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Search/Solr/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function __construct(\VuFind\Config\PluginManager $configLoader)
isset($config->Record->first_last_navigation)
&& $config->Record->first_last_navigation
) {
$this->firstlastNavigation = true;
$this->recordPageFirstLastNavigation = true;
}

// Turn on highlighting if the user has requested highlighting or snippet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(\VuFind\Config\PluginManager $configLoader)
isset($config->Record->first_last_navigation)
&& $config->Record->first_last_navigation
) {
$this->firstlastNavigation = true;
$this->recordPageFirstLastNavigation = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,15 @@ public function testBottomPagination(): void
$session->visit($this->getVuFindUrl() . '/Search/Results');
$page = $session->getPage();

$this->unFindCss($page, '.pagination .page-first');
$this->findCss($page, '.pagination .page-last');
$this->assertEquals('1', $this->findCssAndGetText($page, '.pagination li.active'));
$secondPage = $this->findCss($page, '.pagination li', null, 1);
$secondPage->find('css', 'a')->click();
$this->waitForPageLoad($page);

$this->findCss($page, '.pagination .page-first');
$this->findCss($page, '.pagination .page-last');
$this->assertEquals('2', $this->findCssAndGetText($page, '.pagination li.active'));
}

Expand Down
1 change: 0 additions & 1 deletion themes/bootstrap3/templates/eds/search.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
// Load standard settings from the default search results screen:
$this->slot('side-facet-caption')->set('Refine Results');
$this->paginationOptions = ['disableFirst' => true, 'disableLast' => true];
echo $this->render('search/results.phtml');
11 changes: 7 additions & 4 deletions themes/bootstrap3/templates/search/pagination.phtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?php
$showFirstLast = $this->results->getOptions()->firstLastNavigationSupported();
?>
<?php if ($this->pageCount): ?>
<nav aria-label="<?=$this->transEscAttr('pagination_label')?>">
<?php
Expand All @@ -11,8 +14,8 @@
?>
<ul<?=$ulAttrs?>>
<?php if (isset($this->previous)): ?>
<?php if (!isset($this->options['disableFirst']) || !$this->options['disableFirst']): ?>
<li role="none">
<?php if ($showFirstLast): ?>
<li role="none" class="page-first">
<a href="<?=$this->results->getUrlQuery()->setPage(1)?>" aria-label="<?=$this->transEscAttr('page_first')?>">[1]</a>
</li>
<?php endif; ?>
Expand Down Expand Up @@ -43,8 +46,8 @@
<?=$this->icon('page-next') ?>
</a>
</li>
<?php if (!isset($this->options['disableLast']) || !$this->options['disableLast']): ?>
<li role="none">
<?php if ($showFirstLast): ?>
<li role="none" class="page-last">
<a href="<?=$this->results->getUrlQuery()->setPage($this->pageCount)?>" aria-label="<?=$this->transEscAttr('page_last')?>">[<?=$this->pageCount?>]</a>
</li>
<?php endif; ?>
Expand Down