--- a/fetch.py +++ b/fetch.py @@ -11,10 +11,10 @@ @app.route('/',methods=['GET']) def index(): - if request.args.has_key('json'): - return render_template('index.html',json=request.args['json']) - else: - return render_template('index.html') + if request.args.has_key('json'): + return render_template('index.html',json=request.args['json']) + else: + return render_template('index.html') @app.route('/editor', methods=['GET']) def editor(): @@ -22,27 +22,35 @@ filename = request.args['json'] else: filename = 'test.json' - filename = os.path.join('static', filename) - try: - f = open(filename, 'r') - except: - f = open('static/test.json', 'r') - buf = f.read() - f.close() - return render_template('editor.html', json = buf) + filename = os.path.join('static', filename) + try: + f = open(filename, 'r') + except: + f = open('static/test.json', 'r') + buf = f.read() + f.close() + return render_template('editor.html', json = buf) @app.route('/saveJSON', methods=['POST']) def saveJSON(): - if request.form: - data = request.form - JSON = data['json'] - filename = os.path.join('static', data['filename']) - f = open(filename, 'w') - f.write(JSON) - f.close() - return (data, 200) - else: - return (json.dumps(request.form), 200) # Bad Request + if request.method == 'POST': + response = make_response() + JSON = request.form['json'] + filename = os.path.join('static', request.form['filename']) + ls = glob.glob(filename) + if len(ls) > 0: + response.status_code = 409 + response.status ="409 Conflict" + response.data = "The file that you were trying to save already exits, please try a different name." + return response + f = open(filename, 'w') + f.write(JSON) + f.close() + return response + else: + response = make_response() + response.code = 400 + return reponse @app.route('/history', methods=['GET']) def listJSON(): @@ -50,28 +58,28 @@ ls = glob.glob(path) def sanitize(i): return i.split('/')[-1] - ls = map(sanitize, ls) - return render_template('history.html', ls=ls) + ls = map(sanitize, ls) + return render_template('history.html', ls=ls) if __name__ == "__main__": - app.run(debug=True, host='0.0.0.0') + app.run(debug=True, host='0.0.0.0') # #from bson.code import * -# #from urllib import unquote_plus -# def application(environ, start_response): -# status = '200 OK' -# response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] -# start_response(status, response_headers) -# c = pymongo.Connection() -# db = c['mural'] -# coll = db['data'] -# ret = {} -# x = 0 -# for i in coll.find(): -# del(i['_id']) -# ret[x] = i -# x = x + 1 -# #return repr(recieved) -# return json.dumps(ret) + # #from urllib import unquote_plus + # def application(environ, start_response): + # status = '200 OK' + # response_headers = [('Content-type', 'application/json'),('Access-Control-Allow-Origin', '*')] + # start_response(status, response_headers) + # c = pymongo.Connection() + # db = c['mural'] + # coll = db['data'] + # ret = {} + # x = 0 + # for i in coll.find(): + # del(i['_id']) + # ret[x] = i + # x = x + 1 + # #return repr(recieved) + # return json.dumps(ret) --- a/static/jit.js +++ b/static/jit.js @@ -6764,44 +6764,35 @@ } this.plot() }, - reposition: function() { - this.compute("end"); - var w=this.graph.getNode(this.root).pos.getc().scale(-1); - e.Util.moebiusTransformation(this.graph,[w],["end"],"end","ignore"); - this.graph.eachNode(function(x) { - if(x.ignore){ - x.endPos.rho=x.pos.rho; - x.endPos.theta=x.pos.theta - } - }); + reposition:function(){ + this.compute("end"); + var w=this.graph.getNode(this.root).pos.getc().scale(-1); + e.Util.moebiusTransformation(this.graph,[w],["end"],"end","ignore"); + this.graph.eachNode(function(x){ + if(x.ignore){ + x.endPos.rho=x.pos.rho; + x.endPos.theta=x.pos.theta + } + }) }, - plot: function() { - this.fx.plot(); + plot:function(){ + this.fx.plot() }, - tree_info_template: _.template($('#tree-info-template').html()), - onClick: function(y, w) { - // Ajay - Visual target selection - /*if (this.graph.getNode(y)._angularWidth <= 0.5) { - if (this.graph.getNode(y).data.band == "Character") { - $("#character-value").html(this.graph.getNode(y).name); - } else if (this.graph.getNode(y).data.band == "Jewellery") { - $("#jewellery-value").html(this.graph.getNode(y).name); - } else if (this.graph.getNode(y).data.band == "Material") { - $("#material-value").html(this.graph.getNode(y).name); - } - }*/ - // Ajay - end of visual target selection - var node = this.graph.getNode(y); - var children = $jit.json.getSubtree(tree_json, node.id).children; - if(_.isEmpty(children)) { - $('#tree-info ul').append(this.tree_info_template({ - band: node.data.band, - node: node.name - })); - } - var x = node.pos.getc(true); - this.move(x, w); - }, + onClick:function(y,w){ +// Ajay - Visual target selection + if (this.graph.getNode(y)._angularWidth <= 0.5) { + if (this.graph.getNode(y).data.band == "Character") { + $("#character-value").html(this.graph.getNode(y).name); + } else if (this.graph.getNode(y).data.band == "Jewellery") { + $("#jewellery-value").html(this.graph.getNode(y).name); + } else if (this.graph.getNode(y).data.band == "Material") { + $("#material-value").html(this.graph.getNode(y).name); + } + } +// Ajay - end of visual target selection + var x=this.graph.getNode(y).pos.getc(true); + this.move(x,w) + }, move:function(A,y){ var x=r(A.x,A.y); if(this.busy===false&&x.norm()<0.9){ // Ajay - make it clickable upto the depth of tree DIRECTLY. Increase in value = deeper the length. --- a/static/myVector.js +++ b/static/myVector.js @@ -133,17 +133,16 @@ }; map = new OpenLayers.Map('map', options); $.get(config.indexer+"/fetch", function(data){ - return; - if (data.length != 0) - { - ans.ans = JSON.parse(data); - for(var i in ans.ans) - { - ans.count+=1; - makeBoxes(ans.ans[i]); - } + if (data != undefined) + { + ans.ans = data; + for(var i in ans.ans) + { + ans.count+=1; + makeBoxes(ans.ans[i]); + } - } + } }); var layer = new OpenLayers.Layer.TMS( "TMS Layer","static/", --- a/templates/editor.html +++ b/templates/editor.html @@ -41,9 +41,7 @@ } try { json = JSON.parse(json); - console.log(json); - console.log(filename); - $.post('/saveJSON', {"json": json, "filename": filename}, function(data) { + $.post('/saveJSON', {"json": JSON.stringify(json), "filename": filename}, function(data) { console.log(data); $('#json-saved').show(); }, 'json');