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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,8 +4,8 @@ namespace dipl\Web\Widget;
use dipl\Html\Attributes;
use dipl\Html\BaseHtmlElement;
use dipl\Html\Element;
use dipl\Html\Html;
use dipl\Html\HtmlElement;
class AbstractList extends BaseHtmlElement
{
@ -35,6 +35,6 @@ class AbstractList extends BaseHtmlElement
*/
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;
use dipl\Html\Container;
use dipl\Html\BaseHtmlElement;
class Content extends Container
class Content extends BaseHtmlElement
{
protected $tag = 'div';
protected $contentSeparator = "\n";
protected $defaultAttributes = array('class' => 'content');
protected $defaultAttributes = ['class' => 'content'];
}

View File

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

View File

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