# HG changeset patch # User Steve Losh # Date 1269705897 14400 # Node ID 6df093d9f2384d17881461b9bfba5d3cb50bf759 # Parent 52b91476473291c8e9610bbdb2f1dea802820bb8 Add a read-only mode to the web interface. diff -r 52b914764732 -r 6df093d9f238 review/extension_ui.py --- 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') } diff -r 52b914764732 -r 6df093d9f238 review/web_media/comments.js --- 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; diff -r 52b914764732 -r 6df093d9f238 review/web_templates/base.html --- 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 @@
-
- -

Push comments to:

- {% for name, path in datastore.repo.ui.configitems("paths") %} -
- - -
- {% endfor %} -
- -

Pull comments from:

- {% for name, path in datastore.repo.ui.configitems("paths") %} -
- - -
- {% endfor %} -
-
+ {% if not read_only %} +
+ +

Push comments to:

+ {% for name, path in datastore.repo.ui.configitems("paths") %} +
+ + +
+ {% endfor %} +
+ +

Pull comments from:

+ {% for name, path in datastore.repo.ui.configitems("paths") %} +
+ + +
+ {% endfor %} +
+
+ {% endif %}
{% block content %}{% endblock %}
diff -r 52b914764732 -r 6df093d9f238 review/web_templates/changeset.html --- 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 @@
{% endfor %} - -
-

Add a comment on this changeset

-
-
- - -
-
- -
-
-
- + + {% if not read_only %} +
+

Add a comment on this changeset

+
+
+ + +
+
+ +
+
+
+ {% endif %}

Signoffs

@@ -48,9 +49,11 @@ {% endfor %} -
-

Sign off on this changeset (currently unimplemented)

-
+ {% if not read_only %} +
+

Sign off on this changeset (currently unimplemented)

+
+ {% endif %}

Files

@@ -76,21 +79,22 @@ {% endfor %} -
-

Add a comment on this file

- -
-
- - -
-
- -
- -
-
- + {% if not read_only %} +
+

Add a comment on this file

+ +
+
+ + +
+
+ +
+ +
+
+ {% endif %}
@@ -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'] %} @@ -120,7 +124,7 @@ {% endfor %} {% else %} - + {% for comment in line['comments'] %}
{{ line['number'] }}: {{ line['content'][1:]|escape }}
diff -r 52b914764732 -r 6df093d9f238 review/web_ui.py --- 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)