Module: check_mk
Branch: master
Commit: 0d75b9726573b40bb0ed5317a1d9cb92e6284ef3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0d75b9726573b4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 26 12:24:50 2016 +0100
"Add to X" popup is now checking to which page types an element can be added to
---
web/htdocs/htmllib.py | 3 ++-
web/htdocs/js/checkmk.js | 3 ++-
web/htdocs/pagetypes.py | 12 ++++++++----
web/htdocs/visuals.py | 5 ++++-
4 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 4ee35fa..d93ef06 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1070,7 +1070,8 @@ class html(GUITester):
self.popup_trigger(
self.render_icon("menu", _("Add this view to..."),
cssclass="statusicon iconbutton"),
- 'add_visual', 'add_visual', data=[mode_name,
encoded_vars, {'name': self.var('view_name')}])
+ 'add_visual', 'add_visual', data=[mode_name,
encoded_vars, {'name': self.var('view_name')}],
+ url_vars=[("add_type", "view")])
for img, tooltip in self.status_icons.items():
if type(tooltip) == tuple:
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 65ef71c..3364329 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -772,7 +772,8 @@ function create_graph(data, params) {
toggle_popup(event, this, 'add_visual', 'add_visual',
['pnpgraph',
{ 'host': host, 'service': service },
- { 'timerange': view, 'source': source }]
+ { 'timerange': view, 'source': source }],
+ "add_type=pnpgraph"
);
}
}(data['host'], data['service'], view, source);
diff --git a/web/htdocs/pagetypes.py b/web/htdocs/pagetypes.py
index 9e332cc..86876f3 100644
--- a/web/htdocs/pagetypes.py
+++ b/web/htdocs/pagetypes.py
@@ -944,6 +944,12 @@ class Container:
def sanitize(self, d):
d.setdefault("elements", [])
+ # Which kind of elements are allowed to be added to this container?
+ # Defaulting to all possible elements.
+ @classmethod
+ def may_contain(self, element_type_name):
+ return True
+
def elements(self):
return self._["elements"]
@@ -1057,9 +1063,7 @@ def page_handlers():
return page_handlers
-def render_addto_popup():
+def render_addto_popup(add_type):
for page_type in page_types.values():
- # TODO: Wie sorgen wir dafür, dass nur geeignete Elemente zum hinzufügen
- # angeboten werden? Eine View in eine GraphCollection macht keinen Sinn...
- if issubclass(page_type, Container):
+ if issubclass(page_type, Container) and page_type.may_contain(add_type):
page_type.render_addto_popup()
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index f5859dd..0d9a740 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -1381,8 +1381,11 @@ def transform_old_visual(visual):
# TODO: Remove this code as soon as everything is moved over to pagetypes.py
def ajax_popup_add():
+ add_type = html.var("add_type")
+ html.debug(add_type)
+
html.write("<ul>")
- pagetypes.render_addto_popup()
+ pagetypes.render_addto_popup(add_type)
for visual_type_name, visual_type in visual_types.items():
if "popup_add_handler" in visual_type: