--- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.png *.*~ *.xml +conf.py --- /dev/null +++ b/conf.py.sample @@ -1 +1,2 @@ +SWEET_STORE_URL = 'your sweet store url here' --- a/server.py +++ b/server.py @@ -13,9 +13,14 @@ import json import urllib +import conf +import sweetmaker + app = Flask(__name__) +SWEET_STORE_URL = conf.SWEET_STORE_URL + @app.route('/', methods=['GET']) def index(): if request.args.has_key('url'): @@ -60,15 +65,32 @@ ret = {} keywords_dict = json.loads(request.args['data']) #keywords = json.loads(keywords_dict)['data'] - for i in collection.find(): - for keyword in keywords_dict: + if 'nodes' in keywords_dict: + for i in collection.find(): try: - if keyword in i['nodes']: - del(i['_id']) - ret[y] = i - y = y + 1 + if 'how' in i: + i['nodes'] = i['how'] except: pass + for node in keywords_dict['nodes']: + try: + if node in i['nodes']: + del(i['_id']) + ret[y] = i + y = y + 1 + except: + pass + elif 'where' in keywords_dict: + for i in collection.find({'uri': keywords_dict['where']}): + del(i['_id']) + ret[y] = i + y = y + 1 + for i in collection.find({'where': {'$regex':\ + keywords_dict['where']}}): + del(i['_id']) + ret[y] = i + y = y + 1 + return render_template('blank.html', content = ret) @@ -81,17 +103,26 @@ try: for i in requestData: coll.insert(i) + print 'inserted' + print requestData response = make_response() response.headers['Access-Control-Allow-Origin'] = '*' - response.status = '200 OK' response.status_code = 200 - return response + for i in requestData: + del(i['_id']) + i['how'] = '{concepts: ' + ', '.join(i['how']) + '}' + #i['how'] = attribs + print 'payload for sweet' + print requestData + sweetmaker.sweet(SWEET_STORE_URL, requestData) except: response = make_response() - response.status = "500" + response.status_code = 500 response.data = "Your post could not be saved. Try posting again." - return response + return response + + @app.route('/web/', methods=['GET']) def web(): return render_template('web.html') @@ -116,35 +147,35 @@ # inject the JS toolbar to annotate text jq = root.makeelement('script') - jq.set('src', 'static/jquery-1.9.1.min.js') + jq.set('src', '/static/jquery-1.9.1.min.js') script = root.makeelement('script') - script.set('src', 'static/text-annotation.js') + script.set('src', '/static/text-annotation.js') tree = root.makeelement('script') - tree.set('src', 'static/tree.js') + tree.set('src', '/static/tree.js') bs_js = root.makeelement('script') - bs_js.set('src', 'static/bootstrap.js') + bs_js.set('src', '/static/bootstrap.js') jit = root.makeelement('script') - jit.set('src', 'static/jit.js') + jit.set('src', '/static/jit.js') us = root.makeelement('script') - us.set('src', 'static/underscore-min-1.4.4.js') + us.set('src', '/static/underscore-min-1.4.4.js') link = root.makeelement('link') - link.set('href', 'static/text-annotation.css') + link.set('href', '/static/text-annotation.css') link.set('type', 'text/css') link.set('rel', 'stylesheet') bs = root.makeelement('link') - bs.set('href', 'static/bootstrap.css') + bs.set('href', '/static/bootstrap.css') bs.set('type', 'text/css') bs.set('rel', 'stylesheet') tree_css = root.makeelement('link') - tree_css.set('href', 'static/tree.css') + tree_css.set('href', '/static/tree.css') tree_css.set('type', 'text/css') tree_css.set('rel', 'stylesheet') --- a/static/myVector.js +++ b/static/myVector.js @@ -77,7 +77,7 @@ "test", feature.geometry.getBounds().getCenterLonLat(), new OpenLayers.Size(640,480), - '",null,true); feature.popup = z; z.panMapIfOutOfView = true; map.addPopup(z); --- a/static/text-annotation.js +++ b/static/text-annotation.js @@ -35,6 +35,17 @@ //$(document).mouseover(onHover); //$(document).mouseout(onHoverOut); }; + window.listAnno = function() { // list annotations of current page + console.log('listing annotations'); + $.get(config.indexer + '/search?data=' + + JSON.stringify({'where': window.location.search.split('url=')[1]}), + function(data) { + //console.log(data); + $('#list-anno .modal-body').html(data); + $('#list-anno').modal(); + }); + }; + var removeSelect = function() { var nodes = document.getElementsByTagName('*'); var bar = document.getElementById('annotate-bar'); @@ -56,9 +67,22 @@ '
  • '+ '
  • ' + '
  • '+ + '
  • ' + + '
  • '+ '
  • ' + '' + - '
    '; + '
    '+ + ''; }; var modal_template = function() { --- a/static/tree.js +++ b/static/tree.js @@ -162,23 +162,24 @@ window.location.href; resource = decodeURIComponent(resource).replace('"', '', 'gi'); var data = { - user: user, - type: this.type, - uri: resource, - nodes: this.nodes, + who: user, + what: this.type, + where: resource, + how: this.nodes, name: attribs.name }; if(attribs.hasOwnProperty('top') && attribs.hasOwnProperty('bottom') && attribs.hasOwnProperty('right') && attribs.hasOwnProperty('left')) { - data.top = attribs.top; - data.bottom = attribs.bottom; - data.left = attribs.left; - data.right = attribs.right; + + data.where += '#[' + attribs.top + + ',' + attribs.bottom + + ',' + attribs.left + + ',' + attribs.right + ']'; } if(attribs.hasOwnProperty('xpath')) { - data.xpath = attribs.xpath; + data.where += '#' + attribs.xpath; } this.swts.push(data); this.nodes = []; @@ -193,32 +194,12 @@ url: config.indexer + '/submit', data: {'data': JSON.stringify(this.swts)}, success: function() { - /*$.ajax({ - type: 'POST', - url: config.postTweetUrl, - data: {'data': JSON.stringify(this.swts)}, - success: function() { - $('#posted').show(); - this.swts = []; - }, - error: function() { - $('#fail-posting').show(); - } - });*/ - //$('#posted').html(posted_template()); - //$('#posted').show(); var swts = ''; for(var i in sweet.swts) { var data = sweet.swts[i]; console.log(data); - var swt = '@'+data.user+' '+data.type+' '+data.uri; - if(data.hasOwnProperty('xpath')) { - swt += ' xpath: '+data.xpath; - } - if(data.hasOwnProperty('top')) { - swt += ' #['+data.top+','+data.right+','+data.bottom+','+data.left+']'; - } - swt += ' ' + data.nodes.join(); + var swt = '@'+data.who+' #'+data.what+' / '+data.where; + swt += ' {' + data.how.join() + ' }'; swts += swt + '\n'; } console.log(swts); --- /dev/null +++ b/sweetmaker.py @@ -1 +1,37 @@ +# SwtMaker +# ------- +# Server-side component to make sweets and post them to specified +# sweet store +# +# License: BSD, see LICENSE for more details. +# Servelots 2013 +# Authors: +# Arvind Khadri +# Anon Ray + +import requests +import json +from datetime import datetime + +TIMESTAMP_FORMAT = '%d-%m-%Y %H:%M:%S' + +def sweet(sweet_url, sweet_list): + sweets = makeSweet(sweet_list) + if not sweets: + return False + else: + request = requests.api.post(sweet_url, {'data': json.dumps(sweets)}) + if request.status_code == 200: + return True + else: + return False + +def makeSweet(sweet_list): + for sweet in sweet_list: + if len(sweet['who']) and len(sweet['what']) and len(sweet['where'])\ + and len(sweet['how']): + sweet['created'] = datetime.utcnow().strftime(TIMESTAMP_FORMAT) + else: + return False + return sweet_list --- a/templates/blank.html +++ b/templates/blank.html @@ -1,7 +1,7 @@ {% for obj in content %} -
    +
    {% for key in content[obj].keys() %} -

    {{ key }}: {{ content[obj][key] }}

    +

    {{ key }}: {{ content[obj][key] }}

    {% endfor %}
    {% endfor %} --- a/templates/web.html +++ b/templates/web.html @@ -4,9 +4,9 @@ Web Annotation - - - + + +