Changeset - 7276b170ce8b
[Not reviewed]
beta
0 8 0
Marcin Kuzminski - 14 years ago 2011-11-13 01:16:12
marcin@python-works.com
#71 code-review
- simple inline comments
8 files changed with 202 insertions and 21 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/changeset.py
Show inline comments
 
@@ -53,197 +53,206 @@ class ChangesetController(BaseRepoContro
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def __before__(self):
 
        super(ChangesetController, self).__before__()
 
        c.affected_files_cut_off = 60
 

	
 
    def index(self, revision):
 

	
 
        def wrap_to_table(str):
 

	
 
            return '''<table class="code-difftable">
 
                        <tr class="line">
 
                        <td class="lineno new"></td>
 
                        <td class="code"><pre>%s</pre></td>
 
                        </tr>
 
                      </table>''' % str
 

	
 
        #get ranges of revisions if preset
 
        rev_range = revision.split('...')[:2]
 

	
 
        try:
 
            if len(rev_range) == 2:
 
                rev_start = rev_range[0]
 
                rev_end = rev_range[1]
 
                rev_ranges = c.rhodecode_repo.get_changesets(start=rev_start,
 
                                                            end=rev_end)
 
            else:
 
                rev_ranges = [c.rhodecode_repo.get_changeset(revision)]
 

	
 
            c.cs_ranges = list(rev_ranges)
 
            if not c.cs_ranges:
 
                raise RepositoryError('Changeset range returned empty result')
 

	
 
        except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
 
            log.error(traceback.format_exc())
 
            h.flash(str(e), category='warning')
 
            return redirect(url('home'))
 

	
 
        c.changes = OrderedDict()
 
        c.sum_added = 0
 
        c.sum_removed = 0
 
        c.lines_added = 0
 
        c.lines_deleted = 0
 
        c.cut_off = False  # defines if cut off limit is reached
 

	
 
        c.comments = []
 

	
 
        c.inline_comments = []
 
        c.inline_cnt = 0
 
        # Iterate over ranges (default changeset view is always one changeset)
 
        for changeset in c.cs_ranges:
 
            c.comments.extend(ChangesetCommentsModel()\
 
                              .get_comments(c.rhodecode_db_repo.repo_id,
 
                                            changeset.raw_id))
 

	
 
            inlines = ChangesetCommentsModel()\
 
                        .get_inline_comments(c.rhodecode_db_repo.repo_id,
 
                                             changeset.raw_id)
 
            c.inline_comments.extend(inlines)
 
            c.changes[changeset.raw_id] = []
 
            try:
 
                changeset_parent = changeset.parents[0]
 
            except IndexError:
 
                changeset_parent = None
 

	
 
            #==================================================================
 
            # ADDED FILES
 
            #==================================================================
 
            for node in changeset.added:
 

	
 
                filenode_old = FileNode(node.path, '', EmptyChangeset())
 
                if filenode_old.is_binary or node.is_binary:
 
                    diff = wrap_to_table(_('binary file'))
 
                    st = (0, 0)
 
                else:
 
                    # in this case node.size is good parameter since those are
 
                    # added nodes and their size defines how many changes were
 
                    # made
 
                    c.sum_added += node.size
 
                    if c.sum_added < self.cut_off_limit:
 
                        f_gitdiff = differ.get_gitdiff(filenode_old, node)
 
                        d = differ.DiffProcessor(f_gitdiff, format='gitdiff')
 

	
 
                        st = d.stat()
 
                        diff = d.as_html()
 

	
 
                    else:
 
                        diff = wrap_to_table(_('Changeset is to big and '
 
                                               'was cut off, see raw '
 
                                               'changeset instead'))
 
                        c.cut_off = True
 
                        break
 

	
 
                cs1 = None
 
                cs2 = node.last_changeset.raw_id
 
                c.lines_added += st[0]
 
                c.lines_deleted += st[1]
 
                c.changes[changeset.raw_id].append(('added', node, diff,
 
                                                    cs1, cs2, st))
 

	
 
            #==================================================================
 
            # CHANGED FILES
 
            #==================================================================
 
            if not c.cut_off:
 
                for node in changeset.changed:
 
                    try:
 
                        filenode_old = changeset_parent.get_node(node.path)
 
                    except ChangesetError:
 
                        log.warning('Unable to fetch parent node for diff')
 
                        filenode_old = FileNode(node.path, '',
 
                                                EmptyChangeset())
 

	
 
                    if filenode_old.is_binary or node.is_binary:
 
                        diff = wrap_to_table(_('binary file'))
 
                        st = (0, 0)
 
                    else:
 

	
 
                        if c.sum_removed < self.cut_off_limit:
 
                            f_gitdiff = differ.get_gitdiff(filenode_old, node)
 
                            d = differ.DiffProcessor(f_gitdiff,
 
                                                     format='gitdiff')
 
                            st = d.stat()
 
                            if (st[0] + st[1]) * 256 > self.cut_off_limit:
 
                                diff = wrap_to_table(_('Diff is to big '
 
                                                       'and was cut off, see '
 
                                                       'raw diff instead'))
 
                            else:
 
                                diff = d.as_html()
 

	
 
                            if diff:
 
                                c.sum_removed += len(diff)
 
                        else:
 
                            diff = wrap_to_table(_('Changeset is to big and '
 
                                                   'was cut off, see raw '
 
                                                   'changeset instead'))
 
                            c.cut_off = True
 
                            break
 

	
 
                    cs1 = filenode_old.last_changeset.raw_id
 
                    cs2 = node.last_changeset.raw_id
 
                    c.lines_added += st[0]
 
                    c.lines_deleted += st[1]
 
                    c.changes[changeset.raw_id].append(('changed', node, diff,
 
                                                        cs1, cs2, st))
 

	
 
            #==================================================================
 
            # REMOVED FILES
 
            #==================================================================
 
            if not c.cut_off:
 
                for node in changeset.removed:
 
                    c.changes[changeset.raw_id].append(('removed', node, None,
 
                                                        None, None, (0, 0)))
 

	
 
        # count inline comments
 
        for path, lines in c.inline_comments:
 
            for comments in lines.values():
 
                c.inline_cnt += len(comments)
 

	
 
        if len(c.cs_ranges) == 1:
 
            c.changeset = c.cs_ranges[0]
 
            c.changes = c.changes[c.changeset.raw_id]
 

	
 
            return render('changeset/changeset.html')
 
        else:
 
            return render('changeset/changeset_range.html')
 

	
 
    def raw_changeset(self, revision):
 

	
 
        method = request.GET.get('diff', 'show')
 
        try:
 
            c.scm_type = c.rhodecode_repo.alias
 
            c.changeset = c.rhodecode_repo.get_changeset(revision)
 
        except RepositoryError:
 
            log.error(traceback.format_exc())
 
            return redirect(url('home'))
 
        else:
 
            try:
 
                c.changeset_parent = c.changeset.parents[0]
 
            except IndexError:
 
                c.changeset_parent = None
 
            c.changes = []
 

	
 
            for node in c.changeset.added:
 
                filenode_old = FileNode(node.path, '')
 
                if filenode_old.is_binary or node.is_binary:
 
                    diff = _('binary file') + '\n'
 
                else:
 
                    f_gitdiff = differ.get_gitdiff(filenode_old, node)
 
                    diff = differ.DiffProcessor(f_gitdiff,
 
                                                format='gitdiff').raw_diff()
 

	
 
                cs1 = None
 
                cs2 = node.last_changeset.raw_id
 
                c.changes.append(('added', node, diff, cs1, cs2))
 

	
 
            for node in c.changeset.changed:
 
                filenode_old = c.changeset_parent.get_node(node.path)
 
                if filenode_old.is_binary or node.is_binary:
 
                    diff = _('binary file')
 
                else:
 
                    f_gitdiff = differ.get_gitdiff(filenode_old, node)
 
                    diff = differ.DiffProcessor(f_gitdiff,
 
                                                format='gitdiff').raw_diff()
 

	
 
                cs1 = filenode_old.last_changeset.raw_id
 
                cs2 = node.last_changeset.raw_id
rhodecode/model/comment.py
Show inline comments
 
@@ -4,90 +4,90 @@
 
    ~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
    comments model for RhodeCode
 
    
 
    :created_on: Nov 11, 2011
 
    :author: marcink
 
    :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
 
    :license: GPLv3, see COPYING for more details.
 
"""
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 

	
 
import logging
 
import traceback
 

	
 
from rhodecode.model import BaseModel
 
from rhodecode.model.db import ChangesetComment
 
from sqlalchemy.util.compat import defaultdict
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class ChangesetCommentsModel(BaseModel):
 

	
 

	
 
    def create(self, text, repo_id, user_id, revision, f_path=None,
 
               line_no=None):
 
        """
 
        Creates new comment for changeset
 
        
 
        :param text:
 
        :param repo_id:
 
        :param user_id:
 
        :param revision:
 
        :param f_path:
 
        :param line_no:
 
        """
 

	
 
        if text:
 
        comment = ChangesetComment()
 
        comment.repo_id = repo_id
 
        comment.user_id = user_id
 
        comment.revision = revision
 
        comment.text = text
 
        comment.f_path = f_path
 
        comment.line_no = line_no
 

	
 
        self.sa.add(comment)
 
        self.sa.commit()
 
        return comment
 

	
 
    def delete(self, comment_id):
 
        """
 
        Deletes given comment
 
        
 
        :param comment_id:
 
        """
 
        comment = ChangesetComment.get(comment_id)
 
        self.sa.delete(comment)
 
        self.sa.commit()
 
        return comment
 

	
 

	
 
    def get_comments(self, repo_id, revision):
 
        return ChangesetComment.query()\
 
                .filter(ChangesetComment.repo_id == repo_id)\
 
                .filter(ChangesetComment.revision == revision)\
 
                .filter(ChangesetComment.line_no == None)\
 
                .filter(ChangesetComment.f_path == None).all()
 

	
 
    def get_comments_for_file(self, repo_id, f_path, raw_id):
 
    def get_inline_comments(self, repo_id, revision):
 
        comments = self.sa.query(ChangesetComment)\
 
            .filter(ChangesetComment.repo_id == repo_id)\
 
            .filter(ChangesetComment.commit_id == raw_id)\
 
            .filter(ChangesetComment.f_path == f_path).all()
 
            .filter(ChangesetComment.revision == revision).all()
 

	
 
        paths = defaultdict(lambda:defaultdict(list))
 

	
 
        d = defaultdict(list)
 
        for co in comments:
 
            d[co.line_no].append(co)
 
        return d.items()
 
            paths[co.f_path][co.line_no].append(co)
 
        return paths.items()
rhodecode/model/db.py
Show inline comments
 
@@ -1056,65 +1056,65 @@ class CacheInvalidation(Base, BaseModel)
 
                .filter(CacheInvalidation.cache_key == key)\
 
                .filter(CacheInvalidation.cache_active == False)\
 
                .scalar()
 

	
 
    @classmethod
 
    def set_invalidate(cls, key):
 
        """
 
        Mark this Cache key for invalidation
 
        
 
        :param key:
 
        """
 

	
 
        log.debug('marking %s for invalidation' % key)
 
        inv_obj = Session().query(cls)\
 
            .filter(cls.cache_key == key).scalar()
 
        if inv_obj:
 
            inv_obj.cache_active = False
 
        else:
 
            log.debug('cache key not found in invalidation db -> creating one')
 
            inv_obj = CacheInvalidation(key)
 

	
 
        try:
 
            Session.add(inv_obj)
 
            Session.commit()
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            Session.rollback()
 

	
 
    @classmethod
 
    def set_valid(cls, key):
 
        """
 
        Mark this cache key as active and currently cached
 
        
 
        :param key:
 
        """
 
        inv_obj = Session().query(CacheInvalidation)\
 
            .filter(CacheInvalidation.cache_key == key).scalar()
 
        inv_obj.cache_active = True
 
        Session.add(inv_obj)
 
        Session.commit()
 

	
 

	
 
class ChangesetComment(Base, BaseModel):
 
    __tablename__ = 'changeset_comments'
 
    __table_args__ = ({'extend_existing':True},)
 
    comment_id = Column('comment_id', Integer(), nullable=False, primary_key=True)
 
    repo_id = Column('repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False)
 
    revision = Column('revision', String(40), nullable=False)
 
    line_no = Column('line_no', Integer(), nullable=True)
 
    f_path = Column('f_path', String(1000), nullable=True)
 
    line_no = Column('line_no', Unicode(10), nullable=True)
 
    f_path = Column('f_path', Unicode(1000), nullable=True)
 
    user_id = Column('user_id', Integer(), ForeignKey('users.user_id'), nullable=False)
 
    text = Column('text', String(25000), nullable=False)
 
    modified_at = Column('modified_at', DateTime(timezone=False), nullable=False, default=datetime.datetime.now)
 
    text = Column('text', Unicode(25000), nullable=False)
 
    modified_at = Column('modified_at', DateTime(), nullable=False, default=datetime.datetime.now)
 

	
 
    author = relationship('User')
 
    repo = relationship('Repository')
 

	
 

	
 
class DbMigrateVersion(Base, BaseModel):
 
    __tablename__ = 'db_migrate_version'
 
    __table_args__ = {'extend_existing':True}
 
    repository_id = Column('repository_id', String(250), primary_key=True)
 
    repository_path = Column('repository_path', Text)
 
    version = Column('version', Integer)
 

	
rhodecode/public/css/diff.css
Show inline comments
 
@@ -72,49 +72,58 @@ table.code-difftable td {
 
}
 
.code-difftable .new {
 
	border-right: 1px solid #CCC !important;
 
}
 
.code-difftable .old {
 
    border-right: 1px solid #CCC !important;
 
}
 
.code-difftable .lineno pre{
 
	color:#747474 !important;
 
	font:11px "Bitstream Vera Sans Mono",Monaco,"Courier New",Courier,monospace !important;
 
	letter-spacing:-1px;
 
	text-align:right;
 
	width:20px;
 
}
 
.code-difftable .lineno a{
 
font-weight: 700;
 
cursor: pointer;
 
}
 
.code-difftable .code td{
 
	margin:0;
 
	padding: 0;
 
}
 
.code-difftable .code pre{
 
	margin:0;
 
	padding:0;
 
}
 

	
 
.code { 
 
	display: block;
 
	width: 100%;
 
}
 
.code-diff {
 
    padding: 0px;
 
    margin-top: 5px;
 
    margin-bottom: 5px;
 
    border-left: 2px solid #ccc;
 
}
 
.code-diff pre, .line pre { 
 
	padding: 3px;
 
    margin: 0;
 
}
 
.lineno a { 
 
	text-decoration: none; 
 
}
 

	
 
.line{
 
	padding:0;
 
	margin:0;
 
}
 
\ No newline at end of file
 
}
 

	
 
.line.highlight{
 
	background-color:#FFFFCC;
 
	cursor: pointer;
 
	background-image:url("../images/icons/comment_add.png");
 
	background-repeat:no-repeat;
 
	background-position: right;
 
	background-position: 100% 50%;
 
}
rhodecode/public/css/style.css
Show inline comments
 
@@ -1808,110 +1808,114 @@ h3.files_location {
 
 
#changeset_content {
 
	border: 1px solid #CCC;
 
	padding: 5px;
 
}
 
 
#changeset_compare_view_content {
 
	border: 1px solid #CCC;
 
	padding: 5px;
 
}
 
 
#changeset_content .container {
 
	min-height: 120px;
 
	font-size: 1.2em;
 
	overflow: hidden;
 
}
 
 
#changeset_compare_view_content .compare_view_commits {
 
	width: auto !important;
 
}
 
 
#changeset_compare_view_content .compare_view_commits td {
 
	padding: 0px 0px 0px 12px !important;
 
}
 
 
#changeset_content .container .right {
 
	float: right;
 
	width: 25%;
 
	text-align: right;
 
}
 
 
#changeset_content .container .left .message {
 
	font-style: italic;
 
	color: #556CB5;
 
	white-space: pre-wrap;
 
}
 
 
.cs_files .cur_cs {
 
	margin: 10px 2px;
 
	font-weight: bold;
 
}
 
 
.cs_files .node {
 
	float: left;
 
}
 
 
.cs_files .changes {
 
	float: right;
 
	color:#003367;
 
	
 
}
 
 
.cs_files .changes .added {
 
	background-color: #BBFFBB;
 
	float: left;
 
	text-align: center;
 
	font-size: 90%;
 
	font-size: 9px;
 
    padding: 2px 0px 2px 0px;
 
}
 
 
.cs_files .changes .deleted {
 
	background-color: #FF8888;
 
	float: left;
 
	text-align: center;
 
	font-size: 90%;
 
	font-size: 9px;
 
    padding: 2px 0px 2px 0px;
 
}
 
 
.cs_files .cs_added {
 
	background: url("../images/icons/page_white_add.png") no-repeat scroll
 
		3px;
 
	height: 16px;
 
	padding-left: 20px;
 
	margin-top: 7px;
 
	text-align: left;
 
}
 
 
.cs_files .cs_changed {
 
	background: url("../images/icons/page_white_edit.png") no-repeat scroll
 
		3px;
 
	height: 16px;
 
	padding-left: 20px;
 
	margin-top: 7px;
 
	text-align: left;
 
}
 
 
.cs_files .cs_removed {
 
	background: url("../images/icons/page_white_delete.png") no-repeat
 
		scroll 3px;
 
	height: 16px;
 
	padding-left: 20px;
 
	margin-top: 7px;
 
	text-align: left;
 
}
 
 
#graph {
 
	overflow: hidden;
 
}
 
 
#graph_nodes {
 
	float: left;
 
	margin-right: -6px;
 
	margin-top: 0px;
 
}
 
 
#graph_content {
 
	width: 800px;
 
	float: left;
 
}
 
 
#graph_content .container_header {
 
	border: 1px solid #CCC;
 
	padding: 10px;
 
	height: 45px;
 
@@ -3225,110 +3229,169 @@ div.rst-block  pre {
 
    color: #444;
 
    overflow: auto;
 
    -webkit-box-shadow: rgba(0,0,0,0.07) 0 1px 2px inset;
 
    -webkit-border-radius: 3px;
 
    -moz-border-radius: 3px;
 
    border-radius: 3px;
 
}
 
 
 
 
.comments {
 
    padding:10px 20px;
 
}
 
 
.comments .comment {
 
    border: 1px solid #ddd;
 
    margin-top: 10px;
 
    -webkit-border-radius: 4px;
 
    -moz-border-radius: 4px;
 
    border-radius: 4px;    
 
}
 
 
.comments .comment .meta {
 
    background: #f8f8f8;
 
    padding: 6px;
 
    border-bottom: 1px solid #ddd;
 
}
 
 
.comments .comment .meta img {
 
    vertical-align: middle;
 
}
 
 
.comments .comment .meta .user {
 
    font-weight: bold;
 
}
 
 
.comments .comment .meta .date {
 
    float: right;
 
}
 
 
.comments .comment .text {
 
    padding: 8px 6px 6px 14px;
 
    background-color: #FAFAFA;
 
}
 
 
.comments .comments-number{
 
	padding:0px 0px 10px 0px;
 
	font-weight: bold;
 
}
 
	color: #666;
 
	font-size: 16px;
 
}
 
/** comment form **/
 
 
.comment-form .clearfix{
 
	background: #EEE;
 
    -webkit-border-radius: 4px;
 
    -moz-border-radius: 4px;
 
    border-radius: 4px;
 
    padding: 10px;
 
}
 
 
div.comment-form {
 
    margin-top: 20px;
 
}
 
 
.comment-form strong {
 
    display: block;
 
    margin-bottom: 15px;
 
}
 
 
.comment-form textarea {
 
    width: 100%;
 
    height: 100px;
 
    font-family: 'Monaco', 'Courier', 'Courier New', monospace;
 
}
 
 
form.comment-form {
 
    margin-top: 10px;
 
    margin-left: 10px;
 
}
 
 
.comment-form-submit {
 
    margin-top: 5px;
 
    margin-left: 525px;
 
}
 
 
.file-comments {
 
    display: none;
 
}
 
 
.comment-form .comment {
 
    margin-left: 10px;
 
}
 
 
.comment-form .comment-help{
 
    padding: 0px 0px 5px 0px;
 
    color: #666;
 
}
 
 
.comment-form .comment-button{
 
	padding-top:5px;
 
}
 
 
.add-another-button {
 
    margin-left: 10px;
 
    margin-top: 10px;
 
    margin-bottom: 10px;
 
}
 
 
.comment .buttons {
 
    position: absolute;
 
    right:40px;
 
}
 
 
 
 
/** comment inline form **/
 
 
.comment-inline-form .clearfix{
 
    background: #EEE;
 
    -webkit-border-radius: 4px;
 
    -moz-border-radius: 4px;
 
    border-radius: 4px;
 
    padding: 5px;
 
}
 
 
div.comment-inline-form {
 
    margin-top: 5px;
 
    padding:2px 6px 8px 6px;
 
}
 
 
.comment-inline-form strong {
 
    display: block;
 
    margin-bottom: 15px;
 
}
 
 
.comment-inline-form textarea {
 
    width: 100%;
 
    height: 100px;
 
    font-family: 'Monaco', 'Courier', 'Courier New', monospace;
 
}
 
 
form.comment-inline-form {
 
    margin-top: 10px;
 
    margin-left: 10px;
 
}
 
 
.comment-inline-form-submit {
 
    margin-top: 5px;
 
    margin-left: 525px;
 
}
 
 
.file-comments {
 
    display: none;
 
}
 
 
.comment-inline-form .comment {
 
    margin-left: 10px;
 
}
 
 
.comment-inline-form .comment-help{
 
    padding: 0px 0px 2px 0px;
 
    color: #666666;
 
    font-size: 10px;
 
}
 
 
.comment-inline-form .comment-button{
 
    padding-top:5px;
 
}
 
\ No newline at end of file
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -253,48 +253,86 @@ var q_filter = function(target,nodes,dis
 
		YUD.setStyle(node,'display','none');
 
	}
 
	
 
	F.updateFilter  = function() { 
 
	   // Reset timeout 
 
	   F.filterTimeout = null;
 
	   
 
	   var obsolete = [];
 
	   
 
	   var req = q_filter_field.value.toLowerCase();
 
	   
 
	   var l = nodes.length;
 
	   var i;
 
	   var showing = 0;
 
	   
 
       for (i=0;i<l;i++ ){
 
    	   var n = nodes[i];
 
    	   var target_element = display_element(n)
 
    	   if(req && n.innerHTML.toLowerCase().indexOf(req) == -1){
 
    		   hide_node(target_element);
 
    	   }
 
    	   else{
 
    		   show_node(target_element);
 
    		   showing+=1;
 
    	   }
 
       }	  	   
 

	
 
	   // if repo_count is set update the number
 
	   var cnt = YUD.get('repo_count');
 
	   if(cnt){
 
		   YUD.get('repo_count').innerHTML = showing;
 
	   }       
 
       
 
	}	
 
}
 

	
 
var ajaxPOST = function(url,postData,success) {
 
    var sUrl = url;
 
    var callback = {
 
        success: success,
 
        failure: function (o) {
 
            alert("error");
 
        },
 
    };
 
    var postData = postData;
 
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
 
};
 

	
 

	
 
/** comments **/
 
var removeInlineForm = function(form) {
 
	form.parentNode.removeChild(form);
 
}
 

	
 
var createInlineForm = function(parent_tr, f_path, line) {
 
	var form = document.createElement('tr');
 
	YUD.addClass(form, 'comment-form-inline');
 
	var tmpl = YUD.get('comment-inline-form-template').innerHTML;
 
	tmpl = tmpl.format(f_path, line);
 
	form.innerHTML = '<td class="lineno new"></td>'+
 
		             '<td class="lineno old"></td>'+ 
 
			         '<td>{0}</td>'.format(tmpl);
 

	
 
	// create event for hide button
 
	form = new YAHOO.util.Element(form);
 
	var form_hide_button = new YAHOO.util.Element(form.getElementsByClassName('hide-inline-form')[0]);
 
	form_hide_button.on('click', function(e) {
 
		var newtr = e.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode;
 
		removeInlineForm(newtr);
 
		YUD.removeClass(parent_tr, 'form-open');
 
	});
 
	return form
 
}
 
var getLineNo = function(tr) {
 
	var line;
 
	var o = tr.children[0].id.split('_');
 
	var n = tr.children[1].id.split('_');
 

	
 
	if (n.length == 2) {
 
		line = n[1];
 
	} else if (o.length == 2) {
 
		line = o[1];
 
	}
 

	
 
	return line
 
}
 
\ No newline at end of file
rhodecode/templates/changeset/changeset.html
Show inline comments
 
@@ -69,105 +69,146 @@
 
		                 
 
		            %if c.changeset.parents:
 
		             %for p_cs in reversed(c.changeset.parents):
 
		                 <div class="parent">${_('Parent')} ${p_cs.revision}: ${h.link_to(h.short_id(p_cs.raw_id),
 
		                     h.url('changeset_home',repo_name=c.repo_name,revision=p_cs.raw_id),title=p_cs.message)}
 
		                 </div>
 
		             %endfor
 
                    %else: 
 
                        <div class="parent">${_('No parents')}</div>   
 
                    %endif		             
 
		         <span class="logtags">
 
		             <span class="branchtag" title="${'%s %s' % (_('branch'),c.changeset.branch)}">
 
		             ${h.link_to(c.changeset.branch,h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id))}</span>
 
		             %for tag in c.changeset.tags:
 
		                 <span class="tagtag"  title="${'%s %s' % (_('tag'),tag)}">
 
		                 ${h.link_to(tag,h.url('files_home',repo_name=c.repo_name,revision=c.changeset.raw_id))}</span>
 
		             %endfor
 
		         </span>                                                                 
 
	                </div>              
 
	        </div>
 
	        <span style="font-size:1.1em;font-weight: bold">
 
	        ${_('%s files affected with %s additions and %s deletions.') % (len(c.changeset.affected_files),c.lines_added,c.lines_deleted)}
 
	        </span>
 
	        <div class="cs_files">
 
	                %for change,filenode,diff,cs1,cs2,stat in c.changes:
 
	                    <div class="cs_${change}">
 
		                    <div class="node">${h.link_to(h.safe_unicode(filenode.path),h.url.current(anchor='C-%s-%s' % (h.short_id(filenode.changeset.raw_id),h.safeid(h.safe_unicode(filenode.path)))))}</div>
 
		                    <div class="changes">${h.fancy_file_stats(stat)}</div>
 
	                    </div>
 
	                %endfor
 
	                % if c.cut_off:
 
	                  ${_('Changeset was too big and was cut off...')}
 
	                % endif
 
	        </div>         
 
	    </div>
 
	    
 
    </div>
 
    	
 
	%for change,filenode,diff,cs1,cs2,stat in c.changes:
 
		%if change !='removed':
 
		<div style="clear:both;height:10px"></div>
 
		<div class="diffblock  margined">
 
			<div id="${'C-%s-%s' % (h.short_id(filenode.changeset.raw_id),h.safeid(h.safe_unicode(filenode.path)))}" class="code-header">
 
				<div class="changeset_header">
 
					<span class="changeset_file">
 
						${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)))}
 
					</span>
 
					%if 1:
 
					&raquo; <span>${h.link_to(_('diff'),
 
					h.url('files_diff_home',repo_name=c.repo_name,f_path=h.safe_unicode(filenode.path),diff2=cs2,diff1=cs1,diff='diff'))}</span>
 
					&raquo; <span>${h.link_to(_('raw diff'),
 
					h.url('files_diff_home',repo_name=c.repo_name,f_path=h.safe_unicode(filenode.path),diff2=cs2,diff1=cs1,diff='raw'))}</span>
 
					&raquo; <span>${h.link_to(_('download diff'),
 
					h.url('files_diff_home',repo_name=c.repo_name,f_path=h.safe_unicode(filenode.path),diff2=cs2,diff1=cs1,diff='download'))}</span>
 
					%endif
 
				</div>
 
			</div>
 
			<div class="code-body">        
 
                <div class="full_f_path" path="${filenode.path}"></div>        
 
					%if diff:
 
						${diff|n}
 
					%else:
 
						${_('No changes in this file')}
 
					%endif
 
			</div>
 
		</div>
 
		%endif
 
	%endfor
 
  
 
    <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 
    ## template for inline comment form
 
    ${comment.comment_inline_form()}
 
    
 
    <div class="comments">
 
        <div class="comments-number">${len(c.comments)} comment(s)</div>
 
        <div class="comments-number">${len(c.comments)} comment(s) (${c.inline_cnt} ${_('inline')})</div>
 
        
 
        %for path, lines in c.inline_comments:
 
            <div class="inline-comment-placeholder" path="${path} ">
 
            % for line,comments in lines.iteritems():
 
                <div class="inline-comment-placeholder-line" line="${line}"> 
 
                %for co in comments:
 
                    ${comment.comment_block(co)}
 
                %endfor
 
                </div>
 
            %endfor
 
            </div>
 
        %endfor        
 
        
 
        %for co in c.comments:
 
            ${comment.comment_block(co)}
 
        %endfor
 
        %if c.rhodecode_user.username != 'default':
 
        <div class="comment-form">
 
            ${h.form(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id))}
 
            <strong>Leave a comment</strong>
 
            <strong>${_('Leave a comment')}</strong>
 
            <div class="clearfix">
 
                <div class="comment-help">${_('Comments parsed using RST syntax')}</div>
 
                    ${h.textarea('text')}
 
            </div>
 
            <div class="comment-button">
 
            ${h.submit('save', _('Comment'), class_='ui-button')}
 
            </div>
 
            ${h.end_form()}
 
        </div>
 
        %endif
 
    </div>
 
    <script type="text/javascript">
 
      var deleteComment = function(comment_id){
 

	
 
          var url = "${url('changeset_comment_delete',repo_name=c.repo_name,comment_id='__COMMENT_ID__')}".replace('__COMMENT_ID__',comment_id);
 
          var postData = '_method=delete';
 
          var success = function(o){
 
              var n = YUD.get('comment-'+comment_id);
 
              n.parentNode.removeChild(n);
 
          }
 
          ajaxPOST(url,postData,success);
 
      } 
 

	
 
      YUE.onDOMReady(function(){
 
    	  YUE.on(YUQ('.line'),'mouseenter',function(e){
 
    		  var tr = e.currentTarget;
 
              if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context')){
 
                  return
 
              }    		  
 
    		  YUD.addClass(tr,'highlight');
 
    	  });
 
          YUE.on(YUQ('.line'),'mouseleave',function(e){
 
              YUD.removeClass(e.currentTarget,'highlight');
 
          });
 
          
 
          YUE.on(YUQ('.line'),'click',function(e){
 
        	  var tr = e.currentTarget;
 
        	  if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context')){
 
        		  return
 
        	  }
 
        	  YUD.addClass(tr,'form-open');
 
        	  var node = tr.parentNode.parentNode.parentNode.getElementsByClassName('full_f_path')[0];
 
        	  var f_path = YUD.getAttribute(node,'path');
 
        	  var lineno = getLineNo(tr);
 
        	  var form = createInlineForm(tr, f_path, lineno);
 
        	  YUD.insertAfter(form,tr);
 
          })
 
      })
 
      
 
    </script> 
 
  </div>	
 
</%def>
rhodecode/templates/changeset/changeset_file_comment.html
Show inline comments
 
##usage:
 
## <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 
## ${comment.comment_block(co)}
 
##
 
<%def name="comment_block(co)">
 
  <div class="comment" id="comment-${co.comment_id}">
 
  	<div class="meta">
 
  		<span class="user">
 
  			<img src="${h.gravatar_url(co.author.email, 20)}" />
 
  			${co.author.username}
 
  		</span>
 
  		<a href="${h.url.current(anchor='comment-%s' % co.comment_id)}"> ${_('commented on')} </a>
 
  		${h.short_id(co.revision)}
 
  		%if co.f_path:
 
  			${_(' in file ')}
 
  			${co.f_path}:L${co.line_no}
 
  		%endif
 
  		<span class="date">
 
  			${h.age(co.modified_at)}
 
  		</span>
 
  	</div>
 
  	<div class="text">
 
  		%if h.HasPermissionAny('hg.admin', 'repository.admin')() or co.author.user_id == c.rhodecode_user.user_id:
 
  			<div class="buttons">
 
  				<span onClick="deleteComment(${co.comment_id})" class="delete-comment ui-button-small">${_('Delete')}</span>
 
  			</div>
 
  		%endif
 
  		${h.rst(co.text)|n}
 
  	</div>
 
  </div>
 
</%def>
 
 
 
 
<%def name="comment_inline_form()">
 
<div id='comment-inline-form-template' style="display:none">
 
  <div class="comment-inline-form">
 
      ${h.form(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id))}
 
      <div class="clearfix">
 
          <div class="comment-help">${_('Commenting on line')} {1} ${_('comments parsed using RST syntax')}</div>
 
              ${h.textarea('text')}
 
      </div>
 
      <div class="comment-button">
 
      <input type="hidden" name="f_path" value="{0}">
 
      <input type="hidden" name="line" value="{1}">            
 
      ${h.submit('save', _('Comment'), class_='ui-button-small')}
 
      ${h.reset('hide-inline-form', _('Hide'), class_='ui-button-small hide-inline-form')}
 
      </div>
 
      ${h.end_form()}
 
  </div>
 
</div>  
 
</%def>
 
\ No newline at end of file
0 comments (0 inline, 0 general)