Merge branch 'feature/integrate-ipl-html'

resolves #130
This commit is contained in:
Johannes Meyer 2019-01-17 14:15:27 +01:00
commit 788f690154
45 changed files with 470 additions and 2001 deletions

View file

@ -21,6 +21,7 @@ cache:
env: env:
- ICINGAWEB_VERSION=2.5.1 - ICINGAWEB_VERSION=2.5.1
- IPL_VERSION=0.1.1
before_script: before_script:
- ./test/setup_vendor.sh - ./test/setup_vendor.sh

View file

@ -53,7 +53,7 @@ class NodeController extends Controller
)->setPath($path); )->setPath($path);
$bc = Breadcrumb::create($renderer); $bc = Breadcrumb::create($renderer);
$bc->attributes()->set('data-base-target', '_next'); $bc->getAttributes()->set('data-base-target', '_next');
$content->add($bc); $content->add($bc);
} }
} }

View file

@ -5,11 +5,6 @@ namespace Icinga\Module\Businessprocess\Controllers;
use Icinga\Date\DateFormatter; use Icinga\Date\DateFormatter;
use Icinga\Module\Businessprocess\BpConfig; use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\BpNode; use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\HtmlString;
use Icinga\Module\Businessprocess\Html\HtmlTag;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Node; use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\Renderer\Breadcrumb; use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
use Icinga\Module\Businessprocess\Renderer\Renderer; use Icinga\Module\Businessprocess\Renderer\Renderer;
@ -23,11 +18,13 @@ use Icinga\Module\Businessprocess\Web\Component\ActionBar;
use Icinga\Module\Businessprocess\Web\Component\RenderedProcessActionBar; use Icinga\Module\Businessprocess\Web\Component\RenderedProcessActionBar;
use Icinga\Module\Businessprocess\Web\Component\Tabs; use Icinga\Module\Businessprocess\Web\Component\Tabs;
use Icinga\Module\Businessprocess\Web\Controller; use Icinga\Module\Businessprocess\Web\Controller;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Util\Json; use Icinga\Util\Json;
use Icinga\Web\Notification; use Icinga\Web\Notification;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction; use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\OutputFormat; use Icinga\Web\Widget\Tabextension\OutputFormat;
use ipl\Html\Html;
use ipl\Html\HtmlString;
class ProcessController extends Controller class ProcessController extends Controller
{ {
@ -45,7 +42,7 @@ class ProcessController extends Controller
$this->setTitle($title); $this->setTitle($title);
$this->controls() $this->controls()
->add($this->tabsForCreate()->activate('create')) ->add($this->tabsForCreate()->activate('create'))
->add(HtmlTag::h1($title)); ->add(Html::tag('h1', null, $title));
$this->content()->add( $this->content()->add(
$this->loadForm('bpConfig') $this->loadForm('bpConfig')
@ -66,7 +63,7 @@ class ProcessController extends Controller
$this->setTitle($title); $this->setTitle($title);
$this->controls() $this->controls()
->add($this->tabsForCreate()->activate('upload')) ->add($this->tabsForCreate()->activate('upload'))
->add(HtmlTag::h1($title)); ->add(Html::tag('h1', null, $title));
$this->content()->add( $this->content()->add(
$this->loadForm('BpUpload') $this->loadForm('BpUpload')
@ -113,9 +110,9 @@ class ProcessController extends Controller
} }
$bp->addError(sprintf('There are %d missing nodes: %s', $count, implode(', ', $missing))); $bp->addError(sprintf('There are %d missing nodes: %s', $count, implode(', ', $missing)));
} }
$this->content()->addContent($this->showHints($bp)); $this->content()->add($this->showHints($bp));
$this->content()->addContent($this->showWarnings($bp)); $this->content()->add($this->showWarnings($bp));
$this->content()->addContent($this->showErrors($bp)); $this->content()->add($this->showErrors($bp));
$this->content()->add($renderer); $this->content()->add($renderer);
$this->loadActionForm($bp, $node); $this->loadActionForm($bp, $node);
$this->setDynamicAutorefresh(); $this->setDynamicAutorefresh();
@ -126,27 +123,23 @@ class ProcessController extends Controller
$controls = $this->controls(); $controls = $this->controls();
if ($this->showFullscreen) { if ($this->showFullscreen) {
$controls->attributes()->add('class', 'want-fullscreen'); $controls->getAttributes()->add('class', 'want-fullscreen');
$controls->add( $controls->add(Html::tag(
Link::create( 'a',
Icon::create('resize-small'), [
$this->url()->without('showFullscreen')->without('view'), 'href' => $this->url()->without('showFullscreen')->without('view'),
null, 'title' => $this->translate('Leave full screen and switch back to normal mode'),
array( 'style' => 'float: right'
'style' => 'float: right', ],
'title' => $this->translate( Html::tag('i', ['class' => 'icon icon-resize-small'])
'Leave full screen and switch back to normal mode' ));
)
)
)
);
} }
if (! ($this->showFullscreen || $this->view->compact)) { if (! ($this->showFullscreen || $this->view->compact)) {
$controls->add($this->getProcessTabs($bp, $renderer)); $controls->add($this->getProcessTabs($bp, $renderer));
} }
if (! $this->view->compact) { if (! $this->view->compact) {
$controls->add(Element::create('h1')->setContent($this->view->title)); $controls->add(Html::tag('h1')->setContent($this->view->title));
} }
$controls->add(Breadcrumb::create($renderer)); $controls->add(Breadcrumb::create($renderer));
if (! $this->showFullscreen && ! $this->view->compact) { if (! $this->showFullscreen && ! $this->view->compact) {
@ -259,7 +252,7 @@ class ProcessController extends Controller
} }
if ($form) { if ($form) {
$this->content()->prependContent(HtmlString::create((string) $form)); $this->content()->prepend(HtmlString::create((string) $form));
} }
} }
@ -283,9 +276,9 @@ class ProcessController extends Controller
protected function showWarnings(BpConfig $bp) protected function showWarnings(BpConfig $bp)
{ {
if ($bp->hasWarnings()) { if ($bp->hasWarnings()) {
$ul = Element::create('ul', array('class' => 'warning')); $ul = Html::tag('ul', array('class' => 'warning'));
foreach ($bp->getWarnings() as $warning) { foreach ($bp->getWarnings() as $warning) {
$ul->createElement('li')->addContent($warning); $ul->add(Html::tag('li')->setContent($warning));
} }
return $ul; return $ul;
@ -297,9 +290,9 @@ class ProcessController extends Controller
protected function showErrors(BpConfig $bp) protected function showErrors(BpConfig $bp)
{ {
if ($bp->hasWarnings()) { if ($bp->hasWarnings()) {
$ul = Element::create('ul', array('class' => 'error')); $ul = Html::tag('ul', array('class' => 'error'));
foreach ($bp->getErrors() as $msg) { foreach ($bp->getErrors() as $msg) {
$ul->createElement('li')->addContent($msg); $ul->add(Html::tag('li')->setContent($msg));
} }
return $ul; return $ul;
@ -310,40 +303,41 @@ class ProcessController extends Controller
protected function showHints(BpConfig $bp) protected function showHints(BpConfig $bp)
{ {
$ul = Element::create('ul', array('class' => 'error')); $ul = Html::tag('ul', ['class' => 'error']);
foreach ($bp->getErrors() as $error) { foreach ($bp->getErrors() as $error) {
$ul->createElement('li')->addContent($error); $ul->add(Html::tag('li')->setContent($error));
} }
if ($bp->hasChanges()) { if ($bp->hasChanges()) {
$ul->createElement('li')->setSeparator(' ')->addContent(sprintf( $li = Html::tag('li')->setSeparator(' ');
$li->add(sprintf(
$this->translate('This process has %d pending change(s).'), $this->translate('This process has %d pending change(s).'),
$bp->countChanges() $bp->countChanges()
))->addContent( ))->add(Html::tag(
Link::create( 'a',
$this->translate('Store'), ['href' => Url::fromPath('businessprocess/process/config', ['config' => $bp->getName()])],
'businessprocess/process/config', $this->translate('Store')
array('config' => $bp->getName()) ))->add(Html::tag(
) 'a',
)->addContent( ['href' => $this->url()->with('dismissChanges', true)],
Link::create( $this->translate('Dismiss')
$this->translate('Dismiss'), ));
$this->url()->with('dismissChanges', true), $ul->add($li);
null
)
);
} }
if ($bp->hasSimulations()) { if ($bp->hasSimulations()) {
$ul->createElement('li')->setSeparator(' ')->addContent(sprintf( $li = Html::tag('li')->setSeparator(' ');
$li->add(sprintf(
$this->translate('This process shows %d simulated state(s).'), $this->translate('This process shows %d simulated state(s).'),
$bp->countSimulations() $bp->countSimulations()
))->addContent(Link::create( ))->add(Html::tag(
$this->translate('Dismiss'), 'a',
$this->url()->with('dismissSimulations', true) ['href' => $this->url()->with('dismissSimulations', true)],
$this->translate('Dismiss')
)); ));
$ul->add($li);
} }
if ($ul->hasContent()) { if (! $ul->isEmpty()) {
return $ul; return $ul;
} else { } else {
return null; return null;
@ -380,7 +374,7 @@ class ProcessController extends Controller
$this->setTitle($title); $this->setTitle($title);
$this->controls() $this->controls()
->add($this->tabsForConfig($bp)->activate('source')) ->add($this->tabsForConfig($bp)->activate('source'))
->add(HtmlTag::h1($title)) ->add(Html::tag('h1', null, $title))
->add($this->createConfigActionBar($bp, $showDiff)); ->add($this->createConfigActionBar($bp, $showDiff));
$this->setViewScript('process/source'); $this->setViewScript('process/source');
@ -424,7 +418,7 @@ class ProcessController extends Controller
$this->setTitle($title); $this->setTitle($title);
$this->controls() $this->controls()
->add($this->tabsForConfig($bp)->activate('config')) ->add($this->tabsForConfig($bp)->activate('config'))
->add(HtmlTag::h1($title)) ->add(Html::tag('h1', null, $title))
->add($this->createConfigActionBar($bp)); ->add($this->createConfigActionBar($bp));
$url = Url::fromPath( $url = Url::fromPath(
@ -446,48 +440,42 @@ class ProcessController extends Controller
if ($showDiff) { if ($showDiff) {
$params = array('config' => $config->getName()); $params = array('config' => $config->getName());
$actionBar->add( $actionBar->add(Html::tag(
Link::create( 'a',
$this->translate('Source'), [
'businessprocess/process/source', 'href' => Url::fromPath('businessprocess/process/source', $params),
$params, 'class' => 'icon-doc-text',
array( 'title' => $this->translate('Show source code')
'class' => 'icon-doc-text', ],
'title' => $this->translate('Show source code'), $this->translate('Source')
) ));
)
);
} else { } else {
$params = array( $params = array(
'config' => $config->getName(), 'config' => $config->getName(),
'showDiff' => true 'showDiff' => true
); );
$actionBar->add( $actionBar->add(Html::tag(
Link::create( 'a',
$this->translate('Diff'), [
'businessprocess/process/source', 'href' => Url::fromPath('businessprocess/process/source', $params),
$params, 'class' => 'icon-flapping',
array( 'title' => $this->translate('Highlight changes')
'class' => 'icon-flapping', ],
'title' => $this->translate('Highlight changes'), $this->translate('Diff')
) ));
)
);
} }
$actionBar->add( $actionBar->add(Html::tag(
Link::create( 'a',
$this->translate('Download'), [
'businessprocess/process/download', 'href' => Url::fromPath('businessprocess/process/download', ['config' => $config->getName()]),
array('config' => $config->getName()), 'class' => 'icon-download',
array( 'target' => '_blank',
'target' => '_blank', 'title' => $this->translate('Download process configuration')
'class' => 'icon-download', ],
'title' => $this->translate('Download process configuration') $this->translate('Download')
) ));
)
);
return $actionBar; return $actionBar;
} }

View file

@ -2,8 +2,8 @@
namespace Icinga\Module\Businessprocess; namespace Icinga\Module\Businessprocess;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Web\Url; use Icinga\Module\Businessprocess\Web\Url;
use ipl\Html\Html;
class HostNode extends MonitoredNode class HostNode extends MonitoredNode
{ {
@ -69,6 +69,6 @@ class HostNode extends MonitoredNode
public function getLink() public function getLink()
{ {
return Link::create($this->hostname, $this->getUrl()); return Html::tag('a', ['href' => $this->getUrl()], $this->hostname);
} }
} }

View file

@ -1,130 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Attribute
{
/** @var string */
protected $name;
/** @var string|array */
protected $value;
/**
* Attribute constructor.
*
* @param $name
* @param $value
*/
public function __construct($name, $value)
{
$this->name = $name;
$this->value = $value;
}
/**
* @param $name
* @param $value
* @return static
*/
public static function create($name, $value)
{
return new static($name, $value);
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @param string|array $value
* @return $this
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* @param string $value
* @return $this
*/
public function addValue($value)
{
if (! is_array($this->value)) {
$this->value = array($this->value);
}
if (is_array($value)) {
$this->value = array_merge($this->value, $value);
} else {
$this->value[] = $value;
}
return $this;
}
/**
* @return string
*/
public function render()
{
return sprintf(
'%s="%s"',
$this->renderName(),
$this->renderValue()
);
}
/**
* @return string
*/
public function renderName()
{
return static::escapeName($this->name);
}
/**
* @return string
*/
public function renderValue()
{
return static::escapeValue($this->value);
}
/**
* @param $name
* @return string
*/
public static function escapeName($name)
{
// TODO: escape
return (string) $name;
}
/**
* @param $value
* @return string
*/
public static function escapeValue($value)
{
// TODO: escape differently
if (is_array($value)) {
return Util::escapeForHtml(implode(' ', $value));
} else {
return Util::escapeForHtml((string) $value);
}
}
}

View file

@ -1,194 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Icinga\Exception\IcingaException;
use Icinga\Exception\ProgrammingError;
class Attributes
{
/** @var Attribute[] */
protected $attributes = array();
/** @var callable */
protected $callbacks = array();
/**
* Attributes constructor.
* @param Attribute[] $attributes
*/
public function __construct(array $attributes = null)
{
if (empty($attributes)) {
return;
}
foreach ($attributes as $key => $value) {
if ($value instanceof Attribute) {
$this->addAttribute($value);
} elseif (is_string($key)) {
$this->add($key, $value);
} elseif (is_array($value) && count($value) === 2) {
$this->add(array_shift($value), array_shift($value));
}
}
}
/**
* @param Attribute[] $attributes
* @return static
*/
public static function create(array $attributes = null)
{
return new static($attributes);
}
/**
* @param Attributes|array|null $attributes
* @return Attributes
* @throws IcingaException
*/
public static function wantAttributes($attributes)
{
if ($attributes instanceof Attributes) {
return $attributes;
} else {
$self = new static();
if (is_array($attributes)) {
foreach ($attributes as $k => $v) {
$self->add($k, $v);
}
return $self;
} elseif ($attributes !== null) {
throw new IcingaException(
'Attributes, Array or Null expected, got %s',
Util::getPhpTypeName($attributes)
);
}
return $self;
}
}
/**
* @return Attribute[]
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @param Attribute|string $attribute
* @param string|array $value
* @return $this
*/
public function add($attribute, $value = null)
{
if ($attribute instanceof static) {
foreach ($attribute->getAttributes() as $a) {
$this->add($a);
}
} elseif ($attribute instanceof Attribute) {
$this->addAttribute($attribute);
} elseif (is_array($attribute)) {
foreach ($attribute as $name => $value) {
$this->add($name, $value);
}
} else {
$this->addAttribute(Attribute::create($attribute, $value));
}
return $this;
}
/**
* @param Attribute|string $attribute
* @param string|array $value
* @return $this
*/
public function set($attribute, $value = null)
{
if ($attribute instanceof static) {
foreach ($attribute as $a) {
$this->setAttribute($a);
}
return $this;
} elseif ($attribute instanceof Attribute) {
return $this->setAttribute($attribute);
} else {
return $this->setAttribute(new Attribute($attribute, $value));
}
}
/**
* @param Attribute $attribute
* @return $this
*/
public function addAttribute(Attribute $attribute)
{
$name = $attribute->getName();
if (array_key_exists($name, $this->attributes)) {
$this->attributes[$name]->addValue($attribute->getValue());
} else {
$this->attributes[$name] = $attribute;
}
return $this;
}
/**
* @param Attribute $attribute
* @return $this
*/
public function setAttribute(Attribute $attribute)
{
$name = $attribute->getName();
$this->attributes[$name] = $attribute;
return $this;
}
/**
* Callback must return an instance of Attribute
*
* @param string $name
* @param callable $callback
* @return $this
*/
public function registerCallbackFor($name, $callback)
{
if (! is_callable($callback)) {
throw new ProgrammingError('registerCallBack expects a callable callback');
}
$this->callbacks[$name] = $callback;
return $this;
}
/**
* @inheritdoc
*/
public function render()
{
if (empty($this->attributes) && empty($this->callbacks)) {
return '';
}
$parts = array();
foreach ($this->callbacks as $callback) {
$attribute = call_user_func($callback);
if (! $attribute instanceof Attribute) {
throw new ProgrammingError(
'A registered attribute callback must return an Attribute'
);
}
$parts[] = $attribute->render();
}
foreach ($this->attributes as $attribute) {
$parts[] = $attribute->render();
}
return ' ' . implode(' ', $parts);
}
}

View file

@ -1,117 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Exception;
abstract class BaseElement extends Html
{
/** @var array You may want to set default attributes when extending this class */
protected $defaultAttributes;
/** @var Attributes */
protected $attributes;
/** @var string */
protected $tag;
/**
* @return Attributes
*/
public function attributes()
{
if ($this->attributes === null) {
$default = $this->getDefaultAttributes();
if (empty($default)) {
$this->attributes = new Attributes();
} else {
$this->attributes = Attributes::wantAttributes($default);
}
}
return $this->attributes;
}
/**
* @param Attributes|array|null $attributes
* @return $this
*/
public function setAttributes($attributes)
{
$this->attributes = Attributes::wantAttributes($attributes);
return $this;
}
/**
* @param Attributes|array|null $attributes
* @return $this
*/
public function addAttributes($attributes)
{
$this->attributes()->add($attributes);
return $this;
}
public function getDefaultAttributes()
{
return $this->defaultAttributes;
}
public function setTag($tag)
{
$this->tag = $tag;
return $this;
}
public function getTag()
{
return $this->tag;
}
/**
* Container constructor.
*
* @param string $tag
* @param Attributes|array $attributes
*
* @return Element
*/
public function createElement($tag, $attributes = null)
{
$element = Element::create($tag, $attributes);
$this->add($element);
return $element;
}
public function renderContent()
{
return parent::render();
}
/**
* @return string
*/
public function render()
{
$tag = $this->getTag();
return sprintf(
'<%s%s>%s</%s>',
$tag,
$this->attributes()->render(),
$this->renderContent(),
$tag
);
}
/**
* Whether the given something can be rendered
*
* @param mixed $any
* @return bool
*/
protected function canBeRendered($any)
{
return is_string($any) || is_int($any) || is_null($any);
}
}

View file

@ -1,40 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Container extends BaseElement
{
/** @var string */
protected $contentSeparator = "\n";
/** @var string */
protected $tag = 'div';
protected function __construct()
{
}
/**
* @param Renderable|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,34 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Element extends BaseElement
{
/**
* Container constructor.
*
* @param string $tag
* @param Attributes|array $attributes
*/
public function __construct($tag, $attributes = null)
{
$this->tag = $tag;
if ($attributes !== null) {
$this->attributes = $this->attributes()->add($attributes);
}
}
/**
* Container constructor.
*
* @param string $tag
* @param Attributes|array $attributes
*
* @return static
*/
public static function create($tag, $attributes = null)
{
return new static($tag, $attributes);
}
}

View file

@ -1,174 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Icinga\Exception\ProgrammingError;
use Exception;
class Html implements Renderable
{
protected $contentSeparator = '';
/**
* @var Renderable[]
*/
private $content = array();
public static function escape($any)
{
return Util::wantHtml($any);
}
/**
* @param Renderable $element
* @return $this
*/
public function add(Renderable $element)
{
$this->content[] = $element;
return $this;
}
/**
* @param Renderable $element
* @return $this
*/
public function prepend(Renderable $element)
{
array_unshift($this->content, $element);
return $this;
}
/**
* @param Renderable|array|string $content
* @return $this
*/
public function setContent($content)
{
$this->content = array();
static::addContent($content);
return $this;
}
/**
* @param Renderable|array|string $content
* @return $this
*/
public function addContent($content)
{
if (is_array($content)) {
foreach ($content as $c) {
static::addContent($c);
}
} else {
$this->content[] = static::escape($content);
}
return $this;
}
/**
* @param Renderable|array|string $content
* @return $this
*/
public function prependContent($content)
{
array_unshift($this->content, static::escape($content));
return $this;
}
/**
* return Html
*/
public function getContent()
{
if ($this->content === null) {
$this->content = array(new Html());
}
return $this->content;
}
public function hasContent()
{
if ($this->content === null) {
return false;
}
// TODO: unfinished
// return $this->content->isEmpty();
return true;
}
/**
* @param $separator
* @return $this
*/
public function setSeparator($separator)
{
$this->contentSeparator = $separator;
return $this;
}
/**
* @inheritdoc
*/
public function render()
{
$html = array();
foreach ($this->content as $element) {
if (is_string($element)) {
var_dump($this->content);
}
$html[] = $element->render();
}
return implode($this->contentSeparator, $html);
}
protected function translate($msg)
{
// TODO: Not so nice
return mt('businessprocess', $msg);
}
public static function element($name, $attributes = null)
{
// TODO: This might be anything here, add a better check
if (! ctype_alnum($name)) {
throw new ProgrammingError('Invalid element requested');
}
$class = __NAMESPACE__ . '\\' . $name;
/** @var Element $element */
$element = new $class();
if ($attributes !== null) {
$element->setAttributes($attributes);
}
return $element;
}
/**
* @param Exception|string $error
* @return string
*/
protected function renderError($error)
{
return Util::renderError($error);
}
/**
* @return string
*/
public function __toString()
{
try {
return $this->render();
} catch (Exception $e) {
return $this->renderError($e);
}
}
}

View file

@ -1,8 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class HtmlString extends Text
{
protected $escaped = true;
}

View file

@ -1,28 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
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

@ -1,26 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Icon extends BaseElement
{
protected $tag = 'i';
protected function __construct()
{
}
/**
* @param string $name
* @param array $attributes
*
* @return static
*/
public static function create($name, array $attributes = null)
{
$icon = new static();
$icon->setAttributes($attributes);
$icon->attributes()->add('class', array('icon', 'icon-' . $name));
return $icon;
}
}

View file

@ -1,72 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Web\Url as WebUrl;
class Img extends BaseElement
{
protected $tag = 'img';
/** @var Url */
protected $url;
protected $defaultAttributes = array('alt' => '');
protected function __construct()
{
}
/**
* @param Url|string $url
* @param array $urlParams
* @param array $attributes
*
* @return static
*/
public static function create($url, $urlParams = null, array $attributes = null)
{
$img = new static();
$img->setAttributes($attributes);
$img->attributes()->registerCallbackFor('src', array($img, 'getSrcAttribute'));
$img->setUrl($url, $urlParams);
return $img;
}
public function setUrl($url, $urlParams)
{
if ($url instanceof WebUrl) { // Hint: Url is also a WebUrl
if ($urlParams !== null) {
$url->addParams($urlParams);
}
$this->url = $url;
} else {
if ($urlParams === null) {
$this->url = Url::fromPath($url);
} else {
$this->url = Url::fromPath($url, $urlParams);
}
}
$this->url->getParams();
}
/**
* @return Attribute
*/
public function getSrcAttribute()
{
return new Attribute('src', $this->getUrl()->getAbsoluteUrl('&'));
}
/**
* @return Url
*/
public function getUrl()
{
// TODO: What if null? #?
return $this->url;
}
}

View file

@ -1,72 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Web\Url as WebUrl;
class Link extends BaseElement
{
protected $tag = 'a';
/** @var Url */
protected $url;
protected function __construct()
{
}
/**
* @param Renderable|array|string $content
* @param Url|string $url
* @param array $urlParams
* @param array $attributes
*
* @return static
*/
public static function create($content, $url, $urlParams = null, array $attributes = null)
{
$link = new static();
$link->setContent($content);
$link->setAttributes($attributes);
$link->attributes()->registerCallbackFor('href', array($link, 'getHrefAttribute'));
$link->setUrl($url, $urlParams);
return $link;
}
public function setUrl($url, $urlParams)
{
if ($url instanceof WebUrl) { // Hint: Url is also a WebUrl
if ($urlParams !== null) {
$url->addParams($urlParams);
}
$this->url = $url;
} else {
if ($urlParams === null) {
$this->url = Url::fromPath($url);
} else {
$this->url = Url::fromPath($url, $urlParams);
}
}
$this->url->getParams();
}
/**
* @return Attribute
*/
public function getHrefAttribute()
{
return new Attribute('href', $this->getUrl()->getAbsoluteUrl('&'));
}
/**
* @return Url
*/
public function getUrl()
{
// TODO: What if null? #?
return $this->url;
}
}

View file

@ -1,8 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
interface Renderable
{
public function render();
}

View file

@ -1,82 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
class Text implements Renderable
{
/** @var string */
protected $string;
protected $escaped = false;
/**
* Text constructor.
*
* @param $text
*/
public function __construct($string)
{
$this->string = (string) $string;
}
/**
* @return string
*/
public function getText()
{
return $this->string;
}
/**
* @param bool $escaped
* @return $this
*/
public function setEscaped($escaped = true)
{
$this->escaped = $escaped;
return $this;
}
/**
* @param $text
*
* @return static
*/
public static function create($text)
{
return new static($text);
}
/**
* @return string
*/
public function render()
{
if ($this->escaped) {
return $this->string;
} else {
return Util::escapeForHtml($this->string);
}
}
/**
* @param Exception|string $error
* @return string
*/
protected function renderError($error)
{
return Util::renderError($error);
}
/**
* @return string
*/
public function __toString()
{
try {
return $this->render();
} catch (Exception $e) {
return $this->renderError($e);
}
}
}

View file

@ -1,130 +0,0 @@
<?php
namespace Icinga\Module\Businessprocess\Html;
use Exception;
use Icinga\Exception\IcingaException;
class Util
{
/**
* Charset to be used - we only support UTF-8
*/
const CHARSET = 'UTF-8';
/**
* The flags we use for htmlspecialchars depend on our PHP version
*/
protected static $htmlEscapeFlags;
/**
* Escape the given value top be safely used in view scripts
*
* @param string $value The output to be escaped
* @return string
*/
public static function escapeForHtml($value)
{
return htmlspecialchars(
$value,
static::htmlEscapeFlags(),
self::CHARSET,
true
);
}
/**
* @param Exception|string $error
* @return string
*/
public static function renderError($error)
{
if ($error instanceof Exception) {
$file = preg_split('/[\/\\\]/', $error->getFile(), -1, PREG_SPLIT_NO_EMPTY);
$file = array_pop($file);
$msg = sprintf(
'%s (%s:%d)',
$error->getMessage(),
$file,
$error->getLine()
);
} elseif (is_string($error)) {
$msg = $error;
} else {
$msg = 'Got an invalid error'; // TODO: translate?
}
return sprintf(
'ERROR: %s', // TODO: translate?
static::escapeForHtml($msg)
);
}
/**
* @param $any
* @return Renderable
* @throws IcingaException
*/
public static function wantHtml($any)
{
if ($any instanceof Renderable) {
return $any;
} elseif (static::canBeRenderedAsString($any)) {
return new Text($any);
} elseif (is_array($any)) {
$html = new Html();
foreach ($any as $el) {
$html->add(static::wantHtml($el));
}
return $html;
} else {
// TODO: Should we add a dedicated Exception class?
throw new IcingaException(
'String, Html Element or Array of such expected, got "%s"',
Util::getPhpTypeName($any)
);
}
}
public static function canBeRenderedAsString($any)
{
return is_string($any) || is_int($any) || is_null($any);
}
/**
* @param $any
* @return string
*/
public static function getPhpTypeName($any)
{
if (is_object($any)) {
return get_class($any);
} else {
return gettype($any);
}
}
/**
* This defines the flags used when escaping for HTML
*
* - Single quotes are not escaped (ENT_COMPAT)
* - With PHP >= 5.4, invalid characters are replaced with <EFBFBD> (ENT_SUBSTITUTE)
* - With PHP 5.3 they are ignored (ENT_IGNORE, less secure)
* - Uses HTML5 entities for PHP >= 5.4, disallowing &#013;
*
* @return int
*/
protected static function htmlEscapeFlags()
{
if (self::$htmlEscapeFlags === null) {
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
self::$htmlEscapeFlags = ENT_COMPAT | ENT_SUBSTITUTE | ENT_HTML5;
} else {
self::$htmlEscapeFlags = ENT_COMPAT | ENT_IGNORE;
}
}
return self::$htmlEscapeFlags;
}
}

View file

@ -3,11 +3,11 @@
namespace Icinga\Module\Businessprocess; namespace Icinga\Module\Businessprocess;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\State\MonitoringState; use Icinga\Module\Businessprocess\State\MonitoringState;
use Icinga\Module\Businessprocess\Storage\LegacyStorage; use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Businessprocess\Web\Url;
use Exception; use Exception;
use Icinga\Web\Url;
use ipl\Html\Html;
class ImportedNode extends Node class ImportedNode extends Node
{ {
@ -226,13 +226,15 @@ class ImportedNode extends Node
*/ */
public function getLink() public function getLink()
{ {
return Link::create( return Html::tag(
$this->getAlias(), 'a',
'businessprocess/process/show', [
array( 'href' => Url::fromPath('businessprocess/process/show', [
'config' => $this->configName, 'config' => $this->configName,
'node' => $this->nodeName 'node' => $this->nodeName
) ])
],
$this->getAlias()
); );
} }
} }

View file

@ -2,7 +2,7 @@
namespace Icinga\Module\Businessprocess; namespace Icinga\Module\Businessprocess;
use Icinga\Module\Businessprocess\Html\Link; use ipl\Html\Html;
abstract class MonitoredNode extends Node abstract class MonitoredNode extends Node
{ {
@ -11,9 +11,9 @@ abstract class MonitoredNode extends Node
public function getLink() public function getLink()
{ {
if ($this->isMissing()) { if ($this->isMissing()) {
return Link::create($this->getAlias(), '#'); return Html::tag('a', ['href' => '#'], $this->getAlias());
} else { } else {
return Link::create($this->getAlias(), $this->getUrl()); return Html::tag('a', ['href' => $this->getUrl()], $this->getAlias());
} }
} }
} }

View file

@ -3,7 +3,7 @@
namespace Icinga\Module\Businessprocess; namespace Icinga\Module\Businessprocess;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Module\Businessprocess\Html\Link; use ipl\Html\Html;
abstract class Node abstract class Node
{ {
@ -368,12 +368,9 @@ abstract class Node
return $this->className; return $this->className;
} }
/**
* @return Link
*/
public function getLink() public function getLink()
{ {
return Link::create($this->getAlias(), '#'); return Html::tag('a', ['href' => '#'], $this->getAlias());
} }
public function operatorHtml() public function operatorHtml()

View file

@ -3,14 +3,12 @@
namespace Icinga\Module\Businessprocess\Renderer; namespace Icinga\Module\Businessprocess\Renderer;
use Icinga\Module\Businessprocess\BpNode; use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\Html\BaseElement;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Renderer\TileRenderer\NodeTile; use Icinga\Module\Businessprocess\Renderer\TileRenderer\NodeTile;
use Icinga\Module\Businessprocess\Web\Url; use Icinga\Module\Businessprocess\Web\Url;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class Breadcrumb extends BaseElement class Breadcrumb extends BaseHtmlElement
{ {
protected $tag = 'ul'; protected $tag = 'ul';
@ -32,16 +30,18 @@ class Breadcrumb extends BaseElement
$bpUrl->remove('action'); $bpUrl->remove('action');
} }
$breadcrumb->add(Element::create('li')->add( $breadcrumb->add(Html::tag('li')->add(
Link::create( Html::tag(
Icon::create('dashboard'), 'a',
Url::fromPath('businessprocess'), [
null, 'href' => Url::fromPath('businessprocess'),
['title' => mt('businessprocess', 'Show Overview')] 'title' => mt('businessprocess', 'Show Overview')
],
Html::tag('i', ['class' => 'icon icon-dashboard'])
) )
)); ));
$breadcrumb->add(Element::create('li')->add( $breadcrumb->add(Html::tag('li')->add(
Link::create($bp->getTitle(), $bpUrl) Html::tag('a', ['href' => $bpUrl], $bp->getTitle())
)); ));
$path = $renderer->getCurrentPath(); $path = $renderer->getCurrentPath();
@ -52,7 +52,7 @@ class Breadcrumb extends BaseElement
static::renderNode($bp->getNode($node), $path, $renderer) static::renderNode($bp->getNode($node), $path, $renderer)
); );
} }
$breadcrumb->addContent($parts); $breadcrumb->add($parts);
return $breadcrumb; return $breadcrumb;
} }
@ -70,7 +70,7 @@ class Breadcrumb extends BaseElement
$renderer = clone($renderer); $renderer = clone($renderer);
$renderer->lock()->setIsBreadcrumb(); $renderer->lock()->setIsBreadcrumb();
$p = new NodeTile($renderer, (string) $node, $node, $path); $p = new NodeTile($renderer, (string) $node, $node, $path);
$p->attributes()->add('class', $renderer->getNodeClasses($node)); $p->getAttributes()->add('class', $renderer->getNodeClasses($node));
$p->setTag('li'); $p->setTag('li');
return $p; return $p;
} }

View file

@ -6,14 +6,14 @@ use Icinga\Date\DateFormatter;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Module\Businessprocess\BpNode; use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\BpConfig; use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\Html;
use Icinga\Module\Businessprocess\Html\HtmlString;
use Icinga\Module\Businessprocess\Node; use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\Web\Url; use Icinga\Module\Businessprocess\Web\Url;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlString;
abstract class Renderer extends Html abstract class Renderer extends HtmlDocument
{ {
/** @var BpConfig */ /** @var BpConfig */
protected $config; protected $config;
@ -122,7 +122,7 @@ abstract class Renderer extends Html
/** /**
* @param $summary * @param $summary
* @return Container * @return BaseHtmlElement
*/ */
public function renderStateBadges($summary) public function renderStateBadges($summary)
{ {
@ -136,26 +136,24 @@ abstract class Renderer extends Html
continue; continue;
} }
$elements[] = Element::create( $elements[] = Html::tag(
'span', 'span',
array( [
'class' => array( 'class' => [
'badge', 'badge',
'badge-' . strtolower($state) 'badge-' . strtolower($state)
), ],
// TODO: We should translate this in this module // TODO: We should translate this in this module
'title' => mt('monitoring', $state) 'title' => mt('monitoring', $state)
) ],
)->setContent($cnt); $cnt
);
} }
if (!empty($elements)) { if (!empty($elements)) {
$container = Container::create( $container = Html::tag('div', ['class' => 'badges']);
array('class' => 'badges')
)/* ->renderIfEmpty(false) */;
foreach ($elements as $element) { foreach ($elements as $element) {
$container->addContent($element); $container->add($element);
} }
return $container; return $container;
@ -306,13 +304,14 @@ abstract class Renderer extends Html
return HtmlString::create(''); return HtmlString::create('');
} }
return Element::create( return Html::tag(
'span', 'span',
array( [
'class' => array('relative-time', 'time-since'), 'class' => ['relative-time', 'time-since'],
'title' => DateFormatter::formatDateTime($time), 'title' => DateFormatter::formatDateTime($time)
) ],
)->setContent(DateFormatter::timeSince($time, $timeOnly)); DateFormatter::timeSince($time, $timeOnly)
);
} }
protected function createUnboundParent(BpConfig $bp) protected function createUnboundParent(BpConfig $bp)

View file

@ -2,10 +2,8 @@
namespace Icinga\Module\Businessprocess\Renderer; namespace Icinga\Module\Businessprocess\Renderer;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Renderer\TileRenderer\NodeTile; use Icinga\Module\Businessprocess\Renderer\TileRenderer\NodeTile;
use ipl\Html\Html;
class TileRenderer extends Renderer class TileRenderer extends Renderer
{ {
@ -15,14 +13,12 @@ class TileRenderer extends Renderer
public function render() public function render()
{ {
$bp = $this->config; $bp = $this->config;
$nodesDiv = Container::create( $nodesDiv = Html::tag(
array( 'div',
'class' => array( [
'tiles', 'class' => ['tiles', $this->howMany()],
$this->howMany() 'data-base-target' => '_next'
), ]
'data-base-target' => '_next',
)
); );
$nodes = $this->getChildNodes(); $nodes = $this->getChildNodes();
@ -50,7 +46,7 @@ class TileRenderer extends Renderer
$this->add($this->addNewNode()); $this->add($this->addNewNode());
} }
$nodesDiv->addContent($this->getContent()); $nodesDiv->add($this->getContent());
$this->setContent($nodesDiv); $this->setContent($nodesDiv);
return parent::render(); return parent::render();
@ -80,30 +76,26 @@ class TileRenderer extends Renderer
protected function addNewNode() protected function addNewNode()
{ {
$div = Container::create( $div = Html::tag('div', ['class' => 'addnew', 'data-base-target' => '_self']);
array('class' => 'addnew', 'data-base-target' => '_self')
);
$actions = Container::create( $actions = Html::tag('div', ['class'=> 'actions']);
array('class'=> 'actions')
);
$link = Link::create( $link = Html::tag(
$this->translate('Add'), 'a',
$this->getUrl()->with('action', 'add'), [
null, 'href' => $this->getUrl()->with('action', 'add'),
array( 'title' => mt('businessprocess', 'Add a new business process node')
'title' => $this->translate('Add a new business process node') ],
) mt('businessprocess', 'Add')
); );
$actions->add( $actions->add(
Link::create( Html::tag(
Icon::create('plus'), 'a',
$this->getUrl()->with('action', 'add'), [
null, 'href' => $this->getUrl()->with('action', 'add'),
array( 'title' => mt('businessprocess', 'Add a new business process node')
'title' => $this->translate('Add a new business process node') ],
) Html::tag('i', ['class' => 'icon icon-plus'])
) )
); );

View file

@ -4,18 +4,15 @@ namespace Icinga\Module\Businessprocess\Renderer\TileRenderer;
use Icinga\Module\Businessprocess\BpNode; use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\HostNode; use Icinga\Module\Businessprocess\HostNode;
use Icinga\Module\Businessprocess\Html\BaseElement;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\HtmlString;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\ImportedNode; use Icinga\Module\Businessprocess\ImportedNode;
use Icinga\Module\Businessprocess\MonitoredNode; use Icinga\Module\Businessprocess\MonitoredNode;
use Icinga\Module\Businessprocess\Node; use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\Renderer\Renderer; use Icinga\Module\Businessprocess\Renderer\Renderer;
use Icinga\Module\Businessprocess\ServiceNode; use Icinga\Module\Businessprocess\ServiceNode;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class NodeTile extends BaseElement class NodeTile extends BaseHtmlElement
{ {
protected $tag = 'div'; protected $tag = 'div';
@ -28,7 +25,7 @@ class NodeTile extends BaseElement
protected $path; protected $path;
/** /**
* @var Container * @var BaseHtmlElement
*/ */
private $actions; private $actions;
@ -57,11 +54,12 @@ class NodeTile extends BaseElement
protected function addActions() protected function addActions()
{ {
$this->actions = Container::create( $this->actions = Html::tag(
array( 'div',
[
'class' => 'actions', 'class' => 'actions',
'data-base-target' => '_self' 'data-base-target' => '_self'
) ]
); );
return $this->add($this->actions); return $this->add($this->actions);
@ -72,7 +70,7 @@ class NodeTile extends BaseElement
$renderer = $this->renderer; $renderer = $this->renderer;
$node = $this->node; $node = $this->node;
$attributes = $this->attributes(); $attributes = $this->getAttributes();
$attributes->add('class', $renderer->getNodeClasses($node)); $attributes->add('class', $renderer->getNodeClasses($node));
$attributes->add('id', 'bp-' . (string) $node); $attributes->add('id', 'bp-' . (string) $node);
@ -83,9 +81,9 @@ class NodeTile extends BaseElement
if ($node instanceof BpNode) { if ($node instanceof BpNode) {
if ($renderer->isBreadcrumb()) { if ($renderer->isBreadcrumb()) {
$link->addContent($renderer->renderStateBadges($node->getStateSummary())); $link->add($renderer->renderStateBadges($node->getStateSummary()));
} else { } else {
$this->addContent($renderer->renderStateBadges($node->getStateSummary())); $this->add($renderer->renderStateBadges($node->getStateSummary()));
} }
} }
@ -168,32 +166,22 @@ class NodeTile extends BaseElement
} }
/** /**
* @return Link * @return BaseHtmlElement
*/ */
protected function getMainNodeLink() protected function getMainNodeLink()
{ {
$node = $this->node; $node = $this->node;
$url = $this->getMainNodeUrl($node); $url = $this->getMainNodeUrl($node);
if ($node instanceof ServiceNode) { if ($node instanceof ServiceNode) {
$link = Link::create( $link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getAlias());
$node->getAlias(),
$url,
null,
array('data-base-target' => '_next')
);
} elseif ($node instanceof HostNode) { } elseif ($node instanceof HostNode) {
$link = Link::create( $link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getHostname());
$node->getHostname(),
$url,
null,
array('data-base-target' => '_next')
);
} else { } else {
$link = Link::create($node->getAlias(), $url); $link = Html::tag('a', ['href' => $url], $node->getAlias());
if ($node instanceof ImportedNode) { if ($node instanceof ImportedNode) {
$link->attributes()->add('data-base-target', '_next'); $link->getAttributes()->add('data-base-target', '_next');
} else { } else {
$link->attributes()->add('data-base-target', '_self'); $link->getAttributes()->add('data-base-target', '_self');
} }
} }
@ -206,56 +194,54 @@ class NodeTile extends BaseElement
$url = $this->getMainNodeUrl($node); $url = $this->getMainNodeUrl($node);
if ($node instanceof BpNode) { if ($node instanceof BpNode) {
$this->actions()->add(Link::create( $this->actions()->add(Html::tag(
Icon::create('dashboard'), 'a',
$url->with('mode', 'tile'), [
null, 'data-base-target' => '_self',
array( 'href' => $url->with('mode', 'tile'),
'title' => $this->translate('Show tiles for this subtree'), 'title' => mt('businessprocess', 'Show tiles for this subtree')
'data-base-target' => '_self' ],
) Html::tag('i', ['class' => 'icon icon-dashboard'])
))->add(Link::create( ))->add(Html::tag(
Icon::create('sitemap'), 'a',
$url->with('mode', 'tree'), [
null, 'data-base-target' => '_next',
array( 'href' => $url->with('mode', 'tree'),
'title' => $this->translate('Show this subtree as a tree'), 'title' => mt('businessprocess', 'Show this subtree as a tree')
'data-base-target' => '_next' ],
) Html::tag('i', ['class' => 'icon icon-sitemap'])
)); ));
$url = $node->getInfoUrl(); $url = $node->getInfoUrl();
if ($url !== null) { if ($url !== null) {
$link = Link::create( $link = Html::tag(
Icon::create('info-circled'), 'a',
$url, [
null, 'href' => $url,
array( 'class' => 'node-info',
'title' => sprintf('%s: %s', $this->translate('More information'), $url), 'title' => sprintf('%s: %s', mt('businessprocess', 'More information'), $url)
'class' => 'node-info' ],
) Html::tag('i', ['class' => 'icon icon-circled'])
); );
if (preg_match('#^http(?:s)?://#', $url)) { if (preg_match('#^http(?:s)?://#', $url)) {
$link->addAttributes(array('target' => '_blank')); $link->addAttributes(['target' => '_blank']);
} }
$this->actions()->add($link); $this->actions()->add($link);
} }
} else { } else {
// $url = $this->makeMonitoredNodeUrl($node); // $url = $this->makeMonitoredNodeUrl($node);
if ($node instanceof ServiceNode) { if ($node instanceof ServiceNode) {
$this->actions()->add(Link::create( $this->actions()->add(Html::tag(
Icon::create('service'), 'a',
$node->getUrl(), ['href' => $node->getUrl(), 'data-base-target' => '_next'],
null, Html::tag('i', ['class' => 'icon icon-service'])
array('data-base-target' => '_next')
)); ));
} elseif ($node instanceof HostNode) { } elseif ($node instanceof HostNode) {
$this->actions()->add(Link::create( $this->actions()->add(Html::tag(
Icon::create('host'), 'a',
$node->getUrl(), ['href' => $node->getUrl(), 'data-base-target' => '_next'],
null, Html::tag('i', ['class' => 'icon icon-host'])
array('data-base-target' => '_next')
)); ));
} }
} }
@ -266,21 +252,29 @@ class NodeTile extends BaseElement
$node = $this->node; $node = $this->node;
$renderer = $this->renderer; $renderer = $this->renderer;
if ($node instanceof MonitoredNode) { if ($node instanceof MonitoredNode) {
$this->actions()->add(Link::create( $this->actions()->add(Html::tag(
Icon::create('magic'), 'a',
$renderer->getUrl()->with('action', 'simulation') [
->with('simulationnode', $this->name), 'href' => $renderer->getUrl()
null, ->with('action', 'simulation')
array('title' => $this->translate( ->with('simulationnode', $this->name),
'Show the business impact of this node by simulating a specific state' 'title' => mt(
)) 'businessprocess',
'Show the business impact of this node by simulating a specific state'
)
],
Html::tag('i', ['class' => 'icon icon-magic'])
)); ));
$this->actions()->add(Link::create( $this->actions()->add(Html::tag(
Icon::create('edit'), 'a',
$renderer->getUrl()->with('action', 'editmonitored')->with('editmonitorednode', $node->getName()), [
null, 'href' => $renderer->getUrl()
array('title' => $this->translate('Modify this monitored node')) ->with('action', 'editmonitored')
->with('editmonitorednode', $node->getName()),
'title' => mt('businessprocess', 'Modify this monitored node')
],
Html::tag('i', ['class' => 'icon icon-edit'])
)); ));
} }
@ -291,11 +285,15 @@ class NodeTile extends BaseElement
} }
if ($node instanceof BpNode) { if ($node instanceof BpNode) {
$this->actions()->add(Link::create( $this->actions()->add(Html::tag(
Icon::create('edit'), 'a',
$renderer->getUrl()->with('action', 'edit')->with('editnode', $node->getName()), [
null, 'href' => $renderer->getUrl()
array('title' => $this->translate('Modify this business process node')) ->with('action', 'edit')
->with('editnode', $node->getName()),
'title' => mt('businessprocess', 'Modify this business process node')
],
Html::tag('i', ['class' => 'icon icon-edit'])
)); ));
} }
@ -304,11 +302,13 @@ class NodeTile extends BaseElement
'deletenode' => $node->getName(), 'deletenode' => $node->getName(),
); );
$this->actions()->add(Link::create( $this->actions()->add(Html::tag(
Icon::create('cancel'), 'a',
$renderer->getUrl()->with($params), [
null, 'href' => $renderer->getUrl()->with($params),
array('title' => $this->translate('Delete this node')) 'title' => mt('businessprocess', 'Delete this node')
],
Html::tag('i', ['class' => 'icon icon-cancle'])
)); ));
} }
} }

View file

@ -4,12 +4,9 @@ namespace Icinga\Module\Businessprocess\Renderer;
use Icinga\Module\Businessprocess\BpNode; use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\BpConfig; use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\Element;
use Icinga\Module\Businessprocess\Html\Icon;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Node; use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\Web\Url; use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class TreeRenderer extends Renderer class TreeRenderer extends Renderer
{ {
@ -19,11 +16,12 @@ class TreeRenderer extends Renderer
public function render() public function render()
{ {
$bp = $this->config; $bp = $this->config;
$this->add(Container::create( $this->add(Html::tag(
array( 'div',
[
'id' => $bp->getHtmlId(), 'id' => $bp->getHtmlId(),
'class' => 'bp' 'class' => 'bp'
), ],
$this->renderBp($bp) $this->renderBp($bp)
)); ));
@ -79,16 +77,16 @@ class TreeRenderer extends Renderer
/** /**
* @param Node $node * @param Node $node
* @return Icon[] * @return BaseHtmlElement[]
*/ */
public function getNodeIcons(Node $node) public function getNodeIcons(Node $node)
{ {
$icons = array(); $icons = array();
if ($node->isInDowntime()) { if ($node->isInDowntime()) {
$icons[] = Icon::create('moon'); $icons[] = Html::tag('i', ['class' => 'icon icon-moon']);
} }
if ($node->isAcknowledged()) { if ($node->isAcknowledged()) {
$icons[] = Icon::create('ok'); $icons[] = Html::tag('i', ['class' => 'icon icon-ok']);
} }
return $icons; return $icons;
} }
@ -102,17 +100,17 @@ class TreeRenderer extends Renderer
*/ */
public function renderNode(BpConfig $bp, Node $node, $path = array()) public function renderNode(BpConfig $bp, Node $node, $path = array())
{ {
$table = Element::create( $table = Html::tag(
'table', 'table',
array( [
'id' => $this->getId($node, $path), 'id' => $this->getId($node, $path),
'class' => array( 'class' => array(
'bp', 'bp',
$node->getObjectClassName() $node->getObjectClassName()
) )
) ]
); );
$attributes = $table->attributes(); $attributes = $table->getAttributes();
$attributes->add('class', $this->getStateClassNames($node)); $attributes->add('class', $this->getStateClassNames($node));
if ($node->isHandled()) { if ($node->isHandled()) {
$attributes->add('class', 'handled'); $attributes->add('class', 'handled');
@ -123,57 +121,68 @@ class TreeRenderer extends Renderer
$attributes->add('class', 'node'); $attributes->add('class', 'node');
} }
$tbody = $table->createElement('tbody'); $tbody = Html::tag('tbody');
$tr = $tbody->createElement('tr'); $table->add($tbody);
$tr = Html::tag('tr');
$tbody->add($tr);
if ($node instanceof BpNode) { if ($node instanceof BpNode) {
$tr->createElement( $tr->add(Html::tag(
'th', 'th',
array( ['rowspan' => $node->countChildren() + 1 + ($this->isLocked() ? 0 : 1)],
'rowspan' => $node->countChildren() + 1 + ($this->isLocked() ? 0 : 1) Html::tag('span', ['class' => 'op'], $node->operatorHtml())
) ));
)->createElement(
'span',
array('class' => 'op')
)->setContent($node->operatorHtml());
} }
$td = $tr->createElement('td'); $td = Html::tag('td');
$tr->add($td);
if ($node instanceof BpNode && $node->hasInfoUrl()) { if ($node instanceof BpNode && $node->hasInfoUrl()) {
$td->add($this->createInfoAction($node)); $td->add($this->createInfoAction($node));
} }
if (! $this->isLocked()) { if (! $this->isLocked()) {
$td->addContent($this->getActionIcons($bp, $node)); $td->add($this->getActionIcons($bp, $node));
} }
$link = $node->getLink(); $link = $node->getLink();
$link->attributes()->set('data-base-target', '_next'); $link->getAttributes()->set('data-base-target', '_next');
$link->addContent($this->getNodeIcons($node)); $link->add($this->getNodeIcons($node));
if ($node->hasChildren()) { if ($node->hasChildren()) {
$link->addContent($this->renderStateBadges($node->getStateSummary())); $link->add($this->renderStateBadges($node->getStateSummary()));
} }
if ($time = $node->getLastStateChange()) { if ($time = $node->getLastStateChange()) {
$since = $this->timeSince($time)->prependContent( $since = $this->timeSince($time)->prepend(
sprintf(' (%s ', $node->getStateName()) sprintf(' (%s ', $node->getStateName())
)->addContent(')'); )->add(')');
$link->addContent($since); $link->add($since);
} }
$td->addContent($link); $td->add($link);
foreach ($node->getChildren() as $name => $child) { foreach ($node->getChildren() as $name => $child) {
$tbody->createElement('tr')->createElement('td')->setContent( $tbody->add(Html::tag(
$this->renderNode($bp, $child, $this->getCurrentPath()) 'tr',
); null,
Html::tag(
'td',
null,
$this->renderNode($bp, $child, $this->getCurrentPath())
)
));
} }
if (! $this->isLocked() && $node instanceof BpNode && $bp->getMetadata()->canModify()) { if (! $this->isLocked() && $node instanceof BpNode && $bp->getMetadata()->canModify()) {
$tbody->createElement('tr')->createElement('td')->setContent( $tbody->add(Html::tag(
$this->renderAddNewNode($node) 'tr',
); null,
Html::tag(
'td',
null,
$this->renderAddNewNode($node)
)
));
} }
return $table; return $table;
@ -200,7 +209,7 @@ class TreeRenderer extends Renderer
'action' => 'edit', 'action' => 'edit',
'editnode' => $node->getName() 'editnode' => $node->getName()
)), )),
$this->translate('Modify this node') mt('businessprocess', 'Modify this node')
); );
} }
@ -213,7 +222,7 @@ class TreeRenderer extends Renderer
'action' => 'simulation', 'action' => 'simulation',
'simulationnode' => $node->getName() 'simulationnode' => $node->getName()
)), )),
$this->translate('Simulate a specific state') mt('businessprocess', 'Simulate a specific state')
); );
} }
@ -223,33 +232,35 @@ class TreeRenderer extends Renderer
return $this->actionIcon( return $this->actionIcon(
'help', 'help',
$url, $url,
sprintf('%s: %s', $this->translate('More information'), $url) sprintf('%s: %s', mt('businessprocess', 'More information'), $url)
); );
} }
protected function actionIcon($icon, $url, $title) protected function actionIcon($icon, $url, $title)
{ {
return Link::create( return Html::tag(
Icon::create($icon), 'a',
$url, [
null, 'href' => $url,
array(
'title' => $title, 'title' => $title,
'style' => 'float: right', 'style' => 'float: right'
) ],
Html::tag('i', ['class' => 'icon icon-' . $icon])
); );
} }
protected function renderAddNewNode($parent) protected function renderAddNewNode($parent)
{ {
return Link::create( return Html::tag(
$this->translate('Add'), 'a',
$this->getUrl()->with('action', 'add')->with('node', $parent->getName()), [
null, 'href' => $this->getUrl()
array( ->with('action', 'add')
'class' => 'addnew icon-plus', ->with('node', $parent->getName()),
'title' => $this->translate('Add a new business process node') 'title' => mt('businessprocess', 'Add a new business process node'),
) 'class' => 'addnew icon-plus'
],
mt('businessprocess', 'Add')
); );
} }
} }

View file

@ -7,9 +7,9 @@ use Diff_Renderer_Html_Inline;
use Diff_Renderer_Html_SideBySide; use Diff_Renderer_Html_SideBySide;
use Diff_Renderer_Text_Context; use Diff_Renderer_Text_Context;
use Diff_Renderer_Text_Unified; use Diff_Renderer_Text_Unified;
use Icinga\Module\Businessprocess\Html\Renderable; use ipl\Html\ValidHtml;
class ConfigDiff implements Renderable class ConfigDiff implements ValidHtml
{ {
protected $a; protected $a;

View file

@ -23,6 +23,7 @@ class Bootstrap
Cli::start($testsDir, $configDir) Cli::start($testsDir, $configDir)
->getModuleManager() ->getModuleManager()
->loadModule('ipl', $basedir . '/vendor/ipl')
->loadModule('businessprocess', $basedir); ->loadModule('businessprocess', $basedir);
} }
} }

View file

@ -2,9 +2,9 @@
namespace Icinga\Module\Businessprocess\Web\Component; namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\BaseElement; use ipl\Html\BaseHtmlElement;
class ActionBar extends BaseElement class ActionBar extends BaseHtmlElement
{ {
protected $contentSeparator = ' '; protected $contentSeparator = ' ';

View file

@ -3,15 +3,12 @@
namespace Icinga\Module\Businessprocess\Web\Component; namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\BpConfig; use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\BaseElement; use Icinga\Web\Url;
use Icinga\Module\Businessprocess\Html\Container; use ipl\Html\BaseHtmlElement;
use Icinga\Module\Businessprocess\Html\Element; use ipl\Html\Html;
use Icinga\Module\Businessprocess\Html\Icon; use ipl\Html\Text;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Html\Text;
use Icinga\Module\Businessprocess\Web\Url;
class BpDashboardTile extends BaseElement class BpDashboardTile extends BaseHtmlElement
{ {
protected $tag = 'div'; protected $tag = 'div';
@ -19,33 +16,32 @@ class BpDashboardTile extends BaseElement
public function __construct(BpConfig $bp, $title, $description, $icon, $url, $urlParams = null, $attributes = null) public function __construct(BpConfig $bp, $title, $description, $icon, $url, $urlParams = null, $attributes = null)
{ {
$this->add( if (! isset($attributes['href'])) {
Container::create( $attributes['href'] = Url::fromPath($url, $urlParams ?: []);
['class' => 'bp-link', 'data-base-target' => '_main'], }
Link::create(
Icon::create($icon),
$url,
$urlParams,
$attributes
)->add(
Element::create('span', array('class' => 'header'))->addContent($title)
)->addContent($description)
)
);
$tiles = Container::create(['class' => 'bp-root-tiles']); $this->add(Html::tag(
'div',
['class' => 'bp-link', 'data-base-target' => '_main'],
Html::tag('a', $attributes, Html::tag('i', ['class' => 'icon icon-' . $icon]))
->add(Html::tag('span', ['class' => 'header'], $title))
->add($description)
));
$tiles = Html::tag('div', ['class' => 'bp-root-tiles']);
foreach ($bp->getChildren() as $node) { foreach ($bp->getChildren() as $node) {
$state = strtolower($node->getStateName()); $state = strtolower($node->getStateName());
$tiles->add( $tiles->add(Html::tag(
Link::create( 'a',
Text::create('&nbsp;')->setEscaped(), [
$url, 'href' => Url::fromPath($url, $urlParams ?: [])->with(['node' => $node->getName()]),
$urlParams + ['node' => $node->getName()], 'class' => "badge state-{$state}",
['class' => "badge state-{$state}", 'title' => $node->getAlias()] 'title' => $node->getAlias()
) ],
); Text::create('&nbsp;')->setEscaped()
));
} }
$this->add($tiles); $this->add($tiles);

View file

@ -2,10 +2,12 @@
namespace Icinga\Module\Businessprocess\Web\Component; namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\Container; use ipl\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 = array('class' => 'content');

View file

@ -2,10 +2,12 @@
namespace Icinga\Module\Businessprocess\Web\Component; namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\Container; use ipl\Html\BaseHtmlElement;
class Controls extends Container class Controls extends BaseHtmlElement
{ {
protected $tag = 'div';
protected $contentSeparator = "\n"; protected $contentSeparator = "\n";
protected $defaultAttributes = array('class' => 'controls'); protected $defaultAttributes = array('class' => 'controls');

View file

@ -3,13 +3,12 @@
namespace Icinga\Module\Businessprocess\Web\Component; namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Authentication\Auth; use Icinga\Authentication\Auth;
use Icinga\Module\Businessprocess\Html\BaseElement;
use Icinga\Module\Businessprocess\Html\Container;
use Icinga\Module\Businessprocess\Html\HtmlTag;
use Icinga\Module\Businessprocess\State\MonitoringState; use Icinga\Module\Businessprocess\State\MonitoringState;
use Icinga\Module\Businessprocess\Storage\Storage; use Icinga\Module\Businessprocess\Storage\Storage;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
class Dashboard extends BaseElement class Dashboard extends BaseHtmlElement
{ {
/** @var string */ /** @var string */
protected $contentSeparator = "\n"; protected $contentSeparator = "\n";
@ -40,21 +39,22 @@ class Dashboard extends BaseElement
// TODO: Auth? // TODO: Auth?
$processes = $storage->listProcessNames(); $processes = $storage->listProcessNames();
$this->add( $this->add(
HtmlTag::h1($this->translate('Welcome to your Business Process Overview')) Html::tag('h1', null, mt('businessprocess', 'Welcome to your Business Process Overview'))
); );
$this->add( $this->add(Html::tag(
HtmlTag::p( 'p',
$this->translate( null,
'From here you can reach all your defined Business Process' mt(
. ' configurations, create new or modify existing ones' 'businessprocess',
) 'From here you can reach all your defined Business Process'
. ' configurations, create new or modify existing ones'
) )
); ));
if ($auth->hasPermission('businessprocess/create')) { if ($auth->hasPermission('businessprocess/create')) {
$this->add( $this->add(
new DashboardAction( new DashboardAction(
$this->translate('Create'), mt('businessprocess', 'Create'),
$this->translate('Create a new Business Process configuration'), mt('businessprocess', 'Create a new Business Process configuration'),
'plus', 'plus',
'businessprocess/process/create', 'businessprocess/process/create',
null, null,
@ -62,8 +62,8 @@ class Dashboard extends BaseElement
) )
)->add( )->add(
new DashboardAction( new DashboardAction(
$this->translate('Upload'), mt('businessprocess', 'Upload'),
$this->translate('Upload an existing Business Process configuration'), mt('businessprocess', 'Upload an existing Business Process configuration'),
'upload', 'upload',
'businessprocess/process/upload', 'businessprocess/process/upload',
null, null,
@ -71,10 +71,13 @@ class Dashboard extends BaseElement
) )
); );
} elseif (empty($processes)) { } elseif (empty($processes)) {
$this->addContent( $this->add(
Container::create() Html::tag('div')
->add(HtmlTag::h1($this->translate('Not available'))) ->add(Html::tag('h1', null, mt('businessprocess', 'Not available')))
->add(HtmlTag::p($this->translate('No Business Process has been defined for you'))) ->add(Html::tag('p', null, mt(
'businessprocess',
'No Business Process has been defined for you'
)))
); );
} }

View file

@ -2,12 +2,11 @@
namespace Icinga\Module\Businessprocess\Web\Component; namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\BaseElement; use Icinga\Web\Url;
use Icinga\Module\Businessprocess\Html\Element; use ipl\Html\BaseHtmlElement;
use Icinga\Module\Businessprocess\Html\Icon; use ipl\Html\Html;
use Icinga\Module\Businessprocess\Html\Link;
class DashboardAction extends BaseElement class DashboardAction extends BaseHtmlElement
{ {
protected $tag = 'div'; protected $tag = 'div';
@ -15,15 +14,13 @@ class DashboardAction extends BaseElement
public function __construct($title, $description, $icon, $url, $urlParams = null, $attributes = null) public function __construct($title, $description, $icon, $url, $urlParams = null, $attributes = null)
{ {
$this->add( if (! isset($attributes['href'])) {
Link::create( $attributes['href'] = Url::fromPath($url, $urlParams ?: []);
Icon::create($icon), }
$url,
$urlParams, $this->add(Html::tag('a', $attributes)
$attributes ->add(Html::tag('i', ['class' => 'icon icon-' . $icon]))
)->add( ->add(Html::tag('span', ['class' => 'header'], $title))
Element::create('span', array('class' => 'header'))->addContent($title) ->add($description));
)->addContent($description)
);
} }
} }

View file

@ -4,10 +4,10 @@ namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Authentication\Auth; use Icinga\Authentication\Auth;
use Icinga\Module\Businessprocess\BpConfig; use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Renderer\Renderer; use Icinga\Module\Businessprocess\Renderer\Renderer;
use Icinga\Module\Businessprocess\Renderer\TreeRenderer; use Icinga\Module\Businessprocess\Renderer\TreeRenderer;
use Icinga\Module\Businessprocess\Web\Url; use Icinga\Web\Url;
use ipl\Html\Html;
class RenderedProcessActionBar extends ActionBar class RenderedProcessActionBar extends ActionBar
{ {
@ -16,87 +16,73 @@ class RenderedProcessActionBar extends ActionBar
$meta = $config->getMetadata(); $meta = $config->getMetadata();
if ($renderer instanceof TreeRenderer) { if ($renderer instanceof TreeRenderer) {
$this->add( $this->add(Html::tag(
Link::create( 'a',
$this->translate('Tiles'), [
$url->with('mode', 'tile'), 'href' => $url->with('mode', 'tile'),
null, 'title' => mt('businessprocess', 'Switch to Tile view'),
array( 'class' => 'icon-dashboard'
'class' => 'icon-dashboard', ],
'title' => $this->translate('Switch to Tile view'), mt('businessprocess', 'Tiles')
) ));
)
);
} else { } else {
$this->add( $this->add(Html::tag(
Link::create( 'a',
$this->translate('Tree'), [
$url->with('mode', 'tree'), 'href' => $url->with('mode', 'tree'),
null, 'title' => mt('businessprocess', 'Switch to Tree view'),
array( 'class' => 'icon-sitemap'
'class' => 'icon-sitemap', ],
'title' => $this->translate('Switch to Tree view'), mt('businessprocess', 'Tree')
) ));
)
);
} }
$this->add( $this->add(Html::tag(
Link::create( 'a',
$this->translate('Fullscreen'), [
$url->with('showFullscreen', true), 'data-base-target' => '_main',
null, 'href' => $url->with('showFullscreen', true),
array( 'title' => mt('businessprocess', 'Switch to fullscreen mode'),
'class' => 'icon-resize-full-alt', 'class' => 'icon-resize-full-alt'
'title' => $this->translate('Switch to fullscreen mode'), ],
'data-base-target' => '_main', mt('businessprocess', 'Fullscreen')
) ));
)
);
$hasChanges = $config->hasSimulations() || $config->hasBeenChanged(); $hasChanges = $config->hasSimulations() || $config->hasBeenChanged();
if ($renderer->isLocked()) { if ($renderer->isLocked()) {
$this->add( $this->add(Html::tag(
Link::create( 'a',
$this->translate('Editing locked'), [
$url->with('unlocked', true), 'href' => $url->with('unlocked', true),
null, 'title' => mt('businessprocess', 'Click to unlock editing for this process'),
array( 'class' => 'icon-lock'
'class' => 'icon-lock', ],
'title' => $this->translate('Click to unlock editing for this process'), mt('businessprocess', 'Editing locked')
) ));
)
);
} elseif (! $hasChanges) { } elseif (! $hasChanges) {
$this->add( $this->add(Html::tag(
Link::create( 'a',
$this->translate('Editing unlocked'), [
$url->without('unlocked')->without('action'), 'href' => $url->without('unlocked')->without('action'),
null, 'title' => mt('businessprocess', 'Click to lock editing for this process'),
array( 'class' => 'icon-lock-open'
'class' => 'icon-lock-open', ],
'title' => $this->translate('Click to lock editing for this process'), mt('businessprocess', 'Editing unlocked')
) ));
)
);
} }
if ($renderer->wantsRootNodes() && ( if ($renderer->wantsRootNodes() && (($hasChanges || (! $renderer->isLocked())) && $meta->canModify())) {
($hasChanges || (! $renderer->isLocked())) && $meta->canModify() $this->add(Html::tag(
)) { 'a',
$this->add( [
Link::create( 'data-base-target' => '_next',
$this->translate('Config'), 'href' => Url::fromPath('businessprocess/process/config', $this->currentProcessParams($url)),
'businessprocess/process/config', 'title' => mt('businessprocess', 'Modify this process'),
$this->currentProcessParams($url), 'class' => 'icon-wrench'
array( ],
'class' => 'icon-wrench', mt('businessprocess', 'Config')
'title' => $this->translate('Modify this process'), ));
'data-base-target' => '_next',
)
)
);
} }
} }

View file

@ -2,8 +2,8 @@
namespace Icinga\Module\Businessprocess\Web\Component; namespace Icinga\Module\Businessprocess\Web\Component;
use Icinga\Module\Businessprocess\Html\Renderable; use ipl\Html\ValidHtml;
class Tabs extends WtfTabs implements Renderable class Tabs extends WtfTabs implements ValidHtml
{ {
} }

View file

@ -4,7 +4,6 @@ namespace Icinga\Module\Businessprocess\Web;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Module\Businessprocess\BpConfig; use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Html\HtmlTag;
use Icinga\Module\Businessprocess\Modification\ProcessChanges; use Icinga\Module\Businessprocess\Modification\ProcessChanges;
use Icinga\Module\Businessprocess\Storage\LegacyStorage; use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Businessprocess\Storage\Storage; use Icinga\Module\Businessprocess\Storage\Storage;
@ -16,6 +15,7 @@ use Icinga\Module\Businessprocess\Web\Form\FormLoader;
use Icinga\Web\Controller as ModuleController; use Icinga\Web\Controller as ModuleController;
use Icinga\Web\Notification; use Icinga\Web\Notification;
use Icinga\Web\View; use Icinga\Web\View;
use ipl\Html\Html;
class Controller extends ModuleController class Controller extends ModuleController
{ {
@ -86,9 +86,9 @@ class Controller extends ModuleController
protected function controls() protected function controls()
{ {
if ($this->view->controls === null) { if ($this->view->controls === null) {
$controls = $this->view->controls = Controls::create(); $controls = $this->view->controls = new Controls();
if ($this->view->compact) { if ($this->view->compact) {
$controls->attributes()->add('class', 'compact'); $controls->getAttributes()->add('class', 'compact');
} }
} }
@ -101,9 +101,9 @@ class Controller extends ModuleController
protected function content() protected function content()
{ {
if ($this->view->content === null) { if ($this->view->content === null) {
$content = $this->view->content = Content::create(); $content = $this->view->content = new Content();
if ($this->view->compact) { if ($this->view->compact) {
$content->attributes()->add('class', 'compact'); $content->getAttributes()->add('class', 'compact');
} }
} }
@ -187,7 +187,7 @@ class Controller extends ModuleController
$args = func_get_args(); $args = func_get_args();
array_shift($args); array_shift($args);
$this->view->title = vsprintf($title, $args); $this->view->title = vsprintf($title, $args);
$this->controls()->add(HtmlTag::h1($this->view->title)); $this->controls()->add(Html::tag('h1', null, $this->view->title));
return $this; return $this;
} }

View file

@ -4,10 +4,10 @@ namespace Icinga\Module\Businessprocess\Web\Form;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module; use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\Html\Renderable; use ipl\Html\ValidHtml;
use Zend_Form; use Zend_Form;
abstract class QuickBaseForm extends Zend_Form implements Renderable abstract class QuickBaseForm extends Zend_Form implements ValidHtml
{ {
/** /**
* The Icinga module this form belongs to. Usually only set if the * The Icinga module this form belongs to. Usually only set if the

View file

@ -1,150 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Attribute;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class AttributeTest extends BaseTestCase
{
public function testCreatesFactoryCreatesAttribute()
{
$this->assertInstanceOf(
get_class(new Attribute('a', 'b')),
Attribute::create('a', 'b')
);
}
public function testKnowsItsName()
{
$a = new Attribute('target', '_blank');
$this->assertEquals(
'target',
$a->getName()
);
}
public function testKnowsItsValue()
{
$a = new Attribute('target', '_blank');
$this->assertEquals(
'_blank',
$a->getValue()
);
}
public function testItsValueCanBeModified()
{
$a = new Attribute('target', '_blank');
$a->setValue('_self');
$this->assertEquals(
'_self',
$a->getValue()
);
}
public function testPreservesComplexValues()
{
$a = new Attribute('special', 'süß "\'&');
$this->assertEquals(
'süß "\'&',
$a->getValue()
);
}
public function testAllowsToExtendItsValue()
{
$a = new Attribute('class', 'first');
$a->addValue('second');
$this->assertEquals(
array('first', 'second'),
$a->getValue()
);
$a->addValue('third');
$this->assertEquals(
array('first', 'second', 'third'),
$a->getValue()
);
$a->addValue(array('some', 'more'));
$this->assertEquals(
array('first', 'second', 'third', 'some', 'more'),
$a->getValue()
);
}
public function testAcceptsAndReturnsArrayValues()
{
$value = array('first', 'second', 'third');
$a = new Attribute('class', $value);
$this->assertEquals(
$value,
$a->getValue()
);
$value[] = 'forth';
$a->setValue($value);
$this->assertEquals(
$value,
$a->getValue()
);
}
public function testCorrectlyRendersItsName()
{
$a = new Attribute('class', 'test');
$this->assertEquals(
'class',
$a->renderName()
);
}
public function testCorrectlyRendersItsValue()
{
$a = new Attribute('href', '/some/url?a=b&c=d');
$this->assertEquals(
'/some/url?a=b&amp;c=d',
$a->renderValue()
);
}
public function testCorrectlyRendersArrayValues()
{
$a = new Attribute('weird', array('"sü?ß', '/some/url?a=b&c=d'));
$this->assertEquals(
'&quot;sü?ß /some/url?a=b&amp;c=d',
$a->renderValue()
);
}
public function testCorrectlyEscapesAName()
{
$this->assertEquals(
'class',
Attribute::escapeName('class')
);
}
public function testCorrectlyEscapesAValue()
{
$this->assertEquals(
"&quot;sü?ß' /some/url?a=b&amp;c=d",
Attribute::escapeValue('"sü?ß\' /some/url?a=b&c=d')
);
}
public function testRendersCorrectly()
{
$a = new Attribute('weird', array('"sü?ß', '/some/url?a=b&c=d'));
$this->assertEquals(
'weird="&quot;sü?ß /some/url?a=b&amp;c=d"',
$a->render()
);
}
}

View file

@ -1,111 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Attribute;
use Icinga\Module\Businessprocess\Html\Attributes;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class AttributesTest extends BaseTestCase
{
public function testCanBeConstructedFromANormalArray()
{
$a = new Attributes(
array(
'class' => array('small', 'nice'),
'target' => '_blank'
)
);
$this->assertEquals(
' class="small nice" target="_blank"',
$a->render()
);
}
public function testCanBeInstantiatedThroughCreate()
{
$class = get_class(new Attributes());
$this->assertInstanceOf(
$class,
Attributes::create()
);
$this->assertInstanceOf(
$class,
Attributes::create(array('some' => 'attr'))
);
}
public function testCanBeCreatedForArrayOrNullOrAttributes()
{
$empty = Attributes::wantAttributes(null);
$this->assertEquals('', $empty->render());
$array = Attributes::wantAttributes(array('a' => 'b'));
$this->assertEquals(' a="b"', $array->render());
$attributes = Attributes::wantAttributes(
Attributes::create(array('a' => 'b'))
);
$this->assertEquals(' a="b"', $attributes->render());
}
public function testCanBeExtendedWithAnAttribute()
{
$a = Attributes::create();
$a->add(Attribute::create('a', 'b'));
$this->assertEquals(' a="b"', $a->render());
$a->add(Attribute::create('c', 'd'));
$this->assertEquals(' a="b" c="d"', $a->render());
$a->add(Attribute::create('a', 'c'));
$this->assertEquals(' a="b c" c="d"', $a->render());
}
public function testCanBeExtendedWithAttributes()
{
$a = Attributes::create();
$a->add(Attributes::create(array('a' => 'b')));
$this->assertEquals(' a="b"', $a->render());
$a->add(Attributes::create(
array(
'a' => 'c',
'c' => 'd'
)
));
$this->assertEquals(' a="b c" c="d"', $a->render());
}
public function testCanBeExtendedWithANameValuePair()
{
$a = Attributes::create();
$a->add('a', 'b');
$this->assertEquals(' a="b"', $a->render());
}
public function testAttributesCanBeReplacedWithAnAttribute()
{
$a = Attributes::create();
$a->add(Attribute::create('a', 'b'));
$a->set(Attribute::create('a', 'c'));
$this->assertEquals(' a="c"', $a->render());
}
public function testAttributesCanBeReplacedWithANameValuePair()
{
$a = Attributes::create();
$a->add(Attribute::create('a', 'b'));
$a->set('a', 'c');
$this->assertEquals(' a="c"', $a->render());
}
public function testCanBeConstructedAndRenderedEmpty()
{
$a = new Attributes();
$this->assertEquals('', $a->render());
}
}

View file

@ -1,18 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\HtmlTag;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class HtmlTagTest extends BaseTestCase
{
public function testHeaderIsRendered()
{
$h1 = HtmlTag::h1('Hea & der');
$this->assertEquals(
$h1->render(),
'<h1>Hea &amp; der</h1>'
);
}
}

View file

@ -1,42 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Html;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class HtmlTest extends BaseTestCase
{
public function testContentIsRendered()
{
$h = new Html();
$h->setContent('Some content');
$this->assertEquals(
'Some content',
$h->render()
);
}
public function testContentCanBeExtended()
{
$h = new Html();
$h->setContent('Some content');
$h->addContent('More content');
$this->assertEquals(
'Some contentMore content',
$h->render()
);
}
public function testSeparatorsAreRespected()
{
$h = new Html();
$h->setContent('Some content');
$h->setSeparator(', and ');
$h->addContent('More content');
$this->assertEquals(
'Some content, and More content',
$h->render()
);
}
}

View file

@ -1,43 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Link;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class LinkTest extends BaseTestCase
{
public function testContentFromFactoryIsRendered()
{
$l = Link::create('Click here', 'go/some/where');
$this->assertEquals(
'Click here',
$l->renderContent()
);
}
public function testSimpleLinkRendersCorrectly()
{
$l = Link::create('Click here', 'go/some/where');
$this->assertEquals(
'<a href="/icingaweb2/go/some/where">Click here</a>',
$l->render()
);
}
public function testLinkWithParamsRendersCorrectly()
{
$l = Link::create(
'Click here',
'go/some/where',
array(
'with' => 'me',
'and' => 'aDog'
)
);
$this->assertEquals(
'<a href="/icingaweb2/go/some/where?with=me&amp;and=aDog">Click here</a>',
$l->render()
);
}
}

View file

@ -1,43 +0,0 @@
<?php
namespace Tests\Icinga\Module\Businessprocess\Html;
use Icinga\Module\Businessprocess\Html\Text;
use Icinga\Module\Businessprocess\Test\BaseTestCase;
class TextTest extends BaseTestCase
{
public function testTextIsReturnedAsGiven()
{
$this->assertEquals(
'A & O',
Text::create('A & O')->getText()
);
}
public function testTextIsRenderedAsGivenWhenDeclaredBeingEscaped()
{
$this->assertEquals(
'A & O',
Text::create('A & O')->setEscaped()->render()
);
$this->assertEquals(
'A & O',
Text::create('A & O')->setEscaped(true)->render()
);
$this->assertEquals(
'A &amp; O',
Text::create('A & O')->setEscaped(false)->render()
);
}
public function testTextIsEscapedWhenRendered()
{
$this->assertEquals(
'A &amp; O',
Text::create('A & O')->render()
);
}
}

View file

@ -9,6 +9,8 @@ PHP_VERSION="$(php -r 'echo phpversion();')"
ICINGAWEB_VERSION=${ICINGAWEB_VERSION:=2.5.1} ICINGAWEB_VERSION=${ICINGAWEB_VERSION:=2.5.1}
ICINGAWEB_GITREF=${ICINGAWEB_GITREF:=} ICINGAWEB_GITREF=${ICINGAWEB_GITREF:=}
IPL_VERSION=${IPL_VERSION:=0.1.1}
PHPCS_VERSION=${PHPCS_VERSION:=2.9.1} PHPCS_VERSION=${PHPCS_VERSION:=2.9.1}
if [ "$PHP_VERSION" '<' 5.6.0 ]; then if [ "$PHP_VERSION" '<' 5.6.0 ]; then
@ -52,6 +54,18 @@ fi
ln -svf "${icingaweb_path}"/library/Icinga ln -svf "${icingaweb_path}"/library/Icinga
ln -svf "${icingaweb_path}"/library/vendor/Zend ln -svf "${icingaweb_path}"/library/vendor/Zend
# ipl
ipl_path="ipl"
if [ ! -d "$ipl_path" ]; then
git clone https://github.com/Icinga/icingaweb2-module-ipl.git "$ipl_path"
fi
(
set -e
cd "$ipl_path"
git fetch -p
git checkout -f "stable/$IPL_VERSION"
)
# phpunit # phpunit
phpunit_path="phpunit-${PHPUNIT_VERSION}" phpunit_path="phpunit-${PHPUNIT_VERSION}"
if [ ! -e "${phpunit_path}".phar ]; then if [ ! -e "${phpunit_path}".phar ]; then