fixed some bugs and created data-store for current cache

This commit is contained in:
Timo Volkmann 2019-04-29 20:37:30 +02:00
parent 2cace929d0
commit 65d3e77558
7 changed files with 54 additions and 66 deletions

View File

@ -86,6 +86,7 @@
</q-item-section>
</q-item>
<q-item
v-if="this.$store.state.auth.isAuthenticated"
clickable
class="text-primary"
v-ripple
@ -104,13 +105,13 @@
class="text-primary"
v-ripple
tag="a"
to="/Login"
to="/Register"
>
<q-item-section avatar>
<q-icon name="logout"/>
<q-icon name="assignment"/>
</q-item-section>
<q-item-section>
<q-item-label>Login</q-item-label>
<q-item-label>Registrieren</q-item-label>
</q-item-section>
</q-item>
<q-item
@ -118,13 +119,13 @@
class="text-primary"
v-ripple
tag="a"
to="/Register"
to="/Login"
>
<q-item-section avatar>
<q-icon name="assignment"/>
<q-icon name="logout"/>
</q-item-section>
<q-item-section>
<q-item-label>Register</q-item-label>
<q-item-label>{{ loginText }}</q-item-label>
</q-item-section>
</q-item>
</q-list>
@ -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;
},
}

View File

@ -23,9 +23,9 @@
<div class="">
<div class="" style="max-width: 440px">
<q-btn
:loading="loading"
:outline="userAuthenticated"
:disabled="userAuthenticated"
:loading="loading"
label="Login"
color="primary"
class="full-width"
@ -80,9 +80,8 @@
},
computed: {
userAuthenticated() {
console.log("login: userAuthenticated()")
// console.log(this.$store.getters['auth/IS_AUTHENTICATED']);
// return this.$store.getters['auth/IS_AUTHENTICATED']
console.log("login: userAuthenticated()");
console.log(this.$store.state.auth.isAuthenticated);
return this.$store.state.auth.isAuthenticated;
}
},
@ -103,13 +102,13 @@
console.log("TOKEN");
console.log(response.data.token);
localStorage.setItem('userToken', JSON.stringify(response.data));
this.evalAuthentication();
this.$router.push({path: `/overview`})
})
.catch((error) => {
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 () {

View File

@ -26,7 +26,6 @@
<q-card class="q-mb-md" v-for="cache in caches" :key="cache.id">
<q-expansion-item
class=""
expand-icon-toggle
expand-separator
icon="location_on"
:label="cache.name"
@ -174,43 +173,17 @@
})
},
startCache(cacheID) {
const userToken = JSON.parse(localStorage.getItem('userToken')).token;
let params = {cacheID: cacheID};
if (userToken != null) {
params.token = userToken;
}
console.log(params);
this.$axios.get('/api/startCache', {params})
.then((response) => {
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}`})
}
}
}

View File

@ -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());
},
}

View File

@ -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();

View File

@ -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.";

View File

@ -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