# HG changeset patch # User Marcin Kuzminski # Date 1324175093 -7200 # 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 -r 02a26ed03537 -r d4a7b6c82efe rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py Sun Dec 18 00:12:58 2011 +0200 +++ b/rhodecode/controllers/changeset.py Sun Dec 18 04:24:53 2011 +0200 @@ -50,13 +50,14 @@ 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 @@ pass return ig_ws_global + def _ignorews_url(fileid=None): params = defaultdict(list) @@ -88,14 +90,15 @@ # 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 @@ 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 @@ 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 @@ 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 @@ #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 @@ 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 @@ '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 @@ @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 -r 02a26ed03537 -r d4a7b6c82efe rhodecode/lib/diffs.py --- a/rhodecode/lib/diffs.py Sun Dec 18 00:12:58 2011 +0200 +++ b/rhodecode/lib/diffs.py Sun Dec 18 04:24:53 2011 +0200 @@ -114,15 +114,17 @@ 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 @@ 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 @@ ########################################################### # 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 -r 02a26ed03537 -r d4a7b6c82efe rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css Sun Dec 18 00:12:58 2011 +0200 +++ b/rhodecode/public/css/style.css Sun Dec 18 04:24:53 2011 +0200 @@ -3898,17 +3898,19 @@ 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 @@ 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 -r 02a26ed03537 -r d4a7b6c82efe rhodecode/public/js/rhodecode.js --- a/rhodecode/public/js/rhodecode.js Sun Dec 18 00:12:58 2011 +0200 +++ b/rhodecode/public/js/rhodecode.js Sun Dec 18 04:24:53 2011 +0200 @@ -343,7 +343,7 @@ 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 -r 02a26ed03537 -r d4a7b6c82efe rhodecode/templates/changeset/changeset.html --- a/rhodecode/templates/changeset/changeset.html Sun Dec 18 00:12:58 2011 +0200 +++ b/rhodecode/templates/changeset/changeset.html Sun Dec 18 04:24:53 2011 +0200 @@ -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 -r 02a26ed03537 -r d4a7b6c82efe rhodecode/templates/changeset/changeset_file_comment.html --- a/rhodecode/templates/changeset/changeset_file_comment.html Sun Dec 18 00:12:58 2011 +0200 +++ b/rhodecode/templates/changeset/changeset_file_comment.html Sun Dec 18 04:24:53 2011 +0200 @@ -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)">