Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #46 from fbergkemper/master
Browse files Browse the repository at this point in the history
Sorting via table header columns and result limits per page
  • Loading branch information
frabdev committed Sep 8, 2014
2 parents 390e9e2 + 6d29728 commit f451def
Show file tree
Hide file tree
Showing 32 changed files with 622 additions and 153 deletions.
7 changes: 5 additions & 2 deletions module/Client/config/module.config.php
Expand Up @@ -13,10 +13,13 @@
'client' => array(
'type' => 'segment',
'options' => array(
'route' => '/client[/][:action][/:id]',
'route' => '/client[/][:action][/:id][order_by/:order_by][/:order][/][limit/:limit]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '(?!\blimit\b)(?!\border_by\b)[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order' => 'ASC|DESC',
'limit' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Client\Controller\Client',
Expand Down
16 changes: 13 additions & 3 deletions module/Client/src/Client/Controller/ClientController.php
Expand Up @@ -14,11 +14,21 @@ class ClientController extends AbstractActionController

public function indexAction()
{
$paginator = $this->getClientTable()->fetchAll(true);
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'ClientId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$paginator = $this->getClientTable()->fetchAll(true, $order_by, $order);
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage(25);
$paginator->setItemCountPerPage($limit);

return new ViewModel(array('paginator' => $paginator));
return new ViewModel(
array(
'paginator' => $paginator,
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
)
);
}

public function detailsAction()
Expand Down
16 changes: 12 additions & 4 deletions module/Client/src/Client/Model/ClientTable.php
Expand Up @@ -34,12 +34,19 @@ public function getDbDriverConfig() {
return $config['db']['driver'];
}

public function fetchAll($paginated=false)
public function fetchAll($paginated=false, $order_by=null, $order=null)
{
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$select = new Select();
$select->from($bsqlch->strdbcompat("Client"));

if($order_by != null && $order != null) {
$select->order($bsqlch->strdbcompat($order_by) . " " . $order);
}
else {
$select->order($bsqlch->strdbcompat("ClientId") . " DESC");
}

if($paginated) {
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Client());
Expand All @@ -51,9 +58,10 @@ public function fetchAll($paginated=false)
$paginator = new Paginator($paginatorAdapter);
return $paginator;
}

$resultSet = $this->tableGateway->select();
return $resultSet;
else {
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}
}

public function getClient($id)
Expand Down
21 changes: 18 additions & 3 deletions module/Client/view/client/client/index.phtml
Expand Up @@ -3,11 +3,26 @@
$title = 'Clients';
$this->headTitle($title);

if($order_by == 'ClientId')
$url_order = $order == 'ASC' ? 'DESC' : 'ASC';
elseif($order_by == 'Name')
$url_order = $order == 'ASC' ? 'DESC' : 'ASC';
elseif($order_by == 'Uname')
$url_order = $order == 'ASC' ? 'DESC' : 'ASC';

?>

<h3 class="text-muted"><?php echo $title; ?></h3>
<hr />

<p>
Clients per page:
<a href="<?php echo $this->url('client', array('order_by' => $this->order_by, 'order' => $this->order, 'limit' => '10', null, null, true)); ?>">10</a> |
<a href="<?php echo $this->url('client', array('order_by' => $this->order_by, 'order' => $this->order, 'limit' => '25', null, null, true)); ?>">25</a> |
<a href="<?php echo $this->url('client', array('order_by' => $this->order_by, 'order' => $this->order, 'limit' => '50', null, null, true)); ?>">50</a> |
<a href="<?php echo $this->url('client', array('order_by' => $this->order_by, 'order' => $this->order, 'limit' => '100', null, null, true)); ?>">100</a>
</p>

<div class="row">

<div class="col-md-12">
Expand All @@ -18,9 +33,9 @@ $this->headTitle($title);
<table class="table table-striped table-hover" style="font-size: 9pt;">

<tr>
<th>Client</th>
<th>Name</th>
<th>Version</th>
<th><a href="<?php echo $this->url('client', array('order_by' => 'ClientId', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Client"); ?></a></th>
<th><a href="<?php echo $this->url('client', array('order_by' => 'Name', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Name"); ?></a></th>
<th><a href="<?php echo $this->url('client', array('order_by' => 'Uname', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Version"); ?></a></th>
<th>Autoprune</th>
<th>Fileretention</th>
<th>Jobretention</th>
Expand Down
7 changes: 5 additions & 2 deletions module/Fileset/config/module.config.php
Expand Up @@ -36,10 +36,13 @@
'fileset' => array(
'type' => 'segment',
'options' => array(
'route' => '/fileset[/][:action][/:id]',
'route' => '/fileset[/][:action][/:id][order_by/:order_by][/:order][/][limit/:limit]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '(?!\blimit\b)(?!\border_by\b)[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order' => 'ASC|DESC',
'limit' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Fileset\Controller\Fileset',
Expand Down
16 changes: 13 additions & 3 deletions module/Fileset/src/Fileset/Controller/FilesetController.php
Expand Up @@ -36,11 +36,21 @@ class FilesetController extends AbstractActionController

public function indexAction()
{
$paginator = $this->getFilesetTable()->fetchAll(true);
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'FileSetId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$paginator = $this->getFilesetTable()->fetchAll(true, $order_by, $order);
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage(25);
$paginator->setItemCountPerPage($limit);

return new ViewModel(array('paginator' => $paginator));
return new ViewModel(
array(
'paginator' => $paginator,
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
)
);
}

public function detailsAction()
Expand Down
17 changes: 12 additions & 5 deletions module/Fileset/src/Fileset/Model/FilesetTable.php
Expand Up @@ -57,12 +57,19 @@ public function getDbDriverConfig() {
return $config['db']['driver'];
}

public function fetchAll($paginated=false)
public function fetchAll($paginated=false, $order_by=null, $order=null)
{
$bsqlch = new BareosSqlCompatHelper($this->getDbDriverConfig());
$select = new Select();
$select->from($bsqlch->strdbcompat("FileSet"));

if($order_by != null && $order != null) {
$select->order($bsqlch->strdbcompat($order_by) . " " . $order);
}
else {
$select->order($bsqlch->strdbcompat("FileSetId") . " DESC");
}

if($paginated) {
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Fileset());
Expand All @@ -74,10 +81,10 @@ public function fetchAll($paginated=false)
$paginator = new Paginator($paginatorAdapter);
return $paginator;
}

$resultSet = $this->tableGateway->select();
return $resultSet;

else {
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}
}

public function getFileset($id)
Expand Down
23 changes: 19 additions & 4 deletions module/Fileset/view/fileset/fileset/index.phtml
Expand Up @@ -26,11 +26,26 @@
$title = 'Filesets';
$this->headTitle($title);

if($order_by == 'FileSetId')
$url_order = $order == 'ASC' ? 'DESC' : 'ASC';
elseif($order_by == 'FileSet')
$url_order = $order == 'ASC' ? 'DESC' : 'ASC';
elseif($order_by == 'CreateTime')
$url_order = $order == 'ASC' ? 'DESC' : 'ASC';

?>

<h3 class="text-muted"><?php echo $title; ?></h3>
<hr />

<p>
Filesets per page:
<a href="<?php echo $this->url('fileset', array('order_by' => $this->order_by, 'order' => $this->order, 'limit' => '10', null, null, true)); ?>">10</a> |
<a href="<?php echo $this->url('fileset', array('order_by' => $this->order_by, 'order' => $this->order, 'limit' => '25', null, null, true)); ?>">25</a> |
<a href="<?php echo $this->url('fileset', array('order_by' => $this->order_by, 'order' => $this->order, 'limit' => '50', null, null, true)); ?>">50</a> |
<a href="<?php echo $this->url('fileset', array('order_by' => $this->order_by, 'order' => $this->order, 'limit' => '100', null, null, true)); ?>">100</a>
</p>

<div class="row">

<div class="col-md-12">
Expand All @@ -41,10 +56,10 @@ $this->headTitle($title);
<table class="table table-striped table-hover" style="font-size: 9pt;">

<tr>
<th>Fileset</th>
<th>Name</th>
<th>MD5</th>
<th>Modified</th>
<th><a href="<?php echo $this->url('fileset', array('order_by' => 'FileSetId', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Fileset"); ?></a></th>
<th><a href="<?php echo $this->url('fileset', array('order_by' => 'FileSet', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Name"); ?></a></th>
<th><?php echo $this->translate("MD5"); ?></th>
<th><a href="<?php echo $this->url('fileset', array('order_by' => 'CreateTime', 'order' => $url_order, 'limit' => $this->limit)); ?>"><?php echo $this->translate("Modified"); ?></a></th>
</tr>

<?php foreach($this->paginator as $fileset) : ?>
Expand Down
7 changes: 5 additions & 2 deletions module/Job/config/module.config.php
Expand Up @@ -36,10 +36,13 @@
'job' => array(
'type' => 'segment',
'options' => array(
'route' => '/job[/][:action][/:id]',
'route' => '/job[/][:action][/][:id][order_by/:order_by][/:order][/][limit/:limit]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '(?!\blimit\b)(?!\border_by\b)[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order' => 'ASC|DESC',
'limit' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Job\Controller\Job',
Expand Down
78 changes: 53 additions & 25 deletions module/Job/src/Job/Controller/JobController.php
Expand Up @@ -39,15 +39,20 @@ class JobController extends AbstractActionController

public function indexAction()
{

$paginator = $this->getJobTable()->fetchAll(true);
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'JobId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$paginator = $this->getJobTable()->fetchAll(true, $order_by, $order);
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage(25);
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'paginator' => $paginator,
'allJobs' => $this->getJobTable()->fetchAll()
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
'allJobs' => $this->getJobTable()->fetchAll(),
)
);

Expand All @@ -68,59 +73,82 @@ public function detailsAction()

public function runningAction()
{
$paginator = $this->getJobTable()->getRunningJobs(true);
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'JobId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$paginator = $this->getJobTable()->getRunningJobs(true, $order_by, $order);
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage(25);
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'paginator' => $paginator,
'runningJobs' => $this->getJobTable()->getRunningJobs()
)
);
'paginator' => $paginator,
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
'runningJobs' => $this->getJobTable()->getRunningJobs()
)
);
}

public function waitingAction()
{
$paginator = $this->getJobTable()->getWaitingJobs(true);
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'JobId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$paginator = $this->getJobTable()->getWaitingJobs(true, $order_by, $order);
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage(25);
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'paginator' => $paginator,
'waitingJobs' => $this->getJobTable()->getWaitingJobs()
)
);
'paginator' => $paginator,
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
'waitingJobs' => $this->getJobTable()->getWaitingJobs()
)
);
}

public function unsuccessfulAction()
{
$paginator = $this->getJobTable()->getLast24HoursUnsuccessfulJobs(true);
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'JobId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$paginator = $this->getJobTable()->getLast24HoursUnsuccessfulJobs(true, $order_by, $order);
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage(25);
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'paginator' => $paginator,
'lastUnsuccessfulJobs' => $this->getJobTable()->getLast24HoursUnsuccessfulJobs(),
)
);
'paginator' => $paginator,
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
'lastUnsuccessfulJobs' => $this->getJobTable()->getLast24HoursUnsuccessfulJobs(),
)
);
}

public function successfulAction()
{
$paginator = $this->getJobTable()->getLast24HoursSuccessfulJobs(true);
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'JobId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';
$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$paginator = $this->getJobTable()->getLast24HoursSuccessfulJobs(true, $order_by, $order);
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage(25);
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'paginator' => $paginator,
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
'lastSuccessfulJobs' => $this->getJobTable()->getLast24HoursSuccessfulJobs(),
)
);

}

public function timelineAction()
Expand Down

0 comments on commit f451def

Please sign in to comment.