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

Commit

Permalink
Introduction of datatables
Browse files Browse the repository at this point in the history
This adds support for DataTables in the following modules:

- Client
- Storage
- Volumes
- Pools
- Filesets
- Jobs

Signed-off-by: Frank Bergkemper <frank.bergkemper@dass-it.de>
  • Loading branch information
fbergkemper committed Nov 18, 2015
1 parent a3be545 commit 67925db
Show file tree
Hide file tree
Showing 33 changed files with 3,757 additions and 1,151 deletions.
7 changes: 2 additions & 5 deletions module/Client/config/module.config.php
Expand Up @@ -40,13 +40,10 @@
'client' => array(
'type' => 'segment',
'options' => array(
'route' => '/client[/][:action][/][:id][order_by/:order_by][/:order][/][limit/:limit]',
'route' => '/client[/][:action][/][:id]',
'constraints' => array(
'action' => '(?!\blimit\b)(?!\border_by\b)[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order' => 'ASC|DESC',
'limit' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Client\Controller\Client',
Expand Down
51 changes: 37 additions & 14 deletions module/Client/src/Client/Controller/ClientController.php
Expand Up @@ -27,8 +27,7 @@

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Paginator\Adapter\ArrayAdapter;
use Zend\Paginator\Paginator;
use Zend\Json\Json;

class ClientController extends AbstractActionController
{
Expand All @@ -39,17 +38,11 @@ public function indexAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {

$limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25';
$clients = $this->getClientModel()->getClients();

$paginator = new Paginator(new ArrayAdapter($clients));
$paginator->setCurrentPageNumber( (int) $this->params()->fromQuery('page', 1) );
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'paginator' => $paginator,
'limit' => $limit,
'clients' => $clients,
)
);
}
Expand All @@ -62,12 +55,9 @@ public function detailsAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {

$name = $this->params()->fromRoute('id');

return new ViewModel(
array(
'client' => $this->getClientModel()->getClient($name),
'backups' => $this->getClientModel()->getClientBackups($name, 10, "desc"),
'client' => $this->params()->fromRoute('id')
)
);

Expand All @@ -77,6 +67,40 @@ public function detailsAction()
}
}

public function getDataAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {

$data = $this->params()->fromQuery('data');
$client = $this->params()->fromQuery('client');

if($data == "all") {
$result = $this->getClientModel()->getClients();
}
elseif($data == "details" && isset($client)) {
$result = $this->getClientModel()->getClient($client);
}
elseif($data == "backups" && isset($client)) {
$result = $this->getClientModel()->getClientBackups($client, null, 'desc');
}
else {
$result = null;
}

$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');

if(isset($result)) {
$response->setContent(JSON::encode($result));
}

return $response;
}
else {
return $this->redirect()->toRoute('auth', array('action' => 'login'));
}
}

public function getClientModel()
{
if(!$this->clientModel) {
Expand All @@ -87,4 +111,3 @@ public function getClientModel()
}

}

11 changes: 8 additions & 3 deletions module/Client/src/Client/Model/ClientModel.php
Expand Up @@ -63,7 +63,7 @@ public function getClient($client=null)
$this->director = $this->getServiceLocator()->get('director');
$result = $this->director->send_command($cmd, 2, null);
$client = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $client['result']['clients'][0];
return $client['result']['clients'];
}
else {
return false;
Expand All @@ -72,8 +72,13 @@ public function getClient($client=null)

public function getClientBackups($client=null, $limit=null, $order=null)
{
if(isset($client, $limit, $order)) {
$cmd = 'llist backups client="'.$client.'" limit='.$limit.' order='.$order.'';
if(isset($client)) {
if(isset($limit, $order)) {
$cmd = 'llist backups client="'.$client.'" limit='.$limit.' order='.$order.'';
}
else {
$cmd = 'llist backups client="'.$client.'"';
}
$this->director = $this->getServiceLocator()->get('director');
$result = $this->director->send_command($cmd, 2, null);
if(preg_match("/Select/", $result)) {
Expand Down

0 comments on commit 67925db

Please sign in to comment.