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

Commit

Permalink
Fileset: Native director connectivity
Browse files Browse the repository at this point in the history
Replaces database connection with native director connection.
  • Loading branch information
fbergkemper committed Sep 4, 2015
1 parent 213f551 commit ec20a4e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 149 deletions.
4 changes: 2 additions & 2 deletions module/Fileset/config/module.config.php
Expand Up @@ -43,7 +43,7 @@
'route' => '/fileset[/][:action][/:id][order_by/:order_by][/:order][/][limit/:limit]',
'constraints' => array(
'action' => '(?!\blimit\b)(?!\border_by\b)[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
'id' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order_by' => '[a-zA-Z][a-zA-Z0-9_-]*',
'order' => 'ASC|DESC',
'limit' => '[0-9]+',
Expand All @@ -53,7 +53,7 @@
'action' => 'index',
),
),

),
),
),
Expand Down
45 changes: 20 additions & 25 deletions module/Fileset/src/Fileset/Controller/FilesetController.php
Expand Up @@ -27,29 +27,30 @@

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

class FilesetController extends AbstractActionController
{

protected $filesetTable;
protected $director;

public function indexAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {
$order_by = $this->params()->fromRoute('order_by') ? $this->params()->fromRoute('order_by') : 'FileSetId';
$order = $this->params()->fromRoute('order') ? $this->params()->fromRoute('order') : 'DESC';

$filesets = $this->getFilesets();
$page = (int) $this->params()->fromQuery('page', 1);
$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 = new Paginator(new ArrayAdapter($filesets));
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($limit);

return new ViewModel(
array(
'paginator' => $paginator,
'order_by' => $order_by,
'order' => $order,
'limit' => $limit,
array(
'paginator' => $paginator,
'limit' => $limit,
)
);
}
Expand All @@ -61,19 +62,14 @@ public function indexAction()
public function detailsAction()
{
if($_SESSION['bareos']['authenticated'] == true && $this->SessionTimeoutPlugin()->timeout()) {
$id = (int) $this->params()->fromRoute('id', 0);
$fset = $this->getFilesetTable()->getFileSet($id);
$cmd = 'show fileset="' . $fset->fileset . '"';
$this->director = $this->getServiceLocator()->get('director');

if (!$id) {
return $this->redirect()->toRoute('fileset');
}
$id = $this->params()->fromRoute('id', 0);

$cmd = 'show fileset="' . $id . '"';
$this->director = $this->getServiceLocator()->get('director');

return new ViewModel(
array(
'fileset' => $this->getFilesetTable()->getFileset($id),
'history' => $this->getFilesetTable()->getFilesetHistory($id),
'configuration' => $this->director->send_command($cmd),
)
);
Expand All @@ -83,13 +79,12 @@ public function detailsAction()
}
}

private function getFilesetTable()
private function getFilesets()
{
if(!$this->filesetTable) {
$sm = $this->getServiceLocator();
$this->filesetTable = $sm->get('Fileset\Model\FilesetTable');
}
return $this->filesetTable;
$director = $this->getServiceLocator()->get('director');
$result = $director->send_command("list filesets", 2, null);
$filesets = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
return $filesets['result']['filesets'];
}

}
Expand Down
85 changes: 2 additions & 83 deletions module/Fileset/view/fileset/fileset/details.phtml
Expand Up @@ -5,7 +5,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/)
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -28,92 +28,11 @@ $this->headTitle($title);

?>

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

<div class="row">

<div class="col-md-6">
<div class="panel panel-default">

<div class="panel-heading">
<h3 class="panel-title">General Information</h3>
</div>

<div class="panel-body">

<table class="table table-striped table-hover" style="font-size: 9pt;">

<tr><td>Fileset ID</td><td><?php echo $this->escapeHtml($fileset->filesetid); ?></td></tr>
<tr><td>Fileset Name</td><td><?php echo $this->escapeHtml($fileset->fileset); ?></td></tr>
<tr><td>MD5</td><td><?php echo $this->escapeHtml($fileset->md5); ?></td></tr>
<tr><td>Modified</td><td><?php echo $this->escapeHtml($fileset->createtime); ?></td></tr>

</table>

</div>
</div>
</div>

</div>

<div class="row">

<div class="col-md-6">
<div class="panel panel-default">

<div class="panel-heading">
<h3 class="panel-title"><?php echo $this->translate("Current configuration"); ?></h3>
</div>

<div class="panel-body">
<pre style="font-size: 8pt;">
<pre>
<code>
<?php echo $this->configuration; ?>
</code>
</pre>
</div>

</div>

</div>
</div>

<div class="row">

<div class="col-md-6">
<div class="panel panel-default">

<div class="panel-heading">
<h3 class="panel-title"><?php echo $this->translate("History"); ?></h3>
</div>

<div class="panel-body">

<table class="table table-striped table-hover" style="font-size: 9pt;">

<tr>
<th>Modified</th>
<th>Fileset ID</th>
<th>MD5</th>
</tr>

<?php foreach($history as $fileset) : ?>

<tr>
<td><?php echo $this->escapeHtml($fileset->createtime); ?></td>
<td><?php echo $this->escapeHtml($fileset->filesetid); ?></td>
<td><?php echo $this->escapeHtml($fileset->md5); ?></td>
</tr>

<?php endforeach; ?>

</table>

</div>

</div>
</div>

</div>

51 changes: 12 additions & 39 deletions module/Fileset/view/fileset/fileset/index.phtml
Expand Up @@ -3,9 +3,9 @@
/**
*
* 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/)
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -26,71 +26,44 @@
$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>
<a href="<?php echo $this->url('fileset', array('limit' => '10', null, null, true)); ?>">10</a> |
<a href="<?php echo $this->url('fileset', array('limit' => '25', null, null, true)); ?>">25</a> |
<a href="<?php echo $this->url('fileset', array('limit' => '50', null, null, true)); ?>">50</a> |
<a href="<?php echo $this->url('fileset', array('limit' => '100', null, null, true)); ?>">100</a>
</p>

<div class="row">

<div class="col-md-12">
<div class="panel panel-default">

<div class="panel-body">

<table class="table table-striped table-hover" style="font-size: 9pt;">
<table class="table">

<tr>
<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>
<th><?php echo $this->translate("Fileset"); ?></th>
<th><?php echo $this->translate("Modified"); ?></th>
</tr>

<?php foreach($this->paginator as $fileset) : ?>

<tr>

<td><a href="<?php echo $this->url('fileset', array('action'=>'details', 'id' => $fileset->filesetid)); ?>"><?php echo $this->escapeHtml($fileset->filesetid); ?></a></td>
<td><?php echo $this->escapeHtml($fileset->fileset); ?></td>
<td><?php echo $this->escapeHtml($fileset->md5); ?></td>
<td><?php echo $this->printDate($fileset->createtime); ?></td>
<td><a href="<?php echo $this->url('fileset', array('action'=>'details', 'id' => $fileset['fileset'])); ?>"><?php echo $this->escapeHtml($fileset['fileset']); ?></a></td>
<td><?php echo $this->escapeHtml($fileset['createtime']); ?></td>

</tr>

<?php endforeach; ?>

</table>

</div>
</div>

<?php

echo $this->paginationControl(
$this->paginator,
$this->paginator,
'Elastic',
array('partial/paginator.phtml', 'Fileset'),
array('route' => 'fileset')
);

?>

</div>

</div>

0 comments on commit ec20a4e

Please sign in to comment.