Module: check_mk
Branch: master
Commit: 7cf1b0dc7ceb6b6514ede0f8bc2c01a74b5ce979
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7cf1b0dc7ceb6b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Sep 16 14:19:18 2014 +0200
View editor: only show datasource that make sense
---
web/htdocs/valuespec.py | 7 ++++++-
web/htdocs/views.py | 22 ++++++++++++++++------
web/htdocs/visuals.py | 11 +++++++++--
web/plugins/visuals/context_types.py | 26 +++++++++++++++++++++++---
4 files changed, 54 insertions(+), 12 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 9801552..654a983 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1343,7 +1343,12 @@ class RadioChoice(DropdownChoice):
html.write("<table class=radiochoice>")
html.write("<tr>")
- for n, entry in enumerate(self._choices):
+ if self._sorted:
+ choices = self._choices[:]
+ choices.sort(cmp=lambda a,b: cmp(a[1], b[1]))
+ else:
+ choices = self._choices
+ for n, entry in enumerate(choices):
if self._columns != None:
html.write("<td>")
if len(entry) > 2 and entry[2] != None: # icon!
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 8865787..64be415 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -322,24 +322,34 @@ def page_create_view():
# Seconds step: Select the data source
def page_create_view_ds(next_url =
'edit_view.py?context_type=%s&datasource=%s'):
- context_type = html.var('context_type')
+ context_type_name = html.var('context_type')
available = visuals.context_types.keys()
available.remove('global')
- if context_type not in available:
+ if context_type_name not in available:
raise MKGeneralException(_('The context type is missing'))
+ context_type = visuals.context_types[context_type_name]
# Filter out datasources which are available for this context type. The
# matching is done based on the "info" available for each datasource
datasources = []
for ds_name, ds in multisite_datasources.items():
- datasources.append((ds_name, ds['title'], None,
ds.get('description')))
-
- vs_ds = RadioChoice(
+ if "infos" in context_type:
+ skip = False
+ for needed_info in context_type["infos"]:
+ if needed_info not in ds["infos"]:
+ skip = True
+ break
+ if not skip:
+ datasources.append((ds_name, ds['title']))
+
+ vs_ds = DropdownChoice(
title = _('Datasource'),
choices = datasources,
+ sorted = True,
help = _('The datasources defines which type of objects should be displayed
with this view.'),
columns = 1,
+ default_value = "service",
)
html.header(_('Create View'), stylesheets=["pages"])
@@ -353,7 +363,7 @@ def page_create_view_ds(next_url =
'edit_view.py?context_type=%s&datasource=%s')
ds = vs_ds.from_html_vars('ds')
vs_ds.validate_value(ds, 'ds')
- html.http_redirect(next_url % (context_type, ds))
+ html.http_redirect(next_url % (context_type_name, ds))
return
except MKUserError, e:
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index a208d8f..e1b65b9 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -345,10 +345,17 @@ def page_list(what, title, visuals, custom_columns = []):
def page_create_visual(what, allow_global = False, next_url = None):
what_s = what[:-1]
+ def cmp_context_titles(a, b):
+ return - cmp(context_types[a[0]]["single"],
context_types[b[0]]["single"]) \
+ or cmp(a[1], b[1])
+ context_choices = [ (k, v['title'])
+ for (k, v) in context_types.items()
+ if (allow_global or k != 'global') ]
+ context_choices.sort(cmp=cmp_context_titles)
+
vs_type = DropdownChoice(
title = _('Context Type'),
- choices = [(None, _('--- Select a Context type ---'))]
- + [ (k, v['title']) for k, v in context_types.items() if
allow_global or k != 'global' ],
+ choices = context_choices,
help = _('The context of a %s controls the type of objects to be shown. It
'
'also sets wether single or multiple objects are displayed. The
context '
'type of a %s can not be changed anymore.') % (what_s, what_s),
diff --git a/web/plugins/visuals/context_types.py b/web/plugins/visuals/context_types.py
index 05b287e..7f75b06 100644
--- a/web/plugins/visuals/context_types.py
+++ b/web/plugins/visuals/context_types.py
@@ -33,6 +33,7 @@ context_types['global'] = {
context_types['host'] = {
'title' : _('Single Host'),
'single' : True,
+ 'infos' : [ "host" ],
'parameters' : [
('host', TextUnicode(
title = _('Hostname'),
@@ -43,11 +44,13 @@ context_types['host'] = {
context_types['hosts'] = {
'title' : _('Multiple Hosts'),
'single' : False,
+ 'infos' : [ "host" ],
'parameters' : VisualFilterList(['host']),
}
context_types['service'] = {
'title' : _('Single Service'),
+ 'infos' : [ "host", "service" ],
'single' : True,
'parameters' : [
('host', TextUnicode(
@@ -62,12 +65,14 @@ context_types['service'] = {
context_types['services'] = {
'title' : _('Multiple Services'),
'single' : False,
+ 'infos' : [ "host", "service" ],
'parameters' : VisualFilterList(['service', 'host']),
}
context_types['service_on_hosts'] = {
'title' : _('Single Service on multiple hosts'),
'single' : True,
+ 'infos' : [ "service" ],
'parameters' : [
('service', TextUnicode(
title = _('Service Description'),
@@ -78,6 +83,7 @@ context_types['service_on_hosts'] = {
context_types['hostgroup'] = {
'title' : _('Single Hostgroups'),
'single' : True,
+ 'infos' : [ "hostgroup" ],
'parameters' : [
('hostgroup', TextUnicode(
title = _('Hostgroup Name'),
@@ -88,12 +94,14 @@ context_types['hostgroup'] = {
context_types['hostgroups'] = {
'title' : _('Multiple Hostgroups'),
'single' : False,
+ 'infos' : [ "hostgroup" ],
'parameters' : VisualFilterList(['hostgroup',
'hostgroups']),
}
context_types['servicegroup'] = {
'title' : _('Single Servicegroups'),
'single' : True,
+ 'infos' : [ "servicegroup" ],
'parameters' : [
('servicegroup', TextUnicode(
title = _('Servicegroup Name'),
@@ -104,30 +112,35 @@ context_types['servicegroup'] = {
context_types['servicegroups'] = {
'title' : _('Multiple Servicegroups'),
'single' : False,
+ 'infos' : [ "servicegroup" ],
'parameters' : VisualFilterList(['servicegroup']),
}
context_types['comments'] = {
'title' : _('Multiple Comments'),
'single' : False,
+ 'infos' : [ "host", "service" ],
'parameters' : VisualFilterList(['comment', 'host',
'service']),
}
context_types['downtimes'] = {
'title' : _('Multiple Downtimes'),
'single' : False,
+ 'infos' : [ "host", "service" ],
'parameters' : VisualFilterList(['downtime', 'host',
'service']),
}
context_types['logs'] = {
'title' : _('Multiple Log Entries'),
'single' : False,
+ 'infos' : [ "log", "host", "service" ],
'parameters' : VisualFilterList(['log', 'host',
'service', 'contact', 'command']),
}
context_types['logs_contact'] = {
- 'title' : _('Single Contact Log Entries'),
- 'single' : False,
+ 'title' : _('Single Contact Log Entry'),
+ 'single' : True,
+ 'infos' : [ "log", "host", "service" ],
'parameters' : [
('log_contact_name', TextAscii(
title = _('Contact Name'),
@@ -138,6 +151,7 @@ context_types['logs_contact'] = {
context_types['bi_aggregation'] = {
'title' : _('Single BI Aggregation'),
'single' : True,
+ 'infos' : [ "aggr" ],
'parameters' : [
('aggr_name', TextAscii(
title = _('Aggregation Name'),
@@ -146,14 +160,16 @@ context_types['bi_aggregation'] = {
}
context_types['bi_aggregations'] = {
- 'title' : _('Multiple BI Aggregation'),
+ 'title' : _('Multiple BI Aggregations'),
'single' : False,
+ 'infos' : [ "aggr" ],
'parameters' : VisualFilterList(['aggr']),
}
context_types['bi_host_aggregation'] = {
'title' : _('Single BI Aggregation affected by one host'),
'single' : True,
+ 'infos' : [ "aggr", "host" ],
'parameters' : [
('aggr_host', TextAscii(
title = _('Hostname'),
@@ -164,18 +180,21 @@ context_types['bi_host_aggregation'] = {
context_types['bi_host_aggregations'] = {
'title' : _('Multiple Single Host BI Aggregations'),
'single' : False,
+ 'infos' : [ "aggr", "host" ],
'parameters' : VisualFilterList(['aggr', 'host']),
}
context_types['bi_hostname_aggregations'] = {
'title' : _('Multiple Single Host BI Aggregations (Aggregation name
joined)'),
'single' : False,
+ 'infos' : [ "aggr", "host" ],
'parameters' : VisualFilterList(['aggr', 'host']),
}
context_types['bi_aggregation_group'] = {
'title' : _('Single BI Aggregation group'),
'single' : True,
+ 'infos' : [ "aggr" ],
'parameters' : [
('aggr_group', TextAscii(
title = _('Hostname'),
@@ -186,5 +205,6 @@ context_types['bi_aggregation_group'] = {
context_types['invswpacs'] = {
'title' : _('Multiple Software Packages'),
'single' : False,
+ "infos" : [ "host", "invswpac" ],
'parameters' : VisualFilterList(['invswpac', 'host']),
}