Changeset - 7a31cb862a58
[Not reviewed]
default
0 4 0
domruf - 8 years ago 2017-08-16 17:34:44
dominikruf@gmail.com
changeset: make parent/child navigation activation and javascript reusable

The javascript code is moved from changeset.html to base.js with minimal
changes. The markup code is moved to base.html.

The parameters ajax url and repo_name are stored as data properties on the link
element.

Use _TM['No revisions'] for translation of text.
4 files changed with 109 insertions and 89 deletions:
0 comments (0 inline, 0 general)
kallithea/public/js/base.js
Show inline comments
 
@@ -1504,3 +1504,85 @@ var updateRowCountCallback = function up
 
        $elem.html(count);
 
    }
 
};
 

	
 

	
 
/**
 
 * activate changeset parent/child navigation links
 
 */
 
var activate_parent_child_links = function(){
 
    //next links
 
    $('#child_link').on('click', function(e){
 
        //fetch via ajax what is going to be the next link, if we have
 
        //>1 links show them to user to choose
 
        if(!$('#child_link').hasClass('disabled')){
 
            $.ajax({
 
                url: $('#child_link').data('ajax-url'),
 
                success: function(data) {
 
                    var repo_name = $('#child_link').data('reponame');
 
                    if(data.results.length === 0){
 
                        $('#child_link').addClass('disabled');
 
                        $('#child_link').text(_TM['No revisions']);
 
                    }
 
                    if(data.results.length === 1){
 
                        var commit = data.results[0];
 
                        window.location = pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': commit.raw_id});
 
                    }
 
                    else if(data.results.length === 2){
 
                        $('#child_link').addClass('disabled');
 
                        $('#child_link').addClass('double');
 
                        var _html = '';
 
                        _html +='<a title="__title__" href="__url__">__rev__</a> <i class="icon-right-open"></i>'
 
                                .replace('__rev__','r{0}:{1}'.format(data.results[0].revision, data.results[0].raw_id.substr(0,6)))
 
                                .replace('__title__', data.results[0].message)
 
                                .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[0].raw_id}));
 
                        _html +='<br/>'
 
                        _html +='<a title="__title__" href="__url__">__rev__</a> <i class="icon-right-open"></i>'
 
                                .replace('__rev__','r{0}:{1}'.format(data.results[1].revision, data.results[1].raw_id.substr(0,6)))
 
                                .replace('__title__', data.results[1].message)
 
                                .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[1].raw_id}));
 
                        $('#child_link').html(_html);
 
                    }
 
                }
 
            });
 
        e.preventDefault();
 
        }
 
    });
 

	
 
    //prev links
 
    $('#parent_link').on('click', function(e){
 
        //fetch via ajax what is going to be the next link, if we have
 
        //>1 links show them to user to choose
 
        if(!$('#parent_link').hasClass('disabled')){
 
            $.ajax({
 
                url: $('#parent_link').data('ajax-url'),
 
                success: function(data) {
 
                    var repo_name = $('#parent_link').data('reponame');
 
                    if(data.results.length === 0){
 
                        $('#parent_link').addClass('disabled');
 
                        $('#parent_link').text(_TM['No revisions']);
 
                    }
 
                    if(data.results.length === 1){
 
                        var commit = data.results[0];
 
                        window.location = pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': commit.raw_id});
 
                    }
 
                    else if(data.results.length === 2){
 
                        $('#parent_link').addClass('disabled');
 
                        $('#parent_link').addClass('double');
 
                        var _html = '';
 
                        _html +='<i class="icon-left-open"></i> <a title="__title__" href="__url__">__rev__</a>'
 
                                .replace('__rev__','r{0}:{1}'.format(data.results[0].revision, data.results[0].raw_id.substr(0,6)))
 
                                .replace('__title__', data.results[0].message)
 
                                .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[0].raw_id}));
 
                        _html +='<br/>'
 
                        _html +='<i class="icon-left-open"></i> <a title="__title__" href="__url__">__rev__</a>'
 
                                .replace('__rev__','r{0}:{1}'.format(data.results[1].revision, data.results[1].raw_id.substr(0,6)))
 
                                .replace('__title__', data.results[1].message)
 
                                .replace('__url__', pyroutes.url('changeset_home', {'repo_name': repo_name, 'revision': data.results[1].raw_id}));
 
                        $('#parent_link').html(_html);
 
                    }
 
                }
 
            });
 
        e.preventDefault();
 
        }
 
    });
 
}
kallithea/templates/base/base.html
Show inline comments
 
@@ -528,3 +528,27 @@
 
        });
 
    </script>
 
</%def>
 

	
 
<%def name="parent_child_navigation()">
 
    <div class="parents pull-left">
 
        <div class="parent_link"
 
             data-ajax-url="${h.url('changeset_parents',repo_name=c.repo_name, revision=c.changeset.raw_id)}"
 
             data-reponame="${c.repo_name}">
 
            <i class="icon-left-open"></i> <a href="#">${_('Parent rev.')}</a>
 
        </div>
 
    </div>
 

	
 
    <div class="children pull-right">
 
        <div class="child_link"
 
             data-ajax-url="${h.url('changeset_children',repo_name=c.repo_name, revision=c.changeset.raw_id)}"
 
             data-reponame="${c.repo_name}">
 
            <a href="#">${_('Child rev.')}</a> <i class="icon-right-open"></i>
 
        </div>
 
    </div>
 

	
 
    <script type="text/javascript">
 
      $(document).ready(function(){
 
          activate_parent_child_links();
 
      });
 
    </script>
 
</%def>
kallithea/templates/base/root.html
Show inline comments
 
@@ -41,6 +41,7 @@
 
                'Selection Link': ${h.jshtml(_('Selection Link'))},
 
                'Collapse Diff': ${h.jshtml(_('Collapse Diff'))},
 
                'Expand Diff': ${h.jshtml(_('Expand Diff'))},
 
                'No revisions': ${h.jshtml(_('No revisions'))},
 
                'Type name of user or member to grant permission': ${h.jshtml(_('Type name of user or member to grant permission'))},
 
                'Failed to revoke permission': ${h.jshtml(_('Failed to revoke permission'))},
 
                'Confirm to revoke permission for {0}: {1} ?': ${h.jshtml(_('Confirm to revoke permission for {0}: {1} ?'))},
 
@@ -102,6 +103,7 @@
 

	
 
              pyroutes.register('toggle_following', ${h.js(h.url('toggle_following'))});
 
              pyroutes.register('changeset_info', ${h.js(h.url('changeset_info', repo_name='%(repo_name)s', revision='%(revision)s'))}, ['repo_name', 'revision']);
 
              pyroutes.register('changeset_home', ${h.js(h.url('changeset_home', repo_name='%(repo_name)s', revision='%(revision)s'))}, ['repo_name', 'revision']);
 
              pyroutes.register('repo_size', ${h.js(h.url('repo_size', repo_name='%(repo_name)s'))}, ['repo_name']);
 
              pyroutes.register('repo_refs_data', ${h.js(h.url('repo_refs_data', repo_name='%(repo_name)s'))}, ['repo_name']);
 
             });
kallithea/templates/changeset/changeset.html
Show inline comments
 
@@ -31,17 +31,7 @@ ${self.repo_context_bar('changelog', c.c
 
  <div class="panel-body">
 
    <div class="panel panel-default">
 
        <div class="panel-heading clearfix">
 
            <div class="parents pull-left">
 
                <div id="parent_link">
 
                    <i class="icon-left-open"></i> <a href="#">${_('Parent rev.')}</a>
 
                </div>
 
            </div>
 

	
 
            <div class="pull-right children">
 
                <div id="child_link">
 
                    <a href="#">${_('Child rev.')}</a> <i class="icon-right-open"></i>
 
                </div>
 
            </div>
 
            ${self.parent_child_navigation()}
 

	
 
            <div class="pull-left">
 
                <div class="pull-left" title="${_('Changeset status')}">
 
@@ -214,84 +204,6 @@ ${self.repo_context_bar('changelog', c.c
 

	
 
          move_comments($(".comments .comments-list-chunk"));
 

	
 
          pyroutes.register('changeset_home',
 
                            ${h.js(h.url('changeset_home', repo_name='%(repo_name)s', revision='%(revision)s'))},
 
                            ['repo_name', 'revision']);
 

	
 
          //next links
 
          $('#child_link').on('click', function(e){
 
              //fetch via ajax what is going to be the next link, if we have
 
              //>1 links show them to user to choose
 
              if(!$('#child_link').hasClass('disabled')){
 
                  $.ajax({
 
                    url: ${h.js(h.url('changeset_children',repo_name=c.repo_name, revision=c.changeset.raw_id))},
 
                    success: function(data) {
 
                      if(data.results.length === 0){
 
                          $('#child_link').addClass('disabled');
 
                          $('#child_link').html(${h.jshtml(_('No revisions'))});
 
                      }
 
                      if(data.results.length === 1){
 
                          var commit = data.results[0];
 
                          window.location = pyroutes.url('changeset_home', {'repo_name': ${h.js(c.repo_name)},'revision': commit.raw_id});
 
                      }
 
                      else if(data.results.length === 2){
 
                          $('#child_link').addClass('disabled');
 
                          $('#child_link').addClass('double');
 
                          var _html = '';
 
                          _html +='<a title="__title__" href="__url__">__rev__</a> <i class="icon-right-open"></i>'
 
                                  .replace('__rev__','r{0}:{1}'.format(data.results[0].revision, data.results[0].raw_id.substr(0,6)))
 
                                  .replace('__title__', data.results[0].message)
 
                                  .replace('__url__', pyroutes.url('changeset_home', {'repo_name': ${h.js(c.repo_name)},'revision': data.results[0].raw_id}));
 
                          _html +='<br/>'
 
                          _html +='<a title="__title__" href="__url__">__rev__</a> <i class="icon-right-open"></i>'
 
                                  .replace('__rev__','r{0}:{1}'.format(data.results[1].revision, data.results[1].raw_id.substr(0,6)))
 
                                  .replace('__title__', data.results[1].message)
 
                                  .replace('__url__', pyroutes.url('changeset_home', {'repo_name': ${h.js(c.repo_name)},'revision': data.results[1].raw_id}));
 
                          $('#child_link').html(_html);
 
                      }
 
                    }
 
                  });
 
              e.preventDefault();
 
              }
 
          });
 

	
 
          //prev links
 
          $('#parent_link').on('click', function(e){
 
              //fetch via ajax what is going to be the next link, if we have
 
              //>1 links show them to user to choose
 
              if(!$('#parent_link').hasClass('disabled')){
 
                  $.ajax({
 
                    url: ${h.js(h.url('changeset_parents',repo_name=c.repo_name, revision=c.changeset.raw_id))},
 
                    success: function(data) {
 
                      if(data.results.length === 0){
 
                          $('#parent_link').addClass('disabled');
 
                          $('#parent_link').html(${h.jshtml(_('No revisions'))});
 
                      }
 
                      if(data.results.length === 1){
 
                          var commit = data.results[0];
 
                          window.location = pyroutes.url('changeset_home', {'repo_name': ${h.js(c.repo_name)},'revision': commit.raw_id});
 
                      }
 
                      else if(data.results.length === 2){
 
                          $('#parent_link').addClass('disabled');
 
                          $('#parent_link').addClass('double');
 
                          var _html = '';
 
                          _html +='<i class="icon-left-open"></i> <a title="__title__" href="__url__">__rev__</a>'
 
                                  .replace('__rev__','r{0}:{1}'.format(data.results[0].revision, data.results[0].raw_id.substr(0,6)))
 
                                  .replace('__title__', data.results[0].message)
 
                                  .replace('__url__', pyroutes.url('changeset_home', {'repo_name': ${h.js(c.repo_name)},'revision': data.results[0].raw_id}));
 
                          _html +='<br/>'
 
                          _html +='<i class="icon-left-open"></i> <a title="__title__" href="__url__">__rev__</a>'
 
                                  .replace('__rev__','r{0}:{1}'.format(data.results[1].revision, data.results[1].raw_id.substr(0,6)))
 
                                  .replace('__title__', data.results[1].message)
 
                                  .replace('__url__', pyroutes.url('changeset_home', {'repo_name': ${h.js(c.repo_name)},'revision': data.results[1].raw_id}));
 
                          $('#parent_link').html(_html);
 
                      }
 
                    }
 
                  });
 
              e.preventDefault();
 
              }
 
          });
 

	
 
          // hack: re-navigate to target after JS is done ... if a target is set and setting href thus won't reload
 
          if (window.location.hash != "") {
 
              window.location.href = window.location.href;
0 comments (0 inline, 0 general)