--- a/fetch.py +++ b/fetch.py @@ -10,6 +10,7 @@ import lxml.html import urllib2 import StringIO +import json app = Flask(__name__) @@ -46,19 +47,15 @@ c = pymongo.Connection() db = c['mural'] coll = db['data'] - try: - for i in d: - coll.insert(request.args['data']) - response = make_response() - response.status = '200 OK' - response.status_code = 200 - return response - except: - response = make_response() - response.status = "500" - response.data = "Your post could not be saved. Try posting again." - return response + for i in request.form['data']: + coll.insert(i) + response = make_response() + response.status = "200 OK" + return response +@app.route('/web', methods=['GET']) +def web(): + return render_template('web.html') @app.route('/SWeeText', methods=['GET']) def SWeeText(): @@ -77,13 +74,40 @@ # inject the JS toolbar to annotate text script = root.makeelement('script') script.set('src', 'static/text-annotation.js') + tree = root.makeelement('script') + tree.set('src', 'static/tree.js') + bs_js = root.makeelement('script') + bs_js.set('src', 'static/bootstrap.js') + jq = root.makeelement('script') + jq.set('src', 'static/jquery-1.9.1.min.js') + jit = root.makeelement('script') + jit.set('src', 'static/jit.js') + us = root.makeelement('script') + us.set('src', 'static/underscore-min-1.4.4.js') + link = root.makeelement('link') 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('type', 'text/css') + bs.set('rel', 'stylesheet') + tree_css = root.makeelement('link') + tree_css.set('href', 'static/tree.css') + tree_css.set('type', 'text/css') + tree_css.set('rel', 'stylesheet') + root.body.append(jq) + root.body.append(bs_js) + root.body.append(jit) + root.body.append(us) + root.body.append(tree) root.body.append(script) + + root.head.append(bs) root.head.append(link) + root.head.append(tree_css) return lxml.html.tostring(root) --- a/static/tree.js +++ b/static/tree.js @@ -111,6 +111,7 @@ event.stopPropagation(); } //Log.write('centering node ', node.name); + console.log('centering node', node.name); RGraph.onClick(node.id, { hideLabels: false, onComplete: function() { @@ -150,12 +151,20 @@ user: user, type: this.type, uri: resource, - top: attribs.top, - bottom: attribs.bottom, - left: attribs.left, - right: attribs.right, nodes: this.nodes, }; + 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; + } + if(attribs.hasOwnProperty('xpath')) { + data.xpath = attribs.xpath; + } this.swts.push(data); this.nodes = []; }, @@ -164,12 +173,28 @@ return; } $('#publish').attr('disabled', 'disabled'); + //$('#posted').show(); + var swts = ''; + for(var i in this.swts) { + var data = this.swts[i]; + 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; + swts += swt + '\n'; + } + $('#sweet').html(swts); + $('#sweeted').show(); $.ajax({ type: 'POST', url: config.indexer + '/submit', - data: {'data': JSON.stringify(this.swts)}, + data: {'data': this.swts}, success: function() { - $.ajax({ + /*$.ajax({ type: 'POST', url: config.postTweetUrl, data: {'data': JSON.stringify(this.swts)}, @@ -180,10 +205,26 @@ error: function() { $('#fail-posting').show(); } - }); + });*/ + $('#posted').show(); + var swts = ''; + for(var i in this.swts) { + var data = this.swts[i]; + 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; + swts += swt + '\n'; + } + $('#sweet').html(swts); + this.swts = []; }, error: function() { - $('#fail-posting').show(); + //$('#fail-posting').show(); } }); } @@ -225,7 +266,7 @@ size: 14 }, interpolation: 'polar', - transition: $jit.Trans.Sine.easeInOut, + transition: $jit.Trans.Sine.easeIn, levelDistance: 150, onCreateLabel: function(domElement, node) { console.log('oncreatelabel'); --- a/templates/index.html +++ b/templates/index.html @@ -70,6 +70,7 @@ +