Commit 4c68da79025a5a0c33714b3c642e96945b972bde
- Diff rendering mode:
- inline
- side by side
fetch.py
(49 / 41)
  | |||
11 | 11 | ||
12 | 12 | @app.route('/',methods=['GET']) | |
13 | 13 | def index(): | |
14 | if request.args.has_key('json'): | ||
15 | return render_template('index.html',json=request.args['json']) | ||
16 | else: | ||
17 | return render_template('index.html') | ||
14 | if request.args.has_key('json'): | ||
15 | return render_template('index.html',json=request.args['json']) | ||
16 | else: | ||
17 | return render_template('index.html') | ||
18 | 18 | ||
19 | 19 | @app.route('/editor', methods=['GET']) | |
20 | 20 | def editor(): | |
… | … | ||
22 | 22 | filename = request.args['json'] | |
23 | 23 | else: | |
24 | 24 | filename = 'test.json' | |
25 | filename = os.path.join('static', filename) | ||
26 | try: | ||
27 | f = open(filename, 'r') | ||
28 | except: | ||
29 | f = open('static/test.json', 'r') | ||
30 | buf = f.read() | ||
31 | f.close() | ||
32 | return render_template('editor.html', json = buf) | ||
25 | filename = os.path.join('static', filename) | ||
26 | try: | ||
27 | f = open(filename, 'r') | ||
28 | except: | ||
29 | f = open('static/test.json', 'r') | ||
30 | buf = f.read() | ||
31 | f.close() | ||
32 | return render_template('editor.html', json = buf) | ||
33 | 33 | ||
34 | 34 | @app.route('/saveJSON', methods=['POST']) | |
35 | 35 | def saveJSON(): | |
36 | if request.form: | ||
37 | data = request.form | ||
38 | JSON = data['json'] | ||
39 | filename = os.path.join('static', data['filename']) | ||
40 | f = open(filename, 'w') | ||
41 | f.write(JSON) | ||
42 | f.close() | ||
43 | return (data, 200) | ||
44 | else: | ||
45 | return (json.dumps(request.form), 200) # Bad Request | ||
36 | if request.method == 'POST': | ||
37 | response = make_response() | ||
38 | JSON = request.form['json'] | ||
39 | filename = os.path.join('static', request.form['filename']) | ||
40 | ls = glob.glob(filename) | ||
41 | if len(ls) > 0: | ||
42 | response.status_code = 409 | ||
43 | response.status ="409 Conflict" | ||
44 | response.data = "The file that you were trying to save already exits, please try a different name." | ||
45 | return response | ||
46 | f = open(filename, 'w') | ||
47 | f.write(JSON) | ||
48 | f.close() | ||
49 | return response | ||
50 | else: | ||
51 | response = make_response() | ||
52 | response.code = 400 | ||
53 | return reponse | ||
46 | 54 | ||
47 | 55 | @app.route('/history', methods=['GET']) | |
48 | 56 | def listJSON(): | |
… | … | ||
58 | 58 | ls = glob.glob(path) | |
59 | 59 | def sanitize(i): | |
60 | 60 | return i.split('/')[-1] | |
61 | ls = map(sanitize, ls) | ||
62 | return render_template('history.html', ls=ls) | ||
61 | ls = map(sanitize, ls) | ||
62 | return render_template('history.html', ls=ls) | ||
63 | 63 | ||
64 | 64 | ||
65 | 65 | if __name__ == "__main__": | |
66 | app.run(debug=True, host='0.0.0.0') | ||
66 | app.run(debug=True, host='0.0.0.0') | ||
67 | 67 | ||
68 | 68 | # #from bson.code import * | |
69 | # #from urllib import unquote_plus | ||
70 | # def application(environ, start_response): | ||
71 | # status = '200 OK' | ||
72 | # response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] | ||
73 | # start_response(status, response_headers) | ||
74 | # c = pymongo.Connection() | ||
75 | # db = c['mural'] | ||
76 | # coll = db['data'] | ||
77 | # ret = {} | ||
78 | # x = 0 | ||
79 | # for i in coll.find(): | ||
80 | # del(i['_id']) | ||
81 | # ret[x] = i | ||
82 | # x = x + 1 | ||
83 | # #return repr(recieved) | ||
84 | # return json.dumps(ret) | ||
69 | # #from urllib import unquote_plus | ||
70 | # def application(environ, start_response): | ||
71 | # status = '200 OK' | ||
72 | # response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] | ||
73 | # start_response(status, response_headers) | ||
74 | # c = pymongo.Connection() | ||
75 | # db = c['mural'] | ||
76 | # coll = db['data'] | ||
77 | # ret = {} | ||
78 | # x = 0 | ||
79 | # for i in coll.find(): | ||
80 | # del(i['_id']) | ||
81 | # ret[x] = i | ||
82 | # x = x + 1 | ||
83 | # #return repr(recieved) | ||
84 | # return json.dumps(ret) |
static/jit.js
(27 / 36)
  | |||
6764 | 6764 | } | |
6765 | 6765 | this.plot() | |
6766 | 6766 | }, | |
6767 | reposition: function() { | ||
6768 | this.compute("end"); | ||
6769 | var w=this.graph.getNode(this.root).pos.getc().scale(-1); | ||
6770 | e.Util.moebiusTransformation(this.graph,[w],["end"],"end","ignore"); | ||
6771 | this.graph.eachNode(function(x) { | ||
6772 | if(x.ignore){ | ||
6773 | x.endPos.rho=x.pos.rho; | ||
6774 | x.endPos.theta=x.pos.theta | ||
6775 | } | ||
6776 | }); | ||
6767 | reposition:function(){ | ||
6768 | this.compute("end"); | ||
6769 | var w=this.graph.getNode(this.root).pos.getc().scale(-1); | ||
6770 | e.Util.moebiusTransformation(this.graph,[w],["end"],"end","ignore"); | ||
6771 | this.graph.eachNode(function(x){ | ||
6772 | if(x.ignore){ | ||
6773 | x.endPos.rho=x.pos.rho; | ||
6774 | x.endPos.theta=x.pos.theta | ||
6775 | } | ||
6776 | }) | ||
6777 | 6777 | }, | |
6778 | plot: function() { | ||
6779 | this.fx.plot(); | ||
6778 | plot:function(){ | ||
6779 | this.fx.plot() | ||
6780 | 6780 | }, | |
6781 | tree_info_template: _.template($('#tree-info-template').html()), | ||
6782 | onClick: function(y, w) { | ||
6783 | // Ajay - Visual target selection | ||
6784 | /*if (this.graph.getNode(y)._angularWidth <= 0.5) { | ||
6785 | if (this.graph.getNode(y).data.band == "Character") { | ||
6786 | $("#character-value").html(this.graph.getNode(y).name); | ||
6787 | } else if (this.graph.getNode(y).data.band == "Jewellery") { | ||
6788 | $("#jewellery-value").html(this.graph.getNode(y).name); | ||
6789 | } else if (this.graph.getNode(y).data.band == "Material") { | ||
6790 | $("#material-value").html(this.graph.getNode(y).name); | ||
6791 | } | ||
6792 | }*/ | ||
6793 | // Ajay - end of visual target selection | ||
6794 | var node = this.graph.getNode(y); | ||
6795 | var children = $jit.json.getSubtree(tree_json, node.id).children; | ||
6796 | if(_.isEmpty(children)) { | ||
6797 | $('#tree-info ul').append(this.tree_info_template({ | ||
6798 | band: node.data.band, | ||
6799 | node: node.name | ||
6800 | })); | ||
6801 | } | ||
6802 | var x = node.pos.getc(true); | ||
6803 | this.move(x, w); | ||
6804 | }, | ||
6781 | onClick:function(y,w){ | ||
6782 | // Ajay - Visual target selection | ||
6783 | if (this.graph.getNode(y)._angularWidth <= 0.5) { | ||
6784 | if (this.graph.getNode(y).data.band == "Character") { | ||
6785 | $("#character-value").html(this.graph.getNode(y).name); | ||
6786 | } else if (this.graph.getNode(y).data.band == "Jewellery") { | ||
6787 | $("#jewellery-value").html(this.graph.getNode(y).name); | ||
6788 | } else if (this.graph.getNode(y).data.band == "Material") { | ||
6789 | $("#material-value").html(this.graph.getNode(y).name); | ||
6790 | } | ||
6791 | } | ||
6792 | // Ajay - end of visual target selection | ||
6793 | var x=this.graph.getNode(y).pos.getc(true); | ||
6794 | this.move(x,w) | ||
6795 | }, | ||
6805 | 6796 | move:function(A,y){ | |
6806 | 6797 | var x=r(A.x,A.y); | |
6807 | 6798 | if(this.busy===false&&x.norm()<0.9){ // Ajay - make it clickable upto the depth of tree DIRECTLY. Increase in value = deeper the length. |
static/myVector.js
(9 / 10)
  | |||
133 | 133 | }; | |
134 | 134 | map = new OpenLayers.Map('map', options); | |
135 | 135 | $.get(config.indexer+"/fetch", function(data){ | |
136 | return; | ||
137 | if (data.length != 0) | ||
138 | { | ||
139 | ans.ans = JSON.parse(data); | ||
140 | for(var i in ans.ans) | ||
141 | { | ||
142 | ans.count+=1; | ||
143 | makeBoxes(ans.ans[i]); | ||
144 | } | ||
136 | if (data != undefined) | ||
137 | { | ||
138 | ans.ans = data; | ||
139 | for(var i in ans.ans) | ||
140 | { | ||
141 | ans.count+=1; | ||
142 | makeBoxes(ans.ans[i]); | ||
143 | } | ||
145 | 144 | ||
146 | } | ||
145 | } | ||
147 | 146 | ||
148 | 147 | }); | |
149 | 148 | var layer = new OpenLayers.Layer.TMS( "TMS Layer","static/", |
templates/editor.html
(1 / 3)
  | |||
41 | 41 | } | |
42 | 42 | try { | |
43 | 43 | json = JSON.parse(json); | |
44 | console.log(json); | ||
45 | console.log(filename); | ||
46 | $.post('/saveJSON', {"json": json, "filename": filename}, function(data) { | ||
44 | $.post('/saveJSON', {"json": JSON.stringify(json), "filename": filename}, function(data) { | ||
47 | 45 | console.log(data); | |
48 | 46 | $('#json-saved').show(); | |
49 | 47 | }, 'json'); |