Module: check_mk
Branch: master
Commit: d30eb1586a27bc010b7038cf7cdeaf5823b1d364
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d30eb1586a27bc…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 26 10:55:16 2011 +0200
Multisite: Sorting by joined columns is now possible
---
ChangeLog | 1 +
web/htdocs/views.py | 74 ++++++++++++++++++++++++++++++++++++++------------
2 files changed, 57 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 44f1a52..abe1d18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
on their own.
* Open tabs in views do not prevent reloading the displayed data anymore
* Added display_option "L" to enable/disable column title sortings
+ * Sorting by joined columns is now possible
1.1.11i3:
Core, Setup, etc.:
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index a792f67..862a8ab 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1163,7 +1163,7 @@ def show_view(view, show_heading = False, show_buttons = True, show_footer = Tru
# [4] Sorting - use view sorters or url supplied sorters
sorter_list = html.has_var('sort') and parse_url_sorters(html.var('sort')) or view["sorters"]
- sorters = [ (multisite_sorters[sn], reverse) for sn, reverse in sorter_list ]
+ sorters = [ (multisite_sorters[s[0]],) + s[1:] for s in sorter_list ]
# [5] Grouping
group_painters = [ (multisite_painters[e[0]],) + e[1:] for e in view["group_painters"] ]
@@ -1183,10 +1183,13 @@ def show_view(view, show_heading = False, show_buttons = True, show_footer = Tru
master_painters = [ p for p in all_painters if len(p) < 4 ]
columns = get_needed_columns(master_painters)
join_columns = get_needed_columns(join_painters)
-
- # Columns needed for sorters (what shall we do with the join columns?)
- for s, r in sorters:
- columns += s["columns"]
+
+ # Columns needed for sorters
+ for s in sorters:
+ if len(s) == 2:
+ columns += s[0]["columns"]
+ else:
+ join_columns += s[0]["columns"]
# Add key columns, needed for executing commands
columns += datasource["keys"]
@@ -1218,11 +1221,11 @@ def show_view(view, show_heading = False, show_buttons = True, show_footer = Tru
else:
rows = query_data(datasource, columns, add_columns, query, only_sites, get_limit())
- sort_data(rows, sorters)
-
# Now add join information, if there are join columns
if len(join_painters) > 0:
do_table_join(datasource, rows, filterheaders, join_painters, join_columns, only_sites)
+
+ sort_data(rows, sorters)
else:
rows = []
@@ -1690,13 +1693,23 @@ def merge_data(data, columns):
# for same objects (e.g. host_name in table services and
# simply name in table hosts)
def sort_data(data, sorters):
+
if len(sorters) == 0:
return
- elif len(sorters) == 1:
+
+ # Join the data in case of sorting with joined data
+ # FIXME: Problem: What to do in case of several joined
+ # columns of different services which use the same cols?
+ for row in data:
+ for s in sorters:
+ if len(s) > 2:
+ row.update(row.get("JOIN", {}).get(s[2], {}))
+
+ if len(sorters) == 1:
data.sort(sorters[0][0]["cmp"], None, sorters[0][1])
return
- sort_cmps = [(s["cmp"], (reverse and -1 or 1)) for s, reverse in sorters]
+ sort_cmps = [(s[0]["cmp"], (s[1] and -1 or 1)) for s in sorters]
def multisort(e1, e2):
for func, neg in sort_cmps:
@@ -2217,9 +2230,16 @@ def substract_sorters(base, remove):
base.remove((s[0], not s[1]))
def parse_url_sorters(sort):
+ sorters = []
if not sort:
- return []
- return [ (s.replace('-', ''), s.startswith('-')) for s in sort.split(',') ]
+ return sorters
+ for s in sort.split(','):
+ if not '~' in s:
+ sorters.append((s.replace('-', ''), s.startswith('-')))
+ else:
+ sorter, join_index = s.split('~', 1)
+ sorters.append((sorter.replace('-', ''), sorter.startswith('-'), join_index))
+ return sorters
def get_sorter_name_of_painter(painter):
if 'sorter' in painter:
@@ -2256,6 +2276,10 @@ def get_separated_sorters(view):
return group_sort, user_sort, view_sort
+def get_painter_join_index(view, painter):
+ for e in view["painters"]:
+ if e[0] == painter['name'] and len(e) >= 5:
+ return e[3]
def sort_url(view, painter):
"""
@@ -2272,13 +2296,20 @@ def sort_url(view, painter):
sorter = group_sort + user_sort + view_sort
+ # When painter is joined, then add the join index as 3rd attribute to tuple
+ join_index = get_painter_join_index(view, painter)
+
# Now apply the sorter of the current column:
# - Negate/Disable when at first position
# - Move to the first position when already in sorters
# - Add in the front of the user sorters when not set
sorter_name = get_sorter_name_of_painter(painter)
- this_asc_sorter = (sorter_name, False)
- this_desc_sorter = (sorter_name, True)
+ if join_index:
+ this_asc_sorter = (sorter_name, False, join_index)
+ this_desc_sorter = (sorter_name, True, join_index)
+ else:
+ this_asc_sorter = (sorter_name, False)
+ this_desc_sorter = (sorter_name, True)
if user_sort and this_asc_sorter == user_sort[0]:
# Second click: Change from asc to desc order
@@ -2297,7 +2328,14 @@ def sort_url(view, painter):
# Now add the sorter as primary user sorter
sorter = group_sort + [this_asc_sorter] + user_sort + view_sort
- return ','.join([ (s[1] and '-' or '') + s[0] for s in sorter ])
+ p = []
+ for s in sorter:
+ if len(s) == 2:
+ p.append((s[1] and '-' or '') + s[0])
+ else:
+ p.append((s[1] and '-' or '') + s[0] + '~' + s[2])
+
+ return ','.join(p)
def paint_header(view, p):
painter = p[0]
@@ -2379,16 +2417,16 @@ def cmp_insensitive_string(v1, v2):
# Sorting
def cmp_simple_string(column, r1, r2):
- v1, v2 = r1[column], r2[column]
+ v1, v2 = r1.get(column, ''), r2.get(column, '')
return cmp_insensitive_string(v1, v2)
def cmp_string_list(column, r1, r2):
- v1 = ''.join(r1[column])
- v2 = ''.join(r2[column])
+ v1 = ''.join(r1.get(column, []))
+ v2 = ''.join(r2.get(column, []))
return cmp_insensitive_string(v1, v2)
def cmp_simple_number(column, r1, r2):
- return cmp(r1[column], r2[column])
+ return cmp(r1.get(column), r2.get(column))
def declare_simple_sorter(name, title, column, func):
multisite_sorters[name] = {
Module: check_mk
Branch: master
Commit: 1f26bf2acccf1301e3f52b9135fceed0f8f5c723
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1f26bf2acccf13…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 26 10:54:33 2011 +0200
Updated bug entries
---
.bugs/196 | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/.bugs/196 b/.bugs/196
new file mode 100644
index 0000000..c0697f0
--- /dev/null
+++ b/.bugs/196
@@ -0,0 +1,21 @@
+Title: Gejointe Columns sortieren ist noch ein Hack
+Component: multisite
+Benefit: 5
+State: open
+Cost: 3
+Date: 2011-08-26 10:49:22
+Class: nastiness
+
+Ich musste das sortieren der joined colums umsetzen. Das war gar nicht so trivial.
+Als Hack habe ich es nun geschaft. Das offene Problem, welches noch existiert:
+
+Das Joinen der Columnns passiert für die gesamte Row. Das führt dazu, dass wenn man
+mehrere Join Columns hat, die auf die gleiche Spalte von verschiedenen Services zugreifen,
+diese sich gegenseitig überschreiben können.
+
+Das ist hier momentan tolerierbar, deswegen belasse ich es gerade mal dabei.
+
+Der richtige Weg wäre wohl die Row dann zu joinen, wenn man weiß um welche Column es geht.
+Das Problem ist nur, dass man dies bei den Sortern momentan erst im Sorter selbst weiß.
+Man müsste eine Wrapper Funktion dazwischen schieben, die den Join mit der jeweiligen Column
+macht.
Module: check_mk
Branch: master
Commit: 55312accd136dbc296ec61188279ba7a0fdb005d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=55312accd136db…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Aug 25 11:30:49 2011 +0200
Added display_option "L" to enable/disable column title sortings
---
ChangeLog | 1 +
web/htdocs/dashboard.py | 2 +-
web/htdocs/views.py | 6 ++++--
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 99db10a..44f1a52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
* Views are not reloaded completely anymore. The data tables are reloaded
on their own.
* Open tabs in views do not prevent reloading the displayed data anymore
+ * Added display_option "L" to enable/disable column title sortings
1.1.11i3:
Core, Setup, etc.:
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index f3fce81..ba91148 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -182,7 +182,7 @@ def render_dashlet(nr, dashlet, filename):
# The method "view" is a shortcut for "iframe" with a certain url
if "view" in dashlet:
- dashlet["iframe"] = "view.py?view_name=%s&display_options=SIXHR&_body_class=dashlet" % dashlet["view"]
+ dashlet["iframe"] = "view.py?view_name=%s&display_options=SIXHRL&_body_class=dashlet" % dashlet["view"]
# The content is rendered only if it is fixed. In the
# other cases the initial (re)-size will paint the content.
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 56efde2..79d4049 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1059,7 +1059,7 @@ def get_needed_columns(painters):
# Display view with real data. This is *the* function everying
# is about.
def show_view(view, show_heading = False, show_buttons = True, show_footer = True):
- all_display_options = "HTBFCEOZRSIXDM"
+ all_display_options = "HTBFCEOZRSIXDML"
# Parse display options and
if html.output_format == "html":
@@ -2315,7 +2315,9 @@ def paint_header(view, p):
# - Add the display options (Keeping the same display options as current)
# - Link to _self (Always link to the current frame)
# - Keep the _body_class variable (e.g. for dashlets)
- if view.get('user_sortable', True) and get_sorter_name_of_painter(painter) is not None:
+ if 'L' in html.display_options \
+ and view.get('user_sortable', True) \
+ and get_sorter_name_of_painter(painter) is not None:
params = [
('sort', sort_url(view, painter)),
]
Module: check_mk
Branch: master
Commit: 3d71dd6370816746ffa54e6781d1583abc6edbef
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3d71dd63708167…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Aug 25 11:06:51 2011 +0200
Proceeding with updates after an error
---
web/htdocs/js/check_mk.js | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/web/htdocs/js/check_mk.js b/web/htdocs/js/check_mk.js
index 00364d9..b8d8baa 100644
--- a/web/htdocs/js/check_mk.js
+++ b/web/htdocs/js/check_mk.js
@@ -597,13 +597,6 @@ function startReloadTimer(url) {
gReloadTimer = setTimeout("handleReload('" + url + "')", Math.ceil(parseFloat(gReloadTime) * 1000));
}
-function handleContentReloadError(data, statusCode) {
- var o = document.getElementById('data_container');
- o.innerHTML = '<div class=error>Update failed (' + statusCode
- + '). The shown data might be outdated</div>' + o.innerHTML;
- o = null;
-}
-
function updateHeaderTime() {
var oTime = document.getElementById('headertime');
if(!oTime)
@@ -640,6 +633,16 @@ function handleContentReload(_unused, code) {
startReloadTimer('');
}
+function handleContentReloadError(data, statusCode) {
+ var o = document.getElementById('data_container');
+ o.innerHTML = '<div class=error>Update failed (' + statusCode
+ + '). The shown data might be outdated</div>' + o.innerHTML;
+ o = null;
+
+ // Continue update after the error
+ startReloadTimer('');
+}
+
function handleReload(url) {
// FiXME: Nicht mehr die ganze Seite neu laden, wenn es ein DIV "data_container" gibt.
// In dem Fall wird die aktuelle URL aus "window.location.href" geholt, für den Refresh