dashboard: Use the non-translated versions of pane and dashlet names for storage

This is a dirty quick fix. And calling it *quick* is already an overstatement.
Of course, it's also a breaking change, as **all** non-english users need to
update their dashboard.ini after this change.

Oh, and don't dare to move this over to the new dashboards!

refs #3542
This commit is contained in:
Johannes Meyer 2019-06-26 15:50:35 +02:00
parent 4fdfb190ad
commit fcde2a9eea
2 changed files with 66 additions and 6 deletions

View File

@ -5,6 +5,9 @@ namespace Icinga\Legacy;
use Icinga\Application\Config;
use Icinga\User;
use Icinga\Web\Navigation\DashboardPane;
use Icinga\Web\Navigation\Navigation;
use Icinga\Web\Navigation\NavigationItem;
/**
* Legacy dashboard config class for case insensitive interpretation of dashboard config files
@ -76,6 +79,51 @@ class DashboardConfig extends Config
*/
public function saveIni($filePath = null, $fileMode = 0660)
{
// Preprocessing start, ensures that the non-translated names are used to save module dashboard changes
// TODO: This MUST NOT survive the new dashboard implementation (yes, it's still a thing..)
$dashboardNavigation = new Navigation();
$dashboardNavigation->load('dashboard-pane');
$getDashboardPane = function ($label) use ($dashboardNavigation) {
foreach ($dashboardNavigation as $dashboardPane) {
/** @var DashboardPane $dashboardPane */
if ($dashboardPane->getLabel() === $label) {
return $dashboardPane;
}
foreach ($dashboardPane->getChildren() as $dashlet) {
/** @var NavigationItem $dashlet */
if ($dashlet->getLabel() === $label) {
return $dashlet;
}
}
}
};
foreach (clone $this->config as $name => $options) {
if (strpos($name, '.') !== false) {
list($dashboardLabel, $dashletLabel) = explode('.', $name, 2);
} else {
$dashboardLabel = $name;
$dashletLabel = null;
}
$dashboardPane = $getDashboardPane($dashboardLabel);
if ($dashboardPane !== null) {
$dashboardLabel = $dashboardPane->getName();
}
if ($dashletLabel !== null) {
$dashletItem = $getDashboardPane($dashletLabel);
if ($dashletItem !== null) {
$dashletLabel = $dashletItem->getName();
}
}
unset($this->config[$name]);
$this->config[$dashboardLabel . ($dashletLabel ? '.' . $dashletLabel : '')] = $options;
}
// Preprocessing end
parent::saveIni($filePath, $fileMode);
if ($filePath === null) {
$filePath = $this->configFile;

View File

@ -85,7 +85,7 @@ class Dashboard extends AbstractWidget
}
$this->mergePanes($panes);
$this->loadUserDashboards();
$this->loadUserDashboards($navigation);
return $this;
}
@ -114,10 +114,10 @@ class Dashboard extends AbstractWidget
/**
* Load user dashboards from all config files that match the username
*/
protected function loadUserDashboards()
protected function loadUserDashboards(Navigation $navigation)
{
foreach (DashboardConfig::listConfigFilesForUser($this->user) as $file) {
$this->loadUserDashboardsFromFile($file);
$this->loadUserDashboardsFromFile($file, $navigation);
}
}
@ -128,7 +128,7 @@ class Dashboard extends AbstractWidget
*
* @return bool
*/
protected function loadUserDashboardsFromFile($file)
protected function loadUserDashboardsFromFile($file, Navigation $dashboardNavigation)
{
try {
$config = Config::fromIni($file);
@ -143,8 +143,12 @@ class Dashboard extends AbstractWidget
$dashlets = array();
foreach ($config as $key => $part) {
if (strpos($key, '.') === false) {
if ($this->hasPane($part->title)) {
$panes[$key] = $this->getPane($part->title);
$dashboardPane = $dashboardNavigation->getItem($key);
if ($dashboardPane !== null) {
$key = $dashboardPane->getLabel();
}
if ($this->hasPane($key)) {
$panes[$key] = $this->getPane($key);
} else {
$panes[$key] = new Pane($key);
$panes[$key]->setTitle($part->title);
@ -155,6 +159,14 @@ class Dashboard extends AbstractWidget
}
} else {
list($paneName, $dashletName) = explode('.', $key, 2);
$dashboardPane = $dashboardNavigation->getItem($paneName);
if ($dashboardPane !== null) {
$paneName = $dashboardPane->getLabel();
$dashletItem = $dashboardPane->getChildren()->getItem($dashletName);
if ($dashletItem !== null) {
$dashletName = $dashletItem->getLabel();
}
}
$part->pane = $paneName;
$part->dashlet = $dashletName;
$dashlets[] = $part;