IcingaHostServiceTable, others: cleanup, fix...

...blacklist-styling
This commit is contained in:
Thomas Gelf 2018-05-30 00:45:08 +02:00
parent c2519b65b5
commit 31a6ab0cf2
6 changed files with 40 additions and 23 deletions

View File

@ -76,7 +76,6 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable
/**
* @return \Icinga\Data\SimpleQuery
* @throws \Icinga\Exception\IcingaException
*/
public function prepareQuery()
{
@ -100,7 +99,6 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable
/***
* @return array
* @throws \Icinga\Exception\IcingaException
*/
protected function getAllApplyRules()
{
@ -116,7 +114,6 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable
/**
* @return array
* @throws \Icinga\Exception\IcingaException
*/
protected function fetchAllApplyRules()
{

View File

@ -13,6 +13,7 @@ class IcingaHostServiceTable extends ZfQueryBasedTable
/** @var IcingaHost */
protected $host;
/** @var IcingaHost */
protected $inheritedBy;
protected $searchColumns = [
@ -51,9 +52,15 @@ class IcingaHostServiceTable extends ZfQueryBasedTable
public function renderRow($row)
{
if ($row->blacklisted === 'y') {
$attributes = ['class' => 'strike-links'];
} else {
$attributes = null;
}
return $this::row([
$this->getServiceLink($row)
]);
], $attributes);
}
protected function getServiceLink($row)
@ -95,9 +102,15 @@ class IcingaHostServiceTable extends ZfQueryBasedTable
];
}
/**
* @return \Zend_Db_Select
* @throws \Zend_Db_Select_Exception
*/
public function prepareQuery()
{
return $this->db()->select()->from(
$db = $this->db();
$query = $db->select()->from(
['s' => 'icinga_service'],
[
'id' => 's.id',
@ -114,5 +127,23 @@ class IcingaHostServiceTable extends ZfQueryBasedTable
's.host_id = ?',
$this->host->get('id')
)->order('s.object_name');
if ($this->inheritedBy) {
$query->joinLeft(
['hsb' => 'icinga_host_service_blacklist'],
$db->quoteInto(
's.id = hsb.service_id AND hsb.host_id = ?',
$this->inheritedBy->get('id')
),
[]
);
$query->columns([
'blacklisted' => "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END"
]);
} else {
$query->columns(['blacklisted' => "('n')"]);
}
return $query;
}
}

View File

@ -81,8 +81,6 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
/**
* @param $row
* @return Link
* @throws \Icinga\Exception\IcingaException
* @throws \Icinga\Exception\ProgrammingError
*/
protected function getServiceLink($row)
{
@ -136,8 +134,6 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
/**
* @param HtmlElement $parent
* @throws \Icinga\Exception\IcingaException
* @throws \Icinga\Exception\ProgrammingError
*/
protected function addHostHeaderTo(HtmlElement $parent)
{
@ -180,7 +176,6 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
/**
* @return \Zend_Db_Select
* @throws \Icinga\Exception\IcingaException
* @throws \Zend_Db_Select_Exception
*/
public function prepareQuery()
@ -218,7 +213,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
'blacklisted' => "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END",
]);
} else {
$query->columns(['blacklisted' => "'n'"]);
$query->columns(['blacklisted' => "('n')"]);
}
return $query;

View File

@ -18,8 +18,6 @@ class Link extends BaseHtmlElement
* @param $url
* @param null $urlParams
* @param array|null $attributes
* @throws \Icinga\Exception\IcingaException
* @throws \Icinga\Exception\ProgrammingError
*/
public function __construct($content, $url, $urlParams = null, array $attributes = null)
{
@ -36,8 +34,6 @@ class Link extends BaseHtmlElement
* @param mixed $attributes
*
* @return static
* @throws \Icinga\Exception\IcingaException
* @throws \Icinga\Exception\ProgrammingError
*/
public static function create($content, $url, $urlParams = null, array $attributes = null)
{
@ -48,7 +44,6 @@ class Link extends BaseHtmlElement
/**
* @param $url
* @param $urlParams
* @throws \Icinga\Exception\ProgrammingError
*/
public function setUrl($url, $urlParams)
{
@ -71,7 +66,6 @@ class Link extends BaseHtmlElement
/**
* @return Attribute
* @throws \Icinga\Exception\ProgrammingError
*/
public function getHrefAttribute()
{

View File

@ -4,7 +4,6 @@ namespace dipl\Web\Table;
use Icinga\Data\Db\DbConnection;
use Icinga\Data\Filter\Filter;
use Icinga\Exception\ProgrammingError;
use dipl\Db\Zf1\FilterRenderer;
use dipl\Db\Zf1\SelectPaginationAdapter;
use dipl\Html\DeferredText;
@ -12,6 +11,7 @@ use dipl\Html\Html;
use dipl\Html\Link;
use dipl\Web\Widget\ControlsAndContent;
use dipl\Web\Url;
use LogicException;
use Zend_Db_Adapter_Abstract as DbAdapter;
abstract class ZfQueryBasedTable extends QueryBasedTable
@ -32,10 +32,10 @@ abstract class ZfQueryBasedTable extends QueryBasedTable
$this->connection = $db;
$this->db = $db->getDbAdapter();
} else {
throw new ProgrammingError(
throw new LogicException(sprintf(
'Unable to deal with %s db class',
get_class($db)
);
));
}
}

View File

@ -3,9 +3,9 @@
namespace dipl\Web;
use Icinga\Application\Icinga;
use Icinga\Exception\ProgrammingError;
use Icinga\Web\Url as WebUrl;
use Icinga\Web\UrlParams;
use InvalidArgumentException;
/**
* Class Url
@ -26,10 +26,10 @@ class Url extends WebUrl
}
if (! is_string($url)) {
throw new ProgrammingError(
throw new InvalidArgumentException(sprintf(
'url "%s" is not a string',
$url
);
));
}
$self = new static;