# HG changeset patch # User Marcin Kuzminski # Date 2011-12-18 02:24:53 # Node ID d4a7b6c82efe082bb8a5f9423e04b1f6496b2abd # Parent 02a26ed03537df8397ad0e4557536efcdd30ae10 code garden for changeset ranges and comments - disabled (for now) comments on changeset ranges - code reuse by mako namespaces - added flag for enabling comments in diffs diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -50,13 +50,14 @@ from rhodecode.model.meta import Session log = logging.getLogger(__name__) -def anchor_url(revision,path): +def anchor_url(revision, path): fid = h.FID(revision, path) - return h.url.current(anchor=fid,**request.GET) + return h.url.current(anchor=fid, **request.GET) + def get_ignore_ws(fid, GET): ig_ws_global = request.GET.get('ignorews') - ig_ws = filter(lambda k:k.startswith('WS'),GET.getall(fid)) + ig_ws = filter(lambda k: k.startswith('WS'), GET.getall(fid)) if ig_ws: try: return int(ig_ws[0].split(':')[-1]) @@ -64,6 +65,7 @@ def get_ignore_ws(fid, GET): pass return ig_ws_global + def _ignorews_url(fileid=None): params = defaultdict(list) @@ -88,14 +90,15 @@ def _ignorews_url(fileid=None): # if we have passed in ln_ctx pass it along to our params if ln_ctx: params[ctx_key] += [ctx_val] - + params['anchor'] = fileid return h.link_to(lbl, h.url.current(**params)) + def get_line_ctx(fid, GET): ln_ctx_global = request.GET.get('context') - ln_ctx = filter(lambda k:k.startswith('C'),GET.getall(fid)) - + ln_ctx = filter(lambda k: k.startswith('C'), GET.getall(fid)) + if ln_ctx: retval = ln_ctx[0].split(':')[-1] else: @@ -106,10 +109,11 @@ def get_line_ctx(fid, GET): except: return + def _context_url(fileid=None): """ Generates url for context lines - + :param fileid: """ ig_ws = get_ignore_ws(fileid, request.GET) @@ -131,7 +135,7 @@ def _context_url(fileid=None): params[fileid] += ['C:%s' % ln_ctx] ig_ws_key = fileid ig_ws_val = 'WS:%s' % 1 - + if ig_ws: params[ig_ws_key] += [ig_ws_val] @@ -140,14 +144,16 @@ def _context_url(fileid=None): params['anchor'] = fileid return h.link_to(lbl, h.url.current(**params)) + def wrap_to_table(str_): return ''' - + - +
%s
%s
''' % str_ + class ChangesetController(BaseRepoController): @LoginRequired() @@ -165,9 +171,10 @@ class ChangesetController(BaseRepoContro #get ranges of revisions if preset rev_range = revision.split('...')[:2] - + enable_comments = True try: if len(rev_range) == 2: + enable_comments = False rev_start = rev_range[0] rev_end = rev_range[1] rev_ranges = c.rhodecode_repo.get_changesets(start=rev_start, @@ -233,7 +240,7 @@ class ChangesetController(BaseRepoContro d = diffs.DiffProcessor(f_gitdiff, format='gitdiff') st = d.stat() - diff = d.as_html() + diff = d.as_html(enable_comments=enable_comments) else: diff = wrap_to_table(_('Changeset is to big and ' @@ -281,7 +288,7 @@ class ChangesetController(BaseRepoContro 'and was cut off, see ' 'raw diff instead')) else: - diff = d.as_html() + diff = d.as_html(enable_comments=enable_comments) if diff: c.sum_removed += len(diff) @@ -397,11 +404,10 @@ class ChangesetController(BaseRepoContro @jsonify def delete_comment(self, repo_name, comment_id): co = ChangesetComment.get(comment_id) - owner = lambda : co.author.user_id == c.rhodecode_user.user_id + owner = lambda: co.author.user_id == c.rhodecode_user.user_id if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner: ChangesetCommentsModel().delete(comment=co) Session.commit() return True else: raise HTTPForbidden() - diff --git a/rhodecode/lib/diffs.py b/rhodecode/lib/diffs.py --- a/rhodecode/lib/diffs.py +++ b/rhodecode/lib/diffs.py @@ -114,15 +114,17 @@ class DiffProcessor(object): try: if line1.startswith('--- ') and line2.startswith('+++ '): l1 = line1[4:].split(None, 1) - old_filename = l1[0].lstrip('a/') if len(l1) >= 1 else None + old_filename = (l1[0].replace('a/', '', 1) + if len(l1) >= 1 else None) old_rev = l1[1] if len(l1) == 2 else 'old' l2 = line2[4:].split(None, 1) - new_filename = l2[0].lstrip('b/') if len(l1) >= 1 else None + new_filename = (l2[0].replace('b/', '', 1) + if len(l1) >= 1 else None) new_rev = l2[1] if len(l2) == 2 else 'new' - filename = old_filename if (old_filename != - 'dev/null') else new_filename + filename = (old_filename + if old_filename != '/dev/null' else new_filename) return filename, new_rev, old_rev except (ValueError, IndexError): @@ -359,7 +361,7 @@ class DiffProcessor(object): def as_html(self, table_class='code-difftable', line_class='line', new_lineno_class='lineno old', old_lineno_class='lineno new', - code_class='code'): + code_class='code', enable_comments=False): """ Return udiff as html table with customized css classes """ @@ -429,8 +431,10 @@ class DiffProcessor(object): ########################################################### # CODE ########################################################### - _html.append('''\t''' \ - % {'code_class': code_class}) + comments = '' if enable_comments else 'no-comment' + _html.append('''\t''' \ + % {'code_class': code_class, + 'in-comments': comments}) _html.append('''\n\t\t
%(code)s
\n''' \ % {'code': change['line']}) _html.append('''\t''') diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css +++ b/rhodecode/public/css/style.css @@ -3898,17 +3898,19 @@ form.comment-inline-form { text-decoration: none !important; } .notification-header{ - + padding-top:6px; } .notification-header .desc{ font-size: 16px; height: 24px; - padding-top: 6px; float: left } .notification-list .container.unread{ } +.notification-header .gravatar{ + +} .notification-header .desc.unread{ font-weight: bold; font-size: 17px; @@ -4069,4 +4071,10 @@ table.code-difftable .code pre{ background-repeat:no-repeat !important; background-position: right !important; background-position: 0% 50% !important; +} +.diffblock.margined.comm .line .code.no-comment:hover{ + background-image: none !important; + cursor: auto !important; + background-color: inherit !important; + } \ No newline at end of file diff --git a/rhodecode/public/js/rhodecode.js b/rhodecode/public/js/rhodecode.js --- a/rhodecode/public/js/rhodecode.js +++ b/rhodecode/public/js/rhodecode.js @@ -343,7 +343,7 @@ var createInlineForm = function(parent_t return form }; var injectInlineForm = function(tr){ - if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context')){ + if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context') || YUD.hasClass(tr,'no-comment')){ return } YUD.addClass(tr,'form-open'); diff --git a/rhodecode/templates/changeset/changeset.html b/rhodecode/templates/changeset/changeset.html --- a/rhodecode/templates/changeset/changeset.html +++ b/rhodecode/templates/changeset/changeset.html @@ -114,89 +114,17 @@ - - %for change,filenode,diff,cs1,cs2,stat in c.changes: - %if change !='removed': -
-
-
-
-
- ${h.link_to_if(change!='removed',h.safe_unicode(filenode.path),h.url('files_home',repo_name=c.repo_name, - revision=filenode.changeset.raw_id,f_path=h.safe_unicode(filenode.path)))} -
-
- diff-menu - -
- - - -
-
-
-
- %if diff: - ${diff|n} - %else: - ${_('No changes in this file')} - %endif -
-
- %endif - %endfor - + + ## diff block + <%namespace name="diff_block" file="/changeset/diff_block.html"/> + ${diff_block.diff_block(c.changes)} + + ## template for inline comment form <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> - ## template for inline comment form - ${comment.comment_inline_form()} + ${comment.comment_inline_form(c.changeset)} -
-
${len(c.comments)} comment(s) (${c.inline_cnt} ${_('inline')})
- - %for path, lines in c.inline_comments: - - %endfor - - %for co in c.comments: - ${comment.comment_block(co)} - %endfor - %if c.rhodecode_user.username != 'default': -
- ${h.form(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id))} - ${_('Leave a comment')} -
-
- ${_('Comments parsed using')} RST ${_('syntax')} - ${_('with')} @mention ${_('support')} -
- ${h.textarea('text')} -
-
- ${h.submit('save', _('Comment'), class_='ui-button')} -
- ${h.end_form()} -
- %endif -
+ ${comment.comments(c.changeset)} + - + + + diff --git a/rhodecode/templates/changeset/changeset_file_comment.html b/rhodecode/templates/changeset/changeset_file_comment.html --- a/rhodecode/templates/changeset/changeset_file_comment.html +++ b/rhodecode/templates/changeset/changeset_file_comment.html @@ -1,4 +1,5 @@ -##usage: +## -*- coding: utf-8 -*- +## usage: ## <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> ## ${comment.comment_block(co)} ## @@ -33,12 +34,11 @@ - -<%def name="comment_inline_form()"> +<%def name="comment_inline_form(changeset)">