Author: eallen
Date: 2008-11-01 14:53:36 -0400 (Sat, 01 Nov 2008)
New Revision: 2726
Modified:
mgmt/trunk/cumin/python/cumin/model.py
mgmt/trunk/cumin/python/cumin/pool.py
mgmt/trunk/cumin/python/cumin/stat.py
mgmt/trunk/cumin/python/cumin/stat.strings
mgmt/trunk/cumin/python/cumin/system.py
Log:
Use Itemset for grid widget cells
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-11-01 18:52:43 UTC (rev 2725)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-11-01 18:53:36 UTC (rev 2726)
@@ -608,7 +608,7 @@
self.slot_set = self.ModelSystemSlotSet(cls.model.app, name)
def get_xml_response(self, session, system, *args):
- slots = self.get_slots(session, system)[0]
+ slots = self.get_slots(session, system)
writer = Writer()
writer.write("<slots>")
for slot in slots:
@@ -624,7 +624,7 @@
def get_slots(self, session, system):
cursor = self.slot_set.do_get_items(session, system)
slot_list = self.slot_set.cursor_to_rows(cursor)
- return (slot_list, )
+ return slot_list
class ModelSystemSlotSet(SystemSlotSet):
def render_sql_limit(self, session, *args):
@@ -1838,7 +1838,7 @@
def get_xml_response(self, session, pool, *args):
pool = self.model.get_main_pool()
- jobs = self.get_jobs(session, pool)[0]
+ jobs = self.get_jobs(session, pool)
writer = Writer()
writer.write("<jobs>")
for job in jobs:
@@ -1854,8 +1854,7 @@
def get_jobs(self, session, pool):
cursor = self.job_set.do_get_items(session, pool)
- job_list = self.job_set.cursor_to_rows(cursor)
- return (job_list, )
+ return self.job_set.cursor_to_rows(cursor)
class ModelSystemJobSet(JobSet):
def render_sql_limit(self, session, *args):
Modified: mgmt/trunk/cumin/python/cumin/pool.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/pool.py 2008-11-01 18:52:43 UTC (rev 2725)
+++ mgmt/trunk/cumin/python/cumin/pool.py 2008-11-01 18:53:36 UTC (rev 2726)
@@ -259,34 +259,26 @@
return "Statistics"
class JobUtilizationGrid(StatUtilizationGrid):
- def get_args(self, session):
+ def get_cells(self, session):
pool = self.frame.get_args(session)[0]
action = self.app.model.pool.jobs
return action.get_jobs(session, pool)
- def render_title(self, session, jobs):
+ def render_title(self, session):
return ""
- def render_override_style(self, session, jobs):
- count = self.get_object_count(session, jobs)
- if count > 100:
- return "style=\"width: 15em; height: 15em;\""
-
def get_colors(self, session):
action = self.app.model.pool.jobs
return action.get_colors()
- def render_color(self, session, count, job):
+ def get_color(self, session, job):
action = self.app.model.pool.jobs
return action.get_color(job)
- def render_contents(self, session, count, job):
+ def get_contents(self, session, job):
return ""
- def render_cell_id(self, session, count, job):
- return "%i" % job["id"]
-
- def render_href(self, session, count, job):
+ def get_href(self, session, job):
branch = session.branch()
ojob = Job.get(job["id"])
return self.page.main.pool.job.get_href(branch, ojob)
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2008-11-01 18:52:43 UTC (rev 2725)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2008-11-01 18:53:36 UTC (rev 2726)
@@ -144,73 +144,105 @@
def __init__(self, app, name):
super(StatUtilizationGrid, self).__init__(app, name)
- self.stats_tmpl = Template(self, "cell_html")
+ cells = self.GridCells(app, "grid")
+ self.add_child(cells)
- self.sticky = self.Sticky(app, "sticky_info")
- self.add_child(self.sticky)
-
legend = self.Legend(app, "grid_legend")
self.add_child(legend)
ajax = self.Updater(app, "grid_updater")
self.add_child(ajax)
- def get_args(self, session):
- """ must return a sequence """
- return list()
-
- def render_title(self, session, objects):
+ def render_title(self, session):
return "Utilization"
- def render_grid(self, session, objects):
- writer = Writer()
+ class GridCells(ItemSet):
+ def __init__(self, app, name):
+ super(StatUtilizationGrid.GridCells, self).__init__(app, name)
+
+ self.width = Attribute(app, "width")
+ self.add_attribute(self.width)
- count = self.get_object_count(session, objects)
- for object in objects:
- self.stats_tmpl.render(writer, session, count, object)
- return writer.to_string()
+ self.sticky = self.Sticky(app, "sticky_info")
+ self.add_child(self.sticky)
- def get_object_count(self, session, objects):
- return len(objects)
+ def do_get_items(self, session):
+ cells = self.parent.get_cells(session)
+ self.width.set(session,
+ self.calculate_cell_width(len(cells)))
+ return cells
+
+ def render_cell_id(self, session, cell):
+ return cell["id"]
+
+ def render_cell_width(self, session, cell):
+ return self.width.get(session)
+
+ def calculate_cell_width(self, count):
+ sq = sqrt(count)
+ isq = int(sq)
+ if sq > isq:
+ isq = isq + 1
+
+ if count > 0:
+ return int(100 / isq)
+ else:
+ return 100
+
+ def render_href(self, session, cell):
+ return self.parent.get_href(session, cell)
+
+ def render_color(self, session, cell):
+ return self.parent.get_color(session, cell)
+
+ def render_contents(self, session, cell):
+ return self.parent.get_contents(session, cell)
- def render_override_style(self, session, objects):
- pass
+ def get_sticky_info(self, session):
+ return self.parent.get_sticky_info(session)
+
+ def render_sticky_rows(self, session, cell):
+ return self.sticky.render_items(session, cell)
- def render_cell_width(self, session, count, object):
- sq = sqrt(count)
- isq = int(sq)
- if sq > isq:
- isq = isq + 1
+ class Sticky(ItemSet):
+ def do_get_items(self, session, cell):
+ info = self.parent.get_sticky_info(session)
+ return [(inf, cell["id"]) for inf in info]
- if count > 0:
- return int(100 / isq)
- else:
- return 100
-
- def render_href(self, session, count, object):
+ def render_sticky_name(self, session, item):
+ return item[0][0]
+
+ def render_sticky_title(self, session, item):
+ return item[0][1]
+
+ def render_sticky_object_id(self, session, item):
+ return item[1]
+
+ def get_cells(self, session):
+ """ should return a list of dictionaries """
+ return list()
+
+ def get_href(self, session, cell):
return "#"
- def render_color(self, session, count, object):
+ def get_color(self, session, cell):
return "clear"
- def render_contents(self, session, count, object):
+ def get_contents(self, session, cell):
return ""
- def render_cell_id(self, session, count, object):
- return 1
-
def get_colors(self, session):
return ["clear"]
- def render_sticky_rows(self, session, count, object):
- return self.sticky.render_items(session, object)
-
def get_url(self, session):
""" returns something like
"call.xml?class=system;id=%i;method=slots" % system.id
"""
pass
+ def get_sticky_info(self, session):
+ return [("Name", "Display Title")]
+
def get_fn(self, session):
return self.name
@@ -220,9 +252,6 @@
def elem_id(self, session):
return self.name
- def get_sticky_info(self, session):
- return [("Name", "Display Title")]
-
class Legend(ItemSet):
def do_get_items(self, session, *args):
return self.parent.get_colors(session)
@@ -233,21 +262,6 @@
def render_legend_color(self, session, color):
return color[1]
- class Sticky(ItemSet):
- def do_get_items(self, session, *args):
- info = self.parent.get_sticky_info(session)
- object = args[0]
- return [(inf, self.parent.render_cell_id(session, 1, object)) for inf in
info]
-
- def render_sticky_name(self, session, item):
- return item[0][0]
-
- def render_sticky_title(self, session, item):
- return item[0][1]
-
- def render_sticky_object_id(self, session, item):
- return item[1]
-
class Updater(AjaxField):
def do_render(self, session):
return self.render_script(session)
Modified: mgmt/trunk/cumin/python/cumin/stat.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.strings 2008-11-01 18:52:43 UTC (rev 2725)
+++ mgmt/trunk/cumin/python/cumin/stat.strings 2008-11-01 18:53:36 UTC (rev 2726)
@@ -323,7 +323,7 @@
<div class="StatUtilizationGrid" id="{id}">
<div class="visualization">
<h2>{title}</h2>
- <div id="StatGrid" class="StatGrid" {override_style}>
+ <div id="StatGrid" class="StatGrid">
{grid}
</div>
<div style="clear:left;"><!-- --></div>
@@ -334,7 +334,10 @@
</div>
{grid_updater}
-[StatUtilizationGrid.cell_html]
+[GridCells.html]
+{items}
+
+[GridCells.item_html]
<div id="{cell_id}" class="grid_cell"
style="width:{cell_width}%; height:{cell_width}%;"
onmouseover="over_cell(this)"
@@ -354,7 +357,6 @@
</tr>
[Legend.item_html]
-<div class="legend">
+<li>
<button class="btn {legend_color}" style="background-image: none;
width:1em; height:1em;" ></button> {legend_text}
-</div>
-
\ No newline at end of file
+</li>
Modified: mgmt/trunk/cumin/python/cumin/system.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/system.py 2008-11-01 18:52:43 UTC (rev 2725)
+++ mgmt/trunk/cumin/python/cumin/system.py 2008-11-01 18:53:36 UTC (rev 2726)
@@ -59,26 +59,26 @@
return "Statistics"
class SlotUtilizationGrid(StatUtilizationGrid):
- def get_args(self, session):
+ def get_cells(self, session):
system = self.frame.get_args(session)[0]
action = self.app.model.system.slots
return action.get_slots(session, system)
- def render_title(self, session, slots):
+ def render_title(self, session):
return "Slot Utilization"
def get_colors(self, session):
action = self.app.model.system.slots
return action.get_colors()
- def render_color(self, session, count, slot):
+ def get_color(self, session, slot):
action = self.app.model.system.slots
return action.get_color(slot)
- def render_contents(self, session, count, slot):
+ def get_contents(self, session, slot):
return ""
- def render_href(self, session, count, slot):
+ def get_href(self, session, slot):
branch = session.branch()
try:
job = Job.select("custom_id = '%s'" % slot.JobId)[0]
@@ -86,9 +86,6 @@
return "#"
return self.page.main.pool.job.get_href(branch, job)
- def render_cell_id(self, session, count, slot):
- return "%i" % slot["id"]
-
def get_url(self, session):
system = self.parent.frame.get_args(session)[0]
return "call.xml?class=system;id=%i;method=slots" % system.id