From 67925db1db55fe0365fcc30f03eefcd038a452ae Mon Sep 17 00:00:00 2001 From: Frank Bergkemper Date: Wed, 21 Oct 2015 17:53:19 +0200 Subject: [PATCH] Introduction of datatables This adds support for DataTables in the following modules: - Client - Storage - Volumes - Pools - Filesets - Jobs Signed-off-by: Frank Bergkemper --- module/Client/config/module.config.php | 7 +- .../Client/Controller/ClientController.php | 51 +- .../Client/src/Client/Model/ClientModel.php | 11 +- .../Client/view/client/client/details.phtml | 282 ++++++--- module/Client/view/client/client/index.phtml | 126 ++-- .../view/dashboard/dashboard/index.phtml | 16 +- module/Fileset/config/module.config.php | 7 +- .../Fileset/Controller/FilesetController.php | 47 +- .../src/Fileset/Model/FilesetModel.php | 2 +- .../view/fileset/fileset/details.phtml | 84 ++- .../Fileset/view/fileset/fileset/index.phtml | 91 +-- module/Job/config/module.config.php | 7 +- .../Job/src/Job/Controller/JobController.php | 210 +++---- module/Job/src/Job/Form/JobForm.php | 93 +++ module/Job/src/Job/Model/JobModel.php | 37 +- module/Job/view/job/job/details.phtml | 492 ++++++++++++++-- module/Job/view/job/job/index.phtml | 554 +++++++++++++++--- module/Job/view/job/job/run.phtml | 103 ++-- module/Job/view/job/job/running.phtml | 365 +++++++++--- module/Job/view/job/job/successful.phtml | 449 +++++++++++--- module/Job/view/job/job/unsuccessful.phtml | 382 +++++++++--- module/Job/view/job/job/waiting.phtml | 351 ++++++++--- module/Media/config/module.config.php | 7 +- .../src/Media/Controller/MediaController.php | 40 +- module/Media/view/media/media/index.phtml | 303 ++++++++-- module/Pool/config/module.config.php | 8 +- .../src/Pool/Controller/PoolController.php | 59 +- module/Pool/src/Pool/Model/PoolModel.php | 2 +- module/Pool/view/pool/pool/details.phtml | 424 +++++++++++--- module/Pool/view/pool/pool/index.phtml | 144 +++-- module/Storage/config/module.config.php | 9 +- .../Storage/Controller/StorageController.php | 47 +- .../Storage/view/storage/storage/index.phtml | 98 ++-- 33 files changed, 3757 insertions(+), 1151 deletions(-) create mode 100644 module/Job/src/Job/Form/JobForm.php diff --git a/module/Client/config/module.config.php b/module/Client/config/module.config.php index 5d6de3d6..d399a952 100644 --- a/module/Client/config/module.config.php +++ b/module/Client/config/module.config.php @@ -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', diff --git a/module/Client/src/Client/Controller/ClientController.php b/module/Client/src/Client/Controller/ClientController.php index 219e6d74..a81ee3ff 100644 --- a/module/Client/src/Client/Controller/ClientController.php +++ b/module/Client/src/Client/Controller/ClientController.php @@ -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 { @@ -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, ) ); } @@ -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') ) ); @@ -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) { @@ -87,4 +111,3 @@ public function getClientModel() } } - diff --git a/module/Client/src/Client/Model/ClientModel.php b/module/Client/src/Client/Model/ClientModel.php index b56c3fa8..42eb306f 100644 --- a/module/Client/src/Client/Model/ClientModel.php +++ b/module/Client/src/Client/Model/ClientModel.php @@ -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; @@ -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)) { diff --git a/module/Client/view/client/client/details.phtml b/module/Client/view/client/client/details.phtml index 2a6b1814..4e5a8c89 100644 --- a/module/Client/view/client/client/details.phtml +++ b/module/Client/view/client/client/details.phtml @@ -1,11 +1,33 @@ . + * + */ + $title = 'Client details'; $this->headTitle($title); ?> -
@@ -17,38 +39,15 @@ $this->headTitle($title);
- - - - - - - - - - - - - - - - - - - - - - +
ClientNameVersionAutopruneFileretentionJobretention
escapeHtml($this->client['clientid']); ?>escapeHtml($this->client['name']); ?>escapeHtml($this->client['uname']); ?>escapeHtml($this->client['autoprune']); ?>printRetention($this->client['fileretention']) . " days"; ?>printRetention($this->client['jobretention']) . " days"; ?> - Restore -
+ + + + + + + +
translate("Name"); ?>translate("Version"); ?>translate("Autoprune"); ?>translate("Fileretention"); ?>translate("Jobretention"); ?>translate("Actions"); ?>
@@ -61,50 +60,201 @@ $this->headTitle($title);
-

Last 10 successful backups

+

Last successful backups

- - - - - - - - - - - -backups != null) : ?> +
translate("Job"); ?>translate("Timestamp"); ?>translate("Fileset"); ?>translate("Level"); ?>translate("Files"); ?>translate("Bytes"); ?>
+ + + + + + + + +
translate("Job"); ?>translate("Timestamp"); ?>translate("Fileset"); ?>translate("Level"); ?>translate("Files"); ?>translate("Bytes"); ?>
-backups as $backup) : ?> +
+
+
+
- -escapeHtml($backup['jobid']); ?> -escapeHtml($backup['starttime']); ?> -escapeHtml($backup['fileset']); ?> -escapeHtml($this->printJobLevel($backup['level'])); ?> -escapeHtml($backup['jobfiles']); ?> -escapeHtml($this->printBytes($backup['jobbytes'])); ?> - +headScript()->prependFile($this->basePath() . '/js/jquery.dataTables.min.js'); + echo $this->headScript()->prependFile($this->basePath() . '/js/dataTables.bootstrap.min.js'); + echo $this->headLink()->prependStylesheet($this->basePath() . '/css/dataTables.bootstrap.min.css'); +?> - + diff --git a/module/Client/view/client/client/index.phtml b/module/Client/view/client/client/index.phtml index 1709dc85..bc0c44d9 100644 --- a/module/Client/view/client/client/index.phtml +++ b/module/Client/view/client/client/index.phtml @@ -39,70 +39,82 @@ $this->headTitle($title);
-

-Clients per page: -10 | -25 | -50 | -100 -

- - - - - - - - - - - - - -paginator as $client) : ?> - - - - - - - - - - - - - +
ClientNameVersionAutopruneFileretentionJobretention
escapeHtml($client['clientid']); ?>escapeHtml($client['name']); ?>escapeHtml($client['uname']); ?>escapeHtml($client['autoprune']); ?>printRetention($client['fileretention']) . " days"; ?>printRetention($client['jobretention']) . " days"; ?> Restore -
-
- - + translate("Name"); ?> + translate("Version"); ?> + translate("Actions"); ?> + -echo $this->paginationControl( - $this->paginator, - 'Elastic', - array('partial/paginator.phtml', 'Client'), - array('route' => 'client') - ); - -?> +
+headScript()->prependFile($this->basePath() . '/js/jquery.dataTables.min.js'); + echo $this->headScript()->prependFile($this->basePath() . '/js/dataTables.bootstrap.min.js'); + echo $this->headLink()->prependStylesheet($this->basePath() . '/css/dataTables.bootstrap.min.css'); +?> + + diff --git a/module/Dashboard/view/dashboard/dashboard/index.phtml b/module/Dashboard/view/dashboard/dashboard/index.phtml index 99bd36e8..d91b01ac 100644 --- a/module/Dashboard/view/dashboard/dashboard/index.phtml +++ b/module/Dashboard/view/dashboard/dashboard/index.phtml @@ -48,20 +48,20 @@ $this->headTitle($title); - - + + - - + + - - + + - - + +
translate("Running"); ?>runningJobs; ?>translate("Running"); ?>runningJobs; ?>
translate("Waiting"); ?>waitingJobs; ?>translate("Waiting"); ?>waitingJobs; ?>
translate("Successful"); ?>successfulJobs; ?>translate("Successful"); ?>successfulJobs; ?>
translate("Unsuccessful"); ?>unsuccessfulJobs; ?>translate("Unsuccessful"); ?>unsuccessfulJobs; ?>
diff --git a/module/Fileset/config/module.config.php b/module/Fileset/config/module.config.php index c9c50ec5..5fcabe09 100644 --- a/module/Fileset/config/module.config.php +++ b/module/Fileset/config/module.config.php @@ -40,13 +40,10 @@ 'fileset' => array( 'type' => 'segment', 'options' => array( - 'route' => '/fileset[/][:action][/][:id][order_by/:order_by][/:order][/][limit/:limit]', + 'route' => '/fileset[/][: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' => '[0-9]+', - 'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*', - 'order' => 'ASC|DESC', - 'limit' => '[0-9]+', ), 'defaults' => array( 'controller' => 'Fileset\Controller\Fileset', diff --git a/module/Fileset/src/Fileset/Controller/FilesetController.php b/module/Fileset/src/Fileset/Controller/FilesetController.php index 59239935..99f90ed0 100644 --- a/module/Fileset/src/Fileset/Controller/FilesetController.php +++ b/module/Fileset/src/Fileset/Controller/FilesetController.php @@ -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 FilesetController extends AbstractActionController { @@ -40,17 +39,10 @@ public function indexAction() if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { $filesets = $this->getFilesetModel()->getFilesets(); - $page = (int) $this->params()->fromQuery('page', 1); - $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; - - $paginator = new Paginator(new ArrayAdapter($filesets)); - $paginator->setCurrentPageNumber($page); - $paginator->setItemCountPerPage($limit); return new ViewModel( array( - 'paginator' => $paginator, - 'limit' => $limit, + 'filesets' => $filesets, ) ); } @@ -63,8 +55,8 @@ public function detailsAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $id = $this->params()->fromRoute('id', 0); - $fileset = $this->getFilesetModel()->getFileset($id); + $filesetid = $this->params()->fromRoute('id', 0); + $fileset = $this->getFilesetModel()->getFileset($filesetid); return new ViewModel( array( @@ -77,6 +69,37 @@ public function detailsAction() } } + public function getDataAction() + { + if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { + + $data = $this->params()->fromQuery('data'); + $fileset = $this->params()->fromQuery('fileset'); + + if($data == "all") { + $result = $this->getFilesetModel()->getFilesets(); + } + elseif($data == "details" && isset($fileset)) { + $result = $this->getFilesetModel()->getFileset($fileset); + } + 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 getFilesetModel() { if(!$this->filesetModel) { diff --git a/module/Fileset/src/Fileset/Model/FilesetModel.php b/module/Fileset/src/Fileset/Model/FilesetModel.php index e168cb75..202cea1c 100644 --- a/module/Fileset/src/Fileset/Model/FilesetModel.php +++ b/module/Fileset/src/Fileset/Model/FilesetModel.php @@ -63,7 +63,7 @@ public function getFileset($id) $this->director = $this->getServiceLocator()->get('director'); $result = $this->director->send_command($cmd, 2, null); $fileset = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $fileset['result']['filesets'][0]; + return $fileset['result']['filesets']; } else { return false; diff --git a/module/Fileset/view/fileset/fileset/details.phtml b/module/Fileset/view/fileset/fileset/details.phtml index 3dfcfdf6..92f1f93d 100644 --- a/module/Fileset/view/fileset/fileset/details.phtml +++ b/module/Fileset/view/fileset/fileset/details.phtml @@ -39,27 +39,20 @@ $this->headTitle($title);
- - - - - - - - - - - - - - - +
IdNameMD5Createtime
escapeHtml($fileset['filesetid']); ?>escapeHtml($fileset['fileset']); ?>escapeHtml($fileset['md5']); ?>escapeHtml($fileset['createtime']); ?>
+ + + + + + +
IdNameMD5 checksumCreation time
 
-escapeHtml($fileset['filesettext']); ?>
+escapeHtml($this->fileset[0]['filesettext']); ?>
 
 
@@ -67,3 +60,62 @@ $this->headTitle($title);
+ +headScript()->prependFile($this->basePath() . '/js/jquery.dataTables.min.js'); + echo $this->headScript()->prependFile($this->basePath() . '/js/dataTables.bootstrap.min.js'); + echo $this->headLink()->prependStylesheet($this->basePath() . '/css/dataTables.bootstrap.min.css'); +?> + + diff --git a/module/Fileset/view/fileset/fileset/index.phtml b/module/Fileset/view/fileset/fileset/index.phtml index 0ce7f5f7..e346207f 100644 --- a/module/Fileset/view/fileset/fileset/index.phtml +++ b/module/Fileset/view/fileset/fileset/index.phtml @@ -39,46 +39,67 @@ $this->headTitle($title);
-

-Filesets per page: -10 | -25 | -50 | -100 -

+ -
- - - - - - -paginator as $fileset) : ?> - - - - - - - - - + + + + +
translate("Fileset"); ?>translate("Modified"); ?>
escapeHtml($fileset['fileset']); ?>escapeHtml($fileset['createtime']); ?>
translate("Id"); ?>translate("Name"); ?>translate("Creation time"); ?>
-paginationControl( - $this->paginator, - 'Elastic', - array('partial/paginator.phtml', 'Fileset'), - array('route' => 'fileset') - ); - -?> -
+ +headScript()->prependFile($this->basePath() . '/js/jquery.dataTables.min.js'); + echo $this->headScript()->prependFile($this->basePath() . '/js/dataTables.bootstrap.min.js'); + echo $this->headLink()->prependStylesheet($this->basePath() . '/css/dataTables.bootstrap.min.css'); +?> + + diff --git a/module/Job/config/module.config.php b/module/Job/config/module.config.php index 43766463..1361d033 100644 --- a/module/Job/config/module.config.php +++ b/module/Job/config/module.config.php @@ -40,13 +40,10 @@ 'job' => array( 'type' => 'segment', 'options' => array( - 'route' => '/job[/][:action][/][:id][order_by/:order_by][/:order][/][limit/:limit]', + 'route' => '/job[/][: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' => '[0-9]+', - 'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*', - 'order' => 'ASC|DESC', - 'limit' => '[0-9]+', ), 'defaults' => array( 'controller' => 'Job\Controller\Job', diff --git a/module/Job/src/Job/Controller/JobController.php b/module/Job/src/Job/Controller/JobController.php index ac49cd1c..c4c3b041 100644 --- a/module/Job/src/Job/Controller/JobController.php +++ b/module/Job/src/Job/Controller/JobController.php @@ -28,8 +28,8 @@ use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; -use Zend\Paginator\Adapter\ArrayAdapter; -use Zend\Paginator\Paginator; +use Zend\Json\Json; +use Job\Form\JobForm; class JobController extends AbstractActionController { @@ -40,20 +40,22 @@ public function indexAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - $jobs = $this->getJobModel()->getJobs(); - $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; - $page = (int) $this->params()->fromQuery('page'); + $error = null; + $status = "all"; + $period = 7; - $paginator = new Paginator(new ArrayAdapter($jobs)); - $paginator->setCurrentPageNumber($page); - $paginator->setItemCountPerPage($limit); + $period = $this->params()->fromQuery('period') ? $this->params()->fromQuery('period') : '7'; + $status = $this->params()->fromQuery('status') ? $this->params()->fromQUery('status') : 'all'; - return new ViewModel( - array( - 'paginator' => $paginator, - 'limit' => $limit, - ) - ); + $form = new JobForm($period, $status); + + return new ViewModel( + array( + 'form' => $form, + 'status' => $status, + 'period' => $period + ) + ); } else { return $this->redirect()->toRoute('auth', array('action' => 'login')); @@ -71,6 +73,7 @@ public function detailsAction() return new ViewModel(array( 'job' => $job, 'joblog' => $joblog, + 'jobid' => $jobid )); } else { @@ -87,17 +90,8 @@ public function runningAction() $jobs = array_merge($jobs_R, $jobs_l); - $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; - $page = (int) $this->params()->fromQuery('page', 1); - - $paginator = new Paginator(new ArrayAdapter($jobs)); - $paginator->setCurrentPageNumber($page); - $paginator->setItemCountPerPage($limit); - return new ViewModel( array( - 'paginator' => $paginator, - 'limit' => $limit, 'jobs' => $jobs ) ); @@ -110,41 +104,7 @@ public function runningAction() public function waitingAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - - $jobs_F = $this->getJobModel()->getJobsByStatus('F', null, null); - $jobs_S = $this->getJobModel()->getJobsByStatus('S', null, null); - $jobs_m = $this->getJobModel()->getJobsByStatus('m', null, null); - $jobs_M = $this->getJobModel()->getJobsByStatus('M', null, null); - $jobs_s = $this->getJobModel()->getJobsByStatus('s', null, null); - $jobs_j = $this->getJobModel()->getJobsByStatus('j', null, null); - $jobs_c = $this->getJobModel()->getJobsByStatus('c', null, null); - $jobs_d = $this->getJobModel()->getJobsByStatus('d', null, null); - $jobs_t = $this->getJobModel()->getJobsByStatus('t', null, null); - $jobs_p = $this->getJobModel()->getJobsByStatus('p', null, null); - $jobs_q = $this->getJobModel()->getJobsByStatus('q', null, null); - $jobs_C = $this->getJobModel()->getJobsByStatus('C', null, null); - - $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; - $page = (int) $this->params()->fromQuery('page', 1); - - $jobs = array_merge( - $jobs_F,$jobs_S,$jobs_m,$jobs_M, - $jobs_s,$jobs_j,$jobs_c,$jobs_d, - $jobs_t,$jobs_p,$jobs_q,$jobs_C - ); - - $paginator = new Paginator(new ArrayAdapter($jobs)); - $paginator->setCurrentPageNumber($page); - $paginator->setItemCountPerPage($limit); - - return new ViewModel( - array( - 'paginator' => $paginator, - 'limit' => $limit, - 'jobs' => $jobs - ) - ); - + return new ViewModel(); } else { return $this->redirect()->toRoute('auth', array('action' => 'login')); @@ -154,27 +114,7 @@ public function waitingAction() public function unsuccessfulAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - - $jobs_A = $this->getJobModel()->getJobsByStatus('A', 1, null); // Canceled jobs last 24h - $jobs_E = $this->getJobModel()->getJobsByStatus('E', 1, null); // - $jobs_e = $this->getJobModel()->getJobsByStatus('e', 1, null); // - $jobs_f = $this->getJobModel()->getJobsByStatus('f', 1, null); // - - $jobs = array_merge($jobs_A, $jobs_E, $jobs_e, $jobs_f); - $page = (int) $this->params()->fromQuery('page', 1); - $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; - - $paginator = new Paginator(new ArrayAdapter($jobs)); - $paginator->setCurrentPageNumber($page); - $paginator->setItemCountPerPage($limit); - - return new ViewModel( - array( - 'jobs' => $jobs, - 'paginator' => $paginator, - 'limit' => $limit, - ) - ); + return new ViewModel(); } else { return $this->redirect()->toRoute('auth', array('action' => 'login')); @@ -184,25 +124,7 @@ public function unsuccessfulAction() public function successfulAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - - $jobs_T = $this->getJobModel()->getJobsByStatus('T', 1, null); // Terminated - $jobs_W = $this->getJobModel()->getJobsByStatus('W', 1, null); // Terminated with warnings - - $jobs = array_merge($jobs_T, $jobs_W); - $page = (int) $this->params()->fromQuery('page', 1); - $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; - - $paginator = new Paginator(new ArrayAdapter($jobs)); - $paginator->setCurrentPageNumber($page); - $paginator->setItemCountPerPage($limit); - - return new ViewModel( - array( - 'paginator' => $paginator, - 'limit' => $limit, - 'jobs' => $jobs, - ) - ); + return new ViewModel(); } else { return $this->redirect()->toRoute('auth', array('action' => 'login')); @@ -245,22 +167,7 @@ public function cancelAction() public function runAction() { if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { - - $jobs = $this->getJobModel()->getBackupJobs(); - $page = (int) $this->params()->fromQuery('page', 1); - $limit = $this->params()->fromRoute('limit') ? $this->params()->fromRoute('limit') : '25'; - - $paginator = new Paginator(new ArrayAdapter($jobs)); - $paginator->setCurrentPageNumber($page); - $paginator->setItemCountPerPage($limit); - - return new ViewModel( - array( - 'paginator' => $paginator, - 'jobs' => $jobs, - 'limit' => $limit - ) - ); + return new ViewModel(); } else { return $this->redirect()->toRoute('auth', array('action' => 'login')); @@ -283,6 +190,81 @@ public function queueAction() } } + public function getDataAction() + { + if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) { + + $data = $this->params()->fromQuery('data'); + $jobid = $this->params()->fromQuery('jobid'); + $status = $this->params()->fromQuery('status'); + $period = $this->params()->fromQuery('period'); + + if($data == "jobs" && $status == "all") { + $result = $this->getJobModel()->getJobs($status, $period); + } + elseif($data == "jobs" && $status == "successful") { + $jobs_T = $this->getJobModel()->getJobsByStatus('T', $period, null); // Terminated + $jobs_W = $this->getJobModel()->getJobsByStatus('W', $period, null); // Terminated with warnings + $result = array_merge($jobs_T, $jobs_W); + } + elseif($data == "jobs" && $status == "unsuccessful") { + $jobs_A = $this->getJobModel()->getJobsByStatus('A', $period, null); // Canceled jobs + $jobs_E = $this->getJobModel()->getJobsByStatus('E', $period, null); // + $jobs_e = $this->getJobModel()->getJobsByStatus('e', $period, null); // + $jobs_f = $this->getJobModel()->getJobsByStatus('f', $period, null); // + $result = array_merge($jobs_A, $jobs_E, $jobs_e, $jobs_f); + } + elseif($data == "jobs" && $status == "running") { + $jobs_R = $this->getJobModel()->getJobsByStatus('R', $period, null); + $jobs_l = $this->getJobModel()->getJobsByStatus('l', $period, null); + $result = array_merge($jobs_R, $jobs_l); + } + elseif($data == "jobs" && $status == "waiting") { + $jobs_F = $this->getJobModel()->getJobsByStatus('F', $period, null); + $jobs_S = $this->getJobModel()->getJobsByStatus('S', $period, null); + $jobs_m = $this->getJobModel()->getJobsByStatus('m', $period, null); + $jobs_M = $this->getJobModel()->getJobsByStatus('M', $period, null); + $jobs_s = $this->getJobModel()->getJobsByStatus('s', $period, null); + $jobs_j = $this->getJobModel()->getJobsByStatus('j', $period, null); + $jobs_c = $this->getJobModel()->getJobsByStatus('c', $period, null); + $jobs_d = $this->getJobModel()->getJobsByStatus('d', $period, null); + $jobs_t = $this->getJobModel()->getJobsByStatus('t', $period, null); + $jobs_p = $this->getJobModel()->getJobsByStatus('p', $period, null); + $jobs_q = $this->getJobModel()->getJobsByStatus('q', $period, null); + $jobs_C = $this->getJobModel()->getJobsByStatus('C', $period, null); + $result = array_merge( + $jobs_F,$jobs_S,$jobs_m,$jobs_M, + $jobs_s,$jobs_j,$jobs_c,$jobs_d, + $jobs_t,$jobs_p,$jobs_q,$jobs_C + ); + } + elseif($data == "backupjobs") { + $result = $this->getJobModel()->getBackupJobs(); + } + elseif($data == "details") { + $result = $this->getJobModel()->getJob($jobid); + } + elseif($data == "logs" && isset($jobid)) { + $result = $this->getJobModel()->getJobLog($jobid); + } + 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 getJobModel() { if(!$this->jobModel) { diff --git a/module/Job/src/Job/Form/JobForm.php b/module/Job/src/Job/Form/JobForm.php new file mode 100644 index 00000000..9101a641 --- /dev/null +++ b/module/Job/src/Job/Form/JobForm.php @@ -0,0 +1,93 @@ +. +* +*/ + +namespace Job\Form; + +use Zend\Form\Form; +use Zend\Form\Element; + +class JobForm extends Form +{ + + protected $period; + protected $status; + + public function __construct($period=null, $status=null) + { + parent::__construct('job'); + + $this->period = $period; + $this->status = $status; + + if(isset($period)) { + $this->add(array( + 'name' => 'period', + 'type' => 'select', + 'options' => array( + 'label' => 'Period', + 'value_options' => array( + '1' => 'past 24 hours', + '7' => 'last week', + '31' => 'last month', + '365' => 'last year', + 'all' => 'all' + ) + ), + 'attributes' => array( + 'class' => 'selectpicker', + 'data-size' => '5', + 'id' => 'period', + 'value' => $period + ) + )); + } + + if(isset($status)) { + $this->add(array( + 'name' => 'status', + 'type' => 'select', + 'options' => array( + 'label' => 'Status', + 'value_options' => array( + 'all' => 'all', + 'running' => 'running', + 'waiting' => 'waiting', + 'unsuccessful' => 'unsuccessful', + 'successful' => 'successful' + ) + ), + 'attributes' => array( + 'class' => 'selectpicker', + 'data-size' => '5', + 'id' => 'status', + 'value' => $status + ) + )); + } + + } + +} + diff --git a/module/Job/src/Job/Model/JobModel.php b/module/Job/src/Job/Model/JobModel.php index 0ab8da56..6a8808a6 100644 --- a/module/Job/src/Job/Model/JobModel.php +++ b/module/Job/src/Job/Model/JobModel.php @@ -47,23 +47,46 @@ public function getServiceLocator() return $this->serviceLocator; } - public function getJobs() + public function getJobs($status=null, $period=null) { - $cmd = 'llist jobs'; + if($period == "all") { + $cmd = 'llist jobs'; + } + else { + $cmd = 'llist jobs days='.$period; + } + $this->director = $this->getServiceLocator()->get('director'); $result = $this->director->send_command($cmd, 2, null); - $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return array_reverse($jobs['result']['jobs']); + if(preg_match('/Failed to send result as json. Maybe result message to long?/', $result)) { + //return false; + $error = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $error['result']['error']; + } + else { + $jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $jobs['result']['jobs']; + } } public function getJobsByStatus($status=null, $days=null, $hours=null) { if(isset($status)) { if(isset($days)) { - $cmd = 'llist jobs jobstatus='.$status.' days='.$days.''; + if($days == "all") { + $cmd = 'llist jobs jobstatus='.$status.''; + } + else { + $cmd = 'llist jobs jobstatus='.$status.' days='.$days.''; + } } elseif(isset($hours)) { - $cmd = 'llist jobs jobstatus='.$status.' hours='.$hours.''; + if($hours == "all") { + $cmd = 'llist jobs jobstatus='.$status.''; + } + else { + $cmd = 'llist jobs jobstatus='.$status.' hours='.$hours.''; + } } else { $cmd = 'llist jobs jobstatus='.$status.''; @@ -85,7 +108,7 @@ public function getJob($id=null) $this->director = $this->getServiceLocator()->get('director'); $result = $this->director->send_command($cmd, 2, null); $job = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); - return $job['result']['jobs'][0]; + return $job['result']['jobs']; } else { return false; diff --git a/module/Job/view/job/job/details.phtml b/module/Job/view/job/job/details.phtml index c35c4c72..910763b0 100644 --- a/module/Job/view/job/job/details.phtml +++ b/module/Job/view/job/job/details.phtml @@ -4,10 +4,10 @@ * * bareos-webui - Bareos Web-Frontend * - * @link https://github.com/bareos/bareos-webui for the canonical source repository - * @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/) - * @license GNU Affero General Public License (http://www.gnu.org/licenses/) - * @author Frank Bergkemper + * @link https://github.com/bareos/bareos-webui for the canonical source repository + * @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/) + * @license GNU Affero General Public License (http://www.gnu.org/licenses/) + * @author Frank Bergkemper * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -42,37 +42,39 @@ $this->headTitle($title);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
JobescapeHtml($job['jobid']); ?>Scheduled startprintDate($job['schedtime'], 'iso'); ?>StatusprintJobStatus($job['jobstatus']); ?>
NameescapeHtml($job['job']); ?>Real startprintDate($job['starttime'], 'iso'); ?>ErrorsescapeHtml($job['joberrors']); ?>
ClientescapeHtml($job['client']); ?>EndprintDate($job['endtime'], 'iso'); ?>FilesescapeHtml($job['jobfiles']); ?>
TypeprintJobType($job['type']); ?>FilesetescapeHtml($job['filesetid']); ?>BytesprintBytes($job['jobbytes']); ?>
LevelprintJobLevel($job['level']); ?>PoolescapeHtml($job['poolname']); ?>
+ + + + + + + + + + + +
JobNameClientFilesetTypeLevelPool
+ + + + + + + + + + +
Scheduled startReal startEndReal end
+ + + + + + + + +
FilesBytesErrorsStatus
@@ -94,21 +96,12 @@ $this->headTitle($title);
- - - - - - - - joblog as $log) : ?> +
TimestampMessage
- - - - - - + + + +
escapeHtml($log['time']); ?>escapeHtml($log['logtext'])); ?>
TimestampMessage
@@ -116,3 +109,404 @@ $this->headTitle($title);
+ + +headScript()->prependFile($this->basePath() . '/js/jquery.dataTables.min.js'); + echo $this->headScript()->prependFile($this->basePath() . '/js/dataTables.bootstrap.min.js'); + echo $this->headLink()->prependStylesheet($this->basePath() . '/css/dataTables.bootstrap.min.css'); +?> + + diff --git a/module/Job/view/job/job/index.phtml b/module/Job/view/job/job/index.phtml index 650af5b8..dc2c8688 100644 --- a/module/Job/view/job/job/index.phtml +++ b/module/Job/view/job/job/index.phtml @@ -30,18 +30,25 @@ $this->headTitle($title); ?>
-paginator) > 0) : ?> +
+ +
+ formRow($form->get('period')); ?> +
+ +
+ formRow($form->get('status')); ?> +
+ +
+ +
@@ -50,93 +57,476 @@ $this->headTitle($title);
-

History

+

Overview

-

-Jobs per page: -10 | -25 | -50 | -100 -

- - - - - - - - - - - - - - - - - -paginator as $job) : ?> - - - - - - - - - - - - - - - - - - - -
translate("Job"); ?>translate("Name"); ?>translate("Client"); ?>translate("Type"); ?>translate("Level"); ?>translate("Start"); ?>translate("End"); ?>translate("Files"); ?>translate("Bytes"); ?>translate("Status"); ?>
escapeHtml($job['jobid']); ?>escapeHtml($job['name']); ?>escapeHtml($job['client']); ?>printJobType($job['type']); ?>printJobLevel($job['level']); ?>printDate($job['starttime']); ?>printDate($job['endtime']); ?>escapeHtml($job['jobfiles']); ?>printBytes($job['jobbytes']); ?>printJobStatus($job['jobstatus']); ?> - - - " data-toggle="tooltip" data-placement="left"> - Rerun - - -
- - -echo $this->paginationControl( - $this->paginator, - 'Elastic', - array('partial/paginator.phtml', 'Job'), - array('route' => 'job') - ); + + + translate("Job"); ?> + translate("Name"); ?> + translate("Client"); ?> + translate("Type"); ?> + translate("Level"); ?> + translate("Start"); ?> + translate("End"); ?> + + + translate("Status"); ?> + translate("Actions"); ?> + -?> +
-allJobs) == 0) : ?> -
- -
    -
  • translate("No jobs found."); ?>
  • -
-
- +headScript()->prependFile($this->basePath() . '/js/jquery.dataTables.min.js'); + echo $this->headScript()->prependFile($this->basePath() . '/js/dataTables.bootstrap.min.js'); + echo $this->headLink()->prependStylesheet($this->basePath() . '/css/dataTables.bootstrap.min.css'); +?> + + + + + + diff --git a/module/Job/view/job/job/run.phtml b/module/Job/view/job/job/run.phtml index 4664c4bb..022db31d 100644 --- a/module/Job/view/job/job/run.phtml +++ b/module/Job/view/job/job/run.phtml @@ -30,12 +30,7 @@ $this->headTitle($title); ?> @@ -43,7 +38,7 @@ $this->headTitle($title);
-
+
@@ -53,53 +48,65 @@ $this->headTitle($title);
-

-Jobs per page: -10 | -25 | -50 | -100 -

- - - - - - - - -paginator as $job) : ?> - - - - - - +
translate("Name"); ?>
escapeHtml($job['name']); ?> - - -
+ + + +
translate("Name"); ?>translate("Actions"); ?>
-paginationControl( - $this->paginator, - 'Elastic', - array('partial/paginator.phtml', 'Job'), - array('route' => 'job') - ); - -?> -
+headScript()->prependFile($this->basePath() . '/js/jquery.dataTables.min.js'); + echo $this->headScript()->prependFile($this->basePath() . '/js/dataTables.bootstrap.min.js'); + echo $this->headLink()->prependStylesheet($this->basePath() . '/css/dataTables.bootstrap.min.css'); +?> + diff --git a/module/Job/view/job/job/running.phtml b/module/Job/view/job/job/running.phtml index c3e24a39..e6fef42a 100644 --- a/module/Job/view/job/job/running.phtml +++ b/module/Job/view/job/job/running.phtml @@ -3,7 +3,7 @@ /** * * bareos-webui - Bareos Web-Frontend - * + * * @link https://github.com/bareos/bareos-webui for the canonical source repository * @copyright Copyright (c) 2013-2014 Bareos GmbH & Co. KG (http://www.bareos.org/) * @license GNU Affero General Public License (http://www.gnu.org/licenses/) @@ -29,25 +29,6 @@ $this->headTitle($title); ?> -flashMessenger(); -$flash->setMessageOpenFormat(' - - -
  • ') - ->setMessageSeparatorString('
  • ') - ->setMessageCloseString('
'); - - echo $flash->render('error', array('alert', 'alert-dismissable', 'alert-danger')); - echo $flash->render('info', array('alert', 'alert-dismissable', 'alert-info')); - echo $flash->render('default', array('alert', 'alert-dismissable', 'alert-warning')); - echo $flash->render('success', array('alert', 'alert-dismissable', 'alert-success')); - -?> -