Add custom dashboards

Use the new generic change list feature to support custom dashboards
based on search queries.

Change-Id: Iea339de591da38bccab54c2e044ef7b94d6789cb
This commit is contained in:
James E. Blair 2014-07-12 19:28:37 -07:00
parent 37cfa0b9bb
commit 2fcb7bc219
7 changed files with 40 additions and 16 deletions

View File

@ -160,6 +160,12 @@ class App(object):
self.loop.widget = widget
self.refresh()
def clearHistory(self):
self.log.debug("Clearing screen history")
while self.screens:
widget = self.screens.pop()
self.loop.widget = widget
def refresh(self, data=None):
widget = self.loop.widget
while isinstance(widget, urwid.Overlay):
@ -180,8 +186,15 @@ class App(object):
def help(self):
if not hasattr(self.loop.widget, 'help'):
return
dialog = mywid.MessageDialog('Help', self.loop.widget.help)
lines = self.loop.widget.help.split('\n')
text = mywid.GLOBAL_HELP
for d in self.config.dashboards.values():
space = max(9 - len(d['key']), 0) * ' '
text += '<%s>%s %s\n' % (d['key'], space, d['name'])
text += "\nThis Screen\n"
text += "===========\n"
text += self.loop.widget.help
dialog = mywid.MessageDialog('Help', text)
lines = text.split('\n')
urwid.connect_signal(dialog, 'close',
lambda button: self.backScreen())
self.popup(dialog, min_width=76, min_height=len(lines)+4)
@ -283,6 +296,11 @@ class App(object):
self.quit()
elif key == 'ctrl o':
self.searchDialog()
elif key in self.config.dashboards:
d = self.config.dashboards[key]
self.clearHistory()
view = view_change_list.ChangeListView(self, d['query'], d['name'])
self.changeScreen(view)
def getRepo(self, project_name):
local_path = os.path.join(self.config.git_root, project_name)

View File

@ -1,4 +1,5 @@
# Copyright 2014 OpenStack Foundation
# Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@ -58,10 +59,17 @@ class ConfigSchema(object):
commentlinks = [commentlink]
dashboard = {v.Required('name'): str,
v.Required('query'): str,
v.Required('key'): str}
dashboards = [dashboard]
def getSchema(self, data):
schema = v.Schema({v.Required('servers'): self.servers,
'palettes': self.palettes,
'commentlinks': self.commentlinks,
'dashboards': self.dashboards,
})
return schema
@ -114,6 +122,10 @@ class Config(object):
text="{url}",
url="{url}"))])))
self.dashboards = {}
for d in self.config.get('dashboards', []):
self.dashboards[d['key']] = d
def getServer(self, name=None):
for server in self.config['servers']:
if name is None or name == server['name']:

View File

@ -456,6 +456,8 @@ class DatabaseSession(object):
elif key == 'status':
if data == 'open':
q = q.filter(change_table.c.status.notin_(['MERGED', 'ABANDONED']))
else:
q = q.filter(change_table.c.status==data)
if unreviewed:
q = q.filter(change_table.c.hidden==False, change_table.c.reviewed==False)
try:

View File

@ -293,9 +293,7 @@ class ChangeMessageBox(mywid.HyperText):
self.set_text(text+comment_text)
class ChangeView(urwid.WidgetWrap):
help = mywid.GLOBAL_HELP + """
This Screen
===========
help = """
<c> Checkout the most recent revision into the local repo.
<d> Show the diff of the mont recent revision.
<k> Toggle the hidden flag for the current change.

View File

@ -67,15 +67,13 @@ class ChangeListHeader(urwid.WidgetWrap):
self._w.contents.append((urwid.Text(' %s' % category[0]), self._w.options('given', 3)))
class ChangeListView(urwid.WidgetWrap):
help = mywid.GLOBAL_HELP + """
This Screen
===========
help = """
<k> Toggle the hidden flag for the currently selected change.
<l> Toggle whether only unreviewed or all changes are displayed.
<v> Toggle the reviewed flag for the currently selected change.
"""
def __init__(self, app, query, query_desc=None, unreviewed=True):
def __init__(self, app, query, query_desc=None, unreviewed=False):
super(ChangeListView, self).__init__(urwid.Pile([]))
self.app = app
self.query = query
@ -98,7 +96,7 @@ This Screen
if self.unreviewed:
self.title = u'Unreviewed changes in %s' % self.query_desc
else:
self.title = u'Open changes in %s' % self.query_desc
self.title = u'All changes in %s' % self.query_desc
self.app.status.update(title=self.title)
i = 0
for change in lst:

View File

@ -210,9 +210,7 @@ class DiffContextButton(urwid.WidgetWrap):
self.view.expandChunk(self.diff, self.chunk, from_end=-10)
class DiffView(urwid.WidgetWrap):
help = mywid.GLOBAL_HELP + """
This Screen
===========
help = """
<Enter> Add an inline comment
<p> Select old/new patchsets to diff
"""

View File

@ -66,9 +66,7 @@ class ProjectListHeader(urwid.WidgetWrap):
super(ProjectListHeader, self).__init__(urwid.Columns(cols))
class ProjectListView(urwid.WidgetWrap):
help = mywid.GLOBAL_HELP + """
This Screen
===========
help = """
<l> Toggle whether only subscribed projects or all projects are listed.
<s> Toggle the subscription flag for the currently selected project.
"""