22906da596df webui

Get a barely functional webui running.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 13 Oct 2009 19:46:03 -0400
parents 9539fb54320e
children 73284798e9e9
branches/tags webui
files review/extension_ui.py review/web_templates/index.html review/web_ui.py

Changes

--- a/review/extension_ui.py	Tue Oct 13 19:02:45 2009 -0400
+++ b/review/extension_ui.py	Tue Oct 13 19:46:03 2009 -0400
@@ -15,7 +15,7 @@
     ui.note(messages.WEB_START)
     
     import web_ui
-    web_ui.load_interface(repo)
+    web_ui.load_interface(ui, repo)
 
 def _init_command(ui, repo, **opts):
     ui.note(messages.INIT_START)
--- a/review/web_templates/index.html	Tue Oct 13 19:02:45 2009 -0400
+++ b/review/web_templates/index.html	Tue Oct 13 19:46:03 2009 -0400
@@ -1,13 +1,27 @@
-$def with (repo)
+$def with (rd, revs)
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
 <html>
     <head>
-        <title>Code Review</title>
+        <title>${ basename(rd.target.root) } / hg-review</title>
     </head>
     
     <body>
-        <p>Reviewing: $repo.root</p>
+        <h1>${ basename(rd.target.root) }</h1>
+        
+        <h2>Changesets</h2>
+        <table>
+            $for ctx in revs:
+                $ ctx_node = ctx.node()
+                $ ctx_comments = rd[ctx_node].comments
+                $ ctx_signoffs = rd[ctx_node].signoffs
+                <tr>
+                    <td>${ ctx.rev() }:${ node_short(ctx_node) }</td>
+                    <td>${ ctx.description() }</td>
+                    <td>${ len(ctx_comments) } comments,
+                        ${ len(ctx_signoffs) } signoffs</td>
+                </tr>
+        </table>
     </body>
 </html>
\ No newline at end of file
--- a/review/web_ui.py	Tue Oct 13 19:02:45 2009 -0400
+++ b/review/web_ui.py	Tue Oct 13 19:46:03 2009 -0400
@@ -1,6 +1,8 @@
 """The review extension's web UI."""
 
 import sys, os
+import api
+from mercurial import cmdutil
 
 package_path = os.path.split(os.path.realpath(__file__))[0]
 template_path = os.path.join(package_path, 'web_templates')
@@ -12,22 +14,29 @@
 import web
 
 
-_repo = None
+_rd = None
 urls = (
     '/', 'index'
 )
-render = web.template.render(template_path)
+
+
+from mercurial.node import short
+g = { 'node_short': short, 'basename': os.path.basename, }
+render = web.template.render(template_path, globals=g)
 
 class index:
     def GET(self):
-        return render.index(_repo)
+        rev_max = _rd.target['tip'].rev()
+        rev_min = rev_max - 5 if rev_max >= 5 else 0
+        revs = (_rd.target[r] for r in xrange(rev_max, rev_min, -1))
+        return render.index(_rd, revs)
     
 
 app = web.application(urls, globals())
 
-def load_interface(repo):
-    global _repo
-    _repo = repo
+def load_interface(ui, repo):
+    global _rd
+    _rd = api.ReviewDatastore(ui, repo)
     
     sys.argv = sys.argv[:1]    # Seriously, web.py?  This is such a hack.
     app.run()