Browse Source

Add support for customized dashboard sorting

And suggest 'reversed last seen' as a sort order for the Recently
Seen dashboard.

Change-Id: I99a72b58f4135649167f1230f3847809ad807786
changes/75/277475/2
James E. Blair 6 years ago
parent
commit
7c0220d4e3
  1. 2
      examples/googlesource-gertty.yaml
  2. 2
      examples/openstack-gertty.yaml
  3. 9
      examples/reference-gertty.yaml
  4. 4
      gertty/app.py
  5. 7
      gertty/config.py
  6. 4
      gertty/db.py
  7. 9
      gertty/view/change_list.py

2
examples/googlesource-gertty.yaml

@ -58,6 +58,8 @@ dashboards:
key: "f4"
- name: "Recently seen changes"
query: "recentlyseen:24 hours"
sort-by: "last-seen"
reverse: True
key: "f5"
# Reviewkeys are hotkeys that perform immediate reviews within the

2
examples/openstack-gertty.yaml

@ -101,6 +101,8 @@ dashboards:
key: "f4"
- name: "Recently seen changes"
query: "recentlyseen:24 hours"
sort-by: "last-seen"
reverse: True
key: "f5"
# Reviewkeys are hotkeys that perform immediate reviews within the

9
examples/reference-gertty.yaml

@ -147,9 +147,10 @@ commentlinks:
# selected. The default is "status:open".
# change-list-query: "status:open"
# This section defines default sorting options for the change list. The
# "sort-by" key specifies the sort order, which can be 'number' or 'updated'.
# The 'reverse' key specifies ascending (true) or descending (false) order.
# This section defines default sorting options for the change
# list. The "sort-by" key specifies the sort order, which can be
# 'number', 'updated', or 'last-seen'. The 'reverse' key specifies
# ascending (true) or descending (false) order.
# change-list-options:
# sort-by: 'number'
# reverse: false
@ -207,6 +208,8 @@ dashboards:
key: "f4"
- name: "Recently seen changes"
query: "recentlyseen:24 hours"
sort-by: "last-seen"
reverse: True
key: "f5"
# Reviewkeys are hotkeys that perform immediate reviews within the

4
gertty/app.py

@ -612,7 +612,9 @@ class App(object):
self.doSearch("is:held")
elif key in self.config.dashboards:
d = self.config.dashboards[key]
view = view_change_list.ChangeListView(self, d['query'], d['name'])
view = view_change_list.ChangeListView(self, d['query'], d['name'],
sort_by=d.get('sort-by'),
reverse=d.get('reverse'))
self.changeScreen(view)
elif keymap.FURTHER_INPUT in commands:
self.input_buffer.append(key)

7
gertty/config.py

@ -53,6 +53,8 @@ class ConfigSchema(object):
servers = [server]
sort_by = v.Any('number', 'updated', 'last-seen')
text_replacement = {'text': v.Any(str,
{'color': str,
v.Required('text'): str})}
@ -78,6 +80,8 @@ class ConfigSchema(object):
dashboard = {v.Required('name'): str,
v.Required('query'): str,
v.Optional('sort-by'): sort_by,
v.Optional('reverse'): bool,
v.Required('key'): str}
dashboards = [dashboard]
@ -95,7 +99,7 @@ class ConfigSchema(object):
hide_comments = [hide_comment]
change_list_options = {'sort-by': v.Any('number', 'updated'),
change_list_options = {'sort-by': sort_by,
'reverse': bool}
keymap = {v.Required('name'): str,
@ -216,6 +220,7 @@ class Config(object):
self.dashboards = OrderedDict()
for d in self.config.get('dashboards', []):
self.dashboards[d['key']] = d
self.dashboards[d['key']]
self.reviewkeys = OrderedDict()
for k in self.config.get('reviewkeys', []):

4
gertty/db.py

@ -854,12 +854,14 @@ class DatabaseSession(object):
return None
def getChanges(self, query, unreviewed=False, sort_by='number'):
self.database.log.debug("Search query: %s" % query)
self.database.log.debug("Search query: %s sort: %s" % (query, sort_by))
q = self.session().query(Change).filter(self.search.parse(query))
if unreviewed:
q = q.filter(change_table.c.hidden==False, change_table.c.reviewed==False)
if sort_by == 'updated':
q = q.order_by(change_table.c.updated)
elif sort_by == 'last-seen':
q = q.order_by(change_table.c.last_seen)
else:
q = q.order_by(change_table.c.number)
self.database.log.debug("Search SQL: %s" % q)

9
gertty/view/change_list.py

@ -199,7 +199,7 @@ class ChangeListView(urwid.WidgetWrap):
]
def __init__(self, app, query, query_desc=None, project_key=None,
unreviewed=False):
unreviewed=False, sort_by=None, reverse=None):
super(ChangeListView, self).__init__(urwid.Pile([]))
self.log = logging.getLogger('gertty.view.change_list')
self.app = app
@ -212,8 +212,11 @@ class ChangeListView(urwid.WidgetWrap):
self.project_key = project_key
if project_key is not None:
self.display_project = False
self.sort_by = app.config.change_list_options['sort-by']
self.reverse = app.config.change_list_options['reverse']
self.sort_by = sort_by or app.config.change_list_options['sort-by']
if reverse is not None:
self.reverse = reverse
else:
self.reverse = app.config.change_list_options['reverse']
self.header = ChangeListHeader(self.display_project, self.display_owner,
self.display_updated)
self.categories = []

Loading…
Cancel
Save