Skip to content

Commit 4405b83

Browse files
authored
Merge pull request #58 from NETWAYS/theme-mode
Reintroduce configuration option for theme
2 parents da056a8 + 1425faa commit 4405b83

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

application/controllers/IcingadbimgController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function init()
100100
);
101101

102102
$this->defaultOrgId = $this->myConfig->get('defaultorgid', $this->defaultOrgId);
103-
$this->grafanaTheme = Util::getUserThemeMode(Auth::getInstance()->getUser());
103+
$this->grafanaTheme = Util::getUserThemeMode(Auth::getInstance()->getUser(), $this->myConfig->get('theme', 'dark'));
104104
$this->height = $this->myConfig->get('height', $this->height);
105105
$this->width = $this->myConfig->get('width', $this->width);
106106
$this->proxyTimeout = $this->myConfig->get('proxytimeout', $this->proxyTimeout);

application/forms/Config/GeneralConfigForm.php

+15
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ public function createElements(array $formData)
161161
]
162162
);
163163

164+
// Default theme
165+
$this->addElement(
166+
'select',
167+
'grafana_theme',
168+
array(
169+
'label' => $this->translate('Default theme for graphs'),
170+
'value' => 'dark',
171+
'multiOptions' => array(
172+
'light' => $this->translate('Light'),
173+
'dark' => $this->translate('Dark'),
174+
),
175+
'description' => $this->translate("Default theme for graphs. Hint: the user's theme will take precedence")
176+
)
177+
);
178+
164179
// Grafana datasource configuration
165180
$this->addElement(
166181
'select',

doc/03-module-configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Hint: to display debug information for graphs you can use the URL parameter `&gr
7070
|publicprotocol | **Optional** Use a different protocol for the graph links.|
7171
|custvardisable | **Optional** Custom variable (vars.idontwanttoseeagraph for example) that will disable graphs. Defaults to `grafana_graph_disable`.|
7272
|custvarconfig | **Optional** Custom variable (vars.usegraphconfig for example) that will be used as config name. Defaults to `grafana_graph_config`.|
73+
|theme | **Optional.** Default theme for the graph (light or dark). Hint: the user's theme will take precedence. Defaults to `dark`.|
7374
|ssl_verifypeer | **Proxy mode only** **Optional.** Verify the peer's SSL certificate. Defaults to `false`.|
7475
|ssl_verifyhost | **Proxy mode only** **Optional.** Verify the certificate's name against host. Defaults to `false`.|
7576

library/Grafana/Helpers/Util.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@ public static function graphiteReplace(string $string = ''): string
1616
/**
1717
* getUserThemeMode returns the users configured Theme Mode.
1818
* Since we cannot handle the 'system' setting (it's client-side),
19-
* we default to 'dark'.
19+
* we default to the mode given. This is used to pass the default
20+
* from the module's configuration.
2021
*
2122
* @param User $user
2223
* @return string
2324
*/
24-
public static function getUserThemeMode(User $user): string
25+
public static function getUserThemeMode(User $user, string $defaultMode = 'dark'): string
2526
{
26-
$mode = 'dark';
27+
$mode = $defaultMode;
2728

2829
if (isset($user)) {
2930
$mode = $user->getPreferences()->getValue('icingaweb', 'theme_mode', $mode);
3031
}
3132

3233
// Could be system, which we cannot handle since it's browser-side
3334
if (!in_array($mode, ['dark', 'light'])) {
34-
$mode = 'dark';
35+
$mode = $defaultMode;
3536
}
3637

3738
return $mode;

library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ protected function init()
132132
);
133133

134134
$this->defaultOrgId = $this->config->get('defaultorgid', $this->defaultOrgId);
135-
$this->grafanaTheme = Util::getUserThemeMode(Auth::getInstance()->getUser());
135+
$this->grafanaTheme = Util::getUserThemeMode(Auth::getInstance()->getUser(), $this->config->get('theme', 'dark'));
136136
$this->height = $this->config->get('height', $this->height);
137137
$this->width = $this->config->get('width', $this->width);
138138

0 commit comments

Comments
 (0)