implemented edit Cache, bugfixes

This commit is contained in:
Timo Volkmann 2019-05-14 10:17:06 +02:00
parent 4935298d66
commit 16381ac8c2
4 changed files with 51 additions and 67 deletions

View File

@ -1,7 +1,5 @@
<template> <template>
<div> <div>
<!-- <div :is="stationComponent" @q-tb="scrollToBottomState" :stationObject="tempStation">STATION</div>-->
<!-- <div v-show="!stationComponent">-->
<form> <form>
<div class="q-pa-md q-gutter-y-md"> <div class="q-pa-md q-gutter-y-md">
<p class="text-h5">{{ isNewCache ? "Neuen Cache erstellen" : "Cache bearbeiten"}}</p> <p class="text-h5">{{ isNewCache ? "Neuen Cache erstellen" : "Cache bearbeiten"}}</p>
@ -94,40 +92,56 @@
</q-item> </q-item>
</q-card> </q-card>
<div class="row q-mt-xl"> <div class="row q-mt-xl">
<q-btn @click="saveCache" class="full-width" color="primary" unelevated stack label="Cache speichern" <q-btn @click="saveCache" class="full-width q-mb-md" color="primary" unelevated stack label="Cache speichern"
icon="save_alt"/> icon="save_alt"/>
<q-btn to="/overview" class="full-width" color="negative" unelevated stack label="Abbrechen" />
</div> </div>
</div> </div>
</form> </form>
<!-- </div>-->
</div> </div>
</template> </template>
<script> <script>
// import station from './StationEdit'
import {mapGetters} from 'vuex'; import {mapGetters} from 'vuex';
export default { export default {
name: "Cache", name: "Cache",
data() { data() {
return { return {
// stations: [],
// endStation: {},
//endStation: {},
scrolldown: false, scrolldown: false,
isNewCache: this.$route.params.id === undefined, isNewCache: this.$route.params.id === undefined,
tempCache: {}, //tempCache: {},
} }
}, },
// components: { beforeRouteUpdate(to, from, next) {
// station console.log("beforeRouteUpdate: reset data and fetch");
// }, this.$store.commit('cacheCollector/RESET_NEW_CACHE');
next()
},
beforeCreate: function () { beforeCreate: function () {
}, },
created: function () { created: function () {
console.log("isNewCache: " + this.isNewCache); console.log("isNewCache: " + this.isNewCache);
console.log("fetch Caches from Store"); console.log("Route Params: " + this.$route.params.id);
//this.tempCache = JSON.parse(JSON.stringify(this.cache)); if (!this.isNewCache) {
this.$axios.get('/api/allCaches')
.then((response) => {
console.log("/api/allCaches");
//console.log(JSON.stringify(response.data));
console.log(response.data);
let cache = response.data.find(cache => Number(cache.id) === Number(this.$route.params.id));
console.log(cache);
let stations = cache.stationen.filter(station => station.description !== "Endstation");
let endstation = cache.stationen.find(station => station.description === "Endstation");
console.log(stations);
console.log(endstation);
this.$store.commit('cacheCollector/SET_CACHE', cache);
this.$store.commit('cacheCollector/SET_STATIONS', stations);
this.$store.commit('cacheCollector/SET_ENDSTATION', endstation);
})
}
}, },
beforeMount: function () { beforeMount: function () {
}, },
@ -146,37 +160,12 @@
methods: { methods: {
editEndStation() { editEndStation() {
console.log("editEndStation()"); console.log("editEndStation()");
const station = this.endStation; const station = this.$store.getters['cacheCollector/GET_ENDSTATION'];
console.log(station); 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.$store.commit('cacheCollector/SET_TEMPSTATION', station);
//this.$router.push({path: `/tempendstation/${index}`}); // add parameter
this.$router.push({path: `/tempendstation/`}); // add parameter this.$router.push({path: `/tempendstation/`}); // add parameter
}
}, },
// getStations() {
// console.log("get Stations");
// let stations = this.computedStations.get();
// this.stations = stations.filter(station => station.description !== "Endstation");
// console.log(this.stations);
// this.endStation = stations.filter(station => station.description === "Endstation");
// console.log(this.endStation);
// },
// setStations() {
// let stations = this.stations;
// stations.push(this.endStation);
// this.computedStations.set(stations);
// },
// cacheToStore() {
// // push tempCache to Store
// console.log("set Cache");
// this.$store.commit('cacheCollector/SET_CACHE', JSON.parse(JSON.stringify(this.tempCache)));
// // this.SET_CACHE(JSON.parse(JSON.stringify(this.tempCache)));
// },
addStation() { addStation() {
this.$router.push({path: '/station'}); this.$router.push({path: '/station'});
}, },
@ -233,26 +222,16 @@
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 this.$axios.post('/api/editCache', cache)
.then((response) => {
console.log("POST api/editCache: " + response.statusText);
this.$store.commit('cacheCollector/RESET_NEW_CACHE');
this.$router.push({path: '/overview'});
})
} }
}, },
}, },
computed: { computed: {
...mapGetters({
//cache: 'cacheCollector/GET_CACHE',
//endStation: 'cacheCollector/GET_ENDSTATION'
}),
// computedStations: {
// set(value) {
// console.log("set stations");
// this.computedCache.set(value);
// },
// get() {
// console.log("get stations");
// let stations = this.computedCache.stationen;
// return stations.filter(station => station.description !== "Endstation");
// }
// },
computedCache: { computedCache: {
set(value) { set(value) {
console.log("set cache"); console.log("set cache");

View File

@ -120,10 +120,14 @@
}, },
async created() { async created() {
console.log("created(): " + this.caches); console.log("created(): " + this.caches);
this.loadData();
},
methods: {
async loadData() {
this.render = false;
await this.fetchAllCaches(); await this.fetchAllCaches();
this.render = await this.fetchMyCaches(); this.render = await this.fetchMyCaches();
}, },
methods: {
getColorClass(cache) { getColorClass(cache) {
switch (this.getCacheAccesDefinition(cache)) { switch (this.getCacheAccesDefinition(cache)) {
case -1: case -1:
@ -232,6 +236,7 @@
this.$router.push({path: `/cache`}) this.$router.push({path: `/cache`})
}, },
editCache(cacheID) { editCache(cacheID) {
this.$router.push({path: `/cache/${cacheID}`})
}, },
initMap() { initMap() {
console.log("Signalwort: " + this.pois); console.log("Signalwort: " + this.pois);
@ -249,9 +254,9 @@
}, },
deleteCache(id) { deleteCache(id) {
console.log('delete cache: ' + id); console.log('delete cache: ' + id);
axios.get('/api/deleteCache', {params: {cacheID: id}}) this.$axios.delete('/api/deleteCache', {params: {cacheID: id}})
.then((response) => { .then((response) => {
this.fetchAllCaches() this.loadData();
}).catch((error) => { }).catch((error) => {
let message; let message;
let header = "Fehler: "; let header = "Fehler: ";

View File

@ -42,8 +42,8 @@ export const RESET_NEW_CACHE = (state) => {
}; };
state.endStation = { state.endStation = {
description: "Endstation", description: "Endstation",
longitude: 9.206628, longitude: 0.000,
lattitude: 49.147734, lattitude: 0.000,
solution: "", solution: "",
}; };

View File

@ -11,8 +11,8 @@ export default {
tempStation: {}, tempStation: {},
endStation: { endStation: {
description: "Endstation", description: "Endstation",
longitude: 9.206628, longitude: 0.000,
lattitude: 49.147734, lattitude: 0.000,
solution: "", solution: "",
}, },
} }