From 6e08f4e03888286137425f66a5a5f0ff80406263 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Wed, 29 May 2019 14:01:40 +0200 Subject: [PATCH] Validation of Coordination Format --- .../frontend/src/pages/StationEdit.vue | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/labswp_2019_sose_geocaching_frontend/frontend/src/pages/StationEdit.vue b/labswp_2019_sose_geocaching_frontend/frontend/src/pages/StationEdit.vue index b383296..1de5ced 100644 --- a/labswp_2019_sose_geocaching_frontend/frontend/src/pages/StationEdit.vue +++ b/labswp_2019_sose_geocaching_frontend/frontend/src/pages/StationEdit.vue @@ -110,23 +110,40 @@ console.log(this.station); console.log(this.isNewStation); console.log(this.$route.params.pos); - if (this.isNewStation) { - this.$store.commit('cacheCollector/ADD_STATION', this.station); - } else { - this.$store.commit('cacheCollector/EDIT_STATION', {index: this.$route.params.pos, station: this.station}); - this.$store.commit('cacheCollector/SET_TEMPSTATION', null); + console.log("Test Latlang: " + this.validateLatLangFormat()); + if(!this.validateLatLangFormat()){ + let title = "Falsche Formatierung"; + let msg = "Die Koordinaten sind in einer falschen Formatierung eingegeben. Beispiel: 49.98767, 9.87637"; + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,}); } - let cache = this.$store.getters['cacheCollector/GET_CACHE']; - if (cache.hasOwnProperty('id')) { - this.$router.push({path: `/cache/${cache.id}`}); - } else { - this.$router.push({path: `/cache`}); + if(this.validateEverything()) { + if (this.isNewStation) { + this.$store.commit('cacheCollector/ADD_STATION', this.station); + } else { + this.$store.commit('cacheCollector/EDIT_STATION', {index: this.$route.params.pos, station: this.station}); + this.$store.commit('cacheCollector/SET_TEMPSTATION', null); + } + + let cache = this.$store.getters['cacheCollector/GET_CACHE']; + if (cache.hasOwnProperty('id')) { + this.$router.push({path: `/cache/${cache.id}`}); + } else { + this.$router.push({path: `/cache`}); + } + console.log("Station saved"); } - console.log("station saved.."); + }, dismiss() { this.$store.commit('cacheCollector/SET_TEMPSTATION', null); this.$router.push({path: `/cache`}); + }, + validateLatLangFormat(){ + var re = new RegExp('\\d+(\\.\\d+)?\\,(\\s)?\\d+(\\.\\d+)?'); + return re.test(this.latlang); + }, + validateEverything(){ + return this.validateLatLangFormat(); } } }