Changeset - a33448d81f70
[Not reviewed]
default
0 3 0
Ante Ilic - 11 years ago 2014-09-16 14:44:18
ante@unity3d.com
menu: Added select2 box for "Switch To", work towards having general revision context

Major changes by Takumi IINO <trot.thunder@gmail.com>.
3 files changed with 109 insertions and 19 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/home.py
Show inline comments
 
@@ -130,6 +130,12 @@ class HomeController(BaseController):
 
                'text': _('Branch'),
 
                'children': [{'id': rev, 'text': name, 'type': 'branch'} for name, rev in _branches]
 
            })
 
        _closed_branches = repo.closed_branches.items()
 
        if _closed_branches:
 
            res.append({
 
                'text': _('Closed Branches'),
 
                'children': [{'id': rev, 'text': name, 'type': 'closed-branch'} for name, rev in _closed_branches]
 
            })
 
        _tags = repo.tags.items()
 
        if _tags:
 
            res.append({
kallithea/public/css/contextbar.css
Show inline comments
 
@@ -71,6 +71,10 @@ i[class^='icon-'] {
 
    vertical-align: text-bottom;
 
}
 

	
 
#content #context-bar li span {
 
    margin: 0;
 
}
 

	
 
ul.horizontal-list {
 
    display: block;
 
}
kallithea/templates/base/base.html
Show inline comments
 
@@ -127,20 +127,17 @@
 
      </div>
 
      -->
 
      <ul id="context-pages" class="horizontal-list">
 
        <li ${is_current('summary')}><a href="${h.url('summary_home', repo_name=c.repo_name)}"><i class="icon-doc-text"></i> ${_('Summary')}</a></li>
 
        <li ${is_current('summary')} data-context="summary"><a href="${h.url('summary_home', repo_name=c.repo_name)}"><i class="icon-doc-text"></i> ${_('Summary')}</a></li>
 
        %if rev:
 
        <li ${is_current('changelog')}><a href="${h.url('changelog_file_home', repo_name=c.repo_name, revision=rev, f_path='')}"><i class="icon-clock"></i> ${_('Changelog')}</a></li>
 
        <li ${is_current('changelog')} data-context="changelog"><a href="${h.url('changelog_file_home', repo_name=c.repo_name, revision=rev, f_path='')}"><i class="icon-clock"></i> ${_('Changelog')}</a></li>
 
        %else:
 
        <li ${is_current('changelog')}><a href="${h.url('changelog_home', repo_name=c.repo_name)}"><i class="icon-clock"></i> ${_('Changelog')}</a></li>
 
        <li ${is_current('changelog')} data-context="changelog"><a href="${h.url('changelog_home', repo_name=c.repo_name)}"><i class="icon-clock"></i> ${_('Changelog')}</a></li>
 
        %endif
 
        <li ${is_current('files')}><a href="${h.url('files_home', repo_name=c.repo_name, revision=rev or 'tip')}"><i class="icon-doc-inv"></i> ${_('Files')}</a></li>
 
        <li ${is_current('switch-to')}>
 
          <a href="#" id="branch_tag_switcher_2" class="dropdown"><i class="icon-exchange"></i> ${_('Switch To')}</a>
 
          <ul id="switch_to_list_2" class="switch_to submenu">
 
            <li><a href="#">${_('Loading...')}</a></li>
 
          </ul>
 
        <li ${is_current('files')} data-context="files"><a href="${h.url('files_home', repo_name=c.repo_name, revision=rev or 'tip')}"><i class="icon-doc-inv"></i> ${_('Files')}</a></li>
 
        <li ${is_current('switch-to')} data-context="switch-to">
 
          <input id="branch_switcher" name="branch_switcher" type="hidden">
 
        </li>
 
        <li ${is_current('options')}>
 
        <li ${is_current('options')} data-context="options">
 
             %if h.HasRepoPermissionAll('repository.admin')(c.repo_name):
 
               <a href="${h.url('edit_repo',repo_name=c.repo_name)}" class="dropdown"><i class="icon-wrench"></i> ${_('Options')}</a>
 
             %else:
 
@@ -179,7 +176,7 @@
 
              %endif
 
             </ul>
 
        </li>
 
        <li ${is_current('showpullrequest')}>
 
        <li ${is_current('showpullrequest')} data-context="showpullrequest">
 
          <a href="${h.url('pullrequest_show_all',repo_name=c.repo_name)}" title="${_('Show Pull Requests for %s') % c.repo_name}"> <i class="icon-git-pull-request"></i> ${_('Pull Requests')}
 
            %if c.repository_pull_requests:
 
              <span>${c.repository_pull_requests}</span>
 
@@ -189,15 +186,98 @@
 
      </ul>
 
  </div>
 
  <script type="text/javascript">
 
      YUE.on('branch_tag_switcher_2','mouseover',function(){
 
         var $branch_tag_switcher_2 = $('#branch_tag_switcher_2');
 
         var loaded = $branch_tag_switcher_2.hasClass('loaded');
 
         if(!loaded){
 
             $branch_tag_switcher_2.addClass('loaded');
 
             asynchtml("${h.url('branch_tag_switcher',repo_name=c.repo_name)}", $('#switch_to_list_2'));
 
         }
 
         return false;
 
    $(document).ready(function() {
 
      var bcache = {};
 

	
 
      $("#branch_switcher").select2({
 
          placeholder: '<i class="icon-exchange"></i> ${_('Switch To')}',
 
          dropdownAutoWidth: true,
 
          sortResults: prefixFirstSort,
 
          formatResult: function(obj) {
 
              return obj.text;
 
          },
 
          formatSelection: function(obj) {
 
              return obj.text;
 
          },
 
          formatNoMatches: function(term) {
 
              return "${_('No matches found')}";
 
          },
 
          escapeMarkup: function(m) {
 
              // don't escape our custom placeholder
 
              if (m.substr(0, 29) == '<i class="icon-exchange"></i>') {
 
                  return m;
 
              }
 

	
 
              return Select2.util.escapeMarkup(m);
 
          },
 
          containerCssClass: "repo-switcher",
 
          dropdownCssClass: "repo-switcher-dropdown",
 
          query: function(query) {
 
              var key = 'cache';
 
              var cached = bcache[key];
 
              if (cached) {
 
                  var data = {
 
                      results: []
 
                  };
 
                  // filter results
 
                  $.each(cached.results, function() {
 
                      var section = this.text;
 
                      var children = [];
 
                      $.each(this.children, function() {
 
                          if (query.term.length === 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0) {
 
                              children.push({
 
                                  'id': this.id,
 
                                  'text': this.text,
 
                                  'type': this.type,
 
                                  'obj': this.obj
 
                              });
 
                          }
 
                      });
 
                      if (children.length !== 0) {
 
                          data.results.push({
 
                              'text': section,
 
                              'children': children
 
                          });
 
                      }
 

	
 
                  });
 
                  query.callback(data);
 
              } else {
 
                  $.ajax({
 
                      url: pyroutes.url('repo_refs_data', {
 
                          'repo_name': '${c.repo_name}'
 
                      }),
 
                      data: {},
 
                      dataType: 'json',
 
                      type: 'GET',
 
                      success: function(data) {
 
                          bcache[key] = data;
 
                          query.callback(data);
 
                      }
 
                  });
 
              }
 
          }
 
      });
 

	
 
      $("#branch_switcher").on('select2-selecting', function(e) {
 
          e.preventDefault();
 
          var context = $('#context-bar .current').data('context');
 
          if (context == 'files') {
 
              window.location = pyroutes.url('files_home', {
 
                  'repo_name': REPO_NAME,
 
                  'revision': e.choice.id,
 
                  'f_path': '',
 
                  'at': e.choice.text
 
              });
 
          }
 
          else if(context == 'summary' || context == 'changelog') {
 
              window.location = pyroutes.url('changelog_home', {
 
                  'repo_name': '${c.repo_name}',
 
                  'branch': e.choice.text
 
              });
 
          }
 
      });
 
    });
 
  </script>
 
  <!--- END CONTEXT BAR -->
 
</%def>
0 comments (0 inline, 0 general)