Module: check_mk
Branch: master
Commit: 4a361d49acd6c231e13cdf3af0c55a4a1227acf9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4a361d49acd6c2…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Fri Nov 9 10:48:17 2018 +0100
Refactored views to new snapin API
Change-Id: I422965ed6670c8ff1dfc7cdc3017bd9a775d379f
---
cmk/gui/plugins/sidebar/views.py | 153 +++++++++++++++++++++------------------
1 file changed, 83 insertions(+), 70 deletions(-)
diff --git a/cmk/gui/plugins/sidebar/views.py b/cmk/gui/plugins/sidebar/views.py
index 6ed8387..8c4e87e 100644
--- a/cmk/gui/plugins/sidebar/views.py
+++ b/cmk/gui/plugins/sidebar/views.py
@@ -33,80 +33,93 @@ import cmk.gui.config as config
import cmk.gui.views as views
import cmk.gui.dashboard as dashboard
import cmk.gui.pagetypes as pagetypes
-from cmk.gui.i18n import _
-from cmk.gui.globals import html
-
from cmk.gui.plugins.sidebar import (
- sidebar_snapins,
+ SidebarSnapin,
+ snapin_registry,
visuals_by_topic,
bulletlink,
footnotelinks,
)
+from cmk.gui.i18n import _
+from cmk.gui.globals import html
-def render_views():
- views.load_views()
- dashboard.load_dashboards()
-
- def render_topic(topic, entries):
- first = True
- for t, title, name, is_view in entries:
- if is_view and config.visible_views and name not in config.visible_views:
- continue
- if is_view and config.hidden_views and name in config.hidden_views:
- continue
- if t == topic:
- if first:
- html.begin_foldable_container("views", topic, False, topic,
indent=True)
- first = False
- if is_view:
- bulletlink(title, "view.py?view_name=%s" % name, onclick =
"return wato_views_clicked(this)")
- elif "?name=" in name:
- bulletlink(title, name)
- else:
- bulletlink(title, 'dashboard.py?name=%s' % name, onclick =
"return wato_views_clicked(this)")
-
- # TODO: One day pagestypes should handle the complete snapin.
- # for page_type in pagetypes.all_page_types().values():
- # if issubclass(page_type, pagetypes.PageRenderer):
- # for t, title, url in page_type.sidebar_links():
- # if t == topic:
- # bulletlink(title, url)
-
- if not first: # at least one item rendered
- html.end_foldable_container()
-
- # TODO: One bright day drop this whole visuals stuff and only use page_types
- page_type_topics = {}
- for page_type in pagetypes.all_page_types().values():
- if issubclass(page_type, pagetypes.PageRenderer):
- for t, title, url in page_type.sidebar_links():
- page_type_topics.setdefault(t, []).append((t, title, url, False))
-
- visuals_topics_with_entries = visuals_by_topic(views.permitted_views().items() +
dashboard.permitted_dashboards().items())
- all_topics_with_entries = []
- for topic, entries in visuals_topics_with_entries:
- if topic in page_type_topics:
- entries = entries + page_type_topics[topic]
- del page_type_topics[topic]
- all_topics_with_entries.append((topic, entries))
-
- all_topics_with_entries += sorted(page_type_topics.items())
-
- for topic, entries in all_topics_with_entries:
- render_topic(topic, entries)
-
-
- links = []
- if config.user.may("general.edit_views"):
- if config.debug:
- links.append((_("Export"), "export_views.py"))
- links.append((_("Edit"), "edit_views.py"))
- footnotelinks(links)
-
-sidebar_snapins["views"] = {
- "title" : _("Views"),
- "description" : _("Links to global views and dashboards"),
- "render" : render_views,
- "allowed" : [ "user", "admin", "guest" ],
-}
+(a)snapin_registry.register
+class Views(SidebarSnapin):
+ @staticmethod
+ def type_name():
+ return "views"
+
+ @classmethod
+ def title(cls):
+ return _("Views")
+
+ @classmethod
+ def description(cls):
+ return _("Links to global views and dashboards")
+
+ def show(self):
+ views.load_views()
+ dashboard.load_dashboards()
+
+ def render_topic(topic, entries):
+ first = True
+ for t, title, name, is_view in entries:
+ if is_view and config.visible_views and name not in
config.visible_views:
+ continue
+ if is_view and config.hidden_views and name in config.hidden_views:
+ continue
+ if t == topic:
+ if first:
+ html.begin_foldable_container("views", topic, False,
topic, indent=True)
+ first = False
+ if is_view:
+ bulletlink(
+ title,
+ "view.py?view_name=%s" % name,
+ onclick="return wato_views_clicked(this)")
+ elif "?name=" in name:
+ bulletlink(title, name)
+ else:
+ bulletlink(
+ title,
+ 'dashboard.py?name=%s' % name,
+ onclick="return wato_views_clicked(this)")
+
+ # TODO: One day pagestypes should handle the complete snapin.
+ # for page_type in pagetypes.all_page_types().values():
+ # if issubclass(page_type, pagetypes.PageRenderer):
+ # for t, title, url in page_type.sidebar_links():
+ # if t == topic:
+ # bulletlink(title, url)
+
+ if not first: # at least one item rendered
+ html.end_foldable_container()
+
+ # TODO: One bright day drop this whole visuals stuff and only use page_types
+ page_type_topics = {}
+ for page_type in pagetypes.all_page_types().values():
+ if issubclass(page_type, pagetypes.PageRenderer):
+ for t, title, url in page_type.sidebar_links():
+ page_type_topics.setdefault(t, []).append((t, title, url, False))
+
+ visuals_topics_with_entries = visuals_by_topic(views.permitted_views().items() +
+
dashboard.permitted_dashboards().items())
+ all_topics_with_entries = []
+ for topic, entries in visuals_topics_with_entries:
+ if topic in page_type_topics:
+ entries = entries + page_type_topics[topic]
+ del page_type_topics[topic]
+ all_topics_with_entries.append((topic, entries))
+
+ all_topics_with_entries += sorted(page_type_topics.items())
+
+ for topic, entries in all_topics_with_entries:
+ render_topic(topic, entries)
+
+ links = []
+ if config.user.may("general.edit_views"):
+ if config.debug:
+ links.append((_("Export"), "export_views.py"))
+ links.append((_("Edit"), "edit_views.py"))
+ footnotelinks(links)