-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
132 lines (118 loc) · 4.01 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* SearchWing LogViewer
Copyright 2022 Friedrich Beckmann
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. */
function readfiles(files) {
if (!is_dataflash(files[0].name))
return;
uploadpage = document.getElementById('uploadpage');
uploadpage.style.display="none";
analyzepage = document.getElementById('analyzepage');
analyzepage.style.display="initial";
reader = new FileReader();
reader.onload = function(event) {
console.log("file open");
buffer = event.target.result;
dv = new DataView(buffer);
lf = new logfile(buffer);
document.logfile = lf;
build_navbar (lf.get_msgitem_list());
var ds = lf.get_data_series("BARO", 0, "Alt");
ds.name = ds.name + ":y";
plot = document.getElementById('plot');
const layout = {
yaxis1: {
side: 'left'
},
yaxis2: {
side: 'left',
overlaying: 'y',
position: 0.15
},
yaxis3: {
side: 'right',
overlaying: 'y',
position: 0.85
},
yaxis4: {
side: 'right',
overlaying: 'y'
}
};
Plotly.newPlot(plot, [ds], layout);
add_trace_to_plotctrl(ds);
const gpsds = lf.get_gps_series();
draw_flight_map(gpsds);
get_overview(gpsds, lf.get_boot_time());
}
reader.readAsArrayBuffer(files[0]);
}
function handle_ondrop(event) {
event.preventDefault();
console.log(event.dataTransfer.files);
readfiles(event.dataTransfer.files);
console.log("Hallo");
};
function handle_dragover(event) {
/* Only when the default handler is prevented, the
element is considered an allowed drop target */
event.dataTransfer.dropEffect = 'copy';
event.preventDefault();
};
function handle_dragenter(event) {
event.preventDefault();
};
function handle_onfilechange(event) {
console.log("File here!" + event.currentTarget.files[0].name);
readfiles(event.currentTarget.files);
}
/** Check the filename ending if this a dataflash file. The
* mimetype does not help here because there is no unique mimetype
* for the dataflash file. So we just check the file extension.
*/
function is_dataflash(fname) {
const fileextension = fname.split(".").pop();
return (fileextension.toLowerCase() == "bin");
}
function on_trace_remove(event) {
plot = document.getElementById('plot');
Plotly.deleteTraces('plot',0);
}
function upload_click(event) {
uploadpage = document.getElementById('uploadpage');
uploadpage.style.display="initial";
analyzepage = document.getElementById('analyzepage');
analyzepage.style.display="none";
}
function on_ulSend() {
let logfile = document.getElementById("fileToUpload").files[0];
let locationname = document.getElementById("ulLocation").value;
console.log("Hallo Click");
const chunksize = 1000000;
let chunknr = 0;
for(let filepos = 0;filepos < logfile.size;filepos += chunksize) {
const chunk = logfile.slice(filepos, filepos + chunksize);
const formData = new FormData();
formData.append("fileToUpload", chunk, logfile.name + chunknr++);
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = state => {console.log("Status", xhr.status); };
xhr.timeout = 5000;
xhr.open("POST", 'upload.php');
xhr.send(formData);
}
}
function on_ulSend_onefile() {
let logfile = document.getElementById("fileToUpload").files[0];
let locationname = document.getElementById("ulLocation").value;
console.log("Hallo Click");
let formData = new FormData();
formData.append("fileToUpload", logfile);
formData.append("location", locationname);
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = state => {console.log("Status", xhr.status); };
xhr.timeout = 5000;
xhr.open("POST", 'upload.php');
xhr.send(formData);
}