Module: check_mk
Branch: master
Commit: a0c827ff5861183a0d2a9b7a8990a26f008c10fe
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a0c827ff586118…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 22 10:47:44 2017 +0100
5537 Icon categories can now be customized
The icon categories that can be used for managing custom icons in WATO can
now be configured using a new global setting "Administration tool (WATO) > Icon
categories".
Change-Id: Iaad028fb17a3c038d408a75fb2af043edd2fe7c6
---
.werks/5537 | 11 +++++++++++
web/htdocs/valuespec.py | 28 ++++++++++++++++++----------
web/htdocs/wato.py | 2 +-
web/plugins/config/wato.py | 5 +++++
web/plugins/wato/check_mk_configuration.py | 22 ++++++++++++++++++++++
5 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/.werks/5537 b/.werks/5537
new file mode 100644
index 0000000..2af0749
--- /dev/null
+++ b/.werks/5537
@@ -0,0 +1,11 @@
+Title: Icon categories can now be customized
+Level: 1
+Component: wato
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1511343973
+Class: feature
+
+The icon categories that can be used for managing custom icons in WATO can
+now be configured using a new global setting "Administration tool (WATO) > Icon
categories".
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index a09712a..f529d45 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -4153,12 +4153,6 @@ class TextOrRegExpUnicode(TextOrRegExp):
class IconSelector(ValueSpec):
- _categories = [
- ('logos', _('Logos')),
- ('parts', _('Parts')),
- ('misc', _('Misc')),
- ]
-
def __init__(self, **kwargs):
ValueSpec.__init__(self, **kwargs)
self._allow_empty = kwargs.get('allow_empty', True)
@@ -4169,10 +4163,17 @@ class IconSelector(ValueSpec):
'empty',
]
+
+ @classmethod
+ def categories(cls):
+ import config# FIXME: Clean this up. But how?
+ return (config.wato_icon_categories)
+
+
@classmethod
def category_alias(cls, category_name):
- categories = dict(cls._categories)
- return dict(cls._categories).get(category_name, category_name)
+ return cls.categories().get(category_name, category_name)
+
# All icons within the images/icons directory have the ident of a category
# witten in the PNG meta data. For the default images we have done this scripted.
@@ -4184,7 +4185,7 @@ class IconSelector(ValueSpec):
if not only_local:
dirs.append(os.path.join(cmk.paths.omd_root,
"share/check_mk/web/htdocs/images/icons"))
- valid_categories = dict(self._categories).keys()
+ valid_categories = self.categories().keys()
from PIL import Image
@@ -4226,6 +4227,7 @@ class IconSelector(ValueSpec):
return icons
+
def available_icons_by_category(self, icons):
by_cat = {}
for icon_name, category_name in icons.items():
@@ -4233,11 +4235,12 @@ class IconSelector(ValueSpec):
by_cat[category_name].append(icon_name)
icon_categories = []
- for category_name, category_alias in self._categories:
+ for category_name, category_alias in self.categories().items():
if category_name in by_cat:
icon_categories.append((category_name, category_alias,
by_cat[category_name]))
return icon_categories
+
def render_icon(self, icon_name, onclick = '', title = '', id =
''):
if not icon_name:
icon_name = self._empty_img
@@ -4248,6 +4251,7 @@ class IconSelector(ValueSpec):
return icon
+
def render_input(self, varprefix, value):
self.classtype_info()
if not value:
@@ -4326,6 +4330,7 @@ class IconSelector(ValueSpec):
html.close_div()
+
def from_html_vars(self, varprefix):
icon = html.var(varprefix + '_value')
if icon == 'empty':
@@ -4337,10 +4342,12 @@ class IconSelector(ValueSpec):
# TODO: This is a workaround for a bug. This function needs to return str objects
right now.
return "%s" % self.render_icon(value)
+
def validate_datatype(self, value, varprefix):
if value is not None and type(value) != str:
raise MKUserError(varprefix, _("The type is %s, but should be str")
% type(value))
+
def validate_value(self, value, varprefix):
if not self._allow_empty and not value:
raise MKUserError(varprefix, _("You need to select an icon."))
@@ -4349,6 +4356,7 @@ class IconSelector(ValueSpec):
raise MKUserError(varprefix, _("The selected icon image does not
exist."))
+
class TimeofdayRanges(Transform):
def __init__(self, **args):
self._count = args.get("count", 3)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index eb3df83..4b3d6be 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -15884,7 +15884,7 @@ class ModeIcons(WatoMode):
)),
('category', DropdownChoice(
title = _('Category'),
- choices = IconSelector._categories,
+ choices = config.wato_icon_categories,
no_preselect = True,
))
]
diff --git a/web/plugins/config/wato.py b/web/plugins/config/wato.py
index 0169e92..3895f39 100644
--- a/web/plugins/config/wato.py
+++ b/web/plugins/config/wato.py
@@ -45,6 +45,11 @@ wato_legacy_eval = False
wato_read_only = {}
wato_hide_folders_without_read_permissions = False
wato_pprint_config = False
+wato_icon_categories = [
+ ("logos", "Logos"),
+ ("parts", "Parts"),
+ ("misc", "Misc"),
+]
def tag_alias(tag):
for entry in wato_host_tags:
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 37bc340..505af71 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -1039,6 +1039,28 @@ register_configvar(group,
),
domain = "multisite")
+register_configvar(group,
+ "wato_icon_categories",
+ ListOf(
+ Tuple(
+ elements = [
+ ID(
+ title = _("ID"),
+ ),
+ TextUnicode(
+ title = _("Title"),
+ ),
+ ],
+ orientation = "horizontal",
+ ),
+ title = _("Icon categories"),
+ help = _("You can customize the list of icon categories to be able to assign
"
+ "your <a href=\"?mode=icons\">custom
icons</a> to these categories. "
+ "They will then be shown under this category in the icon
selector."),
+ ),
+ domain = "multisite"
+)
+
#.
# .--User Management-----------------------------------------------------.
# | _ _ __ __ _ |