6df093d9f238

Add a read-only mode to the web interface.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 27 Mar 2010 12:04:57 -0400
parents 52b914764732
children ac324e064f82
branches/tags (none)
files review/extension_ui.py review/web_media/comments.js review/web_templates/base.html review/web_templates/changeset.html review/web_ui.py

Changes

--- a/review/extension_ui.py	Sat Mar 27 11:44:59 2010 -0400
+++ b/review/extension_ui.py	Sat Mar 27 12:04:57 2010 -0400
@@ -15,9 +15,10 @@
 
 def _web_command(ui, repo, **opts):
     ui.note(messages.WEB_START)
+    read_only = opts.pop('read_only')
     
     import web_ui
-    web_ui.load_interface(ui, repo, open=False)
+    web_ui.load_interface(ui, repo, read_only=read_only, open=False)
 
 def _init_command(ui, repo, **opts):
     ui.note(messages.INIT_START)
@@ -303,6 +304,7 @@
         ('l', 'lines',       '',    'the line(s) of the file to comment on'),
         ('U', 'unified',     '5',   'number of lines of context to show'),
         ('w', 'web',         False, 'launch the web interface'),
+        ('',  'read-only',   False, 'make the web interface read-only'),
     ],
     'hg review')
 }
--- a/review/web_media/comments.js	Sat Mar 27 11:44:59 2010 -0400
+++ b/review/web_media/comments.js	Sat Mar 27 12:04:57 2010 -0400
@@ -9,7 +9,7 @@
         return false;
     });
     
-    $("tr.rem,tr.add,tr.con").click(function(event) {
+    $("tr.rem.commentable,tr.add.commentable,tr.con.commentable").click(function(event) {
         $(event.target).closest("tr").addClass("comment-line-selected");
         $(event.target).closest("tr").nextAll("tr.comment-line").first().fadeIn("fast");
         return false;
--- a/review/web_templates/base.html	Sat Mar 27 11:44:59 2010 -0400
+++ b/review/web_templates/base.html	Sat Mar 27 12:04:57 2010 -0400
@@ -25,26 +25,28 @@
             </h1>
         </div>
         <div id="content-wrap">
-            <div id="remote-wrap">
-                <span id="remote-push" class="remote-section">
-                    <h3>Push comments to:</h3>
-                    {% for name, path in datastore.repo.ui.configitems("paths") %}
-                        <form action="/push/" method="post">
-                            <input type="hidden" name="path" value="{{ name }}" />
-                            <input type="submit" value="{{ name }}" />
-                        </form>
-                    {% endfor %}
-                </span>
-                <span id="remote-pull" class="remote-section">
-                    <h3>Pull comments from:</h3>
-                    {% for name, path in datastore.repo.ui.configitems("paths") %}
-                        <form action="/pull/" method="post">
-                            <input type="hidden" name="path" value="{{ name }}" />
-                            <input type="submit" value="{{ name }}" />
-                        </form>
-                    {% endfor %}
-                </span>
-            </div>
+            {% if not read_only %}
+                <div id="remote-wrap">
+                    <span id="remote-push" class="remote-section">
+                        <h3>Push comments to:</h3>
+                        {% for name, path in datastore.repo.ui.configitems("paths") %}
+                            <form action="/push/" method="post">
+                                <input type="hidden" name="path" value="{{ name }}" />
+                                <input type="submit" value="{{ name }}" />
+                            </form>
+                        {% endfor %}
+                    </span>
+                    <span id="remote-pull" class="remote-section">
+                        <h3>Pull comments from:</h3>
+                        {% for name, path in datastore.repo.ui.configitems("paths") %}
+                            <form action="/pull/" method="post">
+                                <input type="hidden" name="path" value="{{ name }}" />
+                                <input type="submit" value="{{ name }}" />
+                            </form>
+                        {% endfor %}
+                    </span>
+                </div>
+            {% endif %}
             <div id="main-wrap">
                 {% block content %}{% endblock %}
             </div>
--- a/review/web_templates/changeset.html	Sat Mar 27 11:44:59 2010 -0400
+++ b/review/web_templates/changeset.html	Sat Mar 27 12:04:57 2010 -0400
@@ -18,20 +18,21 @@
             </div>
         </div>
     {% endfor %}
-
-    <div id="comment-review">
-        <p class="comment-activate"><a href="">Add a comment on this changeset</a></p>
-        <form id="comment-review-form" method="post" action="">
-            <div class="field">
-                <label for="body">Add a comment on this changeset:</label>
-                <textarea cols="60" rows="6" name="new-comment-body"></textarea>
-            </div>
-            <div class="buttons">
-                <input type="submit" class="button" value="Submit" />
-            </div>
-        </form>
-    </div>
-
+    
+    {% if not read_only %}
+        <div id="comment-review">
+            <p class="comment-activate"><a href="">Add a comment on this changeset</a></p>
+            <form id="comment-review-form" method="post" action="">
+                <div class="field">
+                    <label for="body">Add a comment on this changeset:</label>
+                    <textarea cols="60" rows="6" name="new-comment-body"></textarea>
+                </div>
+                <div class="buttons">
+                    <input type="submit" class="button" value="Submit" />
+                </div>
+            </form>
+        </div>
+    {% endif %}
     
     <h2>Signoffs</h2>
     
@@ -48,9 +49,11 @@
         </div>
     {% endfor %}
     
-    <div id="signoff-review">
-        <p class="signoff-activate"><a href="#">Sign off on this changeset (currently unimplemented)</a></p>
-    </div>
+    {% if not read_only %}
+        <div id="signoff-review">
+            <p class="signoff-activate"><a href="#">Sign off on this changeset (currently unimplemented)</a></p>
+        </div>
+    {% endif %}
 
     <h2>Files</h2>
     
@@ -76,21 +79,22 @@
                     </div>
                 {% endfor %}
                 
-                <div id="comment-file">
-                    <p class="comment-activate"><a href="">Add a comment on this file</a></p>
-                    
-                    <form id="comment-file-form" method="post" action="">
-                        <div class="field">
-                            <label for="body">Add a comment on this file:</label>
-                            <textarea cols="60" rows="6" name="new-comment-body"></textarea>
-                        </div>
-                        <div class="buttons">
-                            <input type="submit" class="button" value="Submit" />
-                        </div>
-                        <input type="hidden" name="filename" value="{{ filename }}" />
-                    </form>
-                </div>
-                
+                {% if not read_only %}
+                    <div id="comment-file">
+                        <p class="comment-activate"><a href="">Add a comment on this file</a></p>
+                        
+                        <form id="comment-file-form" method="post" action="">
+                            <div class="field">
+                                <label for="body">Add a comment on this file:</label>
+                                <textarea cols="60" rows="6" name="new-comment-body"></textarea>
+                            </div>
+                            <div class="buttons">
+                                <input type="submit" class="button" value="Submit" />
+                            </div>
+                            <input type="hidden" name="filename" value="{{ filename }}" />
+                        </form>
+                    </div>
+                {% endif %}
                 
                 <div class="diff">
                     <table>
@@ -99,7 +103,7 @@
                             {# We need to ignore the first item from this generator, because
                                we don't care about providing a line-number prefix (for now!). #}
                             {% set ignore_this_variable = annotated_diff.next() %}
-                        
+                            
                             {% for line in annotated_diff %}
                                 {% if line['skipped'] %}
                                     <tr class="skipped">
@@ -120,7 +124,7 @@
                                         </td></tr>
                                     {% endfor %}
                                 {% else %}
-                                    <tr class="{{ utils['line_type'](line['content']) }}">
+                                    <tr class="{{ utils['line_type'](line['content']) }}{% if not read_only %} commentable {% endif %}">
                                         <td class="diff-line"><code>{{ line['number'] }}: {{ line['content'][1:]|escape }}</code></td>
                                         {% for comment in line['comments'] %}
                                             <tr><td class="comment">
--- a/review/web_ui.py	Sat Mar 27 11:44:59 2010 -0400
+++ b/review/web_ui.py	Sat Mar 27 12:04:57 2010 -0400
@@ -48,8 +48,9 @@
 }
 
 class ReviewWebUI(object):
-    def __init__(self, datastore):
+    def __init__(self, datastore, read_only):
         self.datastore = datastore
+        self.read_only = read_only
     
     
     @cherrypy.expose
@@ -59,6 +60,7 @@
         rcsets = [self.datastore[r] for r in xrange(rev_max, rev_min, -1)]
         
         return jinja_env.get_template('index.html').render(
+            read_only=self.read_only,
             utils=utils, datastore=self.datastore, title='',
             rcsets=rcsets,
         )
@@ -70,7 +72,7 @@
             return 'OH GOD HOW DID THIS GET HERE I AM NOT GOOD WITH LINKS'
         rev_id = args[0]
         
-        if kwargs:
+        if kwargs and not self.read_only:
             filename = kwargs.get('filename', '')
             lines = str(kwargs['lines']) if 'lines' in kwargs else ''
             if lines:
@@ -88,38 +90,45 @@
         rev = rcset.target[rev_id]
         
         return jinja_env.get_template('changeset.html').render(
+            read_only=self.read_only,
             utils=utils, datastore=self.datastore,
             title='%s:%s' % (rev.rev(), short(rev.node())),
             rcset=rcset, rev=rev,
         )
     
+    
     @cherrypy.expose
     def pull(self, **kwargs):
-        if 'path' not in kwargs:
-            return 'OH GOD HOW DID THIS GET HERE I AM NOT GOOD WITH LINKS'
-        path = kwargs['path']
-        
-        commands.pull(
-            self.datastore.repo.ui, self.datastore.repo, path, **{
-                'update': True
-            }
-        )
+        if not self.read_only:
+            if 'path' not in kwargs:
+                return 'OH GOD HOW DID THIS GET HERE I AM NOT GOOD WITH LINKS'
+            path = kwargs['path']
+            
+            commands.pull(
+                self.datastore.repo.ui, self.datastore.repo, path, **{
+                    'update': True
+                }
+            )
         
         raise cherrypy.HTTPRedirect("/")
     
+    
     @cherrypy.expose
     def push(self, **kwargs):
-        if 'path' not in kwargs:
-            return 'OH GOD HOW DID THIS GET HERE I AM NOT GOOD WITH LINKS'
-        path = kwargs['path']
-        
-        commands.push(self.datastore.repo.ui, self.datastore.repo, path, **{})
+        if not self.read_only:
+            if 'path' not in kwargs:
+                return 'OH GOD HOW DID THIS GET HERE I AM NOT GOOD WITH LINKS'
+            path = kwargs['path']
+            
+            commands.push(
+                self.datastore.repo.ui,self.datastore.repo, path, **{}
+            )
         
         raise cherrypy.HTTPRedirect("/")
     
 
 
-def load_interface(ui, repo, open=False, port=8080):
+def load_interface(ui, repo, read_only=False, open=False, port=8080):
     if open:
         import webbrowser
         webbrowser.open('http://localhost:%d/' % port)
@@ -131,5 +140,5 @@
         }
     }
     
-    cherrypy.quickstart(ReviewWebUI(api.ReviewDatastore(ui, repo)), config=conf)
+    cherrypy.quickstart(ReviewWebUI(api.ReviewDatastore(ui, repo), read_only=read_only), config=conf)