diff --git a/frontend/src/layouts/MyLayout.vue b/frontend/src/layouts/MyLayout.vue index 23d2b46..7d4edf9 100644 --- a/frontend/src/layouts/MyLayout.vue +++ b/frontend/src/layouts/MyLayout.vue @@ -245,7 +245,7 @@ }, evalAuthentication: function () { this.$store.commit('auth/SET_AUTHENTICATED'); - // this.$store.commit('auth/SET_USER'); + this.$store.commit('auth/SET_USER'); }, logout: function () { console.log("logout()"); diff --git a/frontend/src/pages/CacheEnd.vue b/frontend/src/pages/CacheEnd.vue index 93e4f8c..7012c57 100644 --- a/frontend/src/pages/CacheEnd.vue +++ b/frontend/src/pages/CacheEnd.vue @@ -9,8 +9,8 @@

- - + +
diff --git a/frontend/src/pages/MyCaches.vue b/frontend/src/pages/MyCaches.vue index aa27a91..d541885 100644 --- a/frontend/src/pages/MyCaches.vue +++ b/frontend/src/pages/MyCaches.vue @@ -39,7 +39,7 @@ - {{ startedCache.progress * 100 }}% bereits geschafft + {{ Math.round(startedCache.progress * 100) }}% bereits geschafft diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 0741a0c..4daba55 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -21,13 +21,19 @@ - - + + @@ -43,22 +49,29 @@ - + + + icon="delete" size="xs"/> + icon="edit" size="xs"/> + icon="image" label="QRCodes" size="xs"/> -
+
@@ -94,64 +107,114 @@ tab: 'list', caches: [], stations: [], - pois: [] + pois: [], + render: false } }, mounted: function () { }, computed: { - // ...mapGetters([ - // 'auth/GET_ADMINSTATE' - // ]), - hasAdminState() { return this.$store.getters['auth/GET_ADMINSTATE']; } }, - created: function () { + beforeMount() { + }, + + async created() { console.log("created(): " + this.caches); - this.fetchAllCaches(); - this.$store.commit('auth/SET_AUTHENTICATED'); - this.$store.commit('auth/SET_USER'); + // this.$store.commit('auth/SET_AUTHENTICATED'); + // this.$store.commit('auth/SET_USER'); + await this.fetchAllCaches(); + this.render = await this.fetchMyCaches(); }, methods: { - fetchAllCaches() { - this.$axios.get('/api/allCaches') - .then((response) => { - this.caches = response.data; - for(let cache in this.caches) { + getColorClass(cache) { + switch (this.getCacheAccesDefinition(cache)) { + case -1: + return "primary" + case 0: + return "amber" + case 1: + return "green" + } + }, + getCacheAccesDefinition(cache) { + // console.log("getCacheAccessDefinition") + // console.log(cache.hasOwnProperty('cacheAccesDefinition') ? cache.cacheAccesDefinition : -1) + // can be -1 = no accessdefinition, 0 = started or 1 = finished + return cache.hasOwnProperty('cacheAccesDefinition') ? cache.cacheAccesDefinition : -1; + }, - this.stations[cache]=(this.caches[cache].stationen[0]); - const poiItem = { - Name: this.caches[cache].name, - CategoryID: 3, - Latitude: this.stations[cache].lattitude, - Longitude: this.stations[cache].longitude - }; - this.pois.push(poiItem); + fetchAllCaches() { + return new Promise(resolve => { + this.$axios.get('/api/allCaches') + .then((response) => { + this.caches = response.data; + //this.fetchMyCaches(); + for (let cache in this.caches) { + + this.stations[cache] = (this.caches[cache].stationen[0]); + const poiItem = { + Name: this.caches[cache].name, + CategoryID: 3, + Latitude: this.stations[cache].lattitude, + Longitude: this.stations[cache].longitude + }; + this.pois.push(poiItem); + } + this.initMap(); + resolve(true); + }).catch((error) => { + let message; + let header = "Fehler: "; + if (error.response) { + console.log("ERROR RESPONSE"); + // The request was made and the server responded with a status code + // that falls out of the range of 2xx + message = error.response.data.error; + header += error.response.status; + } else if (error.request) { + // The request was made but no response was received + // `error.request` is an instance of XMLHttpRequest in the browser and an instance of + // http.ClientRequest in node.js + message = "Anfrage fehlgeschlagen."; + } else { + // Something happened in setting up the request that triggered an Error + console.log('Error', error.message); + message = error.message; } - this.initMap(); - }).catch((error) => { - let message; - let header = "Fehler: "; - if (error.response) { - console.log("ERROR RESPONSE"); - // The request was made and the server responded with a status code - // that falls out of the range of 2xx - message = error.response.data.error; - header += error.response.status; - } else if (error.request) { - // The request was made but no response was received - // `error.request` is an instance of XMLHttpRequest in the browser and an instance of - // http.ClientRequest in node.js - message = "Anfrage fehlgeschlagen."; + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: message, title: header,}); + resolve(true); + }) + }) + }, + + fetchMyCaches() { + return new Promise(resolve => { + console.log("fetchMyCaches..."); + if (this.$store.state.auth.isAuthenticated && localStorage.getItem('userToken')) { + const token = JSON.parse(localStorage.getItem('userToken')).token; + this.$axios.get('/api/getMyCaches', {params: {token}}) + .then((response) => { + console.log("process data...") + console.log(response.data) + for (let item of response.data) { + this.caches.forEach(cache => { + if (cache.id === item.cache.id) { + cache.cacheAccesDefinition = item.cacheAccesDefinition.id; + console.log("found accessdefinition: id: " + cache.id + " ad: " + cache.cacheAccesDefinition); + + } + }) + } + console.log(this.caches); + console.log("data processed.") + }).finally(() => resolve(true)) } else { - // Something happened in setting up the request that triggered an Error - console.log('Error', error.message); - message = error.message; + resolve(true); } - console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, }); }) }, @@ -175,17 +238,17 @@ }, editCache() { }, - initMap(){ + initMap() { console.log("Signalwort: " + this.pois); - // this.$axios.post('http://seserver.se.hs-heilbronn.de:3000/api/map', { - // body: this.pois - // }).then((response)=>{ - // console.log(response) - // }) - // }, + // this.$axios.post('http://seserver.se.hs-heilbronn.de:3000/api/map', { + // body: this.pois + // }).then((response)=>{ + // console.log(response) + // }) + // }, this.$axios.get('http://www.se.hs-heilbronn.de:3000/api/map/lon=9&lat=49', { body: this.pois - }).then((response)=>{ + }).then((response) => { console.log(response) }) }, @@ -214,7 +277,7 @@ message = error.message; } console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, }); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: message, title: header,}); }) }, startCache(cacheID) { @@ -224,6 +287,41 @@ this.$store.state.currentCache.currentCacheID = Number(cacheID); this.$router.push({path: `/CacheStart/${cacheID}`}) }, + continueCache(cacheID) { + console.log("cacheID"); + console.log(cacheID); + let currentStationID; + if (localStorage.getItem('userToken')) { + let params = {cacheID: cacheID}; + params.token = JSON.parse(localStorage.getItem('userToken')).token; + this.$axios.get('/api/getCurrentStation', {params}) + .then((response) => { + console.log(response.data); + currentStationID = response.data.aktuelleStation.id; + this.$router.push({path: `/station/${cacheID}/${currentStationID}`}); + }) + .catch((error) => { + }); + } + }, + goToReward(cacheID) { + console.log("cacheID"); + console.log(cacheID); + let currentStationID; + if (localStorage.getItem('userToken')) { + let params = {cacheID: cacheID}; + params.token = JSON.parse(localStorage.getItem('userToken')).token; + this.$axios.get('/api/getCurrentStation', {params}) + .then((response) => { + console.log(response.data); + currentStationID = response.data.aktuelleStation.id; + this.$router.push({path: `/CacheEnd/${params.cacheID}`}); + }) + .catch((error) => { + }); + } + }, + generateQrCodes(cacheID) { this.$router.push({path: `/generator/${cacheID}`}) }