Changeset - 37c7abd34d44
[Not reviewed]
beta
0 6 1
Marcin Kuzminski - 13 years ago 2012-11-13 22:26:06
marcin@python-works.com
implements #636, lazy loading of history and authors to speed up page responsiveness.
- loading full history is not always needed, and it's very heavy operation. Now this is lazy loaded
when clicking on button
7 files changed with 148 insertions and 86 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -489,96 +489,101 @@ def make_map(config):
 
                 '/{repo_name:.*?}/pull-request/{pull_request_id}',
 
                 controller='pullrequests',
 
                 action='delete', conditions=dict(function=check_repo,
 
                                                method=["DELETE"]))
 

	
 
    rmap.connect('pullrequest_show_all',
 
                 '/{repo_name:.*?}/pull-request',
 
                 controller='pullrequests',
 
                 action='show_all', conditions=dict(function=check_repo,
 
                                                method=["GET"]))
 

	
 
    rmap.connect('pullrequest_comment',
 
                 '/{repo_name:.*?}/pull-request-comment/{pull_request_id}',
 
                 controller='pullrequests',
 
                 action='comment', conditions=dict(function=check_repo,
 
                                                method=["POST"]))
 

	
 
    rmap.connect('pullrequest_comment_delete',
 
                 '/{repo_name:.*?}/pull-request-comment/{comment_id}/delete',
 
                controller='pullrequests', action='delete_comment',
 
                conditions=dict(function=check_repo, method=["DELETE"]))
 

	
 
    rmap.connect('summary_home', '/{repo_name:.*?}/summary',
 
                controller='summary', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('shortlog_home', '/{repo_name:.*?}/shortlog',
 
                controller='shortlog', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('branches_home', '/{repo_name:.*?}/branches',
 
                controller='branches', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('tags_home', '/{repo_name:.*?}/tags',
 
                controller='tags', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('bookmarks_home', '/{repo_name:.*?}/bookmarks',
 
                controller='bookmarks', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('changelog_home', '/{repo_name:.*?}/changelog',
 
                controller='changelog', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('changelog_details', '/{repo_name:.*?}/changelog_details/{cs}',
 
                controller='changelog', action='changelog_details',
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_home', '/{repo_name:.*?}/files/{revision}/{f_path:.*}',
 
                controller='files', revision='tip', f_path='',
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_history_home',
 
                 '/{repo_name:.*?}/history/{revision}/{f_path:.*}',
 
                 controller='files', action='history', revision='tip', f_path='',
 
                 conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_diff_home', '/{repo_name:.*?}/diff/{f_path:.*}',
 
                controller='files', action='diff', revision='tip', f_path='',
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_rawfile_home',
 
                 '/{repo_name:.*?}/rawfile/{revision}/{f_path:.*}',
 
                 controller='files', action='rawfile', revision='tip',
 
                 f_path='', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_raw_home',
 
                 '/{repo_name:.*?}/raw/{revision}/{f_path:.*}',
 
                 controller='files', action='raw', revision='tip', f_path='',
 
                 conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_annotate_home',
 
                 '/{repo_name:.*?}/annotate/{revision}/{f_path:.*}',
 
                 controller='files', action='index', revision='tip',
 
                 f_path='', annotate=True, conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_edit_home',
 
                 '/{repo_name:.*?}/edit/{revision}/{f_path:.*}',
 
                 controller='files', action='edit', revision='tip',
 
                 f_path='', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_add_home',
 
                 '/{repo_name:.*?}/add/{revision}/{f_path:.*}',
 
                 controller='files', action='add', revision='tip',
 
                 f_path='', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_archive_home', '/{repo_name:.*?}/archive/{fname}',
 
                controller='files', action='archivefile',
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('files_nodelist_home',
 
                 '/{repo_name:.*?}/nodelist/{revision}/{f_path:.*}',
 
                controller='files', action='nodelist',
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('repo_settings_delete', '/{repo_name:.*?}/settings',
 
                controller='settings', action="delete",
 
                conditions=dict(method=["DELETE"], function=check_repo))
 

	
 
    rmap.connect('repo_settings_update', '/{repo_name:.*?}/settings',
 
                controller='settings', action="update",
 
                conditions=dict(method=["PUT"], function=check_repo))
 

	
 
    rmap.connect('repo_settings_home', '/{repo_name:.*?}/settings',
 
                controller='settings', action='index',
rhodecode/controllers/files.py
Show inline comments
 
@@ -110,117 +110,138 @@ class FilesController(BaseRepoController
 
            h.flash(str(e), category='warning')
 
            redirect(h.url('files_home', repo_name=repo_name,
 
                           revision=cs.raw_id))
 

	
 
        return file_node
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def index(self, repo_name, revision, f_path, annotate=False):
 
        # redirect to given revision from form if given
 
        post_revision = request.POST.get('at_rev', None)
 
        if post_revision:
 
            cs = self.__get_cs_or_redirect(post_revision, repo_name)
 
            redirect(url('files_home', repo_name=c.repo_name,
 
                         revision=cs.raw_id, f_path=f_path))
 

	
 
        c.changeset = self.__get_cs_or_redirect(revision, repo_name)
 
        c.branch = request.GET.get('branch', None)
 
        c.f_path = f_path
 
        c.annotate = annotate
 
        cur_rev = c.changeset.revision
 

	
 
        # prev link
 
        try:
 
            prev_rev = c.rhodecode_repo.get_changeset(cur_rev).prev(c.branch)
 
            c.url_prev = url('files_home', repo_name=c.repo_name,
 
                         revision=prev_rev.raw_id, f_path=f_path)
 
            if c.branch:
 
                c.url_prev += '?branch=%s' % c.branch
 
        except (ChangesetDoesNotExistError, VCSError):
 
            c.url_prev = '#'
 

	
 
        # next link
 
        try:
 
            next_rev = c.rhodecode_repo.get_changeset(cur_rev).next(c.branch)
 
            c.url_next = url('files_home', repo_name=c.repo_name,
 
                     revision=next_rev.raw_id, f_path=f_path)
 
            if c.branch:
 
                c.url_next += '?branch=%s' % c.branch
 
        except (ChangesetDoesNotExistError, VCSError):
 
            c.url_next = '#'
 

	
 
        # files or dirs
 
        try:
 
            c.file = c.changeset.get_node(f_path)
 

	
 
            if c.file.is_file():
 
                c.file_history, _hist = self._get_node_history(c.changeset, f_path)
 
                c.file_changeset = c.changeset
 
                if _hist:
 
                    c.file_changeset = (c.changeset
 
                                        if c.changeset.revision < _hist[0].revision
 
                                        else _hist[0])
 
                c.load_full_history = False
 
                file_last_cs = c.file.last_changeset
 
                c.file_changeset = (c.changeset
 
                                    if c.changeset.revision < file_last_cs.revision
 
                                    else file_last_cs)
 
                _hist = []
 
                c.file_history = []
 
                if c.load_full_history:
 
                    c.file_history, _hist = self._get_node_history(c.changeset, f_path)
 

	
 
                c.authors = []
 
                for a in set([x.author for x in _hist]):
 
                    c.authors.append((h.email(a), h.person(a)))
 
            else:
 
                c.authors = c.file_history = []
 
        except RepositoryError, e:
 
            h.flash(str(e), category='warning')
 
            redirect(h.url('files_home', repo_name=repo_name,
 
                           revision='tip'))
 

	
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
            return render('files/files_ypjax.html')
 

	
 
        return render('files/files.html')
 

	
 
    def history(self, repo_name, revision, f_path, annotate=False):
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
            c.changeset = self.__get_cs_or_redirect(revision, repo_name)
 
            c.f_path = f_path
 
            c.annotate = annotate
 
            c.file = c.changeset.get_node(f_path)
 
            if c.file.is_file():
 
                file_last_cs = c.file.last_changeset
 
                c.file_changeset = (c.changeset
 
                                    if c.changeset.revision < file_last_cs.revision
 
                                    else file_last_cs)
 
                c.file_history, _hist = self._get_node_history(c.changeset, f_path)
 
                c.authors = []
 
                for a in set([x.author for x in _hist]):
 
                    c.authors.append((h.email(a), h.person(a)))
 
                return render('files/files_history_box.html')
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def rawfile(self, repo_name, revision, f_path):
 
        cs = self.__get_cs_or_redirect(revision, repo_name)
 
        file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
 

	
 
        response.content_disposition = 'attachment; filename=%s' % \
 
            safe_str(f_path.split(Repository.url_sep())[-1])
 

	
 
        response.content_type = file_node.mimetype
 
        return file_node.content
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def raw(self, repo_name, revision, f_path):
 
        cs = self.__get_cs_or_redirect(revision, repo_name)
 
        file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path)
 

	
 
        raw_mimetype_mapping = {
 
            # map original mimetype to a mimetype used for "show as raw"
 
            # you can also provide a content-disposition to override the
 
            # default "attachment" disposition.
 
            # orig_type: (new_type, new_dispo)
 

	
 
            # show images inline:
 
            'image/x-icon': ('image/x-icon', 'inline'),
 
            'image/png': ('image/png', 'inline'),
 
            'image/gif': ('image/gif', 'inline'),
 
            'image/jpeg': ('image/jpeg', 'inline'),
 
            'image/svg+xml': ('image/svg+xml', 'inline'),
 
        }
 

	
 
        mimetype = file_node.mimetype
 
        try:
 
            mimetype, dispo = raw_mimetype_mapping[mimetype]
 
        except KeyError:
 
            # we don't know anything special about this, handle it safely
 
            if file_node.is_binary:
 
                # do same as download raw for binary files
 
                mimetype, dispo = 'application/octet-stream', 'attachment'
 
            else:
 
                # do not just use the original mimetype, but force text/plain,
 
                # otherwise it would serve text/html and that might be unsafe.
 
                # Note: underlying vcs library fakes text/plain mimetype if the
 
                # mimetype can not be determined and it thinks it is not
 
                # binary.This might lead to erroneous text display in some
 
@@ -485,90 +506,93 @@ class FilesController(BaseRepoController
 
                                      context=line_context)
 
            diff = diffs.DiffProcessor(_diff, format='gitdiff')
 

	
 
            diff_name = '%s_vs_%s.diff' % (diff1, diff2)
 
            response.content_type = 'text/plain'
 
            response.content_disposition = (
 
                'attachment; filename=%s' % diff_name
 
            )
 
            return diff.as_raw()
 

	
 
        elif c.action == 'raw':
 
            _diff = diffs.get_gitdiff(node1, node2,
 
                                      ignore_whitespace=ignore_whitespace,
 
                                      context=line_context)
 
            diff = diffs.DiffProcessor(_diff, format='gitdiff')
 
            response.content_type = 'text/plain'
 
            return diff.as_raw()
 

	
 
        else:
 
            fid = h.FID(diff2, node2.path)
 
            line_context_lcl = get_line_ctx(fid, request.GET)
 
            ign_whitespace_lcl = get_ignore_ws(fid, request.GET)
 

	
 
            lim = request.GET.get('fulldiff') or self.cut_off_limit
 
            _, cs1, cs2, diff, st = diffs.wrapped_diff(filenode_old=node1,
 
                                         filenode_new=node2,
 
                                         cut_off_limit=lim,
 
                                         ignore_whitespace=ign_whitespace_lcl,
 
                                         line_context=line_context_lcl,
 
                                         enable_comments=False)
 
            op = ''
 
            filename = node1.path
 
            cs_changes = {
 
                'fid': [cs1, cs2, op, filename, diff, st]
 
            }
 
            c.changes = cs_changes
 

	
 
        return render('files/file_diff.html')
 

	
 
    def _get_node_history(self, cs, f_path, changesets=None):
 
        """
 
        get changesets history for given node
 

	
 
        :param cs: changeset to calculate history
 
        :param f_path: path for node to calculate history for
 
        :param changesets: if passed don't calculate history and take
 
            changesets defined in this list
 
        """
 
        import time
 
        s = time.time()
 
        # calculate history based on tip
 
        tip_cs = c.rhodecode_repo.get_changeset()
 
        if changesets is None:
 
            try:
 
                changesets = tip_cs.get_file_history(f_path)
 
            except (NodeDoesNotExistError, ChangesetError):
 
                #this node is not present at tip !
 
                changesets = cs.get_file_history(f_path)
 

	
 
        print time.time()-s
 
        hist_l = []
 

	
 
        changesets_group = ([], _("Changesets"))
 
        branches_group = ([], _("Branches"))
 
        tags_group = ([], _("Tags"))
 
        _hg = cs.repository.alias == 'hg'
 
        for chs in changesets:
 
            _branch = '(%s)' % chs.branch if _hg else ''
 
            #_branch = '(%s)' % chs.branch if _hg else ''
 
            _branch = chs.branch
 
            n_desc = 'r%s:%s %s' % (chs.revision, chs.short_id, _branch)
 
            changesets_group[0].append((chs.raw_id, n_desc,))
 

	
 
        print time.time()-s
 
        hist_l.append(changesets_group)
 

	
 
        for name, chs in c.rhodecode_repo.branches.items():
 
            branches_group[0].append((chs, name),)
 
        hist_l.append(branches_group)
 

	
 
        for name, chs in c.rhodecode_repo.tags.items():
 
            tags_group[0].append((chs, name),)
 
        hist_l.append(tags_group)
 

	
 
        print time.time()-s
 
        return hist_l, changesets
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    @jsonify
 
    def nodelist(self, repo_name, revision, f_path):
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
            cs = self.__get_cs_or_redirect(revision, repo_name)
 
            _d, _f = ScmModel().get_nodes(repo_name, cs.raw_id, f_path,
 
                                          flat=False)
 
            return {'nodes': _d + _f}
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -906,144 +906,143 @@ var fileBrowserListeners = function(curr
 
		}
 
	 });
 
	YUE.on(n_filter,'keyup',function(e){
 
	    clearTimeout(F.filterTimeout); 
 
	    F.filterTimeout = setTimeout(F.updateFilter(e),600);
 
	});
 
};
 

	
 

	
 
var initCodeMirror = function(textAreadId,resetUrl){  
 
    var myCodeMirror = CodeMirror.fromTextArea(YUD.get(textAreadId),{
 
           mode:  "null",
 
           lineNumbers:true
 
         });
 
    YUE.on('reset','click',function(e){
 
        window.location=resetUrl
 
    });
 
    
 
    YUE.on('file_enable','click',function(){
 
        YUD.setStyle('editor_container','display','');
 
        YUD.setStyle('upload_file_container','display','none');
 
        YUD.setStyle('filename_container','display','');
 
    });
 
    
 
    YUE.on('upload_file_enable','click',function(){
 
        YUD.setStyle('editor_container','display','none');
 
        YUD.setStyle('upload_file_container','display','');
 
        YUD.setStyle('filename_container','display','none');
 
    });	
 
};
 

	
 

	
 

	
 
var getIdentNode = function(n){
 
	//iterate thru nodes untill matched interesting node !
 
	
 
	if (typeof n == 'undefined'){
 
		return -1
 
	}
 
	
 
	if(typeof n.id != "undefined" && n.id.match('L[0-9]+')){
 
			return n
 
		}
 
	else{
 
		return getIdentNode(n.parentNode);
 
	}
 
};
 

	
 
var  getSelectionLink = function(selection_link_label) {
 
	return function(){
 
	    //get selection from start/to nodes    	
 
	    if (typeof window.getSelection != "undefined") {
 
	    	s = window.getSelection();
 
var  getSelectionLink = function(e) {
 
	
 
	//get selection from start/to nodes    	
 
	if (typeof window.getSelection != "undefined") {
 
		s = window.getSelection();
 
	
 
	       	from = getIdentNode(s.anchorNode);
 
	       	till = getIdentNode(s.focusNode);
 
	        
 
	        f_int = parseInt(from.id.replace('L',''));
 
	        t_int = parseInt(till.id.replace('L',''));
 
	        
 
	        if (f_int > t_int){
 
	        	//highlight from bottom 
 
	        	offset = -35;
 
	        	ranges = [t_int,f_int];
 
	        	
 
	   	from = getIdentNode(s.anchorNode);
 
	   	till = getIdentNode(s.focusNode);
 
	   	
 
	    f_int = parseInt(from.id.replace('L',''));
 
	    t_int = parseInt(till.id.replace('L',''));
 
	    
 
	    if (f_int > t_int){
 
	    	//highlight from bottom 
 
	    	offset = -35;
 
	    	ranges = [t_int,f_int];
 
	    	
 
	    }
 
	    else{
 
	    	//highligth from top 
 
	    	offset = 35;
 
	    	ranges = [f_int,t_int];
 
	    }
 
	    
 
	    if (ranges[0] != ranges[1]){
 
	        if(YUD.get('linktt') == null){
 
	            hl_div = document.createElement('div');
 
	            hl_div.id = 'linktt';
 
	        }
 
	        else{
 
	        	//highligth from top 
 
	        	offset = 35;
 
	        	ranges = [f_int,t_int];
 
	        }
 
	        anchor = '#L'+ranges[0]+'-'+ranges[1];
 
	        hl_div.innerHTML = '';
 
	        l = document.createElement('a');
 
	        l.href = location.href.substring(0,location.href.indexOf('#'))+anchor;
 
	        l.innerHTML = _TM['Selection link'];
 
	        hl_div.appendChild(l);
 
	        
 
	        if (ranges[0] != ranges[1]){
 
	            if(YUD.get('linktt') == null){
 
	                hl_div = document.createElement('div');
 
	                hl_div.id = 'linktt';
 
	            }
 
	            anchor = '#L'+ranges[0]+'-'+ranges[1];
 
	            hl_div.innerHTML = '';
 
	            l = document.createElement('a');
 
	            l.href = location.href.substring(0,location.href.indexOf('#'))+anchor;
 
	            l.innerHTML = selection_link_label;
 
	            hl_div.appendChild(l);
 
	            
 
	            YUD.get('body').appendChild(hl_div);
 
	            
 
	            xy = YUD.getXY(till.id);
 
	            
 
	            YUD.addClass('linktt','yui-tt');
 
	            YUD.setStyle('linktt','top',xy[1]+offset+'px');
 
	            YUD.setStyle('linktt','left',xy[0]+'px');
 
	            YUD.setStyle('linktt','visibility','visible');
 
	        }
 
	        else{
 
	        	YUD.setStyle('linktt','visibility','hidden');
 
	        }
 
	        YUD.get('body').appendChild(hl_div);
 
	        
 
	        xy = YUD.getXY(till.id);
 
	        
 
	        YUD.addClass('linktt','yui-tt');
 
	        YUD.setStyle('linktt','top',xy[1]+offset+'px');
 
	        YUD.setStyle('linktt','left',xy[0]+'px');
 
	        YUD.setStyle('linktt','visibility','visible');
 
	    }
 
	    else{
 
	    	YUD.setStyle('linktt','visibility','hidden');
 
	    }
 
	}
 
};
 

	
 
var deleteNotification = function(url, notification_id,callbacks){
 
    var callback = { 
 
		success:function(o){
 
		    var obj = YUD.get(String("notification_"+notification_id));
 
		    if(obj.parentNode !== undefined){
 
				obj.parentNode.removeChild(obj);
 
			}
 
			_run_callbacks(callbacks);
 
		},
 
	    failure:function(o){
 
	        alert("error");
 
	    },
 
	};
 
    var postData = '_method=delete';
 
    var sUrl = url.replace('__NOTIFICATION_ID__',notification_id);
 
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, 
 
    											  callback, postData);
 
};	
 

	
 
var readNotification = function(url, notification_id,callbacks){
 
    var callback = { 
 
		success:function(o){
 
		    var obj = YUD.get(String("notification_"+notification_id));
 
		    YUD.removeClass(obj, 'unread');
 
		    var r_button = YUD.getElementsByClassName('read-notification',null,obj.children[0])[0];
 
		    
 
		    if(r_button.parentNode !== undefined){
 
		    	r_button.parentNode.removeChild(r_button);
 
			}		    
 
			_run_callbacks(callbacks);
 
		},
 
	    failure:function(o){
 
	        alert("error");
 
	    },
 
	};
 
    var postData = '_method=put';
 
    var sUrl = url.replace('__NOTIFICATION_ID__',notification_id);
 
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, 
 
    											  callback, postData);
 
};	
 

	
 
/** MEMBERS AUTOCOMPLETE WIDGET **/
 

	
 
var MembersAutoComplete = function (divid, cont, users_list, groups_list) {
rhodecode/templates/base/root.html
Show inline comments
 
@@ -5,96 +5,97 @@
 
        <title>${self.title()}</title>
 
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
 
        <meta name="robots" content="index, nofollow"/>
 
        <link rel="icon" href="${h.url('/images/icons/database_gear.png')}" type="image/png" />
 

	
 
        ## CSS ###
 
        <%def name="css()">
 
            <link rel="stylesheet" type="text/css" href="${h.url('/css/style.css', ver=c.rhodecode_version)}" media="screen"/>
 
            <link rel="stylesheet" type="text/css" href="${h.url('/css/pygments.css', ver=c.rhodecode_version)}"/>
 
            ## EXTRA FOR CSS
 
            ${self.css_extra()}
 
        </%def>
 
        <%def name="css_extra()">
 
        </%def>
 

	
 
        ${self.css()}
 

	
 
        %if c.ga_code:
 
        <!-- Analytics -->
 
	     <script type="text/javascript">
 
	      var _gaq = _gaq || [];
 
	      _gaq.push(['_setAccount', '${c.ga_code}']);
 
	      _gaq.push(['_trackPageview']);
 

	
 
	      (function() {
 
	        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 
	        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 
	        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 
	      })();
 
	     </script>
 
	    %endif
 

	
 
        ## JAVASCRIPT ##
 
        <%def name="js()">
 
            <script type="text/javascript">
 
            //JS translations map
 
            var TRANSLATION_MAP = {
 
                'add another comment':'${_("add another comment")}',
 
                'Stop following this repository':"${_('Stop following this repository')}",
 
                'Start following this repository':"${_('Start following this repository')}",
 
                'Group':"${_('Group')}",
 
                'members':"${_('members')}",
 
                'loading...':"${_('loading...')}",
 
                'search truncated': "${_('search truncated')}",
 
                'no matching files': "${_('no matching files')}",
 
                'Open new pull request': "${_('Open new pull request')}",
 
                'Open new pull request for selected changesets':  "${_('Open new pull request for selected changesets')}",
 
                'Show selected changes __S -> __E': "${_('Show selected changes __S -> __E')}",
 
                'Selection link': "${_('Selection link')}",
 
            };
 
            var _TM = TRANSLATION_MAP;
 
            </script>
 
            <script type="text/javascript" src="${h.url('/js/yui.2.9.js', ver=c.rhodecode_version)}"></script>
 
            <!--[if lt IE 9]>
 
               <script language="javascript" type="text/javascript" src="${h.url('/js/excanvas.min.js')}"></script>
 
            <![endif]-->
 
            <script type="text/javascript" src="${h.url('/js/yui.flot.js', ver=c.rhodecode_version)}"></script>
 
            <script type="text/javascript" src="${h.url('/js/native.history.js', ver=c.rhodecode_version)}"></script>
 
            <script type="text/javascript" src="${h.url('/js/rhodecode.js', ver=c.rhodecode_version)}"></script>
 
           ## EXTRA FOR JS
 
           ${self.js_extra()}
 

	
 
            <script type="text/javascript">
 
            (function(window,undefined){
 

	
 
                // Prepare
 
                var History = window.History; // Note: We are using a capital H instead of a lower h
 
                if ( !History.enabled ) {
 
                     // History.js is disabled for this browser.
 
                     // This is because we can optionally choose to support HTML4 browsers or not.
 
                    return false;
 
                }
 
            })(window);
 
            var follow_base_url  = "${h.url('toggle_following')}";
 

	
 
            var onSuccessFollow = function(target){
 
                var f = YUD.get(target.id);
 
                var f_cnt = YUD.get('current_followers_count');
 

	
 
                if(f.getAttribute('class')=='follow'){
 
                    f.setAttribute('class','following');
 
                    f.setAttribute('title',_TM['Stop following this repository']);
 

	
 
                    if(f_cnt){
 
                        var cnt = Number(f_cnt.innerHTML)+1;
 
                        f_cnt.innerHTML = cnt;
 
                    }
 
                }
 
                else{
 
                    f.setAttribute('class','follow');
 
                    f.setAttribute('title',_TM['Start following this repository']);
 
                    if(f_cnt){
 
                        var cnt = Number(f_cnt.innerHTML)-1;
 
                        f_cnt.innerHTML = cnt;
 
                    }
 
                }
 
            }
rhodecode/templates/files/files.html
Show inline comments
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('%s files') % c.repo_name} - ${c.rhodecode_name}
 
</%def>
 

	
 
<%def name="breadcrumbs_links()">
 
    ${h.link_to(_(u'Home'),h.url('/'))}
 
    &raquo;
 
    ${h.link_to(c.repo_name,h.url('files_home',repo_name=c.repo_name))}
 
    &raquo;
 
    ${_('files')}
 
    %if c.file:
 
        @ r${c.changeset.revision}:${h.short_id(c.changeset.raw_id)}
 
    %endif
 
</%def>
 

	
 
<%def name="page_nav()">
 
    ${self.menu('files')}
 
</%def>
 

	
 
<%def name="main()">
 
<div class="box">
 
    <!-- box / title -->
 
    <div class="title">
 
        ${self.breadcrumbs()}
 
	    <ul class="links">
 
		    <li>
 
		      <span style="text-transform: uppercase;"><a href="#">${_('branch')}: ${c.changeset.branch}</a></span>
 
	        </li>
 
	    </ul>
 
    </div>
 
    <div class="table">
 
		<div id="files_data">
 
			<%include file='files_ypjax.html'/>
 
		</div>
 
    </div>
 
</div>
 

	
 
<script type="text/javascript">
 
var CACHE = {};
 
var CACHE_EXPIRE = 60*1000; //cache for 60s
 
var CACHE_EXPIRE = 5*60*1000; //cache for 5*60s
 
//used to construct links from the search list
 
var url_base = '${h.url("files_home",repo_name=c.repo_name,revision='__REV__',f_path='__FPATH__')}';
 
//send the nodelist request to this url
 
var node_list_url = '${h.url("files_nodelist_home",repo_name=c.repo_name,revision='__REV__',f_path='__FPATH__')}';
 
// send the node history requst to this url
 
var node_history_url = '${h.url("files_history_home",repo_name=c.repo_name,revision='__REV__',f_path='__FPATH__')}';
 

	
 
var ypjax_links = function(){
 
    YUE.on(YUQ('.ypjax-link'), 'click',function(e){
 

	
 
    	//don't do ypjax on middle click
 
    	if(e.which == 2 || !History.enabled){
 
    		return true;
 
    	}
 

	
 
        var el = e.currentTarget;
 
        var url = el.href;
 

	
 
        var _base_url = '${h.url("files_home",repo_name=c.repo_name,revision='',f_path='')}';
 
        _base_url = _base_url.replace('//','/')
 

	
 
        //extract rev and the f_path from url.
 
        parts = url.split(_base_url)
 
        if(parts.length != 2){
 
        	return false;
 
        }
 

	
 
        var parts2 = parts[1].split('/');
 
      	var rev = parts2.shift(); // pop the first element which is the revision
 
      	var f_path = parts2.join('/');
 

	
 
        var title = "${_('%s files') % c.repo_name}" + " - " + f_path;
 

	
 
        var _node_list_url = node_list_url.replace('__REV__',rev).replace('__FPATH__', f_path);
 
        var _url_base = url_base.replace('__REV__',rev);
 

	
 
        // Change our States and save some data for handling events
 
        var data = {url:url,title:title, url_base:_url_base,
 
                    node_list_url:_node_list_url};
 
                    node_list_url:_node_list_url, rev:rev, f_path:f_path};
 
        History.pushState(data, title, url);
 

	
 
        //now we're sure that we can do ypjax things
 
        YUE.preventDefault(e);
 
        return false;
 
    });
 
}
 

	
 
var callbacks = function(State){
 
    ypjax_links();
 
    tooltip_activate();
 
    fileBrowserListeners(State.url, State.data.node_list_url, State.data.url_base);
 
    YUE.on('hlcode','mouseup',getSelectionLink("${_('Selection link')}"));
 

	
 
    
 
    if(YUD.get('hlcode')){
 
    	YUE.on('hlcode', 'mouseup', getSelectionLink);
 
    }
 
    //console.log(State);
 
    if(YUD.get('load_node_history')){
 
      //remove all listeners due to problems of history state
 
      YUE.removeListener('load_node_history', 'click');
 
      YUE.on('load_node_history', 'click', function(e){
 
          var _url = node_history_url.replace('__REV__',State.data.rev).replace('__FPATH__', State.data.f_path);
 
          ypjax(_url, 'node_history', function(o){})
 
      });
 
    }
 
    // Inform Google Analytics of the change
 
    if ( typeof window.pageTracker !== 'undefined' ) {
 
        window.pageTracker._trackPageview(State.url);
 
    }
 
}
 

	
 
YUE.onDOMReady(function(){
 
    ypjax_links();
 
    var container = 'files_data';
 
    //Bind to StateChange Event
 
    History.Adapter.bind(window,'statechange',function(){
 
        var State = History.getState();
 
        cache_key = State.url;
 
        //check if we have this request in cache maybe ?
 
        var _cache_obj = CACHE[cache_key];
 
        var _cur_time = new Date().getTime();
 
        // get from cache if it's there and not yet expired !
 
        if(_cache_obj !== undefined && _cache_obj[0] > _cur_time){
 
            YUD.get(container).innerHTML=_cache_obj[1];
 
            YUD.setStyle(container,'opacity','1.0');
 

	
 
            //callbacks after ypjax call
 
            callbacks(State);
 
        }
 
        else{
 
          ypjax(State.url,container,function(o){
 
          	//callbacks after ypjax call
 
          	callbacks(State);
 
          	if (o !== undefined){
 
          	  //store our request in cache
 
          	  var _expire_on = new Date().getTime()+CACHE_EXPIRE;
 
              CACHE[cache_key] = [_expire_on, o.responseText];
 
            }
 
          });
 
        }
 
    });
 

	
 
    // init the search filter
 
    var _State = {
 
       url: "${h.url.current()}",
 
       data: {
 
         node_list_url: node_list_url.replace('__REV__',"${c.changeset.raw_id}").replace('__FPATH__', "${h.safe_unicode(c.file.path)}"),
 
         url_base: url_base.replace('__REV__',"${c.changeset.raw_id}")
 
         url_base: url_base.replace('__REV__',"${c.changeset.raw_id}"),
 
         rev:"${c.changeset.raw_id}",
 
         f_path: "${h.safe_unicode(c.file.path)}"
 
       }
 
    }
 
    fileBrowserListeners(_State.url, _State.data.node_list_url, _State.data.url_base);
 
});
 

	
 
</script>
 

	
 
</%def>
rhodecode/templates/files/files_history_box.html
Show inline comments
 
new file 100644
 
<dl>
 
    <dt class="file_history">${_('History')}</dt>
 
    <dd>
 
        <div>
 
            <div style="float:left">
 
            ${h.form(h.url('files_diff_home',repo_name=c.repo_name,f_path=c.f_path),method='get')}
 
            ${h.hidden('diff2',c.file_changeset.raw_id)}
 
            ${h.select('diff1',c.file_changeset.raw_id,c.file_history)}
 
            ${h.submit('diff',_('diff to revision'),class_="ui-btn")}
 
            ${h.submit('show_rev',_('show at revision'),class_="ui-btn")}
 
            ${h.hidden('annotate', c.annotate)}
 
            ${h.end_form()}
 
            </div>
 
            <div class="file_author">
 
                <div class="item">${h.literal(ungettext(u'%s author',u'%s authors',len(c.authors)) % ('<b>%s</b>' % len(c.authors))) }</div>
 
                %for email, user in c.authors:
 
                  <div class="contributor tooltip" style="float:left" title="${h.tooltip(user)}">
 
                    <div class="gravatar" style="margin:1px"><img alt="gravatar" src="${h.gravatar_url(email, 20)}"/> </div>
 
                  </div>
 
                %endfor
 
            </div>
 
        </div>
 
        <div style="clear:both"></div>
 
    </dd>
 
</dl>
 
\ No newline at end of file
rhodecode/templates/files/files_source.html
Show inline comments
 
<dl>
 
	<dt class="file_history">${_('History')}</dt>
 
	<dd>
 
        <div>
 
    		<div style="float:left">
 
    		${h.form(h.url('files_diff_home',repo_name=c.repo_name,f_path=c.f_path),method='get')}
 
    		${h.hidden('diff2',c.file_changeset.raw_id)}
 
    		${h.select('diff1',c.file_changeset.raw_id,c.file_history)}
 
    		${h.submit('diff',_('diff to revision'),class_="ui-btn")}
 
    		${h.submit('show_rev',_('show at revision'),class_="ui-btn")}
 
            ${h.hidden('annotate', c.annotate)}
 
    		${h.end_form()}
 
    		</div>
 
            <div class="file_author">
 
                <div class="item">${h.literal(ungettext(u'%s author',u'%s authors',len(c.authors)) % ('<b>%s</b>' % len(c.authors))) }</div>
 
                %for email, user in c.authors:
 
                  <div class="contributor tooltip" style="float:left" title="${h.tooltip(user)}">
 
                    <div class="gravatar" style="margin:1px"><img alt="gravatar" src="${h.gravatar_url(email, 20)}"/> </div>
 
                  </div>
 
                %endfor
 
            </div>
 
        </div>
 
        <div style="clear:both"></div>
 
	</dd>
 
<div id="node_history">
 
%if c.load_full_history:
 
    <%include file='files_history_box.html'/>
 
%else:
 
    <div style="padding-bottom:10px">
 
        <span id="load_node_history" class="ui-btn">${_('Load file history')}</span>
 
    </div>
 
%endif
 
</div>
 

	
 
</dl>
 

	
 
<div id="body" class="codeblock">
 
	<div class="code-header">
 
        <div class="stats">
 
            <div class="left img"><img src="${h.url('/images/icons/file.png')}"/></div>
 
            <div class="left item"><pre class="tooltip" title="${h.tooltip(h.fmt_date(c.file_changeset.date))}">${h.link_to("r%s:%s" % (c.file_changeset.revision,h.short_id(c.file_changeset.raw_id)),h.url('changeset_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id))}</pre></div>
 
            <div class="left item"><pre>${h.format_byte_size(c.file.size,binary=True)}</pre></div>
 
            <div class="left item last"><pre>${c.file.mimetype}</pre></div>
 
            <div class="buttons">
 
              %if c.annotate:
 
                ${h.link_to(_('show source'),    h.url('files_home',         repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
 
              %else:
 
                ${h.link_to(_('show annotation'),h.url('files_annotate_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
 
              %endif
 
              ${h.link_to(_('show as raw'),h.url('files_raw_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
 
              ${h.link_to(_('download as raw'),h.url('files_rawfile_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
 
              % if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name):
 
               % if not c.file.is_binary:
 
                ${h.link_to(_('edit'),h.url('files_edit_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path),class_="ui-btn")}
 
               % endif
 
              % endif
 
            </div>
 
        </div>
 
        <div class="author">
 
            <div class="gravatar">
 
                <img alt="gravatar" src="${h.gravatar_url(h.email_or_none(c.file_changeset.author),16)}"/>
 
            </div>
 
            <div title="${c.file_changeset.author}" class="user">${h.person(c.file_changeset.author)}</div>
 
        </div>
 
		<div class="commit">${h.urlify_commit(c.file_changeset.message,c.repo_name)}</div>
 
	</div>
 
	<div class="code-body">
 
	   %if c.file.is_binary:
 
	       ${_('Binary file (%s)') % c.file.mimetype}
 
	   %else:
 
		% if c.file.size < c.cut_off_limit:
 
            %if c.annotate:
 
              ${h.pygmentize_annotation(c.repo_name,c.file,linenos=True,anchorlinenos=True,lineanchors='L',cssclass="code-highlight")}
 
            %else:
 
			  ${h.pygmentize(c.file,linenos=True,anchorlinenos=True,lineanchors='L',cssclass="code-highlight")}
 
            %endif
 
		%else:
 
			${_('File is too big to display')} ${h.link_to(_('show as raw'),
 
			h.url('files_raw_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path))}
 
		%endif
 
     %endif
 
	</div>
 
</div>
 

	
 
<script type="text/javascript">
 
YUE.onDOMReady(function(){
 
    function highlight_lines(lines){
 
        for(pos in lines){
 
          YUD.setStyle('L'+lines[pos],'background-color','#FFFFBE');
 
        }
 
    }
 
    page_highlights = location.href.substring(location.href.indexOf('#')+1).split('L');
 
    if (page_highlights.length == 2){
 
       highlight_ranges  = page_highlights[1].split(",");
 

	
 
       var h_lines = [];
 
       for (pos in highlight_ranges){
 
            var _range = highlight_ranges[pos].split('-');
 
            if(_range.length == 2){
 
                var start = parseInt(_range[0]);
 
                var end = parseInt(_range[1]);
 
                if (start < end){
 
                    for(var i=start;i<=end;i++){
 
                        h_lines.push(i);
 
                    }
 
                }
 
            }
 
            else{
 
                h_lines.push(parseInt(highlight_ranges[pos]));
 
            }
 
      }
 
    highlight_lines(h_lines);
 

	
 
    //remember original location
 
    var old_hash  = location.href.substring(location.href.indexOf('#'));
 

	
 
    // this makes a jump to anchor moved by 3 posstions for padding
 
    window.location.hash = '#L'+Math.max(parseInt(h_lines[0])-3,1);
 

	
 
    //sets old anchor
 
    window.location.hash = old_hash;
 

	
 
    }
 

	
 
    YUE.on('hlcode','mouseup',getSelectionLink("${_('Selection link')}"))
 
    // select code link event
 
    YUE.on('hlcode', 'mouseup', getSelectionLink);
 

	
 
    //load history of file
 
    YUE.on('load_node_history', 'click', function(e){
 
        var _url = node_history_url.replace('__REV__','${c.file_changeset.raw_id}').replace('__FPATH__', '${c.f_path}');
 
        ypjax(_url, 'node_history', function(o){})
 
    });    
 

	
 
   });
 
   
 
</script>
0 comments (0 inline, 0 general)