Author: tmckay
Date: 2011-05-24 18:01:45 +0000 (Tue, 24 May 2011)
New Revision: 4782
Modified:
trunk/cumin/python/cumin/grid/slotvis.py
trunk/cumin/python/cumin/main.py
trunk/cumin/python/cumin/objectselector.py
trunk/cumin/python/cumin/widgets.py
trunk/wooly/python/wooly/table.py
Log:
Set default sort order of columns based on data type.
Descending for numeric types, ascending for others.
BZ703860
Modified: trunk/cumin/python/cumin/grid/slotvis.py
===================================================================
--- trunk/cumin/python/cumin/grid/slotvis.py 2011-05-24 17:22:27 UTC (rev 4781)
+++ trunk/cumin/python/cumin/grid/slotvis.py 2011-05-24 18:01:45 UTC (rev 4782)
@@ -47,9 +47,7 @@
col = ObjectTableColumn(app, cls.LoadAvg.name, cls.LoadAvg)
self.add_column(col)
- # sort by load average descending
- self.table.sort.default = col.name
- self.table.ascending.default = False
+ self.table.set_default_sort_column(col)
self.enable_csv_export(pool)
Modified: trunk/cumin/python/cumin/main.py
===================================================================
--- trunk/cumin/python/cumin/main.py 2011-05-24 17:22:27 UTC (rev 4781)
+++ trunk/cumin/python/cumin/main.py 2011-05-24 18:01:45 UTC (rev 4782)
@@ -465,9 +465,8 @@
self.add_column(col)
col = self.add_attribute_column(cls.msgDepth)
+ self.set_default_sort_column(col)
- self.sort.default = col.name
-
def init(self):
super(TopQueueTable, self).init()
@@ -515,9 +514,8 @@
self.add_column(col)
col = self.add_attribute_column(cls.loadAverage1Min)
+ self.set_default_sort_column(col)
- self.sort.default = col.name
-
def init(self):
super(TopSystemTable, self).init()
@@ -538,9 +536,8 @@
col = self.DurationColumn(app, cls._qmf_create_time.name,
cls._qmf_create_time)
self.add_column(col)
+ self.set_default_sort_column(col)
- self.sort.default = col.name
-
def init(self):
super(TopSubmissionTable, self).init()
Modified: trunk/cumin/python/cumin/objectselector.py
===================================================================
--- trunk/cumin/python/cumin/objectselector.py 2011-05-24 17:22:27 UTC (rev 4781)
+++ trunk/cumin/python/cumin/objectselector.py 2011-05-24 18:01:45 UTC (rev 4782)
@@ -31,7 +31,6 @@
self.cls = cls
self.update_enabled = True
- self.ascending.default = True
# (RosemaryAttribute this, RosemaryAttribute that, Attribute object)
self.filter_specs = list()
@@ -41,6 +40,12 @@
self.export = None
+ # If ascending.default is None, ascending.default will be
+ # chosen by column data type in init() later on.
+ # To force a default value for ascending, set it explicitly
+ # in a derived class during __init__
+ self.ascending.default = None
+
def init(self):
if not self.adapter:
self.adapter = ObjectSqlAdapter(self.app, self.cls)
@@ -56,9 +61,13 @@
if self.sort.default is None:
for col in self.columns:
if col.sortable:
- self.sort.default = col.name
+ self.set_default_sort_column(col)
break
+ # Now that all columns have been initialized, and we
+ # have a sortable column if possible, set direction
+ self.set_default_sort_direction()
+
def add_attribute_column(self, attr):
assert isinstance(attr, RosemaryAttribute), attr
@@ -696,4 +705,4 @@
pass
class ObjectQmSelectorfTable(QmfValues, ObjectSelectorTable):
- pass
\ No newline at end of file
+ pass
Modified: trunk/cumin/python/cumin/widgets.py
===================================================================
--- trunk/cumin/python/cumin/widgets.py 2011-05-24 17:22:27 UTC (rev 4781)
+++ trunk/cumin/python/cumin/widgets.py 2011-05-24 18:01:45 UTC (rev 4782)
@@ -1586,7 +1586,6 @@
self.replace_child(self.footer)
self.header.limit.default = 5
- self.ascending.default = False
def get_count(self, session):
# avoid extra sql call since we don't show the record count
Modified: trunk/wooly/python/wooly/table.py
===================================================================
--- trunk/wooly/python/wooly/table.py 2011-05-24 17:22:27 UTC (rev 4781)
+++ trunk/wooly/python/wooly/table.py 2011-05-24 18:01:45 UTC (rev 4782)
@@ -23,9 +23,36 @@
self.sort = SymbolParameter(app, "sort")
self.add_parameter(self.sort)
+ # Default for a BooleanParameter is False.
+ # ascending.default can be set to None in a
+ # derived class if set_default_sort_direction will be used.
self.ascending = BooleanParameter(app, "ascending")
self.add_parameter(self.ascending)
+ self._sort_col = None
+ def get_ascending_by_type(self, the_type):
+ # Override this method to do something special
+ # for a particular table
+ return the_type not in (int, float, long, complex)
+
+ def set_default_sort_column(self, column):
+ # Save a reference to the column so that we
+ # can determine type once it's initialized
+ self.sort.default = column.name
+ self._sort_col = column
+
+ def set_default_sort_direction(self):
+ # If the ascending default value has not been
+ # explicitly set, choose ascending based on type
+ if self.ascending.default == None:
+ if self._sort_col:
+ self.ascending.default = \
+ self.get_ascending_by_type(self._sort_col.field.type)
+ else:
+ # If it's still None, and _sort_col was not set,
+ # we have to choose something
+ self.ascending.default = False
+
def add_column(self, column):
self.add_child(column)
@@ -118,28 +145,31 @@
def render_text_align(self, session):
return "left"
-
+
def render_header_href(self, session):
+ # For the current sort column, just invert the sort order.
+ # For other columns, set initial sort order based type
sort = self.table.sort.get(session)
- ascending = self.table.ascending.get(session)
+ if sort == self.name:
+ ascending = not self.table.ascending.get(session)
+ else:
+ ascending = self.table.get_ascending_by_type(self.field.type)
branch = session.branch()
-
self.table.sort.set(branch, self.name)
-
- if sort == self.name:
- self.table.ascending.set(branch, not ascending)
-
+ self.table.ascending.set(branch, ascending)
return branch.marshal()
def render_header_title(self, session):
+ # For the current sort column, just invert the sort order.
+ # For other columns, set initial sort order based type
sort = self.table.sort.get(session)
- ascending = self.table.ascending.get(session)
-
- dir = ascending and "ascending" or "descending"
if sort == self.name:
+ ascending = self.table.ascending.get(session)
dir = ascending and "descending" or "ascending"
-
+ else:
+ ascending = self.table.get_ascending_by_type(self.field.type)
+ dir = ascending and "ascending" or "descending"
name = self.render_header_content(session)
if not name:
name = self.name
@@ -205,7 +235,6 @@
container = self.table
sel = container.sort.get(session)
asc = container.ascending.get(session)
-
if sel == self.parent.name:
if asc:
return "up"