mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 07:44:05 +02:00
Forms: transform addHtmlHint into ipl-aware code
This commit is contained in:
parent
84b6196e79
commit
75fb983622
@ -9,12 +9,15 @@ use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
|||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
use Icinga\Module\Director\Objects\IcingaService;
|
use Icinga\Module\Director\Objects\IcingaService;
|
||||||
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
||||||
|
use ipl\Html\Html;
|
||||||
|
use ipl\Html\Link;
|
||||||
|
|
||||||
class IcingaServiceForm extends DirectorObjectForm
|
class IcingaServiceForm extends DirectorObjectForm
|
||||||
{
|
{
|
||||||
/** @var IcingaHost */
|
/** @var IcingaHost */
|
||||||
private $host;
|
private $host;
|
||||||
|
|
||||||
|
/** @var IcingaServiceSet */
|
||||||
private $set;
|
private $set;
|
||||||
|
|
||||||
private $apply;
|
private $apply;
|
||||||
@ -80,10 +83,7 @@ class IcingaServiceForm extends DirectorObjectForm
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addHtmlHint(
|
$this->addOverrideHint();
|
||||||
$this->getOverrideHint(),
|
|
||||||
array('name' => 'inheritance_hint')
|
|
||||||
);
|
|
||||||
|
|
||||||
$group = $this->getDisplayGroup('custom_fields');
|
$group = $this->getDisplayGroup('custom_fields');
|
||||||
|
|
||||||
@ -142,91 +142,78 @@ class IcingaServiceForm extends DirectorObjectForm
|
|||||||
->setButtons();
|
->setButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOverrideHint()
|
protected function addOverrideHint()
|
||||||
{
|
{
|
||||||
$view = $this->getView();
|
|
||||||
|
|
||||||
if ($this->object && $this->object->usesVarOverrides()) {
|
if ($this->object && $this->object->usesVarOverrides()) {
|
||||||
return $this->translate(
|
$hint = $this->translate(
|
||||||
'This service has been generated in an automated way, but still'
|
'This service has been generated in an automated way, but still'
|
||||||
. ' allows you to override the following properties in a safe way.'
|
. ' allows you to override the following properties in a safe way.'
|
||||||
);
|
);
|
||||||
}
|
} elseif ($this->applyGenerated) {
|
||||||
|
$hint = Html::sprintf(
|
||||||
if ($this->applyGenerated) {
|
|
||||||
return $view->escape(sprintf(
|
|
||||||
$this->translate(
|
$this->translate(
|
||||||
'This service has been generated using an apply rule, assigned where %s'
|
'This service has been generated using an apply rule, assigned where %s'
|
||||||
),
|
),
|
||||||
Filter::fromQueryString($this->applyGenerated->assign_filter)
|
(string) Filter::fromQueryString($this->applyGenerated->assign_filter)
|
||||||
));
|
);
|
||||||
}
|
} elseif ($this->host && $this->set) {
|
||||||
|
$hint = $this->translate(
|
||||||
if ($this->host && $this->set) {
|
|
||||||
return $this->translate(
|
|
||||||
'This service belongs to a Service Set. Still, you might want'
|
'This service belongs to a Service Set. Still, you might want'
|
||||||
. ' to override the following properties for this host only.'
|
. ' to override the following properties for this host only.'
|
||||||
);
|
);
|
||||||
}
|
} elseif ($this->inheritedFrom) {
|
||||||
|
$msg = $this->translate(
|
||||||
if ($this->inheritedFrom) {
|
|
||||||
$msg = $view->escape($this->translate(
|
|
||||||
'This service has been inherited from %s. Still, you might want'
|
'This service has been inherited from %s. Still, you might want'
|
||||||
. ' to change the following properties for this host only.'
|
. ' to change the following properties for this host only.'
|
||||||
));
|
|
||||||
|
|
||||||
$name = $this->inheritedFrom;
|
|
||||||
$link = $view->qlink(
|
|
||||||
$name,
|
|
||||||
'director/service',
|
|
||||||
array(
|
|
||||||
'host' => $name,
|
|
||||||
'name' => $this->object->object_name,
|
|
||||||
),
|
|
||||||
array('data-base-target' => '_next')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return sprintf($msg, $link);
|
$name = $this->inheritedFrom;
|
||||||
|
$link = Link::create(
|
||||||
|
$name,
|
||||||
|
'director/service',
|
||||||
|
[
|
||||||
|
'host' => $name,
|
||||||
|
'name' => $this->object->getObjectName(),
|
||||||
|
],
|
||||||
|
['data-base-target' => '_next']
|
||||||
|
);
|
||||||
|
|
||||||
|
$hint = Html::sprintf($msg, $link);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setSubmitLabel(
|
$this->setSubmitLabel($this->translate('Override vars'));
|
||||||
$this->translate('Override vars')
|
|
||||||
);
|
$this->addHtmlHint($hint, ['name' => 'inheritance_hint']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setupOnHostForSet()
|
protected function setupOnHostForSet()
|
||||||
{
|
{
|
||||||
$view = $this->getView();
|
$msg = $this->translate(
|
||||||
$msg = $view->escape($this->translate(
|
|
||||||
'This service belongs to the service set "%s". Still, you might want'
|
'This service belongs to the service set "%s". Still, you might want'
|
||||||
. ' to change the following properties for this host only.'
|
. ' to change the following properties for this host only.'
|
||||||
));
|
);
|
||||||
|
|
||||||
$name = $this->set->getObjectName();
|
$name = $this->set->getObjectName();
|
||||||
$link = $view->qlink(
|
$link = Link::create(
|
||||||
$name,
|
$name,
|
||||||
'director/serviceset',
|
'director/serviceset',
|
||||||
array(
|
['name' => $name],
|
||||||
'name' => $name,
|
['data-base-target' => '_next']
|
||||||
),
|
|
||||||
array('data-base-target' => '_next')
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addHtmlHint(
|
$this->addHtmlHint(
|
||||||
sprintf($msg, $link),
|
Html::sprintf($msg, $link),
|
||||||
array('name' => 'inheritance_hint')
|
['name' => 'inheritance_hint']
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->addElementsToGroup(
|
$this->addElementsToGroup(
|
||||||
array('inheritance_hint'),
|
['inheritance_hint'],
|
||||||
'custom_fields',
|
'custom_fields',
|
||||||
50,
|
50,
|
||||||
$this->translate('Custom properties')
|
$this->translate('Custom properties')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->setSubmitLabel(
|
$this->setSubmitLabel($this->translate('Override vars'));
|
||||||
$this->translate('Override vars')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addAssignmentElements()
|
protected function addAssignmentElements()
|
||||||
|
@ -86,9 +86,7 @@ class IcingaServiceSetForm extends DirectorObjectForm
|
|||||||
|
|
||||||
if (count($object->get('imports'))) {
|
if (count($object->get('imports'))) {
|
||||||
$this->addHtmlHint(
|
$this->addHtmlHint(
|
||||||
$this->getView()->escape(
|
$object->getResolvedProperty('description')
|
||||||
$object->getResolvedProperty('description')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@ use Icinga\Module\Director\Db\Migrations;
|
|||||||
use Icinga\Module\Director\Objects\IcingaEndpoint;
|
use Icinga\Module\Director\Objects\IcingaEndpoint;
|
||||||
use Icinga\Module\Director\KickstartHelper;
|
use Icinga\Module\Director\KickstartHelper;
|
||||||
use Icinga\Module\Director\Web\Form\DirectorForm;
|
use Icinga\Module\Director\Web\Form\DirectorForm;
|
||||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
use ipl\Html\Html;
|
||||||
|
use ipl\Html\Link;
|
||||||
|
|
||||||
class KickstartForm extends DirectorForm
|
class KickstartForm extends DirectorForm
|
||||||
{
|
{
|
||||||
@ -60,16 +61,17 @@ class KickstartForm extends DirectorForm
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->endpoint && $this->getDb()->hasDeploymentEndpoint()) {
|
if (! $this->endpoint && $this->getDb()->hasDeploymentEndpoint()) {
|
||||||
$hint = sprintf($this->translate(
|
$hint = Html::sprintf(
|
||||||
'Your database looks good, you are ready to %s'
|
$this->translate('Your database looks good, you are ready to %s'),
|
||||||
), $this->getView()->qlink(
|
Link::create(
|
||||||
'start working with the Icinga Director',
|
'start working with the Icinga Director',
|
||||||
'director',
|
'director',
|
||||||
null,
|
null,
|
||||||
array('data-base-target' => '_main')
|
['data-base-target' => '_main']
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$this->addHtmlHint($hint, array('name' => 'HINT_ready'));
|
$this->addHtmlHint($hint, ['name' => 'HINT_ready']);
|
||||||
$this->getDisplayGroup('config')->addElements(
|
$this->getDisplayGroup('config')->addElements(
|
||||||
array($this->getElement('HINT_ready'))
|
array($this->getElement('HINT_ready'))
|
||||||
);
|
);
|
||||||
@ -233,14 +235,15 @@ class KickstartForm extends DirectorForm
|
|||||||
$this->translate('This has to be a MySQL or PostgreSQL database')
|
$this->translate('This has to be a MySQL or PostgreSQL database')
|
||||||
);
|
);
|
||||||
|
|
||||||
$hint = $this->translate('Please click %s to create new DB resources');
|
$this->addHtmlHint(Html::sprintf(
|
||||||
$link = $this->getView()->qlink(
|
$this->translate('Please click %s to create new DB resources'),
|
||||||
$this->translate('here'),
|
Link::create(
|
||||||
'config/resource',
|
$this->translate('here'),
|
||||||
null,
|
'config/resource',
|
||||||
array('data-base-target' => '_main')
|
null,
|
||||||
);
|
['data-base-target' => '_main']
|
||||||
$this->addHtmlHint(sprintf($hint, $link));
|
)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setSubmitLabel($this->storeConfigLabel);
|
$this->setSubmitLabel($this->storeConfigLabel);
|
||||||
@ -308,7 +311,7 @@ class KickstartForm extends DirectorForm
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->addHtmlHint(
|
$this->addHtmlHint(
|
||||||
'<pre>' . $config . '</pre>',
|
Html::tag('pre', null, $config),
|
||||||
array('name' => 'HINT_config_store')
|
array('name' => 'HINT_config_store')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ use Icinga\Data\ResourceFactory;
|
|||||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||||
use Icinga\Exception\NotImplementedError;
|
use Icinga\Exception\NotImplementedError;
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Web\Url;
|
use ipl\Html\Html;
|
||||||
|
use ipl\Html\Link;
|
||||||
use Zend_Db_Expr;
|
use Zend_Db_Expr;
|
||||||
|
|
||||||
class Util
|
class Util
|
||||||
@ -173,14 +174,17 @@ class Util
|
|||||||
'required' => true,
|
'required' => true,
|
||||||
));
|
));
|
||||||
|
|
||||||
if (true && empty($list)) {
|
if (empty($list)) {
|
||||||
if (self::hasPermission('config/application/resources')) {
|
if (self::hasPermission('config/application/resources')) {
|
||||||
$hint = $form->translate('Please click %s to create new resources');
|
$form->addHtmlHint(Html::sprintf(
|
||||||
$link = sprintf(
|
$form->translate('Please click %s to create new resources'),
|
||||||
'<a href="' . Url::fromPath('config/resource') . '" data-base-target="_main">%s</a>',
|
Link::create(
|
||||||
$form->translate('here')
|
$form->translate('here'),
|
||||||
);
|
'config/resource',
|
||||||
$form->addHtmlHint(sprintf($hint, $link));
|
null,
|
||||||
|
['data-base-target' => '_main']
|
||||||
|
)
|
||||||
|
));
|
||||||
$msg = sprintf($form->translate('No %s resource available'), $type);
|
$msg = sprintf($form->translate('No %s resource available'), $type);
|
||||||
} else {
|
} else {
|
||||||
$msg = $form->translate('Please ask an administrator to grant you access to resources');
|
$msg = $form->translate('Please ask an administrator to grant you access to resources');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user