diff --git a/package-lock.json b/package-lock.json index 540d6a9..a94f034 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "flightgear-airports", - "version": "0.0.27", + "version": "0.0.28", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3479d04..e0db463 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ "coordinate-parser": "^1.0.3", "dijkstrajs": "^1.0.1", "electron-debug": "^3.0.1", - "element-ui": "^2.13.2", + "element-ui": "^2.14.1", "file-url": "^3.0.0", "fs": "0.0.1-security", "fs-extra": "^9.0.1", diff --git a/src/renderer/components/EditBar.vue b/src/renderer/components/EditBar.vue index a85c8d1..f4aa8d6 100644 --- a/src/renderer/components/EditBar.vue +++ b/src/renderer/components/EditBar.vue @@ -11,32 +11,84 @@ You should have received a copy of the GNU General Public License along with FG --> @@ -76,6 +128,8 @@ You should have received a copy of the GNU General Public License along with FG const fs = require('fs'); const mapper = require('../check/mapper'); + import {listSaves} from '../loaders/groundnet_loader' + import EditButton from './EditButton' import ZoomButton from './ZoomButton'; import Vue from 'vue' @@ -85,11 +139,14 @@ You should have received a copy of the GNU General Public License along with FG export default { components: { EditButton, ZoomButton }, data () { - return {isEditing: false, uploadVisible: false, centerDialogVisible: false, saveDialogVisible: false, checkDialogVisible: false, checking: false, progress: 0, max: 0, pavementLayerVisible: true} + return {isEditing: false, uploadVisible: false, centerDialogVisible: false, saveDialogVisible: false, checkDialogVisible: false, checking: false, progress: 0, max: 0, pavementLayerVisible: true, saves: [] } }, created () { }, methods: { + cancel () { + this.centerDialogVisible = false + }, zoomout() { this.$parent.$parent.$refs.editLayer.stopDrawing() this.$parent.$parent.zoomUpdated(9) @@ -109,7 +166,7 @@ You should have received a copy of the GNU General Public License along with FG setEditing (editing) { this.isEditing = editing }, - undoFirst () { + revert (file) { this.isEditing = false this.$emit('edit', false) this.centerDialogVisible = false @@ -117,25 +174,32 @@ You should have received a copy of the GNU General Public License along with FG this.$parent.$parent.$refs.editLayer.disableEdit() this.$parent.$parent.$refs.towerLayer.disableEdit() this.$parent.$parent.$refs.thresholdLayer.disableEdit() - this.$parent.$parent.$refs.editLayer.reload(true) + this.$parent.$parent.$refs.editLayer.reload(file) }, - undoLast () { - this.isEditing = false - this.$emit('edit', false) - this.centerDialogVisible = false - this.$parent.$parent.$refs.map.mapObject.options.minZoom = 1; - this.$parent.$parent.$refs.editLayer.disableEdit() - this.$parent.$parent.$refs.towerLayer.disableEdit() - this.$parent.$parent.$refs.thresholdLayer.disableEdit() - this.$parent.$parent.$refs.editLayer.reload(false) - }, - save () { + close () { this.$parent.$parent.$refs.editLayer.stopDrawing() this.isEditing = false this.$emit('edit', false) this.$parent.$parent.$refs.map.mapObject.options.minZoom = 1; Vue.set(this, 'saveDialogVisible', true) this.$emit('edit', false) + Vue.nextTick( function () { + setTimeout( this.closeDefered.bind(this), 100); + }, this) + }, + closeDefered () { + this.$parent.$parent.$refs.editLayer.save() + this.$parent.$parent.$refs.towerLayer.save() + this.$parent.$parent.$refs.thresholdLayer.save() + this.$parent.$parent.$refs.editLayer.disableEdit() + this.$parent.$parent.$refs.towerLayer.disableEdit() + this.$parent.$parent.$refs.thresholdLayer.disableEdit() + this.rescanCurrentGroundnet() + Vue.set(this, 'saveDialogVisible', false) + }, + save () { + Vue.set(this, 'saveDialogVisible', true) + this.$parent.$parent.$refs.editLayer.stopDrawing() Vue.nextTick( function () { setTimeout( this.saveDefered.bind(this), 100); }, this) @@ -144,13 +208,10 @@ You should have received a copy of the GNU General Public License along with FG this.$parent.$parent.$refs.editLayer.save() this.$parent.$parent.$refs.towerLayer.save() this.$parent.$parent.$refs.thresholdLayer.save() - this.$parent.$parent.$refs.editLayer.disableEdit() - this.$parent.$parent.$refs.towerLayer.disableEdit() - this.$parent.$parent.$refs.thresholdLayer.disableEdit() - this.scanGroundnets() + this.rescanCurrentGroundnet() Vue.set(this, 'saveDialogVisible', false) }, - scanGroundnets () { + rescanCurrentGroundnet () { try { const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080/src/renderer/utils/worker.js` @@ -297,6 +358,13 @@ You should have received a copy of the GNU General Public License along with FG this.$parent.$parent.$refs.editLayer.stopDrawing() Vue.set(this, 'checkDialogVisible', true) this.check() + }, + openReload: function() { + this.centerDialogVisible = true + var icao = this.$parent.$parent.$refs.editLayer.icao + if (icao !== undefined && icao !== '') { + this.saves = listSaves(this.$store.state.Settings.settings.airportsDirectory, icao).sort((a, b) => a.mtimeMs - b.mtimeMs) + } } }, computed: { diff --git a/src/renderer/components/EditLayer.vue b/src/renderer/components/EditLayer.vue index 8197115..685f8e7 100644 --- a/src/renderer/components/EditLayer.vue +++ b/src/renderer/components/EditLayer.vue @@ -109,7 +109,7 @@ You should have received a copy of the GNU General Public License along with FG }, data () { return { - maxId: 1, icao: String, checking: false, editing: false + maxId: 1, icao: '', checking: false, editing: false } }, methods: { @@ -128,13 +128,18 @@ You should have received a copy of the GNU General Public License along with FG this.selection = parkings; return parkings; }, - load (icao, force) { + load (icao, filename) { if (this.groundnetLayerGroup !== undefined) { this.groundnetLayerGroup.removeFrom(this.$parent.mapObject) } this.$parent.$parent.setIcao(icao) this.icao = icao - this.groundnetLayerGroup = readGroundnetXML(this.$store.state.Settings.settings.airportsDirectory, icao, force) + var f = path.join(this.$store.state.Settings.settings.airportsDirectory, icao[0], icao[1], icao[2], icao + '.groundnet.new.xml'); + if (!fs.existsSync(f)) { + f = path.join(this.$store.state.Settings.settings.airportsDirectory, icao[0], icao[1], icao[2], icao + '.groundnet.xml'); + } + + this.groundnetLayerGroup = readGroundnetXML(this.$store.state.Settings.settings.airportsDirectory, icao, f) if (this.groundnetLayerGroup === undefined) { console.warn('Groundnet for ICAO not loaded ' + icao) return @@ -912,8 +917,8 @@ You should have received a copy of the GNU General Public License along with FG this.$parent.mapObject.off('click', this.addParking) this.$parent.mapObject._container.style.cursor = '' }, - reload (force) { - this.load(this.icao, force) + reload (filename) { + this.load(this.icao, filename) }, link (index) { var layers = [] @@ -1007,8 +1012,7 @@ You should have received a copy of the GNU General Public License along with FG //console.debug(l) xml.push(l) }) - writeGroundnetXML(this.$store.state.Settings.settings.airportsDirectory, this.icao, xml) - this.load(this.icao, false) + writeGroundnetXML(this.$store.state.Settings.settings.airportsDirectory, this.icao, xml) }, //Copy to test directory test() { diff --git a/src/renderer/components/SettingsPanel.vue b/src/renderer/components/SettingsPanel.vue index d3c8789..4c24817 100644 --- a/src/renderer/components/SettingsPanel.vue +++ b/src/renderer/components/SettingsPanel.vue @@ -6,135 +6,206 @@ -
- - Airports Directory - - - {{ airports_directory }} - - + + + Number of saves : + + + + + + + + + + Airports Directory + + + {{ airports_directory }} - - - - - - Flightgear Data Directory - - - {{ flightgear_directory }} - - - - - - - - Traffic Directory - - - {{ Traffic_directory }} - - - - - APT File - - - {{ apt_file }} - - - - - Export Directory - {{ test_directory }} - - - - - - Phi Host Url - - - - - - - - - Author E-Mail : - - - - - - - - - Author Name : - - - - - - - - - Scan logging : - - - + + + + + + + Flightgear Data Directory + + + {{ flightgear_directory }} - - - - - - - - - - Debugger - - - - -
+ + + + + + + + Traffic Directory + + + {{ Traffic_directory }} + + + + APT File + + + {{ + apt_file + }} + + + + Export Directory : + {{ test_directory }} + + + + + + + + Author E-Mail : + + + + + + + + Author Name : + + + + + + + + + + + Scan logging : + + + + + + + + + + + + + Debugger + + + + + + + + Phi Host Url + + + + + + + + @@ -152,8 +223,7 @@ }, data () { - return { ok: true - } + return { ok: true, activeName: '0' } }, methods: { flightgearDirectorySelect: function (flightgearDirectory) { @@ -173,6 +243,16 @@ } }, computed: { + numberOfSaves: { + // getter + get: function () { + return this.$store.state.Settings.settings.numberOfSaves + }, + // setter + set: function (newValue) { + this.$store.commit('SET_NUMBER_OF_SAVES', newValue) + } + }, email: { // getter get: function () { @@ -293,5 +373,4 @@ padding: 5px; background-color: red; } - diff --git a/src/renderer/loaders/groundnet_loader.js b/src/renderer/loaders/groundnet_loader.js index 84c8b6f..45cd4ab 100644 --- a/src/renderer/loaders/groundnet_loader.js +++ b/src/renderer/loaders/groundnet_loader.js @@ -29,22 +29,37 @@ function addFrequencies (type, value) { } exports.addFeature = function (feature) { - featureLookup[feature.id] = new Array(); + featureLookup[feature.id] = []; } -exports.readGroundnetXML = function (fDir, icao, force) { +exports.listSaves = function (fDir, icao) { + var directory = path.join(fDir, icao[0], icao[1], icao[2]); + var files = fs.readdirSync(directory); + var ret = files + .filter(f => f.includes(icao) ) + .filter(f => f.includes('groundnet') ) + .map(f => { + try { + var fileDate = fs.lstatSync(path.join(directory, f)); + return {file: f, mtime: `${fileDate.mtime}`, mtimeMs: `${fileDate.mtimeMs}`}; + } catch (error) { + console.error(error); + } + }); + ret.forEach( f => { + console.debug(f); + }); + return ret; +} + +exports.readGroundnetXML = function (fDir, icao, f) { try { store.default.dispatch('setGroundnetLoaded', false); var layerGroup = L.layerGroup(); layerGroup.maxId = 0; - var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.xml'); - var fNew = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.new.xml'); - if (f == null || (!fs.existsSync(f) && force)|| (!fs.existsSync(f) && !fs.existsSync(fNew) )) + if (f == null || (!fs.existsSync(f) )) return layerGroup; - if (fNew != null && fs.existsSync(fNew) && !force) { - f = fNew; - } var features = new Array(); diff --git a/src/renderer/loaders/groundnet_writer.js b/src/renderer/loaders/groundnet_writer.js index da34819..bb8c9f2 100644 --- a/src/renderer/loaders/groundnet_writer.js +++ b/src/renderer/loaders/groundnet_writer.js @@ -65,11 +65,22 @@ exports.writeGroundnetXML = function (fDir, icao, featureList) { try { fs.mkdirSync(path.join(fDir, icao[0], icao[1]), { recursive: true })} catch (err) { } try { fs.mkdirSync(path.join(fDir, icao[0], icao[1], icao[2]), { recursive: true })} catch (err) { } + var fileNames = []; + for (let index = 1; index <= store.default.state.Settings.settings.numberOfSaves; index++) { + fileNames.push(path.join(fDir, icao[0], icao[1], icao[2], icao + `.groundnet.bak.${index}.xml`)); + } var f = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.new.xml'); - var fBak = path.join(fDir, icao[0], icao[1], icao[2], icao + '.groundnet.bak.xml'); if( fs.existsSync(f) ) { - fs.copyFileSync(f, fBak); + var previous = ''; + fileNames.reverse().forEach(fBak => { + if (fs.existsSync(fBak) && previous !== '') { + console.debug( `Copy ${fBak} to ${previous}`); + fs.copyFileSync(fBak, previous); + } + previous = fBak; + }); + fs.copyFileSync(f, previous); } if (f == null) return; diff --git a/src/renderer/store/modules/Settings.js b/src/renderer/store/modules/Settings.js index a835589..83ac9b7 100644 --- a/src/renderer/store/modules/Settings.js +++ b/src/renderer/store/modules/Settings.js @@ -3,7 +3,7 @@ const path = require('path'); const fs = require('fs'); const state = { - settings: { flightgearDirectory: '.', testDirectory: '.', email: 'flightgearairports@example.org', name: 'unknown', phi_url: 'http://localhost:8080' }, + settings: { numberOfSaves: 1, flightgearDirectory: '.', testDirectory: '.', email: 'flightgearairports@example.org', name: 'unknown', phi_url: 'http://localhost:8080' }, zoom: 14, center: [47.413220, -1.219482], bounds: undefined, @@ -50,6 +50,9 @@ const mutations = { 'SET_NAME'(state, name) { state.settings.name = name }, + 'SET_NUMBER_OF_SAVES'(state, numberOfSaves) { + state.settings.numberOfSaves = numberOfSaves + }, 'SET_PHI_URL'(state, phi_url) { state.settings.phi_url = phi_url },