Skip to content

Commit

Permalink
Add new PreviousNextPaginator paginator
Browse files Browse the repository at this point in the history
This is because of `VisualPaginator` performance issues. Commit also
refactors all modules to use new `PreviousNextPaginator` instead
of `VisualPaginator`

remp/crm#2512

(cherry picked from commit f8819722b5c5b82992957ff6f37adfde2bb0cbf7)
  • Loading branch information
zoldia authored and rootpd committed Jul 29, 2022
1 parent 873f561 commit a784c89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
19 changes: 9 additions & 10 deletions src/Presenters/ScenariosAdminPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Crm\AdminModule\Presenters\AdminPresenter;
use Crm\ApiModule\Token\InternalToken;
use Crm\ApplicationModule\Components\VisualPaginator;
use Crm\ApplicationModule\Components\PreviousNextPaginator;
use Crm\OneSignalModule\Events\OneSignalNotificationEvent;
use Crm\ScenariosModule\Events\BannerEvent;
use Crm\ScenariosModule\Repository\ScenariosRepository;
Expand Down Expand Up @@ -38,18 +38,17 @@ public function __construct(
*/
public function renderDefault()
{
$products = $this->scenariosRepository->all();
$scenarios = $this->scenariosRepository->all();

$filteredCount = $this->template->filteredCount = $products->count('*');

$vp = new VisualPaginator();
$this->addComponent($vp, 'scenarios_vp');
$paginator = $vp->getPaginator();
$paginator->setItemCount($filteredCount);
$pnp = new PreviousNextPaginator();
$this->addComponent($pnp, 'paginator');
$paginator = $pnp->getPaginator();
$paginator->setItemsPerPage($this->onPage);

$this->template->vp = $vp;
$this->template->scenarios = $products->limit($paginator->getLength(), $paginator->getOffset());
$scenarios = $scenarios->limit($paginator->getLength(), $paginator->getOffset())->fetchAll();
$pnp->setActualItemCount(count($scenarios));

$this->template->scenarios = $scenarios;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/templates/ScenariosAdmin/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

<div class="col-md-12">
<h1>
{_scenarios.admin.scenarios.default.title}
<small>
/ {_system.total} {$filteredCount}
</small>
{_'scenarios.admin.scenarios.default.title'}

<a n:href="new" class="btn btn-success btn-lg pull-right"><i
class="fa fa-sliders-h"></i>
{_scenarios.admin.scenarios.default.new}
Expand Down Expand Up @@ -64,7 +62,7 @@
</tbody>
</table>

{control scenarios_vp}
{control paginator}
</div>

</div>

0 comments on commit a784c89

Please sign in to comment.