Module: check_mk
Branch: master
Commit: b142028db7aedebc1ec5f398e24f61d281538405
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b142028db7aedeā¦
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 6 08:29:38 2015 +0100
Prepared icon painter for new icon plugin api
---
web/htdocs/htmllib.py | 2 +-
web/plugins/icons/builtin.py | 3 +-
web/plugins/views/painters.py | 69 +++++++++++++++++++++++++++++++----------
3 files changed, 54 insertions(+), 20 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 5748609..f92cf9d 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -356,7 +356,7 @@ class html:
def render_icon(self, icon, help="", middle=True):
align = middle and ' align=absmiddle' or ''
title = help and ' title="%s"' % self.attrencode(help) or
""
- if "/" in icon:
+ if "/" in icon or "." in icon:
src = "images/" + icon
else:
src = "images/icon_%s.png" % icon
diff --git a/web/plugins/icons/builtin.py b/web/plugins/icons/builtin.py
index 5f5eeea..0b6c8c8 100644
--- a/web/plugins/icons/builtin.py
+++ b/web/plugins/icons/builtin.py
@@ -110,8 +110,7 @@ def paint_rule_editor(what, row, tags, custom_vars):
else:
title = _("View and edit parameters for this host")
- url = html.makeuri_contextless(urlvars, "wato.py")
- return '<a href="%s">%s</a>' % (url,
html.render_icon('rulesets', title))
+ return 'rulesets', html.makeuri_contextless(urlvars,
"wato.py"), title
multisite_icons.append({
'service_columns': [ 'description', 'check_command',
"host_name" ],
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 3b9cc21..94eb8e8 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -141,12 +141,60 @@ def paint_icons(what, row):
tags = []
output = ""
+ icon_rename_regex = regex('<img
src="([^"]*)"[^>]*>')
for icon in multisite_icons:
if icon.get('type', 'icon') == 'icon':
try:
- icon_output = icon['paint'](what, row, tags, custom_vars)
- if icon_output is not None:
- output += icon_output
+ title = None
+ link = None
+
+ # In old versions, the icons produced html code directly. The new API
+ # is that the icon functions need to return:
+ # a) None - nothing to be rendered
+ # b) single string - the icon name (without .png)
+ # c) tuple - icon, link
+ # d) triple - icon, link, title
+ result = icon['paint'](what, row, tags, custom_vars)a
+
+ if result == None:
+ continue
+
+ elif type(result) in [str,unicode]:
+ if result[0] == '<':
+ # seems like an old format icon (html code). In regular
rendering
+ # case (html), it can simply be appended to the output.
Otherwise
+ # extract the icon name from icon images
+ if html.output_format == "html":
+ output += result
+ else:
+ # Strip icon names out of HTML code that is generated by
htmllib.render_icon()
+ for n in icon_rename_regex.findall(result):
+ if n.startswith("images/"):
+ n = n[7:]
+ if n.startswith("icon_"):
+ n = n[5:]
+ if n.endswith(".png"):
+ n = n[:-4]
+ elif n.endswith(".gif"):
+ n = n[:-4]
+ output += ' '+n.encode('utf-8')
+ continue
+ else:
+ icon_name = result
+ else:
+ if len(result) == 2:
+ icon_name, link = result
+ elif len(result) == 3:
+ icon_name, link, title = result
+
+ if html.output_format == "html":
+ if link:
+ output += '<a href="%s">' % link
+ output += html.render_icon(icon_name, title)
+ if link:
+ output += '</a>'
+ else:
+ output = ' '+icon_name
except Exception, e:
import traceback
output += 'Exception in icon plugin!<br />' +
traceback.format_exc()
@@ -154,20 +202,7 @@ def paint_icons(what, row):
if html.output_format == "html":
return "icons", output
else:
- # Strip icon names out of HTML code that is generated by htmllib.render_icon()
- icon_rename_regex = regex('<img
src="([^"]*)"[^>]*>')
- icons = []
- for n in icon_rename_regex.findall(output):
- if n.startswith("images/"):
- n = n[7:]
- if n.startswith("icon_"):
- n = n[5:]
- if n.endswith(".png"):
- n = n[:-4]
- elif n.endswith(".gif"):
- n = n[:-4]
- icons.append(n.encode('utf-8'))
- return "icons", " ".join(icons)
+ return "icons", output.strip()
def iconpainter_columns(what):
cols = set(['site',