# HG changeset patch # User Drew Perttula # Date 1362640719 28800 # Node ID 93d94f327e8287aa57e83c46c1bcd1eee8873600 # Parent ce779bdd2fb31c1e8da9d3f27a0565cdb67cd579 autocomplete in link page box Ignore-this: 9e2c68e81aaac5dcf25ddbbe6c1f25d6 diff -r ce779bdd2fb3 -r 93d94f327e82 lookup.py --- a/lookup.py Fri Mar 01 01:24:05 2013 -0800 +++ b/lookup.py Wed Mar 06 23:18:39 2013 -0800 @@ -9,6 +9,7 @@ """ import pymongo, bottle, time, urllib, datetime, json, restkit +from collections import defaultdict from urllib2 import urlparse from dateutil.tz import tzlocal from bottle import static_file @@ -32,9 +33,9 @@ username = db['user'].find_one({'_id':agent})['username'] if agent else None return username, agent -@bottle.route('/static/') -def server_static(filename): - return static_file(filename, root='static') +@bottle.route('/static/') +def server_static(path): + return static_file(path, root='static') def recentTags(user, tags=None): out = {'links':[]} @@ -58,6 +59,15 @@ out['stats'] = {'queryTimeMs' : round((time.time() - t1) * 1000, 2)} return out +def allTags(user): + count = defaultdict(lambda: 0) # tag : count + for doc in db['links'].find({'user':user}, fields=['extracted.tags']): + for t in doc.get('extracted', {}).get('tags', []): + count[t] = count[t] + 1 + byFreq = [(n, t) for t,n in count.iteritems()] + byFreq.sort(key=lambda (n,t): (-n, t)) + return [{'label': t, 'count': n} for n, t in byFreq] + def renderWithTime(name, data): t1 = time.time() rendered = renderer.render_name(name, data) @@ -112,13 +122,7 @@ @bottle.route('/', method='GET') def userAll(user): - data = recentTags(user, tags=None) - - data['loginBar'] = getLoginBar() - data['desc'] = "%s's recent links" % user - data['toRoot'] = "." - data['stats']['template'] = 'TEMPLATETIME' - return renderWithTime('links.jade', data) + return userLinks(user, "", toRoot=".") @bottle.route('/', method='POST') def userAddLink(user): @@ -139,12 +143,13 @@ bottle.redirect(siteRoot + '/' + user) @bottle.route('//') -def userLinks(user, tags): +def userLinks(user, tags, toRoot=".."): tags = tags.split('+') data = recentTags(user, tags) data['loginBar'] = getLoginBar() - data['desc'] = "%s's recent links tagged %s" % (user, tags) - data['toRoot'] = ".." + data['desc'] = ("%s's recent links" % user) + (" tagged %s" % (tags,) if tags else "") + data['toRoot'] = toRoot + data['allTags'] = allTags(user) data['pageTags'] = [{"word":t} for t in tags] data['stats']['template'] = 'TEMPLATETIME' diff -r ce779bdd2fb3 -r 93d94f327e82 template/add.jade.mustache --- a/template/add.jade.mustache Fri Mar 01 01:24:05 2013 -0800 +++ b/template/add.jade.mustache Wed Mar 06 23:18:39 2013 -0800 @@ -49,10 +49,18 @@ input(type='text', name='description', data-bind='value: description') div Tags (space-separated): input(type='text', name='tag', data-bind='value: tag') + div Comment: textarea(name='extended', data-bind='value: extended') div Private: ... div Shared: ..? + | type name to autocomplete from bigfoaf service + | bigfoaf-> people ? q= name_or_email_substr + | -> json list of uri, fullname, email, img + | accumulate foaf uris + | upon submit, send msgs to c3po who has to buffer them against resends. + | bigfoaf display should talk to c3po to learn msgs sent from and to this person. + | div button(type='submit', data-bind="text: submitLabel") Add diff -r ce779bdd2fb3 -r 93d94f327e82 template/head.jade.mustache --- a/template/head.jade.mustache Fri Mar 01 01:24:05 2013 -0800 +++ b/template/head.jade.mustache Wed Mar 06 23:18:39 2013 -0800 @@ -1,2 +1,3 @@ meta(name="viewport", content="width=650") +link(rel="stylesheet", href="{{toRoot}}/static/lib/chosen.css") link(rel="stylesheet", href="{{toRoot}}/static/style.css") \ No newline at end of file diff -r ce779bdd2fb3 -r 93d94f327e82 template/links.jade.mustache --- a/template/links.jade.mustache Fri Mar 01 01:24:05 2013 -0800 +++ b/template/links.jade.mustache Wed Mar 06 23:18:39 2013 -0800 @@ -11,11 +11,10 @@ a(href="{{toRoot}}/addLink") Add link | Filter to: - {{#pageTags}} - a.tag(href="{{word}}") {{word}} - | - {{/pageTags}} - input(type="text", id="filterTag") + select#filterTag(multiple='multiple', style='width: 300px', data-bind="selectedOptions: filterTags") + {{#allTags}} + option(value="{{label}}") {{label}} ({{count}}) + {{/allTags}} {{#links}} .link diff -r ce779bdd2fb3 -r 93d94f327e82 template/tail.jade.mustache --- a/template/tail.jade.mustache Fri Mar 01 01:24:05 2013 -0800 +++ b/template/tail.jade.mustache Wed Mar 06 23:18:39 2013 -0800 @@ -1,5 +1,4 @@ script(src='//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js') +script(src='{{toRoot}}/static/lib/chosen-0.9.11.jquery.min.js') +script(src="{{toRoot}}/static/lib/knockout-2.2.0.debug.js") script(src="{{toRoot}}/static/gui.js") -| {{#withKnockout}} -script(src="{{toRoot}}/static/knockout-2.2.0.debug.js") -| {{/withKnockout}} \ No newline at end of file