Module: check_mk
Branch: master
Commit: c602d7201760dfe900e0fd7fc1ceca6e4110a475
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c602d7201760df…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Oct 12 16:05:26 2011 +0200
Dashboard: hide dashlets that have no space
---
web/htdocs/dashboard.py | 64 +++++++++++++++++++++++------------------
web/htdocs/js/dashboard.js | 68 +++++++++++++++++++++++++++----------------
2 files changed, 79 insertions(+), 53 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index ab31ee4..a2cb5a8 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -293,15 +293,22 @@ def ajax_resize():
bottom = abs_position[1]
top = bottom - used_size[1]
- # Allocate used squares in matrix
- for x in range(left, right):
- for y in range(top, bottom):
- used_matrix[(x,y)] = True
-
- # Helper variable for how to grow, both x and y in [-1, 0, 1]
- grow_by = rel_position.compute_grow_by(size)
+ # Allocate used squares in matrix. If not all squares we need are free,
+ # then the dashboard is too small for all dashlets (as it seems).
+ # TEST: Dashlet auf 0/0 setzen, wenn kein Platz dafür da ist.
+ try:
+ for x in range(left, right):
+ for y in range(top, bottom):
+ if (x,y) in used_matrix:
+ raise Exception()
+ used_matrix[(x,y)] = True
+ # Helper variable for how to grow, both x and y in [-1, 0, 1]
+ grow_by = rel_position.compute_grow_by(size)
+
+ positions.append((nr, True, left, top, right, bottom, grow_by))
+ except:
+ positions.append((nr, False, left, top, right, bottom, (0,0)))
- positions.append((nr, left, top, right, bottom, grow_by))
# now resize all elastic dashlets to the max, but only
# by one raster at a time, in order to be fair
@@ -341,29 +348,29 @@ def ajax_resize():
while at_least_one_expanded:
at_least_one_expanded = False
new_positions = []
- for (nr, left, top, right, bottom, grow_by) in positions:
- # html.write(repr((nr, left, top, right, bottom, grow_by)))
- # try to grow in X direction by one
- if grow_by[0] > 0 and right < rastersize[0] and try_allocate(right,
top, right+1, bottom):
- at_least_one_expanded = True
- right += 1
- elif grow_by[0] < 0 and left > 0 and try_allocate(left-1, top, left,
bottom):
- at_least_one_expanded = True
- left -= 1
-
- # try to grow in Y direction by one
- if grow_by[1] > 0 and bottom < rastersize[1] and try_allocate(left,
bottom, right, bottom+1):
- at_least_one_expanded = True
- bottom += 1
- elif grow_by[1] < 0 and top > 0 and try_allocate(left, top-1, right,
top):
- at_least_one_expanded = True
- top -= 1
-
- new_positions.append((nr, left, top, right, bottom, grow_by))
+ for (nr, visible, left, top, right, bottom, grow_by) in positions:
+ if visible:
+ # html.write(repr((nr, left, top, right, bottom, grow_by)))
+ # try to grow in X direction by one
+ if grow_by[0] > 0 and right < rastersize[0] and try_allocate(right,
top, right+1, bottom):
+ at_least_one_expanded = True
+ right += 1
+ elif grow_by[0] < 0 and left > 0 and try_allocate(left-1, top,
left, bottom):
+ at_least_one_expanded = True
+ left -= 1
+
+ # try to grow in Y direction by one
+ if grow_by[1] > 0 and bottom < rastersize[1] and try_allocate(left,
bottom, right, bottom+1):
+ at_least_one_expanded = True
+ bottom += 1
+ elif grow_by[1] < 0 and top > 0 and try_allocate(left, top-1,
right, top):
+ at_least_one_expanded = True
+ top -= 1
+ new_positions.append((nr, visible, left, top, right, bottom, grow_by))
positions = new_positions
resize_info = []
- for nr, left, top, right, bottom, grow_by in positions:
+ for nr, visible, left, top, right, bottom, grow_by in positions:
# html.write(repr((nr, left, top, right, bottom, grow_by)))
# html.write("<br>")
title = board["dashlets"][nr].get("title")
@@ -372,6 +379,7 @@ def ajax_resize():
else:
th = 0
resize_info.append([nr,
+ visible and 1 or 0,
left * raster[0],
top * raster[1] + th,
(right - left) * raster[0],
diff --git a/web/htdocs/js/dashboard.js b/web/htdocs/js/dashboard.js
index b456b38..462234c 100644
--- a/web/htdocs/js/dashboard.js
+++ b/web/htdocs/js/dashboard.js
@@ -29,50 +29,68 @@ function resize_dashlets(id, code)
var oDash = null;
for (var i in resize_info) {
var dashlet = resize_info[i];
+ var d_number = dashlet[0];
+ var d_visible = dashlet[1];
+ var d_left = dashlet[2];
+ var d_top = dashlet[3];
+ var d_width = dashlet[4];
+ var d_height = dashlet[5];
+
+ var disstyle = "block";
+ if (!d_visible) {
+ disstyle = "none";
+ }
// check if dashlet has title and resize its width
- oDash = document.getElementById("dashlet_title_" + dashlet[0]);
+ oDash = document.getElementById("dashlet_title_" + d_number);
if (oDash) {
- oDash.style.width = dashlet[3] + "px";
+ oDash.style.width = d_width + "px";
oDash.style.top = "-" + title_height + "px";
oDash.style.height = title_height + "px";
+ oDash.style.display = disstyle;
}
// resize outer div
- oDash = document.getElementById("dashlet_" + dashlet[0]);
+ oDash = document.getElementById("dashlet_" + d_number);
if(oDash) {
oDash.style.position = 'absolute';
- oDash.style.display = 'block';
- oDash.style.left = dashlet[1] + "px";
- oDash.style.top = dashlet[2] + "px";
- oDash.style.width = dashlet[3] + "px";
- oDash.style.height = dashlet[4] + "px";
+ oDash.style.display = disstyle;
+ oDash.style.left = d_left + "px";
+ oDash.style.top = d_top + "px";
+ oDash.style.width = d_width + "px";
+ oDash.style.height = d_height + "px";
}
// resize shadow images
- oDash = document.getElementById("dashadow_w_" + dashlet[0]);
- if(oDash && dashlet[4] - 32 > 0)
- oDash.style.height = (dashlet[4] - 32) + "px";
- oDash = document.getElementById("dashadow_e_" + dashlet[0]);
- if (oDash && dashlet[4] - 32 > 0)
- oDash.style.height = (dashlet[4] - 32) + "px";
- oDash = document.getElementById("dashadow_n_" + dashlet[0]);
- if (oDash && dashlet[3] - 32 > 0)
- oDash.style.width = (dashlet[3] - 32) + "px";
- oDash = document.getElementById("dashadow_s_" + dashlet[0]);
- if (oDash && dashlet[3] - 32 > 0)
- oDash.style.width = (dashlet[3] - 32) + "px";
+ oDash = document.getElementById("dashadow_w_" + d_number);
+ if (oDash) oDash.style.display = disstyle;
+ if (oDash && d_height - 32 > 0)
+ oDash.style.height = (d_height - 32) + "px";
+ oDash = document.getElementById("dashadow_e_" + d_number);
+ if (oDash) oDash.style.display = disstyle;
+ if (oDash && d_height - 32 > 0)
+ oDash.style.height = (d_height - 32) + "px";
+ oDash = document.getElementById("dashadow_n_" + d_number);
+ if (oDash) oDash.style.display = disstyle;
+ if (oDash && d_width - 32 > 0)
+ oDash.style.width = (d_width - 32) + "px";
+ oDash = document.getElementById("dashadow_s_" + d_number);
+ if (oDash) oDash.style.display = disstyle;
+ if (oDash && d_width - 32 > 0)
+ oDash.style.width = (d_width - 32) + "px";
+
// resize content div
- oDash = document.getElementById("dashlet_inner_" + dashlet[0]);
+ oDash = document.getElementById("dashlet_inner_" + d_number);
if(oDash) {
+ oDash.style.display = disstyle;
oDash.style.position = 'absolute';
oDash.style.left = dashlet_padding + "px";
oDash.style.top = dashlet_padding + "px";
- if((dashlet[3] - 2*dashlet_padding) > 0)
- oDash.style.width = (dashlet[3] - 2*dashlet_padding) + "px";
- if((dashlet[4] - 2*dashlet_padding) > 0)
- oDash.style.height = (dashlet[4] - 2*dashlet_padding) + "px";
+ if((d_width - 2*dashlet_padding) > 0)
+ oDash.style.width = (d_width - 2*dashlet_padding) + "px";
+ if((d_height - 2*dashlet_padding) > 0)
+ oDash.style.height = (d_height - 2*dashlet_padding) + "px";
}
}
oDash = null;