Skip to content

Commit

Permalink
Implement pagination (CO-1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jun 23, 2019
1 parent 10c593c commit 77eebad
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 39 deletions.
6 changes: 6 additions & 0 deletions app/src/Controller/ApiUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
use Cake\Routing\Router;

class ApiUsersController extends StandardController {
public $paginate = [
'order' => [
'ApiUsers.username' => 'asc'
]
];

/**
* Callback run prior to the view rendering.
*
Expand Down
2 changes: 1 addition & 1 deletion app/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function beforeRender(\Cake\Event\Event $event) {

// Available Matchgrids
$this->loadModel('Matchgrids');
$this->set('vv_matchgrids', $this->Matchgrids->find('list')->find('activeMatchGrids')->toArray());
$this->set('vv_matchgrids', $this->Matchgrids->find('list')->find('activeMatchGrids')->order(['table_name' => 'ASC'])->toArray());

// The set of menu permissions, so the layout knows what to render
if($this->Authorization && $curUser) {
Expand Down
6 changes: 6 additions & 0 deletions app/src/Controller/AttributeGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
namespace App\Controller;

class AttributeGroupsController extends StandardController {
public $paginate = [
'order' => [
'AttributeGroups.name' => 'asc'
]
];

/**
* Authorization for this Controller, called by Auth component
* - postcondition: $vv_permissions set with calculated permissions for this Controller
Expand Down
6 changes: 6 additions & 0 deletions app/src/Controller/AttributesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
namespace App\Controller;

class AttributesController extends StandardController {
public $paginate = [
'order' => [
'Attributes.name' => 'asc'
]
];

/**
* Authorization for this Controller, called by Auth component
* - postcondition: $vv_permissions set with calculated permissions for this Controller
Expand Down
7 changes: 7 additions & 0 deletions app/src/Controller/PermissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
namespace App\Controller;

class PermissionsController extends StandardController {
public $paginate = [
'order' => [
'Matchgrids.table_name' => 'asc',
'Permissions.name' => 'asc'
]
];

/**
* Authorization for this Controller, called by Auth component
* - postcondition: $vv_permissions set with calculated permissions for this Controller
Expand Down
7 changes: 7 additions & 0 deletions app/src/Controller/RulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
namespace App\Controller;

class RulesController extends StandardController {
public $paginate = [
'order' => [
'Rules.confidence_mode' => 'asc',
'Rules.ordr' => 'asc'
]
];

/**
* Authorization for this Controller, called by Auth component
* - postcondition: $vv_permissions set with calculated permissions for this Controller
Expand Down
2 changes: 1 addition & 1 deletion app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function index() {
$query = $this->$modelsName->find();
}

$this->set($tableName, $this->Paginator->paginate($query));
$this->set($tableName, $this->Paginator->paginate($query, $this->paginate));

// Default index view title is model name
$this->set('vv_title', __('match.ct.'.$tableName, [99]));
Expand Down
30 changes: 30 additions & 0 deletions app/src/Locale/en_US/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ msgstr "Invalid format"
msgid "match.er.mgid"
msgstr "Could not find Matchgrid ID in request"

msgid "match.er.pagenum.exceeded"
msgstr "Page number may not be larger than {0}"

msgid "match.er.pagenum.nan"
msgstr "Page number must be an integer"

msgid "match.er.parse.json"
msgstr "Unknown type {0} for key {1} (parseFromJSON)"

Expand Down Expand Up @@ -330,6 +336,9 @@ msgstr "Welcome to {0}."
msgid "match.in.matchgrids.none"
msgstr "There are no matchgrids currently defined."

msgid "match.in.pagination.format"
msgstr "Page {{page}} of {{pages}}, Viewing {{start}}-{{end}} of {{count}}"

### Menu Items
msgid "match.me.platform"
msgstr "Platform"
Expand All @@ -356,6 +365,15 @@ msgstr "Edit"
msgid "match.op.edit.a"
msgstr "Edit {0}"

msgid "match.op.first"
msgstr "First"

msgid "match.op.go"
msgstr "Go"

msgid "match.op.last"
msgstr "Last"

msgid "match.op.login"
msgstr "Login"

Expand All @@ -371,6 +389,18 @@ msgstr "Manage {0}"
msgid "match.op.new"
msgstr "New"

msgid "match.op.next"
msgstr "Next"

msgid "match.op.page.display"
msgstr "Display"

msgid "match.op.page.goto"
msgstr "Go To Page"

msgid "match.op.previous"
msgstr "Previous"

msgid "match.op.reconcile"
msgstr "Reconcile Unresolved Requests"

Expand Down
109 changes: 109 additions & 0 deletions app/src/Template/Element/pagination.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/**
* COmanage Common Pagination Element
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package common
* @since COmanage Common v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

/**
* THIS FILE IS MASTERED IN THE COMMON REPOSITORY.
*/

// Which product are we?
$product = __('product.code');
?>

<div id="pagination">
<span class="paginationCounter">
<?= $this->Paginator->counter(['format' => __($product.'.in.pagination.format')]); ?>
</span>
<?php if($this->paginator->hasPage(2)): ?>
<span class="paginationFirst">
<?= $this->Paginator->first(__($product.'.op.first')); ?>
</span>
<span class="paginationPrev">
<?= $this->Paginator->prev(__($product.'.op.previous'), ['class' => 'disabled']); ?>
</span>
<span class="paginationNumbers">
<?= $this->Paginator->numbers(); ?>
</span>
<span class="paginationNext">
<?= $this->Paginator->next(__($product.'.op.next'), ['class' => 'disabled']); ?>
</span>
<span class="paginationLast">
<?= $this->Paginator->last(__($product.'.op.last')); ?>
</span>
<?php endif; ?>

<?php if($this->paginator->hasPage(2)): ?>
<!-- show the Goto page form if there is more than 1 page -->
<form id="goto-page"
class="pagination-form"
method="get"
onsubmit="gotoPage(this.pageNum.value,
<?= $this->Paginator->counter('{{pages}}');?>,
'<?= __($product.'.er.pagenum.nan');?>',
'<?= __($product.'.er.pagenum.exceeded', [$this->Paginator->counter('{{pages}}')]);?>');
return false;">
<label for="pageNum"><?= __($product.'.op.page.goto'); ?></label>
<input type="text" size="3" name="pageNum" id="pageNum"/>
<input type="submit" value="<?= __($product.'.op.go'); ?>"/>
</form>
<?php endif; ?>

<?php
if($this->Paginator->counter('{{pages}}') > 25) {
// Provide a form for setting the page limit.
// Default is 25 records, current maximum is 100.
// For now we will simply hard-code the options from 25 - 100.

print $this->Form->create(null, [ 'type' => 'get' ]);

// This is similar to Paginator->limitControl, but we have to manually
// re-insert query params that we want to maintain through the limit adjustment

$queryParams = ['page', 'sort', 'direct'];

if(!empty($vv_primary_link)) {
$queryParams[] = $vv_primary_link;
}

foreach($queryParams as $p) {
if(!empty($this->request->getQuery($p))) {
print $this->Form->hidden($p, ['default' => $this->request->getQuery($p)]);
}
}

print $this->Form->control('limit', [
'type' => 'select',
'label' => __($product.'.op.page.display'),
'value' => $this->request->getQuery('limit'),
'options' => [25 => 25, 50 => 50, 100 => 100],
'onChange' => 'this.form.submit()'
]);

print $this->Form->end();
}
?>
</div>

2 changes: 1 addition & 1 deletion app/src/Template/Permissions/columns.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
*/

$indexColumns = [
'matchgrid_id' => [ 'type' => 'fk' ],
'username' => [
'type' => 'link'
],
'matchgrid_id' => [ 'type' => 'fk' ],
'permission' => [
'type' => 'enum',
'class' => 'PermissionEnum'
Expand Down
Loading

0 comments on commit 77eebad

Please sign in to comment.