From 65d3e77558fc52b10ac8cca94466178d6d638e09 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 29 Apr 2019 20:37:30 +0200 Subject: [PATCH] fixed some bugs and created data-store for current cache --- frontend/src/layouts/MyLayout.vue | 29 ++++++++------- frontend/src/pages/Login.vue | 12 +++---- frontend/src/pages/Overview.vue | 49 ++++++-------------------- frontend/src/pages/Profile.vue | 8 +++-- frontend/src/pages/StationView.vue | 2 +- frontend/src/store/dialog/mutations.js | 8 ++--- frontend/src/store/index.js | 12 +++++-- 7 files changed, 54 insertions(+), 66 deletions(-) diff --git a/frontend/src/layouts/MyLayout.vue b/frontend/src/layouts/MyLayout.vue index a2a51d5..7054c59 100644 --- a/frontend/src/layouts/MyLayout.vue +++ b/frontend/src/layouts/MyLayout.vue @@ -86,6 +86,7 @@ - + - Login + Registrieren - + - Register + {{ loginText }} @@ -172,37 +173,41 @@ }; }, computed: { + loginText() { + let text = this.$store.state.auth.isAuthenticated ? "Logout" : "Login"; + return text; + }, dialogShow: { get() { - console.log("get dialogShow: "+this.$store.state.dialog.dialog.show) + // console.log("get dialogShow: "+this.$store.state.dialog.dialog.show) return this.$store.state.dialog.dialog.show; }, set(val) { - console.log("set dialogShow: "+val) + // console.log("set dialogShow: "+val) this.$store.state.dialog.dialog.show = val; } }, dialogMessage: { get() { - console.log("get dialogMessage: "+this.$store.state.dialog.dialog.message) + // console.log("get dialogMessage: "+this.$store.state.dialog.dialog.message) return this.$store.state.dialog.dialog.message; }, }, dialogTitle: { get() { - console.log("get dialogTitle: "+this.$store.state.dialog.dialog.title) + // console.log("get dialogTitle: "+this.$store.state.dialog.dialog.title) return this.$store.state.dialog.dialog.title; }, }, dialogColorBg: { get() { - console.log("get dialogColorBg: " + this.$store.state.dialog.dialog.colorBackground) + // console.log("get dialogColorBg: " + this.$store.state.dialog.dialog.colorBackground) return this.$store.state.dialog.dialog.colorBackground; }, }, dialogColorBtn: { get() { - console.log("get dialogColorBtn: "+this.$store.state.dialog.dialog.colorButton) + // console.log("get dialogColorBtn: "+this.$store.state.dialog.dialog.colorButton) return this.$store.state.dialog.dialog.colorButton; }, } diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 881b3d7..21376da 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -23,9 +23,9 @@
{ let message; let header = "Fehler: "; if (error.response) { - console.log("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; @@ -128,6 +127,7 @@ this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, }); }).finally(() => { this.loading = false; + this.evalAuthentication(); }) }, evalAuthentication: function () { diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index ee39fe9..20dc7e7 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -26,7 +26,6 @@ { - console.log(response.data); - // TODO wenn cache angefangen, dann suche die letzte gefundene Station - let stationID = this.caches.find(x => x.id === cacheID).stationen[0].id; - console.log(stationID); - //this.$router.push({path: `/station/${stationID}`}) - this.$router.push({path: `/CacheStart/${cacheID}`}) - }).catch((error) => { - // 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; - } else if (error.request) { - // The request was made but no response was received - title = "Problem with request!"; - msg = "Error occured due to wrong server request!" - 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); - } - console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); - }) + console.log("startCache()"); + // const userToken = JSON.parse(localStorage.getItem('userToken')).token; + // let params = {cacheID: cacheID}; + // if (userToken != null) { + // params.token = userToken; + // } + // console.log(params); + this.$store.state.currentCache.cache = this.caches.find(cache => cache.id === Number(cacheID)); + console.log(this.$store.state.currentCache.cache); + this.$store.state.currentCache.currentCacheID = Number(cacheID); + this.$router.push({path: `/CacheStart/${cacheID}`}) } } } diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index 810a559..8fe3df2 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -267,7 +267,11 @@ }, methods: { fetchUserCaches: function () { - const token = JSON.parse(localStorage.getItem('userToken')).token; + if (localStorage.getItem('userToken')) { + const token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } this.$axios.get('/api/getMyCaches', {params: {token}}) .then((response) => { this.startedCaches = response.data; @@ -297,7 +301,7 @@ continueCache(cacheID) { }, validateEmail(email) { - var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); }, } diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue index 453ffb8..1a19b9c 100644 --- a/frontend/src/pages/StationView.vue +++ b/frontend/src/pages/StationView.vue @@ -80,7 +80,7 @@ } }, created: function () { - console.log("StationView: ") + console.log("StationView: "); // console.log("'id' from url: " + this.$route.params.id) // console.log("'cache' from url: " + this.$route.params.cache) this.fetchData(); diff --git a/frontend/src/store/dialog/mutations.js b/frontend/src/store/dialog/mutations.js index 8994399..4a14ffa 100644 --- a/frontend/src/store/dialog/mutations.js +++ b/frontend/src/store/dialog/mutations.js @@ -1,12 +1,12 @@ export function NEW_MESSAGE_DIALOG (state, messageObject) { - console.log("NEW_MESSAGE_DIALOG"); - console.log(messageObject); + // console.log("NEW_MESSAGE_DIALOG"); + // console.log(messageObject); if (messageObject == null) { state.dialog.show = true; return; } - console.log(messageObject); + // console.log(messageObject); if (messageObject.hasOwnProperty('color')) { switch (messageObject.color) { @@ -39,7 +39,7 @@ export function NEW_MESSAGE_DIALOG (state, messageObject) { state.dialog.show = true; } export function RESET_MESSAGE_DIALOG (state) { - console.log("RESET_MESSAGE_DIALOG"); + // console.log("RESET_MESSAGE_DIALOG"); state.dialog.colorBackground = "bg-red-9 text-white"; state.dialog.colorButton = "red-9"; state.dialog.message = "Ein unbekannter Fehler ist aufgetreten. Bitte versuchen Sie es noch einmal."; diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 58a40f8..9a7a3b2 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -4,6 +4,7 @@ import Axios from "axios"; import auth from "./auth" import cacheCollector from "./cacheCollector" import dialog from "./dialog" +import currentCache from "./currentCache" // import example from './module-example' @@ -19,7 +20,8 @@ export default function (/* { ssrContext } */) { modules: { auth, cacheCollector, - dialog + dialog, + currentCache }, // enable strict mode (adds overhead!) @@ -42,11 +44,15 @@ export default function (/* { ssrContext } */) { module.hot.accept(['./cacheCollector'], () => { const cacheCollector = require('./cacheCollector').default; store.hotUpdate({ modules: { cacheCollector: newCacheCollector } }) - }) + }); module.hot.accept(['./dialog'], () => { const dialog = require('./dialog').default; store.hotUpdate({ modules: { dialog: newDialog } }) - }) + }); + module.hot.accept(['./currentCache'], () => { + const currentCache = require('./currentCache').default; + store.hotUpdate({ modules: { currentCache: newCurrentCache } }) + }); } return Store