Added file transfer from web to flask server

This commit is contained in:
Igor Nurullaev
2019-08-28 18:21:02 +03:00
parent 30ea2d6ab3
commit 6c3af9382d
7 changed files with 341 additions and 27 deletions

55
Server/static/js/file.js Normal file
View File

@@ -0,0 +1,55 @@
let animationInput = document.getElementById('animationFile');
let configInput = document.getElementById('configFile');
let arucoInput = document.getElementById('arucoFile');
animationInput.onchange = function (e) {
document.getElementById('animationFileLabel').innerText = animationInput.files[0].name;
};
configInput.onchange = function (e) {
document.getElementById('configFileLabel').innerText = configInput.files[0].name;
};
arucoInput.onchange = function (e) {
document.getElementById('arucoFileLabel').innerText = arucoInput.files[0].name;
};
function sendRows(selectedRows) {
var animationFile = animationInput.files[0];
var configFile = configInput.files[0];
var arucoFile = arucoInput.files[0];
spinner.style.display = 'inline-block';
setTimeout(function () {
selectedRows.forEach(function (element) {
if (animationFile) {
let animReq = new XMLHttpRequest();
let animFormData = new FormData();
animFormData.append("file", animationFile);
animReq.open("POST", '/set/animation?ip=' + element._row.data.ip, false);
animReq.send(animFormData);
}
if (configFile) {
let configReq = new XMLHttpRequest();
let congifFormData = new FormData();
congifFormData.append("file", configFile);
configReq.open("POST", '/set/config?ip=' + element._row.data.ip, false);
configReq.send(congifFormData);
}
if (arucoFile) {
let arucoReq = new XMLHttpRequest();
let arucoFormData = new FormData();
arucoFormData.append("file", arucoFile);
arucoReq.open("POST", '/set/animation?ip=' + element._row.data.ip, false);
arucoReq.send(arucoFormData);
}
element.deselect();
});
spinner.style.display = 'none';
}, 20);
}
function sendSelected() {
sendRows(table.getSelectedRows());
}
function sendAll() {
sendRows(table.getRows());
}

View File

@@ -1,3 +1,4 @@
let spinner = document.getElementById('spinner');
var tabledata = [];
updateData();
@@ -11,6 +12,7 @@ function updateData() {
var table = new Tabulator("#copters-table", {
data: tabledata,
reactiveData: true,
selectable: true,
layout: "fitColumns",
columns: [
{title: "Name", field: "name"},
@@ -22,3 +24,28 @@ var table = new Tabulator("#copters-table", {
{title: "Time", field: "time"},
],
});
function refreshRows(selectedRows) {
spinner.style.display = 'inline-block';
setTimeout(function () {
selectedRows.forEach(function (element) {
let req = new XMLHttpRequest();
req.open('POST', '/selfcheck/selected?ip=' + element._row.data.ip, false);
req.send();
element.deselect();
let response = JSON.parse(req.response);
Object.keys(response).forEach(function (item) {
element._row.data[item] = response[item];
});
});
spinner.style.display = 'none';
}, 20);
}
function refreshSelected() {
refreshRows(table.getSelectedRows());
}
function refreshAll() {
refreshRows(table.getRows());
}