Author: eallen
Date: 2008-10-29 16:24:01 -0400 (Wed, 29 Oct 2008)
New Revision: 2698
Modified:
mgmt/trunk/cumin/python/cumin/stat.py
mgmt/trunk/cumin/python/cumin/stat.strings
Log:
Add a new stat type: grid. Used to display a grid of child objects and their state/status
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2008-10-29 20:22:50 UTC (rev 2697)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2008-10-29 20:24:01 UTC (rev 2698)
@@ -140,6 +140,134 @@
def render_stat_name(self, session, stat, object):
return stat.name
+class StatUtilizationGrid(Widget):
+ def __init__(self, app, name):
+ super(StatUtilizationGrid, self).__init__(app, name)
+
+ self.stats_tmpl = Template(self, "cell_html")
+ self.sticky_names_tmpl = Template(self, "sticky_name_html")
+ self.sticky_values_tmpl = Template(self, "sticky_value_html")
+ self.legend_tmpl = Template(self, "legend_html")
+
+ self.ajax = self.Updater(app, "grid_updater")
+ self.add_child(self.ajax)
+
+ def get_args(self, session):
+ """ must return a sequence """
+ return list()
+
+ def render_title(self, session, objects):
+ return "Utilization"
+
+ def render_grid(self, session, objects):
+ writer = Writer()
+
+ count = self.get_object_count(session, objects)
+ for object in objects:
+ self.stats_tmpl.render(writer, session, count, object)
+ return writer.to_string()
+
+ def get_object_count(self, objects):
+ return len(objects)
+
+ def render_override_style(self, session, objects):
+ pass
+
+ def render_legends(self, session, slots):
+ colors = self.get_colors(session)
+ writer = Writer()
+
+ sorted_keys = sorted(colors.keys())
+ for key in sorted_keys:
+ self.legend_tmpl.render(writer, session, colors, key)
+ return writer.to_string()
+
+ def render_legend_color(self, session, colors, key):
+ return colors[key]
+
+ def render_legend_text(self, session, colors, key):
+ return key
+
+ def render_cell_width(self, session, count, object):
+ sq = sqrt(count)
+ isq = int(sq)
+ if sq > isq:
+ isq = isq + 1
+
+ if count > 0:
+ return int(100 / isq)
+ else:
+ return 100
+
+ def render_color(self, session, count, object):
+ return "clear"
+
+ def render_contents(self, session, count, object):
+ return ""
+
+ def render_cell_id(self, session, count, object):
+ return 1
+
+ def get_url(self, session):
+ """ returns something like
+ "call.xml?class=system;id=%i;method=slots" % system.id
+ """
+ pass
+
+ def get_fn(self, session):
+ return self.ajax.name
+
+ def got_fn(self, session):
+ return self.ajax.name
+
+ def elem_id(self, session):
+ return self.ajax.name
+
+ def render_sticky_names(self, session, count, object):
+ names = self.do_get_sticky_info(session)
+ writer = Writer()
+
+ for name, desc in names:
+ self.sticky_names_tmpl.render(writer, session, desc)
+ return writer.to_string()
+
+ def render_sticky_title(self, session, desc):
+ return desc
+
+ def render_sticky_values(self, session, count, object):
+ names = self.do_get_sticky_info(session)
+ writer = Writer()
+
+ for name, desc in names:
+ self.sticky_values_tmpl.render(writer, session, name, object)
+ return writer.to_string()
+
+ def render_sticky_name(self, session, name, object):
+ return name
+
+ def render_sticky_object_id(self, session, name, object):
+ return self.render_cell_id(session, 1, object)
+
+ def do_get_sticky_info(self, session):
+ return [("Name", "Display Title")]
+
+ class Updater(AjaxField):
+ def do_render(self, session):
+ return self.render_script(session)
+
+ def get_url(self, session):
+ return self.parent.get_url(session)
+
+ def get_fn(self, session):
+ return self.parent.get_fn(session)
+
+ def got_fn(self, session):
+ return self.parent.got_fn(session)
+
+ def elem_id(self, session):
+ return self.parent.elem_id(session)
+
+
class StatChartPage(Page):
def __init__(self, app, name):
super(StatChartPage, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/stat.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.strings 2008-10-29 20:22:50 UTC (rev 2697)
+++ mgmt/trunk/cumin/python/cumin/stat.strings 2008-10-29 20:24:01 UTC (rev 2698)
@@ -164,3 +164,113 @@
<span class="swatch" style="background-color:
{stat_color}"> </span>
<span class="ph" statname="{stat_name}"
statmode="{mode}">{stat_value}</span>
</li>
+
+[StatUtilizationGrid.css]
+div.StatGrid{
+ width: 10em;
+ height: 10em;
+}
+div.grid_cell {
+ float:left;
+ position: relative;
+}
+div.grid_cell button {
+ width:95%;
+ height:95%;
+}
+.btn.yellow { background: #ffc; }
+.btn.green { background: #cfc; }
+.btn.blue { background: #ccf; }
+.btn.red { background: #fcc; }
+.btn.black { background: #444; }
+.btn.clear { background: white; }
+.btn:hover { border: 1px solid #a00; }
+.btn:active { background-color: #444; }
+.btn[class] { background-image: url(resource?name=shade1.png); background-position:
bottom; }
+
+div.visualization {
+ padding-right: 2em;
+}
+
+div.StatUtilizationGrid {
+ margin-top: 1em;
+ margin-left: 1em;
+}
+
+div.grid_cell div.sticky_note {
+ display: none;
+ position: absolute;
+ top: 60%;
+ left: 100%;
+ width: 24em;
+ padding: 1em;
+ background-color: #ffffaa;
+ background-image: url(resource?name=shade.png);
+ background-position: bottom right;
+ background-repeat: repeat-x;
+ border: 1px solid #cccc99;
+ z-index: 1;
+}
+div.sticky_names {
+ float: left;
+ font-weight: bold;
+ line-height: 1em;
+ margin-right: 1em;
+}
+div.sticky_values {
+ float: left;
+ line-height: 1em;
+}
+div#cell_legend {
+ margin: 1em;
+ font-size: 0.8em;
+ color: #000;
+}
+div#cell_legend button {
+ position: relative;
+ top: -2px;
+}
+
+[StatUtilizationGrid.html]
+<div class="StatUtilizationGrid" id="{id}">
+ <div class="visualization">
+ <h2>{title}</h2>
+ <div class="StatGrid" {override_style}>
+ {grid}
+ </div>
+ <div style="clear:left;"><!-- --></div>
+ </div>
+</div>
+<div id="cell_legend">
+ {legends}
+</div>
+{grid_updater}
+
+[StatUtilizationGrid.legend_html]
+<div class="legend">
+ <button class="btn {legend_color}" style="background-image: none;
width:1em; height:1em;"/> {legend_text}
+</div>
+
+[StatUtilizationGrid.cell_html]
+ <div class="grid_cell" style="width:{cell_width}%;
height:{cell_width}%;"
+ onmouseover="document.getElementById('note_{cell_id}').style.display='block';"
+ onmouseout="document.getElementById('note_{cell_id}').style.display='none';">
+ <a href="#"><button id="button_{cell_id}" class="btn
{color}" >{contents}</button></a>
+ <div id="note_{cell_id}" class="sticky_note">
+ <div class="sticky_names">
+ {sticky_names}
+ </div>
+ <div class="sticky_values">
+ {sticky_values}
+ </div>
+ <div style="clear:left;"><!-- --></div>
+ </div>
+ </div>
+
+[StatUtilizationGrid.sticky_name_html]
+ <div>{sticky_title}:</div>
+
+[StatUtilizationGrid.sticky_value_html]
+ <div id="cell_{sticky_name}_{sticky_object_id}"></div>
+
+
\ No newline at end of file