Module: check_mk
Branch: master
Commit: 2b3e0edaab0943bea8031a512b424cf2025eff35
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2b3e0edaab0943…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 30 15:52:23 2015 +0200
icon selector wird auch in host/service icons genutzt
---
web/htdocs/valuespec.py | 20 ++++---
web/plugins/wato/check_mk_configuration.py | 85 +++++-----------------------
2 files changed, 24 insertions(+), 81 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index bd2b677..36868ac 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -3266,13 +3266,17 @@ class IconSelector(ValueSpec):
return icon_categories
def render_icon(self, icon, onclick = '', title = '', id =
''):
+ if not icon:
+ icon = self._empty_img
path = "%s/%s%s.png" % (self._html_path, self._prefix,
html.attrencode(icon))
+ icon = ''
if onclick:
- html.write('<a href="javascript:void(0)"
onclick="%s">' % onclick)
- html.write('<img align=absmiddle id="%s" class=icon
title="%s" src="%s">' % (id, title, path))
+ icon += '<a href="javascript:void(0)"
onclick="%s">' % onclick
+ icon += '<img align=absmiddle id="%s" class=icon
title="%s" src="%s">' % (id, title, path)
if onclick:
- html.write('</a>')
+ icon += '</a>'
+ return icon
def render_input(self, varprefix, value):
if not value:
@@ -3285,7 +3289,7 @@ class IconSelector(ValueSpec):
('varprefix', varprefix),
('allow_empty', self._allow_empty and
'1' or '0')]))
if value:
- self.render_icon(value, '', _('Choose another Icon'), id =
varprefix + '_img')
+ html.write(self.render_icon(value, '', _('Choose another
Icon'), id = varprefix + '_img'))
else:
html.write(_('Select an Icon'))
html.end_popup_trigger()
@@ -3314,9 +3318,9 @@ class IconSelector(ValueSpec):
display = active_category != category_name and '
style="display:none"' or ''
html.write('<div%s id="%s_%s_container"
class="%s_container">' % (display, varprefix, category_name, varprefix))
for nr, icon in enumerate(empty + icons):
- self.render_icon(icon,
+ html.write(self.render_icon(icon,
onclick = 'vs_iconselector_select(event, \'%s\',
\'%s\')' % (varprefix, icon),
- title = _('Choose this icon'), id = varprefix + '_i_'
+ icon)
+ title = _('Choose this icon'), id = varprefix + '_i_'
+ icon))
html.write('</div>')
if self._upload:
@@ -3328,8 +3332,6 @@ class IconSelector(ValueSpec):
html.write('</div>')
html.write('</div>')
-
-
def from_html_vars(self, varprefix):
icon = html.var(varprefix + '_value')
if icon == 'empty':
@@ -3338,7 +3340,7 @@ class IconSelector(ValueSpec):
return icon
def value_to_text(self, value):
- self.render_icon(value)
+ return self.render_icon(value)
def validate_datatype(self, value, varprefix):
if value is not None and type(value) != str:
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 9dada8c..f368f48 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -2133,72 +2133,10 @@ register_rule(group,
"will also be reflected in the past.")),
itemtype = "service")
-class MonitoringIcon(ValueSpec):
- def __init__(self, **kwargs):
- ValueSpec.__init__(self, **kwargs)
-
- def available_icons(self):
- if defaults.omd_root:
- dirs = [ defaults.omd_root +
"/local/share/check_mk/web/htdocs/images/icons",
- defaults.omd_root +
"/share/check_mk/web/htdocs/images/icons" ]
- else:
- dirs = [ defaults.web_dir + "/htdocs/images/icons" ]
-
- icons = []
- for dir in dirs:
- if os.path.exists(dir):
- icons += [ i for i in os.listdir(dir)
- if '.' in i and os.path.isfile(dir + "/" +
i) ]
- icons.sort()
- return icons
-
- def render_input(self, varprefix, value):
- if value is None:
- value = ""
- num_columns = 12
- html.write("<table>")
- for nr, filename in enumerate([""] + self.available_icons()):
- if nr % num_columns == 0:
- html.write("<tr>")
- html.write("<td>")
- html.radiobutton(varprefix, str(nr), value == filename,
- self.value_to_text(filename))
- html.write(" </td>")
- if nr % num_columns == num_columns - 1:
- html.write("</tr>")
- if nr != num_columns - 1:
- html.write("</tr>")
- html.write("</table>")
-
- def value_to_text(self, value):
- if value:
- return '<img align=middle title="%s" class=icon
src="images/icons/%s">' % \
- (value, value)
- else:
- return _("none")
-
- def from_html_vars(self, varprefix):
- nr = int(html.var(varprefix))
- if nr == 0:
- return None
- else:
- return self.available_icons()[nr-1]
-
- 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 value and value not in self.available_icons():
- raise MKUserError(varprefix, _("The selected icon image does not
exist."))
- ValueSpec.custom_validate(self, value, varprefix)
-
-
register_rule(group,
"extra_host_conf:icon_image",
- MonitoringIcon(
+ IconSelector(
title = _("Icon image for hosts in status GUI"),
help = _("You can assign icons to hosts for the status GUI. "
"Put your images into <tt>%s</tt>. ") %
@@ -2207,21 +2145,24 @@ register_rule(group,
or defaults.web_dir + "/htdocs/images/icons" ),
))
+
register_rule(group,
"extra_service_conf:icon_image",
- MonitoringIcon(
- title = _("Icon image for services in status GUI"),
- help = _("You can assign icons to services for the status GUI. "
- "Put your images into <tt>%s</tt>. ") %
- ( defaults.omd_root
- and defaults.omd_root +
"/local/share/check_mk/web/htdocs/images/icons"
- or defaults.web_dir + "/htdocs/images/icons" ),
+ Transform(
+ IconSelector(
+ title = _("Icon image for services in status GUI"),
+ help = _("You can assign icons to services for the status GUI. "
+ "Put your images into <tt>%s</tt>. ") %
+ ( defaults.omd_root
+ and defaults.omd_root +
"/local/share/check_mk/web/htdocs/images/icons"
+ or defaults.web_dir + "/htdocs/images/icons" ),
),
+ forth = lambda v: v and v[:-4] or v,
+ back = lambda v: v and v+'.png' or v,
+ ),
itemtype = "service")
-
-
register_rulegroup("agent", _("Access to Agents"),
_("Settings concerning the connection to the Check_MK and SNMP agents"))