ipl-related fixes

This commit is contained in:
Thomas Gelf 2018-05-05 18:29:17 +02:00
parent 988319dcf6
commit df7c77a0f6
13 changed files with 136 additions and 57 deletions

View File

@ -4,7 +4,7 @@ namespace Icinga\Module\Director\Web\Table;
use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaServiceSet; use Icinga\Module\Director\Objects\IcingaServiceSet;
use dipl\Html\Element; use dipl\Html\HtmlElement;
use dipl\Html\Link; use dipl\Html\Link;
use dipl\Web\Table\ZfQueryBasedTable; use dipl\Web\Table\ZfQueryBasedTable;
@ -67,7 +67,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
return $this; return $this;
} }
protected function addHeaderColumnsTo(Element $parent) protected function addHeaderColumnsTo(HtmlElement $parent)
{ {
if ($this->host || $this->affectedHost) { if ($this->host || $this->affectedHost) {
$this->addHostHeaderTo($parent); $this->addHostHeaderTo($parent);
@ -125,7 +125,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable
return $this->title ?: $this->translate('Servicename'); return $this->title ?: $this->translate('Servicename');
} }
protected function addHostHeaderTo(Element $parent) protected function addHostHeaderTo(HtmlElement $parent)
{ {
if (! $this->host) { if (! $this->host) {
$deleteLink = ''; $deleteLink = '';

View File

@ -2,13 +2,13 @@
namespace Icinga\Module\Director\Web\Widget; namespace Icinga\Module\Director\Web\Widget;
use dipl\Html\HtmlElement;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\ConfigDiff; use Icinga\Module\Director\ConfigDiff;
use Icinga\Module\Director\Db; use Icinga\Module\Director\Db;
use Icinga\Module\Director\Forms\RestoreObjectForm; use Icinga\Module\Director\Forms\RestoreObjectForm;
use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaObject;
use dipl\Html\Container;
use dipl\Html\Html; use dipl\Html\Html;
use dipl\Html\Icon; use dipl\Html\Icon;
use dipl\Html\Link; use dipl\Html\Link;
@ -66,13 +66,13 @@ class ActivityLogInfo extends Html
/** /**
* @param Url $url * @param Url $url
* @return Container * @return HtmlElement
*/ */
public function getPagination(Url $url) public function getPagination(Url $url)
{ {
/** @var Url $url */ /** @var Url $url */
$url = $url->without('checksum')->without('show'); $url = $url->without('checksum')->without('show');
$div = Container::create([ $div = Html::tag('div', [
'class' => 'pagination-control', 'class' => 'pagination-control',
'style' => 'float: right; width: 5em' 'style' => 'float: right; width: 5em'
]); ]);

View File

@ -54,6 +54,7 @@ abstract class BaseHtmlElement extends HtmlDocument
/** /**
* @param Attributes|array|null $attributes * @param Attributes|array|null $attributes
* @return $this * @return $this
* @throws \Icinga\Exception\IcingaException
*/ */
public function setAttributes($attributes) public function setAttributes($attributes)
{ {
@ -61,6 +62,12 @@ abstract class BaseHtmlElement extends HtmlDocument
return $this; return $this;
} }
/**
* @param $key
* @param $value
* @return $this
* @throws \Icinga\Exception\ProgrammingError
*/
public function setAttribute($key, $value) public function setAttribute($key, $value)
{ {
$this->getAttributes()->set($key, $value); $this->getAttributes()->set($key, $value);
@ -70,6 +77,7 @@ abstract class BaseHtmlElement extends HtmlDocument
/** /**
* @param Attributes|array|null $attributes * @param Attributes|array|null $attributes
* @return $this * @return $this
* @throws \Icinga\Exception\ProgrammingError
*/ */
public function addAttributes($attributes) public function addAttributes($attributes)
{ {
@ -77,6 +85,9 @@ abstract class BaseHtmlElement extends HtmlDocument
return $this; return $this;
} }
/**
* @return array
*/
public function getDefaultAttributes() public function getDefaultAttributes()
{ {
return $this->defaultAttributes; return $this->defaultAttributes;
@ -102,6 +113,10 @@ abstract class BaseHtmlElement extends HtmlDocument
{ {
} }
/**
* @param array|ValidHtml|string $content
* @return $this
*/
public function add($content) public function add($content)
{ {
if (! $this->hasBeenAssembled) { if (! $this->hasBeenAssembled) {

View File

@ -2,6 +2,9 @@
namespace dipl\Html; namespace dipl\Html;
/**
* @deprecated
*/
class Container extends BaseHtmlElement class Container extends BaseHtmlElement
{ {
/** @var string */ /** @var string */

View File

@ -5,10 +5,7 @@ namespace dipl\Html;
use Exception; use Exception;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
/** class Html
* TODO: This should no longer extend HtmlDocument
*/
class Html extends HtmlDocument
{ {
/** Charset to be used - we only support UTF-8 */ /** Charset to be used - we only support UTF-8 */
const CHARSET = 'UTF-8'; const CHARSET = 'UTF-8';
@ -210,30 +207,23 @@ class Html extends HtmlDocument
return self::$htmlEscapeFlags; return self::$htmlEscapeFlags;
} }
/** /*
* @deprecated // @deprecated
*/
public static function element($name, $attributes = null) public static function element($name, $attributes = null)
{ {
return Html::tag($name, $attributes); return Html::tag($name, $attributes);
} }
/** // @deprecated
* @deprecated
* @see Html::add()
*/
public function addContent($content) public function addContent($content)
{ {
return $this->add($content); return $this->add($content);
} }
/** // @deprecated
* @deprecated
*
* @return bool
*/
public function hasContent() public function hasContent()
{ {
return ! $this->isEmpty(); return ! $this->isEmpty();
} }
*/
} }

View File

@ -20,9 +20,12 @@ class HtmlDocument implements ValidHtml, Countable
/** @var array */ /** @var array */
private $contentIndex = []; private $contentIndex = [];
protected $hasBeenAssembled = false;
/** /**
* @param ValidHtml|array|string $content * @param ValidHtml|array|string $content
* @return $this * @return $this
* @throws \Icinga\Exception\IcingaException
*/ */
public function add($content) public function add($content)
{ {
@ -75,6 +78,7 @@ class HtmlDocument implements ValidHtml, Countable
/** /**
* @param $content * @param $content
* @return $this * @return $this
* @throws \Icinga\Exception\IcingaException
*/ */
public function prepend($content) public function prepend($content)
{ {
@ -108,6 +112,7 @@ class HtmlDocument implements ValidHtml, Countable
/** /**
* @param $string * @param $string
* @return HtmlDocument * @return HtmlDocument
* @throws \Icinga\Exception\IcingaException
*/ */
public function addPrintf($string) public function addPrintf($string)
{ {
@ -122,6 +127,7 @@ class HtmlDocument implements ValidHtml, Countable
/** /**
* @param HtmlDocument|array|string $content * @param HtmlDocument|array|string $content
* @return $this * @return $this
* @throws \Icinga\Exception\IcingaException
*/ */
public function setContent($content) public function setContent($content)
{ {
@ -151,7 +157,10 @@ class HtmlDocument implements ValidHtml, Countable
public function render() public function render()
{ {
$html = []; $html = [];
if (! $this->hasBeenAssembled) {
$this->hasBeenAssembled = true;
$this->assemble(); $this->assemble();
}
foreach ($this->content as $element) { foreach ($this->content as $element) {
if (is_string($element)) { if (is_string($element)) {

View File

@ -11,21 +11,21 @@ abstract class HtmlTag
* @param $content * @param $content
* @param Attributes|array $attributes * @param Attributes|array $attributes
* *
* @return Element * @return HtmlElement
*/ */
public static function h1($content, $attributes = null) public static function h1($content, $attributes = null)
{ {
return Element::create('h1', $attributes)->setContent($content); return HtmlElement::create('h1', $attributes)->setContent($content);
} }
/** /**
* @param $content * @param $content
* @param Attributes|array $attributes * @param Attributes|array $attributes
* *
* @return Element * @return HtmlElement
*/ */
public static function p($content, $attributes = null) public static function p($content, $attributes = null)
{ {
return Element::create('p', $attributes)->setContent($content); return HtmlElement::create('p', $attributes)->setContent($content);
} }
} }

View File

@ -11,16 +11,16 @@ class Table extends BaseHtmlElement
/** @var string */ /** @var string */
protected $tag = 'table'; protected $tag = 'table';
/** @var Element */ /** @var HtmlElement */
private $caption; private $caption;
/** @var Element */ /** @var HtmlElement */
private $header; private $header;
/** @var Element */ /** @var HtmlElement */
private $body; private $body;
/** @var Element */ /** @var HtmlElement */
private $footer; private $footer;
/** @var array */ /** @var array */
@ -49,7 +49,7 @@ class Table extends BaseHtmlElement
*/ */
public function setCaption($content) public function setCaption($content)
{ {
$this->caption = Element::create('caption')->addContent( $this->caption = Html::tag('caption')->add(
$content $content
); );
@ -61,11 +61,11 @@ class Table extends BaseHtmlElement
* *
* @param Attributes|array $attributes * @param Attributes|array $attributes
* @param Html|array|string $content * @param Html|array|string $content
* @return Element * @return HtmlElement
*/ */
public static function tr($content = null, $attributes = null) public static function tr($content = null, $attributes = null)
{ {
return Element::create('tr', $attributes, $content); return Html::tag('tr', $attributes, $content);
} }
/** /**
@ -73,11 +73,11 @@ class Table extends BaseHtmlElement
* *
* @param Attributes|array $attributes * @param Attributes|array $attributes
* @param Html|array|string $content * @param Html|array|string $content
* @return Element * @return HtmlElement
*/ */
public static function th($content = null, $attributes = null) public static function th($content = null, $attributes = null)
{ {
return Element::create('th', $attributes, $content); return HtmlElement::create('th', $attributes, $content);
} }
/** /**
@ -85,13 +85,20 @@ class Table extends BaseHtmlElement
* *
* @param Attributes|array $attributes * @param Attributes|array $attributes
* @param Html|array|string $content * @param Html|array|string $content
* @return Element * @return HtmlElement
*/ */
public static function td($content = null, $attributes = null) public static function td($content = null, $attributes = null)
{ {
return Element::create('td', $attributes, $content); return HtmlElement::create('td', $attributes, $content);
} }
/**
* @param $row
* @param null $attributes
* @param string $tag
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public static function row($row, $attributes = null, $tag = 'td') public static function row($row, $attributes = null, $tag = 'td')
{ {
$tr = static::tr(); $tr = static::tr();
@ -106,6 +113,10 @@ class Table extends BaseHtmlElement
return $tr; return $tr;
} }
/**
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function generateHeader() public function generateHeader()
{ {
return $this->nextHeader()->add( return $this->nextHeader()->add(
@ -113,14 +124,23 @@ class Table extends BaseHtmlElement
); );
} }
/**
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function generateFooter() public function generateFooter()
{ {
return Element::create('tfoot')->add( return HtmlElement::create('tfoot')->add(
$this->addHeaderColumnsTo(static::tr()) $this->addHeaderColumnsTo(static::tr())
); );
} }
protected function addHeaderColumnsTo(Element $parent) /**
* @param HtmlElement $parent
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
protected function addHeaderColumnsTo(HtmlElement $parent)
{ {
foreach ($this->getColumnsToBeRendered() as $column) { foreach ($this->getColumnsToBeRendered() as $column) {
$parent->add( $parent->add(
@ -139,15 +159,25 @@ class Table extends BaseHtmlElement
return $this->columnsToBeRendered; return $this->columnsToBeRendered;
} }
/**
* @param array $columns
* @return $this
*/
public function setColumnsToBeRendered(array $columns) public function setColumnsToBeRendered(array $columns)
{ {
$this->columnsToBeRendered = $columns; $this->columnsToBeRendered = $columns;
return $this; return $this;
} }
/**
* @param $row
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function renderRow($row) public function renderRow($row)
{ {
$tr = $this->addRowClasses(Element::create('tr'), $row); $tr = $this->addRowClasses(Html::tag('tr'), $row);
$columns = $this->getColumnsToBeRendered(); $columns = $this->getColumnsToBeRendered();
if ($columns === null) { if ($columns === null) {
@ -166,7 +196,13 @@ class Table extends BaseHtmlElement
return $tr; return $tr;
} }
public function addRowClasses(Element $tr, $row) /**
* @param HtmlElement $tr
* @param $row
* @return HtmlElement
* @throws \Icinga\Exception\ProgrammingError
*/
public function addRowClasses(HtmlElement $tr, $row)
{ {
$classes = $this->getRowClasses($row); $classes = $this->getRowClasses($row);
if (! empty($classes)) { if (! empty($classes)) {
@ -176,6 +212,11 @@ class Table extends BaseHtmlElement
return $tr; return $tr;
} }
/**
* @param Traversable $rows
* @return HtmlDocument|HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function renderRows(Traversable $rows) public function renderRows(Traversable $rows)
{ {
$body = $this->body(); $body = $this->body();
@ -186,24 +227,34 @@ class Table extends BaseHtmlElement
return $body; return $body;
} }
/**
* @return HtmlElement
*/
public function body() public function body()
{ {
if ($this->body === null) { if ($this->body === null) {
$this->body = Element::create('tbody')->setSeparator("\n"); $this->body = Html::tag('tbody')->setSeparator("\n");
} }
return $this->body; return $this->body;
} }
/**
* @return HtmlElement
*/
public function header() public function header()
{ {
if ($this->header === null) { if ($this->header === null) {
$this->header = Element::create('thead')->setSeparator("\n"); $this->header = Html::tag('thead')->setSeparator("\n");
} }
return $this->header; return $this->header;
} }
/**
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function footer() public function footer()
{ {
if ($this->footer === null) { if ($this->footer === null) {
@ -213,6 +264,9 @@ class Table extends BaseHtmlElement
return $this->footer; return $this->footer;
} }
/**
* @return HtmlElement
*/
public function nextBody() public function nextBody()
{ {
if ($this->body !== null) { if ($this->body !== null) {
@ -223,6 +277,9 @@ class Table extends BaseHtmlElement
return $this->body(); return $this->body();
} }
/**
* @return HtmlElement
*/
public function nextHeader() public function nextHeader()
{ {
if ($this->header !== null) { if ($this->header !== null) {
@ -233,6 +290,9 @@ class Table extends BaseHtmlElement
return $this->header(); return $this->header();
} }
/**
* @return string
*/
public function renderContent() public function renderContent()
{ {
if (null !== $this->caption) { if (null !== $this->caption) {

View File

@ -7,7 +7,6 @@ use Icinga\Data\Filter\Filter;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use dipl\Db\Zf1\FilterRenderer; use dipl\Db\Zf1\FilterRenderer;
use dipl\Db\Zf1\SelectPaginationAdapter; use dipl\Db\Zf1\SelectPaginationAdapter;
use dipl\Html\Container;
use dipl\Html\DeferredText; use dipl\Html\DeferredText;
use dipl\Html\Html; use dipl\Html\Html;
use dipl\Html\Link; use dipl\Html\Link;
@ -119,7 +118,7 @@ abstract class ZfQueryBasedTable extends QueryBasedTable
public function dumpSqlQuery(Url $url) public function dumpSqlQuery(Url $url)
{ {
$self = $this; $self = $this;
return Container::create(['class' => 'sql-dump'], [ return Html::tag('div', ['class' => 'sql-dump'], [
Link::create('[ close ]', $url->without('format')), Link::create('[ close ]', $url->without('format')),
Html::tag('h3', null, $this->translate('SQL Query')), Html::tag('h3', null, $this->translate('SQL Query')),
Html::tag('pre', null, new DeferredText( Html::tag('pre', null, new DeferredText(

View File

@ -4,8 +4,8 @@ namespace dipl\Web\Widget;
use dipl\Html\Attributes; use dipl\Html\Attributes;
use dipl\Html\BaseHtmlElement; use dipl\Html\BaseHtmlElement;
use dipl\Html\Element;
use dipl\Html\Html; use dipl\Html\Html;
use dipl\Html\HtmlElement;
class AbstractList extends BaseHtmlElement class AbstractList extends BaseHtmlElement
{ {
@ -35,6 +35,6 @@ class AbstractList extends BaseHtmlElement
*/ */
public function addItem($content, $attributes = null) public function addItem($content, $attributes = null)
{ {
return $this->add(Element::create('li', $attributes, $content)); return $this->add(HtmlElement::create('li', $attributes, $content));
} }
} }

View File

@ -2,11 +2,13 @@
namespace dipl\Web\Widget; namespace dipl\Web\Widget;
use dipl\Html\Container; use dipl\Html\BaseHtmlElement;
class Content extends Container class Content extends BaseHtmlElement
{ {
protected $tag = 'div';
protected $contentSeparator = "\n"; protected $contentSeparator = "\n";
protected $defaultAttributes = array('class' => 'content'); protected $defaultAttributes = ['class' => 'content'];
} }

View File

@ -3,15 +3,16 @@
namespace dipl\Web\Widget; namespace dipl\Web\Widget;
use dipl\Html\BaseHtmlElement; use dipl\Html\BaseHtmlElement;
use dipl\Html\Container;
use dipl\Html\Html; use dipl\Html\Html;
use dipl\Html\HtmlDocument; use dipl\Html\HtmlDocument;
class Controls extends Container class Controls extends BaseHtmlElement
{ {
protected $tag = 'div';
protected $contentSeparator = "\n"; protected $contentSeparator = "\n";
protected $defaultAttributes = array('class' => 'controls'); protected $defaultAttributes = ['class' => 'controls'];
/** @var Tabs */ /** @var Tabs */
private $tabs; private $tabs;

View File

@ -4,15 +4,15 @@ namespace dipl\Web\Widget;
use dipl\Html\Attributes; use dipl\Html\Attributes;
use dipl\Html\BaseHtmlElement; use dipl\Html\BaseHtmlElement;
use dipl\Html\Element;
use dipl\Html\Html; use dipl\Html\Html;
use dipl\Html\ValidHtml;
class ListItem extends BaseHtmlElement class ListItem extends BaseHtmlElement
{ {
protected $contentSeparator = "\n"; protected $contentSeparator = "\n";
/** /**
* @param Html|array|string $content * @param ValidHtml|array|string $content
* @param Attributes|array $attributes * @param Attributes|array $attributes
* *
* @return $this * @return $this
@ -20,7 +20,7 @@ class ListItem extends BaseHtmlElement
public function addItem($content, $attributes = null) public function addItem($content, $attributes = null)
{ {
return $this->add( return $this->add(
Element::create('li', $content, $attributes) Html::tag('li', $attributes, $content)
); );
} }
} }