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
 
@@ -109,41 +109,47 @@ class HomeController(BaseController):
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def branch_tag_switcher(self, repo_name):
 
        if request.is_xhr:
 
            c.db_repo = Repository.get_by_repo_name(repo_name)
 
            if c.db_repo:
 
                c.db_repo_scm_instance = c.db_repo.scm_instance
 
                return render('/switch_to_list.html')
 
        raise HTTPBadRequest()
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    @jsonify
 
    def repo_refs_data(self, repo_name):
 
        repo = Repository.get_by_repo_name(repo_name).scm_instance
 
        res = []
 
        _branches = repo.branches.items()
 
        if _branches:
 
            res.append({
 
                '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({
 
                'text': _('Tag'),
 
                'children': [{'id': rev, 'text': name, 'type': 'tag'} for name, rev in _tags]
 
            })
 
        _bookmarks = repo.bookmarks.items()
 
        if _bookmarks:
 
            res.append({
 
                'text': _('Bookmark'),
 
                'children': [{'id': rev, 'text': name, 'type': 'book'} for name, rev in _bookmarks]
 
            })
 
        data = {
 
            'more': False,
 
            'results': res
 
        }
 
        return data
kallithea/public/css/contextbar.css
Show inline comments
 
@@ -50,48 +50,52 @@ i[class^='icon-'] {
 

	
 
#content #context-bar h2 {
 
    display: inline-block;
 
    color: #FFF;
 
}
 

	
 
#header #header-inner #quick a,
 
#content #context-bar,
 
#content #context-bar a {
 
    color: #FFFFFF;
 
}
 

	
 
#header #header-inner #quick a:hover,
 
#content #context-bar a:hover {
 
    text-decoration: none;
 
}
 

	
 
#content #context-bar .icon {
 
    display: inline-block;
 
    width: 16px;
 
    height: 16px;
 
    vertical-align: text-bottom;
 
}
 

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

	
 
ul.horizontal-list {
 
    display: block;
 
}
 

	
 
ul.horizontal-list > li {
 
    float: left;
 
    position: relative;
 
}
 

	
 
#header #header-inner #quick ul,
 
ul.horizontal-list > li ul {
 
    position: absolute;
 
    display: none;
 
    right: 0;
 
    z-index: 999;
 
}
 

	
 
#header #header-inner #quick li:hover > ul,
 
ul.horizontal-list li:hover > ul {
 
    display: block;
 
}
 

	
 
#header #header-inner #quick li ul li,
 
ul.horizontal-list ul li {
kallithea/templates/base/base.html
Show inline comments
 
@@ -106,119 +106,199 @@
 
  <div id="context-bar" class="box">
 
      <h2>
 
        ${repotag(c.db_repo)}
 

	
 
        ## public/private
 
        %if c.db_repo.private:
 
          <i class="icon-keyhole-circled"></i>
 
        %else:
 
          <i class="icon-globe"></i>
 
        %endif
 
        ${h.repo_link(c.db_repo.groups_and_repo)}
 

	
 
        %if current == 'createfork':
 
         - ${_('Create Fork')}
 
        %endif
 
      </h2>
 
      <!--
 
      <div id="breadcrumbs">
 
        ${h.link_to(_('Repositories'),h.url('home'))}
 
        &raquo;
 
        ${h.repo_link(c.db_repo.groups_and_repo)}
 
      </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:
 
               <a href="#" class="dropdown"><i class="icon-wrench"></i> ${_('Options')}</a>
 
             %endif
 
          <ul>
 
             %if h.HasRepoPermissionAll('repository.admin')(c.repo_name):
 
                   <li><a href="${h.url('edit_repo',repo_name=c.repo_name)}"><i class="icon-gear"></i> ${_('Settings')}</a></li>
 
             %endif
 
              %if c.db_repo.fork:
 
               <li><a href="${h.url('compare_url',repo_name=c.db_repo.fork.repo_name,org_ref_type=c.db_repo.landing_rev[0],org_ref_name=c.db_repo.landing_rev[1], other_repo=c.repo_name,other_ref_type='branch' if request.GET.get('branch') else c.db_repo.landing_rev[0],other_ref_name=request.GET.get('branch') or c.db_repo.landing_rev[1], merge=1)}">
 
                   <i class="icon-git-compare"></i> ${_('Compare Fork')}</a></li>
 
              %endif
 
              <li><a href="${h.url('compare_home',repo_name=c.repo_name)}"><i class="icon-git-compare"></i> ${_('Compare')}</a></li>
 

	
 
              <li><a href="${h.url('search_repo',repo_name=c.repo_name)}"><i class="icon-search"></i> ${_('Search')}</a></li>
 

	
 
              %if h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name) and c.db_repo.enable_locking:
 
                %if c.db_repo.locked[0]:
 
                  <li><a href="${h.url('toggle_locking', repo_name=c.repo_name)}"><i class="icon-lock"></i> ${_('Unlock')}</a></li>
 
                %else:
 
                  <li><a href="${h.url('toggle_locking', repo_name=c.repo_name)}"><i class="icon-lock-open-alt"></i> ${_('Lock')}</li>
 
                %endif
 
              %endif
 
              ## TODO: this check feels wrong, it would be better to have a check for permissions
 
              ## also it feels like a job for the controller
 
              %if c.authuser.username != 'default':
 
                  <li>
 
                   <a class="${'following' if c.repository_following else 'follow'}" onclick="toggleFollowingRepo(this, ${c.db_repo.repo_id});">
 
                    <span class="show-follow"><i class="icon-heart-empty"></i> ${_('Follow')}</span>
 
                    <span class="show-following"><i class="icon-heart"></i> ${_('Unfollow')}</span>
 
                   </a>
 
                  </li>
 
                  <li><a href="${h.url('repo_fork_home',repo_name=c.repo_name)}"><i class="icon-git-pull-request"></i> ${_('Fork')}</a></li>
 
                  <li><a href="${h.url('pullrequest_home',repo_name=c.repo_name)}"><i class="icon-git-pull-request"></i> ${_('Create Pull Request')}</a></li>
 
              %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>
 
            %endif
 
          </a>
 
        </li>
 
      </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>
 

	
 
<%def name="menu(current=None)">
 
  <%
 
  def is_current(selected):
 
      if selected == current:
 
          return h.literal('class="current"')
 
  %>
 

	
 
  <ul id="quick" class="horizontal-list">
 
    <!-- repo switcher -->
 
    <li ${is_current('repositories')}>
 
      <input id="repo_switcher" name="repo_switcher" type="hidden">
 
    </li>
 

	
 
    ##ROOT MENU
 
    %if c.authuser.username != 'default':
 
      <li ${is_current('journal')}>
 
        <a class="menu_link" title="${_('Show recent activity')}"  href="${h.url('journal')}">
 
          <i class="icon-book"></i> ${_('Journal')}
 
        </a>
 
      </li>
0 comments (0 inline, 0 general)