Commit c9ef076d authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

add 'Import' functionality.

parent 4bb4b06e
......@@ -38,6 +38,12 @@ def front_page():
return redirect(url_for('static', filename='index.html'))
@app.route("/postJSONFile", methods=["POST", "OPTIONS"])
def postJSONFile():
data = json.load(request.files['file'])
app.logger.debug("postJSONFile:%r" % data)
return jsonify(data)
@app.route("/positionGraph", methods=["POST", "OPTIONS"])
def positionGraph():
"""Uses graphviz to position nodes of the graph.
......
......@@ -26,6 +26,9 @@
<a id="layout_graph">Layout Graph</a>
<a id="zoom_in">Zoom +</a>
<a id="zoom_out">Zoom -</a>
<a id="export">Export</a>
<a id="import">Import</a>
<form id="import_form" style="display:none"><input id="import_file" name="file" type="file"></input></form>
</div>
</div>
......
......@@ -439,6 +439,40 @@
dream_instance.zoom_out();
});
// Enable "Export" button
$("#export").button().click(
function (e) {
alert('not yet implemented');
});
// Enable "Import" button
$("#import").button().click(
function (e) {
$('#import_file').click();
});
$("#import_file").change(function() {
var form = $(this).parent('form')[0];
var form_data = new FormData(form);
$.ajax('/postJSONFile', {
type: 'POST',
contentType: false,
processData: false,
data: form_data,
dataType: 'json',
error: function() {
console.log('error');
},
success: function(data, textStatus, jqXHR) {
form.reset();
id_container = {};
dream_instance.clearAll();
$("#json_output").val(JSON.stringify(data));
loadData(data);
}
});
return false;
});
// Redraw if the graph area or the window is resized
$('#main').resizable().resize(function () {
dream_instance.redraw();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment