Skip to content

Commit 2dc930f

Browse files
committed
fixed sonar duplicated lines
1 parent e6ff51d commit 2dc930f

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

js/main.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -903,47 +903,32 @@ function BlackboxLogViewer() {
903903
reader.readAsText(file);
904904
}
905905

906-
function exportCsv(file, options={}) {
907-
908-
function onSuccess(data) {
909-
console.debug("CSV export finished in", (performance.now() - startTime) / 1000, "secs");
906+
function createExportCallback(fileExtension, fileType, file, startTime) {
907+
const callback = function(data) {
908+
console.debug(`${fileExtension.toUpperCase()} export finished in ${(performance.now() - startTime) / 1000} secs`);
910909
if (!data) {
911910
console.debug("Empty data, nothing to save");
912911
return;
913912
}
914-
let blob = new Blob([data], {type: 'text/csv'}),
913+
let blob = new Blob([data], {type: fileType}),
915914
e = document.createEvent('MouseEvents'),
916915
a = document.createElement('a');
917-
a.download = file || $(".log-filename").text() + ".csv";
916+
a.download = file || $(".log-filename").text() + "." + fileExtension;
918917
a.href = window.URL.createObjectURL(blob);
919-
a.dataset.downloadurl = ['text/csv', a.download, a.href].join(':');
918+
a.dataset.downloadurl = [fileType, a.download, a.href].join(':');
920919
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
921920
a.dispatchEvent(e);
922-
}
921+
}
922+
return callback;
923+
}
923924

924-
let startTime = performance.now();
925+
function exportCsv(file, options={}) {
926+
const onSuccess = createExportCallback('csv', 'text/csv', file, performance.now());
925927
CsvExporter(flightLog, options).dump(onSuccess);
926928
}
927929

928930
function exportGpx(file) {
929-
930-
function onSuccess(data) {
931-
console.debug("Gpx export finished in", (performance.now() - startTime) / 1000, "secs");
932-
if (!data) {
933-
console.debug("Empty data, nothing to save");
934-
return;
935-
}
936-
let blob = new Blob([data], {type: 'GPX File'}),
937-
e = document.createEvent('MouseEvents'),
938-
a = document.createElement('a');
939-
a.download = file || $(".log-filename").text() + ".gpx";
940-
a.href = window.URL.createObjectURL(blob);
941-
a.dataset.downloadurl = ['GPX File', a.download, a.href].join(':');
942-
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
943-
a.dispatchEvent(e);
944-
}
945-
946-
let startTime = performance.now();
931+
const onSuccess = createExportCallback('gpx', 'GPX File', file, performance.now());
947932
GpxExporter(flightLog).dump(onSuccess);
948933
}
949934

js/webworkers/gpx-export-worker.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
importScripts("/node_modules/lodash/lodash.min.js");
22

33
onmessage = function (event) {
4-
const header = `
5-
<?xml version="1.0" encoding="UTF-8"?>
4+
const header = `<?xml version="1.0" encoding="UTF-8"?>
65
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.topografix.com/GPX/gpx_style/0/2 http://www.topografix.com/GPX/gpx_style/0/2/gpx_style.xsd" xmlns:gpx_style="http://www.topografix.com/GPX/gpx_style/0/2"
76
version="1.1"
87
creator="https://github.com/betaflight/blackbox-log-viewer">
@@ -41,20 +40,20 @@ onmessage = function (event) {
4140
let trkpt = `<trkpt lat="${lat}" lon="${lng}">`;
4241
trkpt += `<ele>${altitude}</ele>`;
4342
trkpt += `<time>${date.toISOString()}</time>`;
44-
trkpt += `<speed>${speed}</speed>`;
45-
trkpt += `<degreesType>${groundCourse}</degreesType>`;
46-
trkpt += `<sat>${numSat}</sat>`;
43+
// trkpt += `<speed>${speed}</speed>`;
44+
// trkpt += `<degreesType>${groundCourse}</degreesType>`;
45+
// trkpt += `<sat>${numSat}</sat>`;
4746
trkpt += `</trkpt>\n`;
4847

4948
trkpts += trkpt;
5049
}
5150
}
5251

53-
let trk = `
54-
<trk>
55-
<trkseg>${trkpts}</trkseg>
56-
</trk>
57-
`;
52+
let trk = ` <trk>
53+
<trkseg>
54+
${trkpts}
55+
</trkseg>
56+
</trk>`;
5857

5958
postMessage(header + "\n" + trk + "\n" + footer);
6059
};

0 commit comments

Comments
 (0)