diff --git a/frontend/src/boot/axios.js b/frontend/src/boot/axios.js index 8523d48..ea842da 100644 --- a/frontend/src/boot/axios.js +++ b/frontend/src/boot/axios.js @@ -1,7 +1,8 @@ import axios from "axios"; const axiosInstance = axios.create({ - baseURL: process.env.API + baseURL: process.env.API, + timeout: 3000 }); console.log("process.env.DEV: "+process.env.DEV); console.log("process.env.API: "+process.env.API); diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue index e3126cf..db80dbb 100644 --- a/frontend/src/pages/Cache.vue +++ b/frontend/src/pages/Cache.vue @@ -1,75 +1,108 @@ @@ -81,7 +114,7 @@ name: "Cache", data() { return { - // stationComponent: null, + //endStation: {}, scrolldown: false, isNewCache: this.$route.params.id === undefined, tempCache: {}, @@ -112,16 +145,20 @@ //this.scrollToBottom(); }, methods: { - // ...mapMutations([ - // 'cacheCollector/SET_CACHE', - // 'cacheCollector/ADD_STATION', - // 'cacheCollector/REMOVE_STATION', - // 'cacheCollector/RESET_NEW_CACHE', - // 'cacheCollector/LOAD_REMOTE_CACHE' - // ]), - // swapComponent: function (component) { - // this.stationComponent = component; - // }, + editEndStation() { + console.log("editEndStation()"); + const station = this.endStation; + console.log(station); + if (station.hasOwnProperty('id')) { + //this.$router.push({ path: '/station/'+station.id}); + } else { + // TODO Stationen bearbeitbar machen bevor sie abgeschickt werden. Am besten Station Objekt als Übergabe Parameter bei Router + this.$store.commit('cacheCollector/SET_TEMPSTATION', station); + //this.$router.push({path: `/tempendstation/${index}`}); // add parameter + this.$router.push({path: `/tempendstation/`}); // add parameter + } + + }, cacheToStore() { // push tempCache to Store console.log("set Cache"); @@ -129,20 +166,20 @@ // this.SET_CACHE(JSON.parse(JSON.stringify(this.tempCache))); }, addStation() { - this.$router.push({ path: '/station' }); + this.$router.push({path: '/station'}); //this.swapComponent(station); // create Station and add it to array tempCache.stationen }, editStation(index) { - console.log("editStation("+index+")"); + console.log("editStation(" + index + ")"); const station = this.cache.stationen[index]; - console.log(station) - if (station.hasOwnProperty('id') ) { + console.log(station); + if (station.hasOwnProperty('id')) { //this.$router.push({ path: '/station/'+station.id}); } else { // TODO Stationen bearbeitbar machen bevor sie abgeschickt werden. Am besten Station Objekt als Übergabe Parameter bei Router this.$store.commit('cacheCollector/SET_TEMPSTATION', station); - this.$router.push({ path: `/station-l/${index}` }); // add parameter + this.$router.push({path: `/tempstation/${index}`}); // add parameter } }, deleteStation(index) { @@ -153,12 +190,14 @@ // commit to store, send to api, if success -> reset store if (this.isNewCache) { console.log(this.cache); - console.log(JSON.stringify(this.cache)); - this.$axios.post('/api/createCache', this.cache) + let cache = this.cache; + cache.stationen.push(this.endStation); + + this.$axios.post('/api/createCache', cache) .then((response) => { console.log("POST api/createCache: " + response.statusText); this.$store.commit('cacheCollector/RESET_NEW_CACHE'); - this.$router.push({ path: '/overview' }); + this.$router.push({path: '/overview'}); }).catch((error) => { // Error let msg; @@ -179,16 +218,17 @@ console.log('Error', error.message); } console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,}); }) - } else { + } else { // TODO update existing Cache } - }, + }, }, computed: { ...mapGetters({ - cache: 'cacheCollector/GET_CACHE' + cache: 'cacheCollector/GET_CACHE', + endStation: 'cacheCollector/GET_ENDSTATION' }), // computedCache: { // set(value) { diff --git a/frontend/src/pages/CacheStart.vue b/frontend/src/pages/CacheStart.vue index faef40b..2cc51de 100644 --- a/frontend/src/pages/CacheStart.vue +++ b/frontend/src/pages/CacheStart.vue @@ -1,17 +1,38 @@ @@ -68,13 +59,13 @@ export default { data() { return { + loading: false, user: { email: "volkmann@geocaching.de", password: "0123456789", //token: "", // evalAuthentication: false }, - credentialsDialog: false, }; }, // beforeMount: { @@ -97,7 +88,7 @@ }, methods: { login: function () { - + this.loading = true; const data = { email: this.user.email, password: this.user.password @@ -135,7 +126,9 @@ } console.log(error.config); this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, }); - }) + }).finally(() => { + this.loading = false; + }) }, evalAuthentication: function () { this.$store.commit('auth/SET_AUTHENTICATED'); diff --git a/frontend/src/pages/StationEdit.vue b/frontend/src/pages/StationEdit.vue index f51add4..3e1a6e8 100644 --- a/frontend/src/pages/StationEdit.vue +++ b/frontend/src/pages/StationEdit.vue @@ -3,14 +3,16 @@

Neue Station

+ ['bold', 'italic', 'strike', 'underline'], + ['undo', 'redo'], + ['hr', 'link'], + ['fullscreen'], + ]" + v-model="station.description" min-height="10rem"/> - - - + + +

Location

- +
-

Lösung

- - + + +
@@ -37,6 +40,7 @@ + + diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue index 767193d..75fb24a 100644 --- a/frontend/src/pages/StationView.vue +++ b/frontend/src/pages/StationView.vue @@ -17,10 +17,29 @@
- - - - +
+

Um den QR-Code scannen zu können, müssen Sie den Zugriff auf Ihre Kamera erlauben.

+ + +
+
+ + +
+
+
+ +
+
+
+
+
@@ -45,13 +64,25 @@ code: 213812, solution: "Schneeglöckchen" } - } + }, + + // Following Params belong to QR-Code Scanner + askForPermission: true, + activateCamera: false, + isValid: false, + validating: false, + loading: false, + paused: false, + result: null, + params: null, + noStreamApiSupport: false + } }, created: function () { console.log("StationView: ") - console.log("'id' from url: " + this.$route.params.id) - console.log("'cache' from url: " + this.$route.params.cache) + // console.log("'id' from url: " + this.$route.params.id) + // console.log("'cache' from url: " + this.$route.params.cache) this.fetchData(); }, beforeMount: function () { @@ -129,7 +160,104 @@ console.log(error.config); this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); }) + }, + + setParams() { + console.log("setParams: "); + let params = {}; + params.cacheID = this.code.split('/')[0]; + params.stationID = this.code.split('/')[1]; + params.durchgefuehrterCacheID = this.cacheID; + console.log(params.cacheID + " und " + params.stationID); + if (localStorage.getItem('userToken')) { + params.token = JSON.parse(localStorage.getItem('userToken')).token; + } + return params; + }, + + async onDecode(content) { + this.result = content; + + this.pauseCamera(); + + this.validating = true; + this.isValid = await this.validate(); + this.validating = false; + + this.unPauseCamera(); + // window.setTimeout(() => { + // this.unPauseCamera(); + // }, 2000) + }, + + validate() { + return new Promise(resolve => { + + let params = this.setParams(); + this.$axios.get('/api/checkStation', {params}) + .then((response) => { + console.log("resolve(true)"); + resolve(true); + this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`}); + }).catch((error) => { + console.log("resolve(false)"); + // Error + let msg; + let title; + if (error.response) { + // The request was made and the server responded with a status code + title = "Problem with response!"; + msg = error.response.data.message + ? error.response.data.message + : error.response.data; + } else if (error.request) { + // The request was made but no response was received + title = "Problem with request!"; + msg = "Der Server antwortet nicht." + console.log(error.request); + } else { + // Something happened in setting up the request that triggered an Error + title = "Error"; + msg = error.message; + console.log('Error', error.message.data); + } + console.log(error.config); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,}); + resolve(false); + }); + }) + }, + + pauseCamera() { + this.paused = true + }, + + unPauseCamera() { + this.paused = false + }, + + toggleCamera(bool) { + this.activateCamera = bool + }, + + logErrors(promise) { + promise.catch(console.error) + }, + + async onInit(promise) { + this.loading = true; + try { + await promise + } catch (error) { + if (error.name === 'StreamApiNotSupportedError') { + this.noStreamApiSupport = true + } + } finally { + this.loading = false; + this.askForPermission = false; + } } + } } diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js index 158b079..1a1e7ff 100644 --- a/frontend/src/router/routes.js +++ b/frontend/src/router/routes.js @@ -31,10 +31,20 @@ const routes = [ children: [{ path: "", component: () => import("pages/StationEdit.vue") }] }, { - path: "/station-l/:pos", + path: "/endstation/", + component: () => import("layouts/MyLayout.vue"), + children: [{ path: "", component: () => import("pages/StationEndEdit.vue") }] + }, + { + path: "/tempstation/:pos", component: () => import("layouts/MyLayout.vue"), children: [{path: "", component: () => import("pages/StationEdit.vue")}] }, + { + path: "/tempendstation/", + component: () => import("layouts/MyLayout.vue"), + children: [{path: "", component: () => import("pages/StationEndEdit.vue")}] + }, { path: "/station/:cache/:id", component: () => import("layouts/MyLayout.vue"), diff --git a/frontend/src/store/cacheCollector/getters.js b/frontend/src/store/cacheCollector/getters.js index b2b2dbe..d2bea70 100644 --- a/frontend/src/store/cacheCollector/getters.js +++ b/frontend/src/store/cacheCollector/getters.js @@ -6,3 +6,7 @@ export const GET_TEMPSTATION = (state) => { console.log("GET_TEMPSTATION: retrieve cache from store. "); return state.tempStation; }; +export const GET_ENDSTATION = (state) => { + console.log("GET_ENDSTATION: retrieve cache from store. "); + return state.endStation; +}; diff --git a/frontend/src/store/cacheCollector/mutations.js b/frontend/src/store/cacheCollector/mutations.js index 383330d..72f58e1 100644 --- a/frontend/src/store/cacheCollector/mutations.js +++ b/frontend/src/store/cacheCollector/mutations.js @@ -6,6 +6,10 @@ export const SET_TEMPSTATION = (state, station) => { console.log("SET_TEMPSTATION: add new station to cache: "+station); state.tempStation = station; }; +export const SET_ENDSTATION = (state, station) => { + console.log("SET_ENDSTATION: "+station); + state.endStation = station; +}; export const ADD_STATION = (state, station) => { console.log("ADD_STATION: add new station to cache: "+station); state.newCache.stationen.push(station); @@ -29,6 +33,11 @@ export const RESET_NEW_CACHE = (state) => { rankingPoints: 0, stationen: [] }; + state.endStation = { + description: "Endstation", + longitude: 0.0001, + lattitude: 0.0001, + }; console.log("resetted new Cache"); }; export const LOAD_REMOTE_CACHE = (state, id) => { diff --git a/frontend/src/store/cacheCollector/state.js b/frontend/src/store/cacheCollector/state.js index 7087a3a..0f32de1 100644 --- a/frontend/src/store/cacheCollector/state.js +++ b/frontend/src/store/cacheCollector/state.js @@ -3,6 +3,7 @@ export default { name: "", description: "", rankingPoints: 0, + reward: "", stationen: [] }, // newCache: { @@ -41,4 +42,9 @@ export default { // ] // }, tempStation: {}, + endStation: { + description: "Endstation", + longitude: 9.206628, + lattitude: 49.147734, + }, }