Changeset - 5143b8df576c
[Not reviewed]
beta
0 5 0
Marcin Kuzminski - 13 years ago 2012-06-01 18:34:32
marcin@python-works.com
Added mentions autocomplete into main comments form
- recompiled yui.2.9.js using google compiler
3 files changed:
0 comments (0 inline, 0 general)
rhodecode/controllers/changeset.py
Show inline comments
 
@@ -2,96 +2,97 @@
 
"""
 
    rhodecode.controllers.changeset
 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
    changeset controller for pylons showoing changes beetween
 
    revisions
 

	
 
    :created_on: Apr 25, 2010
 
    :author: marcink
 
    :copyright: (C) 2010-2012 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 collections import defaultdict
 
from webob.exc import HTTPForbidden
 

	
 
from pylons import tmpl_context as c, url, request, response
 
from pylons.i18n.translation import _
 
from pylons.controllers.util import redirect
 
from pylons.decorators import jsonify
 

	
 
from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetError, \
 
    ChangesetDoesNotExistError
 
from rhodecode.lib.vcs.nodes import FileNode
 

	
 
import rhodecode.lib.helpers as h
 
from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 
from rhodecode.lib.base import BaseRepoController, render
 
from rhodecode.lib.utils import EmptyChangeset
 
from rhodecode.lib.compat import OrderedDict
 
from rhodecode.lib import diffs
 
from rhodecode.model.db import ChangesetComment
 
from rhodecode.model.comment import ChangesetCommentsModel
 
from rhodecode.model.meta import Session
 
from rhodecode.lib.diffs import wrapped_diff
 
from rhodecode.model.repo import RepoModel
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
def _update_with_GET(params, GET):
 
    for k in ['diff1', 'diff2', 'diff']:
 
        params[k] += GET.getall(k)
 

	
 

	
 
def anchor_url(revision, path, GET):
 
    fid = h.FID(revision, path)
 
    return h.url.current(anchor=fid, **dict(GET))
 

	
 

	
 
def get_ignore_ws(fid, GET):
 
    ig_ws_global = GET.get('ignorews')
 
    ig_ws = filter(lambda k: k.startswith('WS'), GET.getall(fid))
 
    if ig_ws:
 
        try:
 
            return int(ig_ws[0].split(':')[-1])
 
        except:
 
            pass
 
    return ig_ws_global
 

	
 

	
 
def _ignorews_url(GET, fileid=None):
 
    fileid = str(fileid) if fileid else None
 
    params = defaultdict(list)
 
    _update_with_GET(params, GET)
 
    lbl = _('show white space')
 
    ig_ws = get_ignore_ws(fileid, GET)
 
    ln_ctx = get_line_ctx(fileid, GET)
 
    # global option
 
    if fileid is None:
 
        if ig_ws is None:
 
            params['ignorews'] += [1]
 
            lbl = _('ignore white space')
 
        ctx_key = 'context'
 
        ctx_val = ln_ctx
 
    # per file options
 
    else:
 
        if ig_ws is None:
 
            params[fileid] += ['WS:1']
 
            lbl = _('ignore white space')
 

	
 
        ctx_key = fileid
 
        ctx_val = 'C:%s' % ln_ctx
 
    # if we have passed in ln_ctx pass it along to our params
 
@@ -120,96 +121,99 @@ def get_line_ctx(fid, GET):
 

	
 
def _context_url(GET, fileid=None):
 
    """
 
    Generates url for context lines
 

	
 
    :param fileid:
 
    """
 

	
 
    fileid = str(fileid) if fileid else None
 
    ig_ws = get_ignore_ws(fileid, GET)
 
    ln_ctx = (get_line_ctx(fileid, GET) or 3) * 2
 

	
 
    params = defaultdict(list)
 
    _update_with_GET(params, GET)
 

	
 
    # global option
 
    if fileid is None:
 
        if ln_ctx > 0:
 
            params['context'] += [ln_ctx]
 

	
 
        if ig_ws:
 
            ig_ws_key = 'ignorews'
 
            ig_ws_val = 1
 

	
 
    # per file option
 
    else:
 
        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]
 

	
 
    lbl = _('%s line context') % ln_ctx
 

	
 
    params['anchor'] = fileid
 
    img = h.image(h.url('/images/icons/table_add.png'), lbl, class_='icon')
 
    return h.link_to(img, h.url.current(**params), title=lbl, class_='tooltip')
 

	
 

	
 
class ChangesetController(BaseRepoController):
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def __before__(self):
 
        super(ChangesetController, self).__before__()
 
        c.affected_files_cut_off = 60
 
        repo_model = RepoModel()
 
        c.users_array = repo_model.get_users_js()
 
        c.users_groups_array = repo_model.get_users_groups_js()
 

	
 
    def index(self, revision):
 

	
 
        c.anchor_url = anchor_url
 
        c.ignorews_url = _ignorews_url
 
        c.context_url = _context_url
 
        limit_off = request.GET.get('fulldiff')
 
        #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,
 
                                                            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.lines_added = 0  # count of lines added
 
        c.lines_deleted = 0  # count of lines removes
 

	
 
        cumulative_diff = 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)
rhodecode/public/css/style.css
Show inline comments
 
@@ -2775,96 +2775,103 @@ table.code-browser .submodule-dir {
 
.info_box .rev {
 
	color: #003367;
 
	font-size: 1.6em;
 
	font-weight: bold;
 
	vertical-align: sub;
 
}
 
 
.info_box input#at_rev,.info_box input#size {
 
	background: #FFF;
 
	border-top: 1px solid #b3b3b3;
 
	border-left: 1px solid #b3b3b3;
 
	border-right: 1px solid #eaeaea;
 
	border-bottom: 1px solid #eaeaea;
 
	color: #000;
 
	font-size: 12px;
 
	margin: 0;
 
	padding: 1px 5px 1px;
 
}
 
 
.info_box input#view {
 
	text-align: center;
 
	padding: 4px 3px 2px 2px;
 
}
 
 
.yui-overlay,.yui-panel-container {
 
	visibility: hidden;
 
	position: absolute;
 
	z-index: 2;
 
}
 
 
.yui-tt {
 
	visibility: hidden;
 
	position: absolute;
 
	color: #666;
 
	background-color: #FFF;
 
	border: 2px solid #003367;
 
	font: 100% sans-serif;
 
	width: auto;
 
	opacity: 1px;
 
	padding: 8px;
 
	white-space: pre-wrap;
 
	-webkit-border-radius: 8px 8px 8px 8px;
 
	-khtml-border-radius: 8px 8px 8px 8px;
 
	-moz-border-radius: 8px 8px 8px 8px;
 
	border-radius: 8px 8px 8px 8px;
 
	box-shadow: 0 2px 2px rgba(0, 0, 0, 0.6);
 
}
 
 
.mentions-container{
 
	width: 100% !important;
 
}
 
.mentions-container .yui-ac-content{
 
	width: 90% !important;
 
}
 
 
.ac {
 
	vertical-align: top;
 
}
 
 
.ac .yui-ac {
 
	position: inherit;
 
	font-size: 100%;
 
}
 
 
.ac .perm_ac {
 
	width: 20em;
 
}
 
 
.ac .yui-ac-input {
 
	width: 100%;
 
}
 
 
.ac .yui-ac-container {
 
	position: absolute;
 
	top: 1.6em;
 
	width: auto;
 
}
 
 
.ac .yui-ac-content {
 
	position: absolute;
 
	border: 1px solid gray;
 
	background: #fff;
 
	z-index: 9050;
 
	
 
}
 
 
.ac .yui-ac-shadow {
 
	position: absolute;
 
	width: 100%;
 
	background: #000;
 
	-moz-opacity: 0.1px;
 
	opacity: .10;
 
	filter: alpha(opacity = 10);
 
	z-index: 9049;
 
	margin: .3em;
 
}
 
 
.ac .yui-ac-content ul {
 
	width: 100%;
 
	margin: 0;
 
	padding: 0;
 
	z-index: 9050;
 
}
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -943,96 +943,279 @@ var MembersAutoComplete = function (user
 
                    displaylname = lname;
 
                }
 

	
 
                if (nnameMatchIndex > -1) {
 
                    displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")";
 
                } else {
 
                    displaynname = nname ? "(" + nname + ")" : "";
 
                }
 

	
 
                return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk);
 
            } else {
 
                return '';
 
            }
 
        };
 
    membersAC.formatResult = custom_formatter;
 
    ownerAC.formatResult = custom_formatter;
 

	
 
    var myHandler = function (sType, aArgs) {
 

	
 
            var myAC = aArgs[0]; // reference back to the AC instance
 
            var elLI = aArgs[1]; // reference to the selected LI element
 
            var oData = aArgs[2]; // object literal of selected item's result data
 
            //fill the autocomplete with value
 
            if (oData.nname != undefined) {
 
                //users
 
                myAC.getInputEl().value = oData.nname;
 
                YUD.get('perm_new_member_type').value = 'user';
 
            } else {
 
                //groups
 
                myAC.getInputEl().value = oData.grname;
 
                YUD.get('perm_new_member_type').value = 'users_group';
 
            }
 
        };
 

	
 
    membersAC.itemSelectEvent.subscribe(myHandler);
 
    if(ownerAC.itemSelectEvent){
 
    	ownerAC.itemSelectEvent.subscribe(myHandler);
 
    }
 

	
 
    return {
 
        memberDS: memberDS,
 
        ownerDS: ownerDS,
 
        membersAC: membersAC,
 
        ownerAC: ownerAC,
 
    };
 
}
 

	
 

	
 
var MentionsAutoComplete = function (divid, cont, users_list, groups_list, group_lbl, members_lbl) {
 
    var myUsers = users_list;
 
    var myGroups = groups_list;
 

	
 
    // Define a custom search function for the DataSource of users
 
    var matchUsers = function (sQuery) {
 
    	    var org_sQuery = sQuery;
 
    	    if(this.mentionQuery == null){
 
    	    	return []    	    	
 
    	    }
 
    	    sQuery = this.mentionQuery;
 
            // Case insensitive matching
 
            var query = sQuery.toLowerCase();
 
            var i = 0;
 
            var l = myUsers.length;
 
            var matches = [];
 

	
 
            // Match against each name of each contact
 
            for (; i < l; i++) {
 
                contact = myUsers[i];
 
                if ((contact.fname.toLowerCase().indexOf(query) > -1) || (contact.lname.toLowerCase().indexOf(query) > -1) || (contact.nname && (contact.nname.toLowerCase().indexOf(query) > -1))) {
 
                    matches[matches.length] = contact;
 
                }
 
            }
 
            return matches
 
        };
 

	
 
    //match all
 
    var matchAll = function (sQuery) {
 
            u = matchUsers(sQuery);
 
            return u
 
        };
 

	
 
    // DataScheme for owner
 
    var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers);
 
    ownerDS.responseSchema = {
 
        fields: ["id", "fname", "lname", "nname", "gravatar_lnk"]
 
    };
 

	
 
    // Instantiate AutoComplete for mentions
 
    var ownerAC = new YAHOO.widget.AutoComplete(divid, cont, ownerDS);
 
    ownerAC.useShadow = false;
 
    ownerAC.resultTypeList = false;
 
    ownerAC.suppressInputUpdate = true;
 

	
 
    // Helper highlight function for the formatter
 
    var highlightMatch = function (full, snippet, matchindex) {
 
            return full.substring(0, matchindex) 
 
            + "<span class='match'>" 
 
            + full.substr(matchindex, snippet.length) 
 
            + "</span>" + full.substring(matchindex + snippet.length);
 
        };
 

	
 
    // Custom formatter to highlight the matching letters
 
    ownerAC.formatResult = function (oResultData, sQuery, sResultMatch) {
 
		    var org_sQuery = sQuery;
 
		    if(this.dataSource.mentionQuery != null){
 
		    	sQuery = this.dataSource.mentionQuery;		    	
 
		    }
 

	
 
            var query = sQuery.toLowerCase();
 
            var _gravatar = function(res, em, group){
 
            	if (group !== undefined){
 
            		em = '/images/icons/group.png'
 
            	}
 
            	tmpl = '<div class="ac-container-wrap"><img class="perm-gravatar-ac" src="{0}"/>{1}</div>'
 
            	return tmpl.format(em,res)
 
            }
 
            if (oResultData.fname != undefined) {
 
                var fname = oResultData.fname,
 
                    lname = oResultData.lname,
 
                    nname = oResultData.nname || "",
 
                    // Guard against null value
 
                    fnameMatchIndex = fname.toLowerCase().indexOf(query),
 
                    lnameMatchIndex = lname.toLowerCase().indexOf(query),
 
                    nnameMatchIndex = nname.toLowerCase().indexOf(query),
 
                    displayfname, displaylname, displaynname;
 

	
 
                if (fnameMatchIndex > -1) {
 
                    displayfname = highlightMatch(fname, query, fnameMatchIndex);
 
                } else {
 
                    displayfname = fname;
 
                }
 

	
 
                if (lnameMatchIndex > -1) {
 
                    displaylname = highlightMatch(lname, query, lnameMatchIndex);
 
                } else {
 
                    displaylname = lname;
 
                }
 

	
 
                if (nnameMatchIndex > -1) {
 
                    displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")";
 
                } else {
 
                    displaynname = nname ? "(" + nname + ")" : "";
 
                }
 

	
 
                return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk);
 
            } else {
 
                return '';
 
            }
 
        };
 

	
 
    if(ownerAC.itemSelectEvent){
 
    	ownerAC.itemSelectEvent.subscribe(function (sType, aArgs) {
 

	
 
            var myAC = aArgs[0]; // reference back to the AC instance
 
            var elLI = aArgs[1]; // reference to the selected LI element
 
            var oData = aArgs[2]; // object literal of selected item's result data
 
            //fill the autocomplete with value
 
            if (oData.nname != undefined) {
 
                //users
 
            	//Replace the mention name with replaced
 
            	var re = new RegExp();
 
            	var org = myAC.getInputEl().value;
 
            	var chunks = myAC.dataSource.chunks
 
            	// replace middle chunk(the search term) with actuall  match
 
            	chunks[1] = chunks[1].replace('@'+myAC.dataSource.mentionQuery,
 
            								  '@'+oData.nname+' ');
 
                myAC.getInputEl().value = chunks.join('')
 
                YUD.get(myAC.getInputEl()).focus(); // Y U NO WORK !?
 
            } else {
 
                //groups
 
                myAC.getInputEl().value = oData.grname;
 
                YUD.get('perm_new_member_type').value = 'users_group';
 
            }
 
        });
 
    }
 

	
 
    // in this keybuffer we will gather current value of search !
 
    // since we need to get this just when someone does `@` then we do the
 
    // search
 
    ownerAC.dataSource.chunks = [];
 
    ownerAC.dataSource.mentionQuery = null;
 

	
 
    ownerAC.get_mention = function(msg, max_pos) {
 
    	var org = msg;
 
    	var re = new RegExp('(?:^@|\s@)([a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+)$')
 
    	var chunks  = [];
 

	
 
		
 
    	// cut first chunk until curret pos
 
		var to_max = msg.substr(0, max_pos);		
 
		var at_pos = Math.max(0,to_max.lastIndexOf('@')-1);
 
		var msg2 = to_max.substr(at_pos);
 

	
 
		chunks.push(org.substr(0,at_pos))// prefix chunk
 
		chunks.push(msg2)                // search chunk
 
		chunks.push(org.substr(max_pos)) // postfix chunk
 

	
 
		// clean up msg2 for filtering and regex match
 
		var msg2 = msg2.replace(' ','').replace('\n','');
 

	
 
		if(re.test(msg2)){
 
			var unam = re.exec(msg2)[1];
 
			return [unam, chunks];
 
		}
 
		return [null, null];
 
    };    
 
	ownerAC.textboxKeyUpEvent.subscribe(function(type, args){
 
		
 
		var ac_obj = args[0];
 
		var currentMessage = args[1];
 
		var currentCaretPosition = args[0]._elTextbox.selectionStart;
 

	
 
		var unam = ownerAC.get_mention(currentMessage, currentCaretPosition); 
 
		var curr_search = null;
 
		if(unam[0]){
 
			curr_search = unam[0];
 
		}
 
		
 
		ownerAC.dataSource.chunks = unam[1];
 
		ownerAC.dataSource.mentionQuery = curr_search;
 

	
 
	})
 

	
 
    return {
 
        ownerDS: ownerDS,
 
        ownerAC: ownerAC,
 
    };
 
}
 

	
 

	
 

	
 

	
 
/**
 
 * QUICK REPO MENU
 
 */
 
var quick_repo_menu = function(){
 
    YUE.on(YUQ('.quick_repo_menu'),'mouseenter',function(e){
 
            var menu = e.currentTarget.firstElementChild.firstElementChild;
 
            if(YUD.hasClass(menu,'hidden')){
 
                YUD.replaceClass(e.currentTarget,'hidden', 'active');
 
                YUD.replaceClass(menu, 'hidden', 'active');
 
            }
 
        })
 
    YUE.on(YUQ('.quick_repo_menu'),'mouseleave',function(e){
 
            var menu = e.currentTarget.firstElementChild.firstElementChild;
 
            if(YUD.hasClass(menu,'active')){
 
                YUD.replaceClass(e.currentTarget, 'active', 'hidden');
 
                YUD.replaceClass(menu, 'active', 'hidden');
 
            }
 
        })
 
};
 

	
 

	
 
/**
 
 * TABLE SORTING
 
 */
 

	
 
// returns a node from given html;
 
var fromHTML = function(html){
 
	  var _html = document.createElement('element');
 
	  _html.innerHTML = html;
 
	  return _html;
 
}
 
var get_rev = function(node){
 
    var n = node.firstElementChild.firstElementChild;
 
    
 
    if (n===null){
 
        return -1
 
    }
 
    else{
 
        out = n.firstElementChild.innerHTML.split(':')[0].replace('r','');
 
        return parseInt(out);
 
    }
 
}
 

	
 
var get_name = function(node){
 
	 var name = node.firstElementChild.children[2].innerHTML; 
 
	 return name
 
}

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)