mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-24 08:45:26 +03:00
Fix for Load/Save mission not working (#783)
* Offline missions (with FC disconnected) are now available for load and save to file. Supports XML file format, should be compatible enough with other software * removed default file name * removed code in early stage of future developments * code style and fc buttons * map resize handling * fix include nwdialog and fs packages * xml2js lib with all dependencies in a single file
This commit is contained in:
parent
87f8f73c0a
commit
e1d92bc114
4 changed files with 10662 additions and 12 deletions
|
@ -61,6 +61,8 @@ sources.js = [
|
||||||
'./js/libraries/d3.min.js',
|
'./js/libraries/d3.min.js',
|
||||||
'./js/libraries/jquery.nouislider.all.min.js',
|
'./js/libraries/jquery.nouislider.all.min.js',
|
||||||
'./node_modules/three/three.min.js',
|
'./node_modules/three/three.min.js',
|
||||||
|
'./node_modules/nw-dialog/index.js',
|
||||||
|
'./js/libraries/bundle_xml2js.js',
|
||||||
'./js/libraries/Projector.js',
|
'./js/libraries/Projector.js',
|
||||||
'./js/libraries/CanvasRenderer.js',
|
'./js/libraries/CanvasRenderer.js',
|
||||||
'./js/libraries/jquery.flightindicators.js',
|
'./js/libraries/jquery.flightindicators.js',
|
||||||
|
|
10649
js/libraries/bundle_xml2js.js
Normal file
10649
js/libraries/bundle_xml2js.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -24,6 +24,7 @@
|
||||||
"archiver": "^2.0.3",
|
"archiver": "^2.0.3",
|
||||||
"bluebird": "3.4.1",
|
"bluebird": "3.4.1",
|
||||||
"del": "^3.0.0",
|
"del": "^3.0.0",
|
||||||
|
"fs": "0.0.1-security",
|
||||||
"graceful-fs": "^4.1.15",
|
"graceful-fs": "^4.1.15",
|
||||||
"gulp": "^4.0.0",
|
"gulp": "^4.0.0",
|
||||||
"gulp-concat": "^2.6.1",
|
"gulp-concat": "^2.6.1",
|
||||||
|
|
|
@ -526,18 +526,16 @@ TABS.mission_control.initialize = function (callback) {
|
||||||
$('#loadFileMissionButton').on('click', function () {
|
$('#loadFileMissionButton').on('click', function () {
|
||||||
if (markers.length && !confirm(chrome.i18n.getMessage('confirm_delete_all_points'))) return;
|
if (markers.length && !confirm(chrome.i18n.getMessage('confirm_delete_all_points'))) return;
|
||||||
removeAllPoints();
|
removeAllPoints();
|
||||||
var dialog = require('nw-dialog');
|
nwdialog.setContext(document);
|
||||||
dialog.setContext(document);
|
nwdialog.openFileDialog(function(result) {
|
||||||
dialog.openFileDialog(function(result) {
|
|
||||||
loadMissionFile(result);
|
loadMissionFile(result);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#saveFileMissionButton').on('click', function () {
|
$('#saveFileMissionButton').on('click', function () {
|
||||||
//if (!markers.length) return;
|
//if (!markers.length) return;
|
||||||
var dialog = require('nw-dialog');
|
nwdialog.setContext(document);
|
||||||
dialog.setContext(document);
|
nwdialog.saveFileDialog('', '.mission', function(result) {
|
||||||
dialog.saveFileDialog('', '.mission', function(result) {
|
|
||||||
saveMissionFile(result);
|
saveMissionFile(result);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -616,8 +614,8 @@ TABS.mission_control.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMissionFile(filename) {
|
function loadMissionFile(filename) {
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs');
|
||||||
const xml2js = require('xml2js');
|
if (!window.xml2js) return GUI.log('<span style="color: red">Error reading file (xml2js not found)</span>');
|
||||||
|
|
||||||
fs.readFile(filename, (err, data) => {
|
fs.readFile(filename, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -625,7 +623,7 @@ TABS.mission_control.initialize = function (callback) {
|
||||||
return console.error(err);
|
return console.error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
xml2js.Parser({ 'explicitChildren': true, 'preserveChildrenOrder': true }).parseString(data, (err, result) => {
|
window.xml2js.Parser({ 'explicitChildren': true, 'preserveChildrenOrder': true }).parseString(data, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
GUI.log('<span style="color: red">Error parsing file</span>');
|
GUI.log('<span style="color: red">Error parsing file</span>');
|
||||||
return console.error(err);
|
return console.error(err);
|
||||||
|
@ -739,8 +737,8 @@ TABS.mission_control.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveMissionFile(filename) {
|
function saveMissionFile(filename) {
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs');
|
||||||
const xml2js = require('xml2js');
|
if (!window.xml2js) return GUI.log('<span style="color: red">Error writing file (xml2js not found)</span>');
|
||||||
|
|
||||||
var center = ol.proj.toLonLat(map.getView().getCenter());
|
var center = ol.proj.toLonLat(map.getView().getCenter());
|
||||||
var zoom = map.getView().getZoom();
|
var zoom = map.getView().getZoom();
|
||||||
|
@ -770,7 +768,7 @@ TABS.mission_control.initialize = function (callback) {
|
||||||
data.missionitem.push({ $: { 'no': (markers.length + 1), 'action': 'RTH', 'lon': 0, 'lat': 0, 'alt': (settings.alt / 100), 'parameter1': ($('#rthLanding').is(':checked') ? 1 : 0) } });
|
data.missionitem.push({ $: { 'no': (markers.length + 1), 'action': 'RTH', 'lon': 0, 'lat': 0, 'alt': (settings.alt / 100), 'parameter1': ($('#rthLanding').is(':checked') ? 1 : 0) } });
|
||||||
}
|
}
|
||||||
|
|
||||||
var builder = new xml2js.Builder({ 'rootName': 'mission', 'renderOpts': { 'pretty': true, 'indent': '\t', 'newline': '\n' } });
|
var builder = new window.xml2js.Builder({ 'rootName': 'mission', 'renderOpts': { 'pretty': true, 'indent': '\t', 'newline': '\n' } });
|
||||||
var xml = builder.buildObject(data);
|
var xml = builder.buildObject(data);
|
||||||
fs.writeFile(filename, xml, (err) => {
|
fs.writeFile(filename, xml, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue