basic file up and download working

This commit is contained in:
Clemens 2016-06-01 23:12:49 +02:00 committed by Maximilian Hils
parent cf544318ae
commit a219d33430
3 changed files with 14 additions and 4 deletions

View File

@ -178,6 +178,7 @@ class DumpFlows(RequestHandler):
sio.close() sio.close()
def post(self): def post(self):
# self.state.clear()
sio = StringIO(self.request.body) sio = StringIO(self.request.body)
self.state.load_flows(FlowReader(sio).stream()) self.state.load_flows(FlowReader(sio).stream())
sio.close() sio.close()

View File

@ -122,7 +122,7 @@ export var FlowActions = {
upload: (file) => { upload: (file) => {
var filereader = new FileReader(); var filereader = new FileReader();
filereader.file = file; filereader.file = file;
filereader.onload = (e) => $.post("/flows/dump", e.target.result); filereader.onload = (e) => {$.post("/flows/dump", e.target.result); e.preventDefault();};
filereader.readAsBinaryString(file); filereader.readAsBinaryString(file);
} }
}; };

View File

@ -344,11 +344,15 @@ var FileMenu = React.createClass({
} }
}, },
handleOpenClick: function (e) { handleOpenClick: function (e) {
$('#uploadFileInput').trigger('click');
e.preventDefault(); e.preventDefault();
}, },
handleOpenChange: function (e) { handleOpenFile: function (e) {
if (e.target.files.length > 0) {
FlowActions.upload(e.target.files[0]);
$('#uploadFileInput').val("");
}
e.preventDefault(); e.preventDefault();
FlowActions.upload(e.target.files[0]);
}, },
handleSaveClick: function (e) { handleSaveClick: function (e) {
e.preventDefault(); e.preventDefault();
@ -372,7 +376,12 @@ var FileMenu = React.createClass({
</a> </a>
</li> </li>
<li> <li>
<input type="file" onChange={this.handleOpenChange}/> <a href="#" onClick={this.handleOpenClick}>
<i className="fa fa-fw fa-folder-open"></i>
Open...
</a>
<input id="uploadFileInput" className="hidden" type="file" onChange={this.handleOpenFile}/>
</li> </li>
<li> <li>
<a href="#" onClick={this.handleSaveClick}> <a href="#" onClick={this.handleSaveClick}>