Commit c6d359e0d93c019dc8a6c40499d2a570ef951858

Intermediate commit
  • Diff rendering mode:
  • inline
  • side by side

fetch.py

10import lxml.html10import lxml.html
11import urllib211import urllib2
12import StringIO12import StringIO
13import json
1314
14app = Flask(__name__)15app = Flask(__name__)
1516
47 c = pymongo.Connection()47 c = pymongo.Connection()
48 db = c['mural']48 db = c['mural']
49 coll = db['data']49 coll = db['data']
50 try:
51 for i in d:
52 coll.insert(request.args['data'])
53 response = make_response()
54 response.status = '200 OK'
55 response.status_code = 200
56 return response
57 except:
58 response = make_response()
59 response.status = "500"
60 response.data = "Your post could not be saved. Try posting again."
61 return response
50 for i in request.form['data']:
51 coll.insert(i)
52 response = make_response()
53 response.status = "200 OK"
54 return response
6255
56@app.route('/web', methods=['GET'])
57def web():
58 return render_template('web.html')
6359
64@app.route('/SWeeText', methods=['GET'])60@app.route('/SWeeText', methods=['GET'])
65def SWeeText():61def SWeeText():
74 # inject the JS toolbar to annotate text74 # inject the JS toolbar to annotate text
75 script = root.makeelement('script')75 script = root.makeelement('script')
76 script.set('src', 'static/text-annotation.js')76 script.set('src', 'static/text-annotation.js')
77 tree = root.makeelement('script')
78 tree.set('src', 'static/tree.js')
79 bs_js = root.makeelement('script')
80 bs_js.set('src', 'static/bootstrap.js')
81 jq = root.makeelement('script')
82 jq.set('src', 'static/jquery-1.9.1.min.js')
83 jit = root.makeelement('script')
84 jit.set('src', 'static/jit.js')
85 us = root.makeelement('script')
86 us.set('src', 'static/underscore-min-1.4.4.js')
87
77 link = root.makeelement('link')88 link = root.makeelement('link')
78 link.set('href', 'static/text-annotation.css')89 link.set('href', 'static/text-annotation.css')
79 link.set('type', 'text/css')90 link.set('type', 'text/css')
80 link.set('rel', 'stylesheet')91 link.set('rel', 'stylesheet')
92 bs = root.makeelement('link')
93 bs.set('href', 'static/bootstrap.css')
94 bs.set('type', 'text/css')
95 bs.set('rel', 'stylesheet')
96 tree_css = root.makeelement('link')
97 tree_css.set('href', 'static/tree.css')
98 tree_css.set('type', 'text/css')
99 tree_css.set('rel', 'stylesheet')
81100
101 root.body.append(jq)
102 root.body.append(bs_js)
103 root.body.append(jit)
104 root.body.append(us)
105 root.body.append(tree)
82 root.body.append(script)106 root.body.append(script)
107
108 root.head.append(bs)
83 root.head.append(link)109 root.head.append(link)
110 root.head.append(tree_css)
84111
85 return lxml.html.tostring(root)112 return lxml.html.tostring(root)
86113

static/tree.js

111 event.stopPropagation();111 event.stopPropagation();
112 }112 }
113 //Log.write('centering node ', node.name);113 //Log.write('centering node ', node.name);
114 console.log('centering node', node.name);
114 RGraph.onClick(node.id, { 115 RGraph.onClick(node.id, {
115 hideLabels: false, 116 hideLabels: false,
116 onComplete: function() { 117 onComplete: function() {
151 user: user,151 user: user,
152 type: this.type,152 type: this.type,
153 uri: resource,153 uri: resource,
154 top: attribs.top,
155 bottom: attribs.bottom,
156 left: attribs.left,
157 right: attribs.right,
158 nodes: this.nodes,154 nodes: this.nodes,
159 };155 };
156 if(attribs.hasOwnProperty('top') &&
157 attribs.hasOwnProperty('bottom') &&
158 attribs.hasOwnProperty('right') &&
159 attribs.hasOwnProperty('left')) {
160 data.top = attribs.top;
161 data.bottom = attribs.bottom;
162 data.left = attribs.left;
163 data.right = attribs.right;
164 }
165 if(attribs.hasOwnProperty('xpath')) {
166 data.xpath = attribs.xpath;
167 }
160 this.swts.push(data);168 this.swts.push(data);
161 this.nodes = [];169 this.nodes = [];
162 },170 },
173 return;173 return;
174 }174 }
175 $('#publish').attr('disabled', 'disabled');175 $('#publish').attr('disabled', 'disabled');
176 //$('#posted').show();
177 var swts = '';
178 for(var i in this.swts) {
179 var data = this.swts[i];
180 var swt = '@'+data.user+' '+data.type+' '+data.uri;
181 if(data.hasOwnProperty('xpath')) {
182 swt += ' xpath: '+data.xpath;
183 }
184 if(data.hasOwnProperty('top')) {
185 swt += ' #['+data.top+','+data.right+','+data.bottom+','+data.left+']';
186 }
187 swt += ' ' + data.nodes;
188 swts += swt + '\n';
189 }
190 $('#sweet').html(swts);
191 $('#sweeted').show();
176 $.ajax({192 $.ajax({
177 type: 'POST',193 type: 'POST',
178 url: config.indexer + '/submit',194 url: config.indexer + '/submit',
179 data: {'data': JSON.stringify(this.swts)},
195 data: {'data': this.swts},
180 success: function() {196 success: function() {
181 $.ajax({
197 /*$.ajax({
182 type: 'POST',198 type: 'POST',
183 url: config.postTweetUrl,199 url: config.postTweetUrl,
184 data: {'data': JSON.stringify(this.swts)},200 data: {'data': JSON.stringify(this.swts)},
205 error: function() {205 error: function() {
206 $('#fail-posting').show();206 $('#fail-posting').show();
207 }207 }
208 });
208 });*/
209 $('#posted').show();
210 var swts = '';
211 for(var i in this.swts) {
212 var data = this.swts[i];
213 var swt = '@'+data.user+' '+data.type+' '+data.uri;
214 if(data.hasOwnProperty('xpath')) {
215 swt += ' xpath: '+data.xpath;
216 }
217 if(data.hasOwnProperty('top')) {
218 swt += ' #['+data.top+','+data.right+','+data.bottom+','+data.left+']';
219 }
220 swt += ' ' + data.nodes;
221 swts += swt + '\n';
222 }
223 $('#sweet').html(swts);
224 this.swts = [];
209 },225 },
210 error: function() {226 error: function() {
211 $('#fail-posting').show();
227 //$('#fail-posting').show();
212 }228 }
213 });229 });
214 }230 }
266 size: 14266 size: 14
267 },267 },
268 interpolation: 'polar',268 interpolation: 'polar',
269 transition: $jit.Trans.Sine.easeInOut,
269 transition: $jit.Trans.Sine.easeIn,
270 levelDistance: 150,270 levelDistance: 150,
271 onCreateLabel: function(domElement, node) {271 onCreateLabel: function(domElement, node) {
272 console.log('oncreatelabel');272 console.log('oncreatelabel');

templates/index.html

70 <!-- PLEASE, LET THIS NOTE ABOUT AUTHOR AND PROJECT SOMEWHERE ON YOUR WEBSITE, OR AT LEAST IN THE COMMENT IN HTML. THANK YOU -->70 <!-- PLEASE, LET THIS NOTE ABOUT AUTHOR AND PROJECT SOMEWHERE ON YOUR WEBSITE, OR AT LEAST IN THE COMMENT IN HTML. THANK YOU -->
71 </div>71 </div>
7272
73 </div>
73 </div>74 </div>
7475
75 <script type="text/javascript" >resize();</script>76 <script type="text/javascript" >resize();</script>