Mercurial > code > home > repos > href
changeset 22:fa55f4439977
fix autocomplete. less console.log
Ignore-this: 302e2080d044221c430c4eb77ccd4221
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Thu, 11 Jul 2013 01:05:22 -0700 |
parents | 8008ec2fd763 |
children | d6a09e8efa56 |
files | lookup.py static/links.js |
diffstat | 2 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/lookup.py Thu Jul 11 00:45:55 2013 -0700 +++ b/lookup.py Thu Jul 11 01:05:22 2013 -0700 @@ -116,11 +116,21 @@ def tagFilterComplete(): params = bottle.request.params haveTags = filter(None, params['have'].split(',')) - return {'tags' : [ - {'id': t['label'], - 'text': "%s (%s%s)" % (t['label'], t['count'], " left" if haveTags else "")} - for t in allTags(params.user, - withTags=haveTags)]} + if haveTags and len(haveTags[-1]) > 0: + haveTags, partialTerm = haveTags[:-1], haveTags[-1] + else: + partialTerm = "" + + out = [] + for t in allTags(params.user, withTags=haveTags): + if partialTerm and partialTerm not in t['label']: + continue + out.append({'id': t['label'], + 'text': "%s (%s%s)" % (t['label'], + t['count'], + " left" if haveTags else "")}) + + return {'tags' : out} @bottle.route('/<user>/') def userSlash(user):
--- a/static/links.js Thu Jul 11 00:45:55 2013 -0700 +++ b/static/links.js Thu Jul 11 01:05:22 2013 -0700 @@ -50,7 +50,6 @@ ko.computed(function () { var tags = model.filterTags(); var newPath = window.location.pathname; - console.log("currently", newPath, toRoot); if (toRoot == ".") { newPath += "/"; toRoot = ".."; @@ -58,7 +57,6 @@ newPath = newPath.replace( /(.*\/)[^\/]*$/, "$1") } - console.log("user root", newPath); if (tags.length) { newPath += tags.join("+") } else { @@ -70,7 +68,6 @@ }); function changePage(newPath) { - console.log("changePage", newPath); if (window.location.pathname != newPath) { window.history.pushState({}, "", newPath); @@ -116,8 +113,13 @@ query: function (opts) { $.ajax({ url: toRoot + "/tags", - data: {user: user, have: opts.element.val()}, + data: {user: user, have: opts.element.val() + "," + opts.term}, success: function (data) { + // I don't want to do this, but select2 gets too slow + var maxRowsInAutocomplete = 300; + if (data.tags.length > maxRowsInAutocomplete) { + data.tags = data.tags.slice(0, maxRowsInAutocomplete); + } opts.callback({results: data.tags}); } });