Mercurial > kallithea
changeset 5579:a33448d81f70
menu: Added select2 box for "Switch To", work towards having general revision context
Major changes by Takumi IINO <trot.thunder@gmail.com>.
author | Ante Ilic <ante@unity3d.com> |
---|---|
date | Tue, 16 Sep 2014 14:44:18 +0200 |
parents | bfde3237d6ad |
children | c6dcda2c9402 |
files | kallithea/controllers/home.py kallithea/public/css/contextbar.css kallithea/templates/base/base.html |
diffstat | 3 files changed, 109 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/home.py Fri Nov 13 00:22:35 2015 +0900 +++ b/kallithea/controllers/home.py Tue Sep 16 14:44:18 2014 +0200 @@ -130,6 +130,12 @@ '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({
--- a/kallithea/public/css/contextbar.css Fri Nov 13 00:22:35 2015 +0900 +++ b/kallithea/public/css/contextbar.css Tue Sep 16 14:44:18 2014 +0200 @@ -71,6 +71,10 @@ vertical-align: text-bottom; } +#content #context-bar li span { + margin: 0; +} + ul.horizontal-list { display: block; }
--- a/kallithea/templates/base/base.html Fri Nov 13 00:22:35 2015 +0900 +++ b/kallithea/templates/base/base.html Tue Sep 16 14:44:18 2014 +0200 @@ -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>