Module: check_mk
Branch: master
Commit: 2dec90a1666170b4be744574e25d2b15eb616d29
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2dec90a1666170…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Thu Nov 8 14:44:27 2018 +0100
Moved views from shipped.py to dedicated module
Change-Id: I4c22bb8e29c6eec2234ece600244244cf5cb8f3f
---
cmk/gui/plugins/sidebar/shipped.py | 79 --------------------------
cmk/gui/plugins/sidebar/views.py | 112 +++++++++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+), 79 deletions(-)
diff --git a/cmk/gui/plugins/sidebar/shipped.py b/cmk/gui/plugins/sidebar/shipped.py
index 2e8c04b..3f54f4d 100644
--- a/cmk/gui/plugins/sidebar/shipped.py
+++ b/cmk/gui/plugins/sidebar/shipped.py
@@ -36,7 +36,6 @@ import cmk.paths
import cmk.gui.config as config
import cmk.gui.views as views
import cmk.gui.dashboard as dashboard
-import cmk.gui.pagetypes as pagetypes
import cmk.gui.sites as sites
from cmk.gui.htmllib import HTML
from cmk.gui.i18n import _
@@ -56,84 +55,6 @@ from cmk.gui.plugins.sidebar import (
)
#.
-# .--Views---------------------------------------------------------------.
-# | __ ___ |
-# | \ \ / (_) _____ _____ |
-# | \ \ / /| |/ _ \ \ /\ / / __| |
-# | \ V / | | __/\ V V /\__ \ |
-# | \_/ |_|\___| \_/\_/ |___/ |
-# | |
-# '----------------------------------------------------------------------'
-
-
-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" ],
-}
-
-#.
# .--Dashboards----------------------------------------------------------.
# | ____ _ _ _ |
# | | _ \ __ _ ___| |__ | |__ ___ __ _ _ __ __| |___ |
diff --git a/cmk/gui/plugins/sidebar/views.py b/cmk/gui/plugins/sidebar/views.py
new file mode 100644
index 0000000..6ed8387
--- /dev/null
+++ b/cmk/gui/plugins/sidebar/views.py
@@ -0,0 +1,112 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+# TODO: Split this file into single snapin or topic files
+
+# TODO: Refactor all snapins to the new snapin API and move page handlers
+# from sidebar.py to the snapin objects that need these pages.
+
+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,
+ visuals_by_topic,
+ bulletlink,
+ footnotelinks,
+)
+
+
+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" ],
+}