GeneratedConfigFileTable: move and refactor
This commit is contained in:
parent
374b6d4a60
commit
b016b1954b
|
@ -1,101 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
|
||||
class GeneratedConfigFileTable extends QuickTable
|
||||
{
|
||||
protected $deploymentId;
|
||||
|
||||
protected $activeFile;
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
$columns = array(
|
||||
'file_path' => 'cf.file_path',
|
||||
'size' => 'LENGTH(f.content)',
|
||||
'cnt_object' => 'f.cnt_object',
|
||||
'cnt_template' => 'f.cnt_template',
|
||||
'cnt_apply' => 'f.cnt_apply',
|
||||
'cnt_all' => "f.cnt_object || ' / ' || f.cnt_template || ' / ' || f.cnt_apply",
|
||||
'checksum' => 'LOWER(HEX(f.checksum))',
|
||||
'config_checksum' => 'LOWER(HEX(cf.config_checksum))',
|
||||
);
|
||||
|
||||
if ($this->connection->isPgsql()) {
|
||||
$columns['checksum'] = "LOWER(ENCODE(f.checksum, 'hex'))";
|
||||
$columns['config_checksum'] = "LOWER(ENCODE(cf.config_checksum, 'hex'))";
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function setActiveFilename($filename)
|
||||
{
|
||||
$this->activeFile = $filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getRowClasses($row)
|
||||
{
|
||||
if ($row->file_path === $this->activeFile) {
|
||||
return 'active';
|
||||
}
|
||||
|
||||
return parent::getRowClasses($row);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
$params = array(
|
||||
'config_checksum' => $row->config_checksum,
|
||||
'file_path' => $row->file_path
|
||||
);
|
||||
|
||||
if ($this->deploymentId) {
|
||||
$params['deployment_id'] = $this->deploymentId;
|
||||
}
|
||||
|
||||
return $this->url('director/config/file', $params);
|
||||
}
|
||||
|
||||
public function setDeploymentId($id)
|
||||
{
|
||||
$this->deploymentId = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'file_path' => $view->translate('File'),
|
||||
'cnt_all' => $view->translate('Object/Tpl/Apply'),
|
||||
/*
|
||||
'cnt_object' => $view->translate('Objects'),
|
||||
'cnt_template' => $view->translate('Templates'),
|
||||
'cnt_apply' => $view->translate('Apply rules'),
|
||||
*/
|
||||
'size' => $view->translate('Size'),
|
||||
);
|
||||
}
|
||||
|
||||
public function setConfigChecksum($checksum)
|
||||
{
|
||||
$this->enforceFilter('config_checksum', $checksum);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('cf' => 'director_generated_config_file'),
|
||||
array()
|
||||
)->join(
|
||||
array('f' => 'director_generated_file'),
|
||||
'cf.file_checksum = f.checksum',
|
||||
array()
|
||||
)->order('cf.file_path ASC');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class GeneratedConfigFileTable extends ZfQueryBasedTable
|
||||
{
|
||||
use DbHelper;
|
||||
|
||||
protected $searchColumns = ['file_path'];
|
||||
|
||||
protected $deploymentId;
|
||||
|
||||
protected $activeFile;
|
||||
|
||||
/** @var IcingaConfig */
|
||||
protected $config;
|
||||
|
||||
public static function load(IcingaConfig $config, Db $db)
|
||||
{
|
||||
$table = new static($db);
|
||||
$table->config = $config;
|
||||
$table->attributes()->set('data-base-target', '_self');
|
||||
return $table;
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
$counts = implode(' / ', [
|
||||
$row->cnt_object,
|
||||
$row->cnt_template,
|
||||
$row->cnt_apply
|
||||
]);
|
||||
|
||||
$tr = $this::row([
|
||||
$this->getFileLink($row),
|
||||
$counts,
|
||||
$row->size
|
||||
]);
|
||||
|
||||
if ($row->file_path === $this->activeFile) {
|
||||
$tr->attributes()->add('class', 'active');
|
||||
}
|
||||
|
||||
return $tr;
|
||||
}
|
||||
|
||||
public function setActiveFilename($filename)
|
||||
{
|
||||
$this->activeFile = $filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getFileLink($row)
|
||||
{
|
||||
$params = [
|
||||
'config_checksum' => $row->config_checksum,
|
||||
'file_path' => $row->file_path
|
||||
];
|
||||
|
||||
if ($this->deploymentId) {
|
||||
$params['deployment_id'] = $this->deploymentId;
|
||||
}
|
||||
|
||||
return Link::create($row->file_path, 'director/config/file', $params);
|
||||
}
|
||||
|
||||
public function setDeploymentId($id)
|
||||
{
|
||||
if ($id) {
|
||||
$this->deploymentId = (int) $id;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('File'),
|
||||
$this->translate('Object/Tpl/Apply'),
|
||||
$this->translate('Size'),
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
$columns = [
|
||||
'file_path' => 'cf.file_path',
|
||||
'size' => 'LENGTH(f.content)',
|
||||
'cnt_object' => 'f.cnt_object',
|
||||
'cnt_template' => 'f.cnt_template',
|
||||
'cnt_apply' => 'f.cnt_apply',
|
||||
'cnt_all' => "f.cnt_object || ' / ' || f.cnt_template || ' / ' || f.cnt_apply",
|
||||
'checksum' => 'LOWER(HEX(f.checksum))',
|
||||
'config_checksum' => 'LOWER(HEX(cf.config_checksum))',
|
||||
];
|
||||
|
||||
if ($this->isPgsql()) {
|
||||
$columns['checksum'] = "LOWER(ENCODE(f.checksum, 'hex'))";
|
||||
$columns['config_checksum'] = "LOWER(ENCODE(cf.config_checksum, 'hex'))";
|
||||
}
|
||||
|
||||
return $this->db()->select()->from(
|
||||
['cf' => 'director_generated_config_file'],
|
||||
$columns
|
||||
)->join(
|
||||
['f' => 'director_generated_file'],
|
||||
'cf.file_checksum = f.checksum',
|
||||
[]
|
||||
)->where(
|
||||
'config_checksum = ?',
|
||||
$this->quoteBinary($this->config->getChecksum())
|
||||
)->order('cf.file_path ASC');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue