Show a notification for every successful action

This commit is contained in:
Yonas Habteab 2021-08-31 17:12:22 +02:00 committed by Johannes Meyer
parent 62a7203095
commit c67b873096
13 changed files with 319 additions and 0 deletions

View file

@ -11,6 +11,7 @@ use Icinga\Forms\ConfirmRemovalForm;
use Icinga\Module\Icingadb\Command\Transport\CommandTransportConfig;
use Icinga\Module\Icingadb\Forms\ApiTransportForm;
use Icinga\Module\Icingadb\Widget\ItemList\CommandTransportList;
use Icinga\Web\Notification;
use ipl\Html\HtmlString;
use ipl\Web\Widget\ButtonLink;
@ -64,6 +65,8 @@ class CommandTransportController extends ConfigController
Filter::where('name', $transportName)
);
Notification::success(sprintf(t('Updated command transport "%s" successfully'), $transportName));
$this->redirectNow('icingadb/command-transport');
});
@ -80,6 +83,9 @@ class CommandTransportController extends ConfigController
$form = new ApiTransportForm();
$form->on(ApiTransportForm::ON_SUCCESS, function (ApiTransportForm $form) {
(new CommandTransportConfig())->insert('transport', $form->getValues());
Notification::success(t('Created command transport successfully'));
$this->redirectNow('icingadb/command-transport');
});
@ -103,6 +109,8 @@ class CommandTransportController extends ConfigController
Filter::where('name', $transportName)
);
Notification::success(sprintf(t('Removed command transport "%s" successfully'), $transportName));
$this->redirectNow('icingadb/command-transport');
});

View file

@ -7,6 +7,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Instance;
use Icinga\Module\Icingadb\Command\Instance\ToggleInstanceFeatureCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Orm\Model;
use ipl\Web\FormDecorator\IcingaFormDecorator;
@ -18,6 +19,13 @@ class ToggleInstanceFeaturesForm extends CommandForm
protected $featureStatus;
/**
* ToggleFeature(s) being used to submit this form
*
* @var ToggleInstanceFeatureCommand[]
*/
protected $submittedFeatures = [];
public function __construct($featureStatus)
{
$this->featureStatus = $featureStatus;
@ -37,6 +45,67 @@ class ToggleInstanceFeaturesForm extends CommandForm
];
$this->getAttributes()->add('class', 'instance-features');
$this->on(self::ON_SUCCESS, function () {
foreach ($this->submittedFeatures as $feature) {
$enabled = $feature->getEnabled();
switch ($feature->getFeature()) {
case ToggleInstanceFeatureCommand::FEATURE_ACTIVE_HOST_CHECKS:
if ($enabled) {
$message = t('Enabled active host checks successfully');
} else {
$message = t('Disabled active host checks successfully');
}
break;
case ToggleInstanceFeatureCommand::FEATURE_ACTIVE_SERVICE_CHECKS:
if ($enabled) {
$message = t('Enabled active service checks successfully');
} else {
$message = t('Disabled active service checks successfully');
}
break;
case ToggleInstanceFeatureCommand::FEATURE_EVENT_HANDLERS:
if ($enabled) {
$message = t('Enabled event handlers successfully');
} else {
$message = t('Disabled event handlers checks successfully');
}
break;
case ToggleInstanceFeatureCommand::FEATURE_FLAP_DETECTION:
if ($enabled) {
$message = t('Enabled flap detection successfully');
} else {
$message = t('Disabled flap detection successfully');
}
break;
case ToggleInstanceFeatureCommand::FEATURE_NOTIFICATIONS:
if ($enabled) {
$message = t('Enabled notifications successfully');
} else {
$message = t('Disabled notifications successfully');
}
break;
case ToggleInstanceFeatureCommand::FEATURE_PERFORMANCE_DATA:
if ($enabled) {
$message = t('Enabled performance data successfully');
} else {
$message = t('Disabled performance data successfully');
}
break;
default:
$message = t('Invalid feature option');
break;
}
Notification::success($message);
}
});
}
protected function assembleElements()
@ -76,6 +145,8 @@ class ToggleInstanceFeaturesForm extends CommandForm
$command->setFeature($feature);
$command->setEnabled((int) $featureState);
$this->submittedFeatures[] = $command;
yield $command;
}
}

View file

@ -10,6 +10,8 @@ use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\AcknowledgeProblemCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
use ipl\Html\Attributes;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
@ -21,6 +23,28 @@ class AcknowledgeProblemForm extends CommandForm
{
use Auth;
public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
if (current($this->getObjects()) instanceof Host) {
$message = sprintf(tp(
'Acknowledged problem successfully',
'Acknowledged problem on %d hosts successfully',
$countObjects
), $countObjects);
} else {
$message = sprintf(tp(
'Acknowledged problem successfully',
'Acknowledged problem on %d services successfully',
$countObjects
), $countObjects);
}
Notification::success($message);
});
}
protected function assembleElements()
{
$this->addHtml(new HtmlElement(

View file

@ -10,6 +10,8 @@ use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\AddCommentCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
use ipl\Html\Attributes;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
@ -21,6 +23,26 @@ class AddCommentForm extends CommandForm
{
use Auth;
public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
if (current($this->getObjects()) instanceof Host) {
$message = sprintf(
tp('Added comment successfully', 'Added comment to %d hosts successfully', $countObjects),
$countObjects
);
} else {
$message = sprintf(
tp('Added comment successfully', 'Added comment to %d services successfully', $countObjects),
$countObjects
);
}
Notification::success($message);
});
}
protected function assembleElements()
{
$this->addHtml(new HtmlElement(

View file

@ -7,6 +7,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object;
use Icinga\Module\Icingadb\Command\Object\DeleteCommentCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Orm\Model;
use ipl\Web\Common\RedirectOption;
use ipl\Web\Widget\Icon;
@ -16,6 +17,18 @@ class DeleteCommentForm extends CommandForm
use Auth;
use RedirectOption;
public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
Notification::success(sprintf(
tp('Removed comment successfully', 'Removed comment from %d objects successfully', $countObjects),
$countObjects
));
});
}
protected function assembleElements()
{
$this->addElement($this->createRedirectOption());

View file

@ -7,6 +7,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object;
use Icinga\Module\Icingadb\Command\Object\DeleteDowntimeCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Orm\Model;
use ipl\Web\Common\RedirectOption;
use ipl\Web\Widget\Icon;
@ -18,6 +19,18 @@ class DeleteDowntimeForm extends CommandForm
protected $defaultAttributes = ['class' => 'inline'];
public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
Notification::success(sprintf(
tp('Removed downtime successfully', 'Removed downtime from %d objects successfully', $countObjects),
$countObjects
));
});
}
protected function assembleElements()
{
$this->addElement($this->createRedirectOption());

View file

@ -8,6 +8,7 @@ use Icinga\Module\Icingadb\Command\Object\ProcessCheckResultCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
use ipl\Html\Attributes;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
@ -19,6 +20,28 @@ class ProcessCheckResultForm extends CommandForm
{
use Auth;
public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
if (current($this->getObjects()) instanceof Host) {
$message = sprintf(tp(
'Submitted passive check result successfully',
'Submitted passive check result for %d hosts successfully',
$countObjects
), $countObjects);
} else {
$message = sprintf(tp(
'Submitted passive check result successfully',
'Submitted passive check result for %d services successfully',
$countObjects
), $countObjects);
}
Notification::success($message);
});
}
protected function assembleElements()
{
$this->addHtml(new HtmlElement(

View file

@ -7,6 +7,8 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object;
use Icinga\Module\Icingadb\Command\Object\RemoveAcknowledgementCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
use ipl\Orm\Model;
use ipl\Web\Widget\Icon;
@ -14,6 +16,28 @@ class RemoveAcknowledgementForm extends CommandForm
{
use Auth;
public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
if (current($this->getObjects()) instanceof Host) {
$message = sprintf(tp(
'Removed acknowledgment successfully',
'Removed acknowledgment from %d hosts successfully',
$countObjects
), $countObjects);
} else {
$message = sprintf(tp(
'Removed acknowledgment successfully',
'Removed acknowledgment from %d services successfully',
$countObjects
), $countObjects);
}
Notification::success($message);
});
}
protected $defaultAttributes = ['class' => 'inline'];
protected function assembleElements()

View file

@ -9,6 +9,8 @@ use DateTime;
use Icinga\Module\Icingadb\Command\Object\ScheduleCheckCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
use ipl\Html\Attributes;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
@ -20,6 +22,26 @@ class ScheduleCheckForm extends CommandForm
{
use Auth;
public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
if (current($this->getObjects()) instanceof Host) {
$message = sprintf(
tp('Scheduled check successfully', 'Scheduled check for %d hosts successfully', $countObjects),
$countObjects
);
} else {
$message = sprintf(
tp('Scheduled check successfully', 'Scheduled check for %d services successfully', $countObjects),
$countObjects
);
}
Notification::success($message);
});
}
protected function assembleElements()
{
$this->addHtml(new HtmlElement(

View file

@ -9,6 +9,7 @@ use DateTime;
use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\PropagateHostDowntimeCommand;
use Icinga\Module\Icingadb\Command\Object\ScheduleHostDowntimeCommand;
use Icinga\Web\Notification;
use ipl\Orm\Model;
use ipl\Web\FormDecorator\IcingaFormDecorator;
@ -35,6 +36,15 @@ class ScheduleHostDowntimeForm extends ScheduleServiceDowntimeForm
$flexibleDuration = $config->get('settings', 'hostdowntime_flexible_duration', 'PT2H');
$this->flexibleDuration = new DateInterval($flexibleDuration);
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
Notification::success(sprintf(
tp('Scheduled downtime successfully', 'Scheduled downtime for %d hosts successfully', $countObjects),
$countObjects
));
});
}
protected function assembleElements()

View file

@ -10,6 +10,7 @@ use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\ScheduleServiceDowntimeCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Html\Attributes;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
@ -57,6 +58,15 @@ class ScheduleServiceDowntimeForm extends CommandForm
$flexibleDuration = $config->get('settings', 'servicedowntime_flexible_duration', 'PT2H');
$this->flexibleDuration = new DateInterval($flexibleDuration);
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
Notification::success(sprintf(
tp('Scheduled downtime successfully', 'Scheduled downtime for %d services successfully', $countObjects),
$countObjects
));
});
}
protected function assembleElements()

View file

@ -8,6 +8,8 @@ use Icinga\Application\Config;
use Icinga\Module\Icingadb\Command\Object\SendCustomNotificationCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Module\Icingadb\Model\Host;
use Icinga\Web\Notification;
use ipl\Html\Attributes;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
@ -19,6 +21,28 @@ class SendCustomNotificationForm extends CommandForm
{
use Auth;
public function __construct()
{
$this->on(self::ON_SUCCESS, function () {
$countObjects = count($this->getObjects());
if (current($this->getObjects()) instanceof Host) {
$message = sprintf(tp(
'Sent custom notification successfully',
'Sent custom notification for %d hosts successfully',
$countObjects
), $countObjects);
} else {
$message = sprintf(tp(
'Sent custom notification successfully',
'Sent custom notification for %d services successfully',
$countObjects
), $countObjects);
}
Notification::success($message);
});
}
protected function assembleElements()
{
$this->addHtml(new HtmlElement(

View file

@ -7,6 +7,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object;
use Icinga\Module\Icingadb\Command\Object\ToggleObjectFeatureCommand;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
use Icinga\Web\Notification;
use ipl\Orm\Model;
use ipl\Web\FormDecorator\IcingaFormDecorator;
@ -20,6 +21,13 @@ class ToggleObjectFeaturesForm extends CommandForm
protected $featureStatus;
/**
* ToggleFeature(s) being used to submit this form
*
* @var ToggleObjectFeatureCommand[]
*/
protected $submittedFeatures = [];
public function __construct($featureStatus)
{
$this->featureStatus = $featureStatus;
@ -47,6 +55,51 @@ class ToggleObjectFeaturesForm extends CommandForm
];
$this->getAttributes()->add('class', 'object-features');
$this->on(self::ON_SUCCESS, function () {
foreach ($this->submittedFeatures as $feature) {
$enabled = $feature->getEnabled();
switch ($feature->getFeature()) {
case ToggleObjectFeatureCommand::FEATURE_ACTIVE_CHECKS:
if ($enabled) {
$message = t('Enabled active checks successfully');
} else {
$message = t('Disabled active checks successfully');
}
break;
case ToggleObjectFeatureCommand::FEATURE_EVENT_HANDLER:
if ($enabled) {
$message = t('Enabled event handler successfully');
} else {
$message = t('Disabled event handler checks successfully');
}
break;
case ToggleObjectFeatureCommand::FEATURE_FLAP_DETECTION:
if ($enabled) {
$message = t('Enabled flap detection successfully');
} else {
$message = t('Disabled flap detection successfully');
}
break;
case ToggleObjectFeatureCommand::FEATURE_NOTIFICATIONS:
if ($enabled) {
$message = t('Enabled notifications successfully');
} else {
$message = t('Disabled notifications successfully');
}
break;
default:
$message = t('Invalid feature option');
break;
}
Notification::success($message);
}
});
}
protected function assembleElements()
@ -109,6 +162,8 @@ class ToggleObjectFeaturesForm extends CommandForm
$command->setFeature($feature);
$command->setEnabled((int) $featureState);
$this->submittedFeatures[] = $command;
yield $command;
}
}