Divide store into modules
This commit is contained in:
@@ -1,24 +1,26 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import EventBus from '../_bus'
|
|
||||||
|
import AddressStore from './stores/address'
|
||||||
|
import CrmDataStore from './stores/crmdata'
|
||||||
|
import TeamerStore from './stores/teamer'
|
||||||
|
import EventsStore from './stores/events'
|
||||||
|
|
||||||
const configElement = document.getElementById('appconfig');
|
const configElement = document.getElementById('appconfig');
|
||||||
const config = JSON.parse(configElement.innerHTML);
|
const config = JSON.parse(configElement.innerHTML);
|
||||||
|
|
||||||
axios.defaults.baseURL = config.myEpApiBaseUrl;
|
axios.defaults.baseURL = config.myEpApiBaseUrl;
|
||||||
|
|
||||||
const createAuthenticatingClient = () => {
|
|
||||||
return axios.create({
|
|
||||||
headers: {
|
|
||||||
'X-Auth-Token': sessionStorage.getItem('token')
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Vue.use(Vuex);
|
Vue.use(Vuex);
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
|
modules: {
|
||||||
|
address: AddressStore,
|
||||||
|
crmdata: CrmDataStore,
|
||||||
|
teamer: TeamerStore,
|
||||||
|
events: EventsStore
|
||||||
|
},
|
||||||
state: {
|
state: {
|
||||||
config: config,
|
config: config,
|
||||||
loading: false,
|
loading: false,
|
||||||
@@ -38,6 +40,7 @@ export default new Vuex.Store({
|
|||||||
},
|
},
|
||||||
logout (state) {
|
logout (state) {
|
||||||
state.loggedIn = false;
|
state.loggedIn = false;
|
||||||
|
state.teamer = false;
|
||||||
},
|
},
|
||||||
isTeamer (state) {
|
isTeamer (state) {
|
||||||
state.teamer = true;
|
state.teamer = true;
|
||||||
@@ -133,116 +136,6 @@ export default new Vuex.Store({
|
|||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
commit('setJobProfiles', response.data['hydra:member']);
|
commit('setJobProfiles', response.data['hydra:member']);
|
||||||
});
|
});
|
||||||
},
|
|
||||||
loadAddress ({ commit }) {
|
|
||||||
commit('loadingBegin');
|
|
||||||
|
|
||||||
const client = createAuthenticatingClient();
|
|
||||||
|
|
||||||
return client.get('/api/addresses')
|
|
||||||
.then((response) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
return response.data['hydra:member'][0];
|
|
||||||
}).catch((error) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
commit('logout');
|
|
||||||
EventBus.$emit('forcedLogout');
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
saveAddress ({ commit }, data) {
|
|
||||||
commit('loadingBegin');
|
|
||||||
|
|
||||||
const client = createAuthenticatingClient();
|
|
||||||
|
|
||||||
return client.put('/api/addresses/' + data.id, data)
|
|
||||||
.then(() => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
commit('logout');
|
|
||||||
EventBus.$emit('forcedLogout');
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
loadEvents ({ commit }) {
|
|
||||||
commit('loadingBegin');
|
|
||||||
|
|
||||||
const client = createAuthenticatingClient();
|
|
||||||
|
|
||||||
return client.get('/api/events')
|
|
||||||
.then((response) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
return response.data['hydra:member'];
|
|
||||||
}).catch((error) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
commit('logout');
|
|
||||||
EventBus.$emit('forcedLogout');
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
loadCrmData ({ commit }) {
|
|
||||||
commit('loadingBegin');
|
|
||||||
|
|
||||||
const client = createAuthenticatingClient();
|
|
||||||
|
|
||||||
return client.get('/api/crm-selections')
|
|
||||||
.then((response) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
return response.data['hydra:member'][0];
|
|
||||||
}).catch((error) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
commit('logout');
|
|
||||||
EventBus.$emit('forcedLogout');
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
saveCrmData ({ commit }, data) {
|
|
||||||
commit('loadingBegin');
|
|
||||||
|
|
||||||
const client = createAuthenticatingClient();
|
|
||||||
|
|
||||||
return client.put('/api/crm-selections/' + data.id, data)
|
|
||||||
.then(() => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
}).catch((error) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
commit('logout');
|
|
||||||
EventBus.$emit('forcedLogout');
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
loadTeamerData ({ commit }) {
|
|
||||||
commit('loadingBegin');
|
|
||||||
|
|
||||||
const client = createAuthenticatingClient();
|
|
||||||
|
|
||||||
return client.get('/api/teamers/' + sessionStorage.getItem('teamerId'))
|
|
||||||
.then((response) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
return response.data;
|
|
||||||
}).catch((error) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
commit('logout');
|
|
||||||
EventBus.$emit('forcedLogout');
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
saveTeamerData ({ commit }, data) {
|
|
||||||
commit('loadingBegin');
|
|
||||||
|
|
||||||
const client = createAuthenticatingClient();
|
|
||||||
|
|
||||||
return client.put('/api/teamers/' + sessionStorage.getItem('teamerId'), data)
|
|
||||||
.then(() => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
}).catch((error) => {
|
|
||||||
commit('loadingFinish');
|
|
||||||
commit('logout');
|
|
||||||
EventBus.$emit('forcedLogout');
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
|
|||||||
@@ -137,7 +137,7 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchAddress () {
|
fetchAddress () {
|
||||||
this.$store.dispatch('loadAddress')
|
this.$store.dispatch('address/load')
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
this.address = data;
|
this.address = data;
|
||||||
this.picker.setDate(new Date(this.address.dateOfBirth), true);
|
this.picker.setDate(new Date(this.address.dateOfBirth), true);
|
||||||
@@ -150,7 +150,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
saveAddress () {
|
saveAddress () {
|
||||||
this.$store.dispatch('saveAddress', this.address)
|
this.$store.dispatch('address/save', this.address)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.message = 'Die Änderungen wurden gespeichert';
|
this.message = 'Die Änderungen wurden gespeichert';
|
||||||
this.messageClass = 'alert-success';
|
this.messageClass = 'alert-success';
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchSelections () {
|
fetchSelections () {
|
||||||
this.$store.dispatch('loadCrmData')
|
this.$store.dispatch('crmdata/load')
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
this.crmData = data;
|
this.crmData = data;
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
saveSelections () {
|
saveSelections () {
|
||||||
this.$store.dispatch('saveCrmData', this.crmData)
|
this.$store.dispatch('crmdata/save', this.crmData)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.message = 'Die Änderungen wurden gespeichert';
|
this.message = 'Die Änderungen wurden gespeichert';
|
||||||
this.messageClass = 'alert-success';
|
this.messageClass = 'alert-success';
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchEvents () {
|
fetchEvents () {
|
||||||
this.$store.dispatch('loadEvents')
|
this.$store.dispatch('events/load')
|
||||||
.then((events) => {
|
.then((events) => {
|
||||||
this.events = events;
|
this.events = events;
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
|
|||||||
@@ -121,14 +121,14 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchTeamerData () {
|
fetchTeamerData () {
|
||||||
this.$store.dispatch('loadTeamerData')
|
this.$store.dispatch('teamer/load')
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
this.teamerData = data;
|
this.teamerData = data;
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
saveTeamerData () {
|
saveTeamerData () {
|
||||||
this.$store.dispatch('saveTeamerData', this.teamerData)
|
this.$store.dispatch('teamer/save', this.teamerData)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.message = 'Die Änderungen wurden gespeichert';
|
this.message = 'Die Änderungen wurden gespeichert';
|
||||||
this.messageClass = 'alert-success';
|
this.messageClass = 'alert-success';
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import EventBus from '../../_bus';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state: {},
|
||||||
|
actions: {
|
||||||
|
load ({ commit }) {
|
||||||
|
commit('loadingBegin', null, { root: true });
|
||||||
|
|
||||||
|
const client = axios.create({
|
||||||
|
headers: {
|
||||||
|
'X-Auth-Token': sessionStorage.getItem('token')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return client.get('/api/addresses')
|
||||||
|
.then((response) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
return response.data['hydra:member'][0];
|
||||||
|
}).catch((error) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
commit('logout', null, { root: true });
|
||||||
|
EventBus.$emit('forcedLogout');
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
save ({ commit }, data) {
|
||||||
|
commit('loadingBegin', null, { root: true });
|
||||||
|
|
||||||
|
const client = axios.create({
|
||||||
|
headers: {
|
||||||
|
'X-Auth-Token': sessionStorage.getItem('token')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return client.put('/api/addresses/' + data.id, data)
|
||||||
|
.then(() => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
commit('logout', null, { root: true });
|
||||||
|
EventBus.$emit('forcedLogout');
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import EventBus from '../../_bus';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state: {},
|
||||||
|
actions: {
|
||||||
|
load ({ commit }) {
|
||||||
|
commit('loadingBegin', null, { root: true });
|
||||||
|
|
||||||
|
const client = axios.create({
|
||||||
|
headers: {
|
||||||
|
'X-Auth-Token': sessionStorage.getItem('token')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return client.get('/api/crm-selections')
|
||||||
|
.then((response) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
return response.data['hydra:member'][0];
|
||||||
|
}).catch((error) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
commit('logout', null, { root: true });
|
||||||
|
EventBus.$emit('forcedLogout');
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
save ({ commit }, data) {
|
||||||
|
commit('loadingBegin', null, { root: true });
|
||||||
|
|
||||||
|
const client = axios.create({
|
||||||
|
headers: {
|
||||||
|
'X-Auth-Token': sessionStorage.getItem('token')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return client.put('/api/crm-selections/' + data.id, data)
|
||||||
|
.then(() => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
}).catch((error) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
commit('logout', null, { root: true });
|
||||||
|
EventBus.$emit('forcedLogout');
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import EventBus from '../../_bus';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state: {},
|
||||||
|
actions: {
|
||||||
|
load ({ commit }) {
|
||||||
|
commit('loadingBegin', null, { root: true });
|
||||||
|
|
||||||
|
const client = axios.create({
|
||||||
|
headers: {
|
||||||
|
'X-Auth-Token': sessionStorage.getItem('token')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return client.get('/api/events')
|
||||||
|
.then((response) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
return response.data['hydra:member'];
|
||||||
|
}).catch((error) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
commit('logout', null, { root: true });
|
||||||
|
EventBus.$emit('forcedLogout');
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import EventBus from '../../_bus';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state: {},
|
||||||
|
actions: {
|
||||||
|
load ({ commit }) {
|
||||||
|
commit('loadingBegin', null, { root: true });
|
||||||
|
|
||||||
|
const client = axios.create({
|
||||||
|
headers: {
|
||||||
|
'X-Auth-Token': sessionStorage.getItem('token')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return client.get('/api/teamers/' + sessionStorage.getItem('teamerId'))
|
||||||
|
.then((response) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
return response.data;
|
||||||
|
}).catch((error) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
commit('logout', null, { root: true });
|
||||||
|
EventBus.$emit('forcedLogout');
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
save ({ commit }, data) {
|
||||||
|
commit('loadingBegin', null, { root: true });
|
||||||
|
|
||||||
|
const client = axios.create({
|
||||||
|
headers: {
|
||||||
|
'X-Auth-Token': sessionStorage.getItem('token')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return client.put('/api/teamers/' + sessionStorage.getItem('teamerId'), data)
|
||||||
|
.then(() => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
}).catch((error) => {
|
||||||
|
commit('loadingFinish', null, { root: true });
|
||||||
|
commit('logout', null, { root: true });
|
||||||
|
EventBus.$emit('forcedLogout');
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user