Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct notification messages and add missing translations #444

Merged
merged 6 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3965,16 +3955,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