Merge branch 'feature/refresh-ipl'

This commit is contained in:
Thomas Gelf 2018-05-08 17:04:35 +02:00
commit cbd0d03d36
17 changed files with 162 additions and 246 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

@ -1,35 +0,0 @@
<?php
namespace dipl\Html;
/**
* @deprecated
*/
abstract class BaseElement extends BaseHtmlElement
{
/**
* @deprecated
*/
public function attributes()
{
return $this->getAttributes();
}
/**
* Container constructor.
*
* @param string $tag
* @param Attributes|array $attributes
*
* @deprecated
*
* @return HtmlElement
*/
public function addElement($tag, $attributes = null)
{
$element = Html::tag($tag, $attributes);
$this->add($element);
return $element;
}
}

View File

@ -36,6 +36,8 @@ abstract class BaseHtmlElement extends HtmlDocument
/**
* @return Attributes
* @throws \Icinga\Exception\IcingaException
* @throws \Icinga\Exception\ProgrammingError
*/
public function getAttributes()
{
@ -54,6 +56,7 @@ abstract class BaseHtmlElement extends HtmlDocument
/**
* @param Attributes|array|null $attributes
* @return $this
* @throws \Icinga\Exception\IcingaException
*/
public function setAttributes($attributes)
{
@ -61,6 +64,13 @@ abstract class BaseHtmlElement extends HtmlDocument
return $this;
}
/**
* @param string $key
* @param mixed $value
* @return $this
* @throws \Icinga\Exception\ProgrammingError
* @throws \Icinga\Exception\IcingaException
*/
public function setAttribute($key, $value)
{
$this->getAttributes()->set($key, $value);
@ -70,6 +80,7 @@ abstract class BaseHtmlElement extends HtmlDocument
/**
* @param Attributes|array|null $attributes
* @return $this
* @throws \Icinga\Exception\ProgrammingError
*/
public function addAttributes($attributes)
{
@ -77,6 +88,9 @@ abstract class BaseHtmlElement extends HtmlDocument
return $this;
}
/**
* @return array
*/
public function getDefaultAttributes()
{
return $this->defaultAttributes;
@ -102,6 +116,11 @@ abstract class BaseHtmlElement extends HtmlDocument
{
}
/**
* @param array|ValidHtml|string $content
* @return $this
* @throws \Icinga\Exception\IcingaException
*/
public function add($content)
{
if (! $this->hasBeenAssembled) {
@ -109,11 +128,14 @@ abstract class BaseHtmlElement extends HtmlDocument
$this->assemble();
}
return parent::add($content);
parent::add($content);
return $this;
}
/**
* @return string
* @throws \Icinga\Exception\ProgrammingError
*/
public function render()
{
@ -141,6 +163,10 @@ abstract class BaseHtmlElement extends HtmlDocument
}
}
/**
* @return string
* @throws \Icinga\Exception\ProgrammingError
*/
public function renderAttributes()
{
if ($this->attributes === null && empty($this->defaultAttributes)) {

View File

@ -1,40 +0,0 @@
<?php
namespace dipl\Html;
class Container extends BaseHtmlElement
{
/** @var string */
protected $contentSeparator = "\n";
/** @var string */
protected $tag = 'div';
protected function __construct()
{
}
/**
* @param Html|array|string $content
* @param Attributes|array $attributes
* @param string $tag
*
* @return static
*/
public static function create($attributes = null, $content = null, $tag = null)
{
$container = new static();
if ($content !== null) {
$container->setContent($content);
}
if ($attributes !== null) {
$container->setAttributes($attributes);
}
if ($tag !== null) {
$container->setTag($tag);
}
return $container;
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace dipl\Html;
/**
* @deprecated
*/
class Element extends HtmlElement
{
}

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';
@ -209,31 +206,4 @@ class Html extends HtmlDocument
return self::$htmlEscapeFlags;
}
/**
* @deprecated
*/
public static function element($name, $attributes = null)
{
return Html::tag($name, $attributes);
}
/**
* @deprecated
* @see Html::add()
*/
public function addContent($content)
{
return $this->add($content);
}
/**
* @deprecated
*
* @return bool
*/
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

@ -1,31 +0,0 @@
<?php
namespace dipl\Html;
/**
* @deprecated
*/
abstract class HtmlTag
{
/**
* @param $content
* @param Attributes|array $attributes
*
* @return Element
*/
public static function h1($content, $attributes = null)
{
return Element::create('h1', $attributes)->setContent($content);
}
/**
* @param $content
* @param Attributes|array $attributes
*
* @return Element
*/
public static function p($content, $attributes = null)
{
return Element::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 */
@ -46,10 +46,11 @@ class Table extends BaseHtmlElement
*
* @param $content
* @return $this
* @throws \Icinga\Exception\IcingaException
*/
public function setCaption($content)
{
$this->caption = Element::create('caption')->addContent(
$this->caption = Html::tag('caption')->add(
$content
);
@ -61,11 +62,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 +74,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 +86,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 +114,10 @@ class Table extends BaseHtmlElement
return $tr;
}
/**
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function generateHeader()
{
return $this->nextHeader()->add(
@ -113,14 +125,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 +160,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 +197,13 @@ class Table extends BaseHtmlElement
return $tr;
}
public function addRowClasses(Element $tr, $row)
/**
* @param HtmlElement $tr
* @param $row
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function addRowClasses(HtmlElement $tr, $row)
{
$classes = $this->getRowClasses($row);
if (! empty($classes)) {
@ -176,6 +213,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 +228,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 +265,10 @@ class Table extends BaseHtmlElement
return $this->footer;
}
/**
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function nextBody()
{
if ($this->body !== null) {
@ -223,6 +279,10 @@ class Table extends BaseHtmlElement
return $this->body();
}
/**
* @return HtmlElement
* @throws \Icinga\Exception\IcingaException
*/
public function nextHeader()
{
if ($this->header !== null) {
@ -233,6 +293,10 @@ class Table extends BaseHtmlElement
return $this->header();
}
/**
* @return string
* @throws \Icinga\Exception\IcingaException
*/
public function renderContent()
{
if (null !== $this->caption) {

View File

@ -1,57 +0,0 @@
<?php
namespace dipl\Html;
/**
* @deprecated
*/
class Util
{
/**
* @deprecated
*/
public static function escapeForHtml($value)
{
return Html::escapeForHtml($value);
}
/**
* @deprecated
*/
public static function renderError($error)
{
return Html::renderError($error);
}
/**
* @deprecated
*/
public static function showTraces($show = null)
{
return Html::showTraces($show);
}
/**
* @deprecated
*/
public static function wantHtml($any)
{
return Html::wantHtml($any);
}
/**
* @deprecated
*/
public static function canBeRenderedAsString($any)
{
return Html::canBeRenderedAsString($any);
}
/**
* @deprecated
*/
public static function getPhpTypeName($any)
{
return Html::getPhpTypeName($any);
}
}

View File

@ -33,7 +33,7 @@ trait ControlsAndContentHelper
public function controls()
{
if ($this->controls === null) {
$this->view->controls = $this->controls = Controls::create();
$this->view->controls = $this->controls = new Controls();
}
return $this->controls;
@ -72,7 +72,7 @@ trait ControlsAndContentHelper
public function content()
{
if ($this->content === null) {
$this->view->content = $this->content = Content::create();
$this->view->content = $this->content = new Content();
}
return $this->content;

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;
@ -32,6 +33,7 @@ class Controls extends Container
* @param $title
* @param null $subTitle
* @return $this
* @throws \Icinga\Exception\IcingaException
*/
public function addTitle($title, $subTitle = null)
{
@ -43,6 +45,11 @@ class Controls extends Container
return $this->setTitleElement($this->renderTitleElement());
}
/**
* @param BaseHtmlElement $element
* @return $this
* @throws \Icinga\Exception\IcingaException
*/
public function setTitleElement(BaseHtmlElement $element)
{
if ($this->titleElement !== null) {
@ -85,6 +92,7 @@ class Controls extends Container
/**
* @param Tabs $tabs
* @return $this
* @throws \Icinga\Exception\ProgrammingError
*/
public function prependTabs(Tabs $tabs)
{
@ -102,7 +110,8 @@ class Controls extends Container
}
/**
* @return Html
* @return ActionBar
* @throws \Icinga\Exception\IcingaException
*/
public function getActionBar()
{
@ -113,6 +122,11 @@ class Controls extends Container
return $this->actions;
}
/**
* @param HtmlDocument $actionBar
* @return $this
* @throws \Icinga\Exception\IcingaException
*/
public function setActionBar(HtmlDocument $actionBar)
{
if ($this->actions !== null) {
@ -127,10 +141,11 @@ class Controls extends Container
/**
* @return BaseHtmlElement
* @throws \Icinga\Exception\IcingaException
*/
protected function renderTitleElement()
{
$h1 = Html::tag('h1')->setContent($this->title);
$h1 = Html::tag('h1', null, $this->title);
if ($this->subTitle) {
$h1->setSeparator(' ')->add(
Html::tag('small', null, $this->subTitle)
@ -140,6 +155,10 @@ class Controls extends Container
return $h1;
}
/**
* @return string
* @throws \Icinga\Exception\IcingaException
*/
public function renderContent()
{
if (null !== $this->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)
);
}
}