Module: check_mk
Branch: master
Commit: aec126fff4d9ffcffd846e5a348bc664f6478277
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=aec126fff4d9ff…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jan 22 10:19:49 2016 +0100
Prepare Views snapin for links to custom graphs
---
web/htdocs/pagetypes.py | 25 +++++++++++++++++++++----
web/htdocs/visuals.py | 6 ++++--
web/plugins/sidebar/shipped.py | 11 +++++------
3 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/web/htdocs/pagetypes.py b/web/htdocs/pagetypes.py
index d057041..9e332cc 100644
--- a/web/htdocs/pagetypes.py
+++ b/web/htdocs/pagetypes.py
@@ -167,6 +167,9 @@ class Base:
def description(self):
return self._.get("description", "")
+ def is_empty(self):
+ return False
+
# Default values for the creation dialog can be overridden by the
# sub class.
@classmethod
@@ -326,6 +329,14 @@ class PageRenderer:
page.render()
+ # Links for the sidebar
+ @classmethod
+ def sidebar_links(self):
+ for page in self.pages():
+ if not page.is_empty() and not page.is_hidden():
+ yield page.topic(), page.title(), page.page_url()
+
+
#.
# .--Overridable---------------------------------------------------------.
@@ -692,10 +703,10 @@ class Overridable:
### if render_custom_context_buttons:
### render_custom_context_buttons()
- ### for other_what, info in visual_types.items():
- ### if what != other_what:
- ### html.context_button(info["plural_title"].title(),
'edit_%s.py' % other_what, other_what[:-1])
- ### html.end_context_buttons()
+
+ for other_type_name, other_pagetype in page_types.items():
+ if self.type_name() != other_type_name:
+
html.context_button(other_pagetype.phrase("title_plural").title(),
'%ss.py' % other_type_name, other_type_name)
html.end_context_buttons()
# Deletion
@@ -1018,13 +1029,19 @@ def declare(page_type):
page_type.declare_overriding_permissions()
page_types[page_type.type_name()] = page_type
+
def page_type(page_type_name):
return page_types[page_type_name]
+
def has_page_type(page_type_name):
return page_type_name in page_types
+def all_page_types():
+ return page_types
+
+
# Global module functions for the integration into the rest of the code
# index.py uses the following function in order to complete its
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index 2995cd7..f5859dd 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -279,9 +279,11 @@ def page_list(what, title, visuals, custom_columns = [],
for other_what, info in visual_types.items():
if what != other_what:
html.context_button(info["plural_title"].title(),
'edit_%s.py' % other_what, other_what[:-1])
+
# TODO: We hack in those visuals that already have been moved to pagetypes here
- html.context_button(_("Graph collections"),
"graph_collections.py", "graph_collection")
- html.context_button(_("Bookmarks lists"), "bookmark_lists.py",
"bookmark_list")
+ html.context_button(_("Graph Collections"),
"graph_collections.py", "graph_collection")
+ html.context_button(_("Custom Graphs"), "custom_graphs.py",
"custom_graph")
+ html.context_button(_("Bookmark Lists"), "bookmark_lists.py",
"bookmark_list")
html.end_context_buttons()
diff --git a/web/plugins/sidebar/shipped.py b/web/plugins/sidebar/shipped.py
index 9580b08..a4b93cf 100644
--- a/web/plugins/sidebar/shipped.py
+++ b/web/plugins/sidebar/shipped.py
@@ -29,8 +29,6 @@ import pagetypes, table
from valuespec import *
from lib import *
-
-#.
# .--About---------------------------------------------------------------.
# | _ _ _ |
# | / \ | |__ ___ _ _| |_ |
@@ -110,10 +108,11 @@ def render_views():
bulletlink(title, 'dashboard.py?name=%s' % name, onclick =
"return wato_views_clicked(this)")
# TODO: One day pagestypes should handle the complete snapin.
- if pagetypes.has_page_type("graph_collection"):
- for t, title, url in
pagetypes.page_type("graph_collection").sidebar_links():
- if t == topic:
- bulletlink(title, url)
+ 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()