Skip to content

Commit

Permalink
Correct notification messages and add missing translations (#444)
Browse files Browse the repository at this point in the history
fixes #405
  • Loading branch information
sukhwinder33445 authored Apr 22, 2024
1 parent 1c38d23 commit c43128b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions application/forms/BpConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected function onRequest()
$this->bp->clearAppliedChanges();
$this->storage->deleteProcess($name);
$this->setSuccessUrl('businessprocess');
$this->redirectOnSuccess(sprintf('Process %s has been deleted', $name));
$this->redirectOnSuccess(sprintf($this->translate('Process %s has been deleted'), $name));
}
}
}
Expand Down Expand Up @@ -197,10 +197,10 @@ public function onSuccess()
array('config' => $name, 'unlocked' => true)
)
);
$this->setSuccessMessage(sprintf('Process %s has been created', $name));
$this->setSuccessMessage(sprintf($this->translate('Process %s has been created'), $name));
} else {
$config = $this->bp;
$this->setSuccessMessage(sprintf('Process %s has been stored', $name));
$this->setSuccessMessage(sprintf($this->translate('Process %s has been stored'), $name));
}
$meta = $config->getMetadata();
foreach ($this->getValues() as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion application/forms/BpUploadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function onSuccess()
}

$this->storage->storeProcess($config);
Notification::success(sprintf('Process %s has been stored', $name));
Notification::success(sprintf($this->translate('Process %s has been stored'), $name));

$this->getSuccessUrl()->setParam('config', $name);

Expand Down
13 changes: 13 additions & 0 deletions application/forms/CleanupNodeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,28 @@ public function onSuccess()
{
$changes = ProcessChanges::construct($this->bp, $this->session);

/** @var string[] $nodesToCleanup */
$nodesToCleanup = $this->getValue('cleanup_all') === '1'
? array_keys($this->bp->getMissingChildren())
: $this->getValue('nodes');

$nodeName = null;
foreach ($nodesToCleanup as $nodeName) {
$node = $this->bp->getNode($nodeName);
$changes->deleteNode($node);
}


$count = count($nodesToCleanup);
$this->setSuccessMessage(sprintf(
$this->translatePlural(
'Successfully removed missing node %s',
'Successfully removed %d missing nodes',
$count
),
$count === 1 ? $nodeName : $count
));

unset($changes);

parent::onSuccess();
Expand Down
8 changes: 8 additions & 0 deletions application/forms/DeleteNodeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,17 @@ public function onSuccess()
switch ($confirm) {
case 'yes':
$changes->deleteNode($this->node, $this->parentNode === null ? null : $this->parentNode->getName());
$this->setSuccessMessage(sprintf(
$this->translate('Node %s has been deleted'),
$this->node->getAlias()
));
break;
case 'all':
$changes->deleteNode($this->node);
$this->setSuccessMessage(sprintf(
$this->translate('All occurrences of node %s have been deleted'),
$this->node->getAlias()
));
break;
case 'no':
$this->setSuccessMessage($this->translate('Well, maybe next time'));
Expand Down
2 changes: 1 addition & 1 deletion application/forms/MoveNodeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function onSuccess()
// Trigger session destruction to make sure it get's stored.
unset($changes);

$this->notifySuccess($this->getSuccessMessage($this->translate('Node order updated')));
$this->notifySuccess($this->translate('Node order updated'));

$response = $this->getRequest()->getResponse()
->setHeader('X-Icinga-Container', 'ignore')
Expand Down
2 changes: 1 addition & 1 deletion application/forms/ProcessForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function onSuccess()

Notification::success(
sprintf(
'Process %s has been modified',
$this->translate('Process %s has been modified'),
$this->bp->getName()
)
);
Expand Down
4 changes: 2 additions & 2 deletions application/forms/SimulationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public function onSuccess()
$state = $this->getValue('state');

if ($state !== null && ctype_digit($state)) {
$this->notifySuccess($this->translate('Simulation has been set'));
$this->setSuccessMessage($this->translate('Simulation has been set'));
$this->simulation->set($nodeName, (object) array(
'state' => $this->getValue('state'),
'acknowledged' => $this->getValue('acknowledged'),
'in_downtime' => $this->getValue('in_downtime'),
));
} else {
if ($this->simulation->remove($nodeName)) {
$this->notifySuccess($this->translate('Simulation has been removed'));
$this->setSuccessMessage($this->translate('Simulation has been removed'));
}
}

Expand Down
12 changes: 3 additions & 9 deletions library/Businessprocess/Web/Form/QuickBaseForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use ipl\Html\ValidHtml;
use ipl\I18n\Translation;
use Zend_Form;

abstract class QuickBaseForm extends Zend_Form implements ValidHtml
{
use Translation;

/**
* The Icinga module this form belongs to. Usually only set if the
* form is initialized through the FormLoader
Expand Down Expand Up @@ -154,13 +157,4 @@ protected function valueIsEmpty($value)

return strlen($value) === 0;
}

public function translate($string)
{
if ($this->icingaModuleName === null) {
return t($string);
} else {
return mt($this->icingaModuleName, $string);
}
}
}
20 changes: 0 additions & 20 deletions phpstan-baseline-standard.neon
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,6 @@ parameters:
count: 1
path: application/forms/BpUploadForm.php

-
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
count: 1
path: application/forms/CleanupNodeForm.php

-
message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Forms\\\\CleanupNodeForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -645,11 +640,6 @@ parameters:
count: 1
path: application/forms/CleanupNodeForm.php

-
message: "#^Parameter \\#1 \\$name of method Icinga\\\\Module\\\\Businessprocess\\\\BpConfig\\:\\:getNode\\(\\) expects string, mixed given\\.$#"
count: 1
path: application/forms/CleanupNodeForm.php

-
message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Forms\\\\DeleteNodeForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -3955,16 +3945,6 @@ parameters:
count: 1
path: library/Businessprocess/Web/Form/QuickBaseForm.php

-
message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:translate\\(\\) has no return type specified\\.$#"
count: 1
path: library/Businessprocess/Web/Form/QuickBaseForm.php

-
message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:translate\\(\\) has parameter \\$string with no type specified\\.$#"
count: 1
path: library/Businessprocess/Web/Form/QuickBaseForm.php

-
message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:valueIsEmpty\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
9 changes: 7 additions & 2 deletions public/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@
].join('&');

var $container = $source.closest('.container');
icinga.loader.loadUrl(actionUrl, $container, data, 'POST');
var icingaLoader = this.module.icinga.loader;
icingaLoader.loadUrl(actionUrl, $container, data, 'POST')
.done((_, __, req) => icingaLoader.processNotificationHeader(req));
}
},

Expand Down Expand Up @@ -155,7 +157,10 @@
].join('&');

var $container = $target.closest('.container');
icinga.loader.loadUrl(actionUrl, $container, data, 'POST');
var icingaLoader = this.module.icinga.loader;
icingaLoader.loadUrl(actionUrl, $container, data, 'POST')
.done((_, __, req) => icingaLoader.processNotificationHeader(req));

event.stopPropagation();
}
},
Expand Down

0 comments on commit c43128b

Please sign in to comment.