Module: check_mk
Branch: master
Commit: 593cd90bbdd5896247223c1256ff87e63199504d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=593cd90bbdd589…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Thu Nov 22 15:19:33 2018 +0100
Refactored dashboards snapin to new snapin API
Change-Id: Iaf525761884eda56bf8d0c63a2971001e95945d8
---
cmk/gui/plugins/sidebar/dashboards.py | 90 +++++++++++++++++++----------------
1 file changed, 49 insertions(+), 41 deletions(-)
diff --git a/cmk/gui/plugins/sidebar/dashboards.py
b/cmk/gui/plugins/sidebar/dashboards.py
index b403cbf..a43d4eb 100644
--- a/cmk/gui/plugins/sidebar/dashboards.py
+++ b/cmk/gui/plugins/sidebar/dashboards.py
@@ -29,58 +29,66 @@ import cmk.gui.dashboard as dashboard
from cmk.gui.globals import html
from cmk.gui.i18n import _
from cmk.gui.plugins.sidebar import (
- sidebar_snapins,
+ SidebarSnapin,
+ snapin_registry,
visuals_by_topic,
bulletlink,
footnotelinks,
)
-def render_dashboards():
- dashboard.load_dashboards()
+(a)snapin_registry.register
+class Dashboards(SidebarSnapin):
+ @staticmethod
+ def type_name():
+ return "dashboards"
- def render_topic(topic, s, foldable=True):
- first = True
- for t, title, name, _is_view in s:
- if t == topic:
- if first:
- if foldable:
- html.begin_foldable_container(
- "dashboards", topic, False, topic, indent=True)
- else:
- html.open_ul()
- first = False
- bulletlink(
- title, 'dashboard.py?name=%s' % name, onclick="return
wato_views_clicked(this)")
+ @classmethod
+ def title(cls):
+ return _("Dashboards")
- if not first: # at least one item rendered
- if foldable:
- html.end_foldable_container()
- else:
- html.open_ul()
+ @classmethod
+ def description(cls):
+ return _("Links to all dashboards")
- by_topic = visuals_by_topic(
- dashboard.permitted_dashboards().items(), default_order=[_('Overview')])
- topics = [topic for topic, _entry in by_topic]
+ def show(self):
+ dashboard.load_dashboards()
- if len(topics) < 2:
- render_topic(by_topic[0][0], by_topic[0][1], foldable=False)
+ def render_topic(topic, s, foldable=True):
+ first = True
+ for t, title, name, _is_view in s:
+ if t == topic:
+ if first:
+ if foldable:
+ html.begin_foldable_container(
+ "dashboards", topic, False, topic,
indent=True)
+ else:
+ html.open_ul()
+ first = False
+ bulletlink(
+ title,
+ 'dashboard.py?name=%s' % name,
+ onclick="return wato_views_clicked(this)")
- else:
- for topic, s in by_topic:
- render_topic(topic, s)
+ if not first: # at least one item rendered
+ if foldable:
+ html.end_foldable_container()
+ else:
+ html.open_ul()
- links = []
- if config.user.may("general.edit_dashboards"):
- if config.debug:
- links.append((_("Export"), "export_dashboards.py"))
- links.append((_("Edit"), "edit_dashboards.py"))
- footnotelinks(links)
+ by_topic = visuals_by_topic(
+ dashboard.permitted_dashboards().items(),
default_order=[_('Overview')])
+ topics = [topic for topic, _entry in by_topic]
+ if len(topics) < 2:
+ render_topic(by_topic[0][0], by_topic[0][1], foldable=False)
+ else:
+ for topic, s in by_topic:
+ render_topic(topic, s)
-sidebar_snapins["dashboards"] = {
- "title": _("Dashboards"),
- "description": _("Links to all dashboards"),
- "render": render_dashboards,
- "allowed": ["user", "admin", "guest"],
-}
+ links = []
+ if config.user.may("general.edit_dashboards"):
+ if config.debug:
+ links.append((_("Export"), "export_dashboards.py"))
+ links.append((_("Edit"), "edit_dashboards.py"))
+ footnotelinks(links)