Changeset - 3c720eeaca89
[Not reviewed]
default
0 2 0
Søren Løvborg - 9 years ago 2017-02-10 23:02:57
sorenl@unity3d.com
compare: refactor drop-down UI code

Don't rely on fake ref_names in the controller; instead put the code in
the HTML together with the other UI code.
2 files changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/compare.py
Show inline comments
 
@@ -161,25 +161,25 @@ class CompareController(BaseRepoControll
 
                ancestors = [re.findall(r'[0-9a-fA-F]{40}', so)[0]]
 
            org_changesets = []
 

	
 
        else:
 
            raise Exception('Bad alias only git and hg is allowed')
 

	
 
        return other_changesets, org_changesets, ancestors
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionLevelDecorator('read')
 
    def index(self, repo_name):
 
        c.compare_home = True
 
        c.a_ref_name = c.cs_ref_name = _('Select changeset')
 
        c.a_ref_name = c.cs_ref_name = None
 
        return render('compare/compare_diff.html')
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionLevelDecorator('read')
 
    def compare(self, repo_name, org_ref_type, org_ref_name, other_ref_type, other_ref_name):
 
        org_ref_name = org_ref_name.strip()
 
        other_ref_name = other_ref_name.strip()
 

	
 
        # If merge is True:
 
        #   Show what org would get if merged with other:
 
        #   List changesets that are ancestors of other but not of org.
 
        #   New changesets in org is thus ignored.
kallithea/templates/compare/compare_diff.html
Show inline comments
 
@@ -92,27 +92,27 @@ ${self.repo_context_bar('changelog')}
 
          <h4>${_('Changeset was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}">${_('Show full diff')}</a></h4>
 
        % endif
 
      </div>
 
    %endif
 
    </div>
 

	
 
</div>
 
    <script type="text/javascript">
 

	
 
   $(document).ready(function(){
 
    var cache = {};
 

	
 
    function make_revision_dropdown(css_selector, placeholder, repo_name, cache_key) {
 
    function make_revision_dropdown(css_selector, repo_name, ref_name, cache_key) {
 
      $(css_selector).select2({
 
        placeholder: placeholder,
 
        placeholder: '{0}@{1}'.format(repo_name, ref_name || ${h.jshtml(_('Select changeset'))}),
 
        formatSelection: function(obj){
 
            return '{0}@{1}'.format(repo_name, obj.text);
 
        },
 
        dropdownAutoWidth: true,
 
        maxResults: 50,
 
        query: function(query){
 
          var key = cache_key;
 
          var cached = cache[key] ;
 
          if(cached) {
 
            var data = {results: []};
 
            var queryLower = query.term.toLowerCase();
 
            //filter results
 
@@ -140,26 +140,26 @@ ${self.repo_context_bar('changelog')}
 
                dataType: 'json',
 
                type: 'GET',
 
                success: function(data) {
 
                  cache[key] = data;
 
                  query.callback(data);
 
                }
 
              });
 
          }
 
        }
 
    });
 
    }
 

	
 
    make_revision_dropdown("#compare_org",   ${h.jshtml('%s@%s' % (c.a_repo.repo_name, c.a_ref_name))},   ${h.jshtml(c.a_repo.repo_name)},  'cache');
 
    make_revision_dropdown("#compare_other", ${h.jshtml('%s@%s' % (c.cs_repo.repo_name, c.cs_ref_name))}, ${h.jshtml(c.cs_repo.repo_name)}, 'cache2');
 
    make_revision_dropdown("#compare_org",   ${h.jshtml(c.a_repo.repo_name)},  ${h.jshtml(c.a_ref_name)},  'cache');
 
    make_revision_dropdown("#compare_other", ${h.jshtml(c.cs_repo.repo_name)}, ${h.jshtml(c.cs_ref_name)}, 'cache2');
 

	
 
    var values_changed = function() {
 
        var values = $('#compare_org').select2('data') && $('#compare_other').select2('data');
 
        if (values) {
 
             $('#compare_revs').removeClass("disabled");
 
             // TODO: the swap button ... if any
 
        } else {
 
             $('#compare_revs').addClass("disabled");
 
             // TODO: the swap button ... if any
 
        }
 
    }
 
    values_changed();
0 comments (0 inline, 0 general)