Divide store into modules
This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
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 config = JSON.parse(configElement.innerHTML);
|
||||
|
||||
axios.defaults.baseURL = config.myEpApiBaseUrl;
|
||||
|
||||
const createAuthenticatingClient = () => {
|
||||
return axios.create({
|
||||
headers: {
|
||||
'X-Auth-Token': sessionStorage.getItem('token')
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
address: AddressStore,
|
||||
crmdata: CrmDataStore,
|
||||
teamer: TeamerStore,
|
||||
events: EventsStore
|
||||
},
|
||||
state: {
|
||||
config: config,
|
||||
loading: false,
|
||||
@@ -38,6 +40,7 @@ export default new Vuex.Store({
|
||||
},
|
||||
logout (state) {
|
||||
state.loggedIn = false;
|
||||
state.teamer = false;
|
||||
},
|
||||
isTeamer (state) {
|
||||
state.teamer = true;
|
||||
@@ -133,116 +136,6 @@ export default new Vuex.Store({
|
||||
}).then((response) => {
|
||||
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: {
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
},
|
||||
methods: {
|
||||
fetchAddress () {
|
||||
this.$store.dispatch('loadAddress')
|
||||
this.$store.dispatch('address/load')
|
||||
.then((data) => {
|
||||
this.address = data;
|
||||
this.picker.setDate(new Date(this.address.dateOfBirth), true);
|
||||
@@ -150,7 +150,7 @@
|
||||
});
|
||||
},
|
||||
saveAddress () {
|
||||
this.$store.dispatch('saveAddress', this.address)
|
||||
this.$store.dispatch('address/save', this.address)
|
||||
.then(() => {
|
||||
this.message = 'Die Änderungen wurden gespeichert';
|
||||
this.messageClass = 'alert-success';
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
},
|
||||
methods: {
|
||||
fetchSelections () {
|
||||
this.$store.dispatch('loadCrmData')
|
||||
this.$store.dispatch('crmdata/load')
|
||||
.then((data) => {
|
||||
this.crmData = data;
|
||||
}).catch(() => {
|
||||
@@ -70,7 +70,7 @@
|
||||
});
|
||||
},
|
||||
saveSelections () {
|
||||
this.$store.dispatch('saveCrmData', this.crmData)
|
||||
this.$store.dispatch('crmdata/save', this.crmData)
|
||||
.then(() => {
|
||||
this.message = 'Die Änderungen wurden gespeichert';
|
||||
this.messageClass = 'alert-success';
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
},
|
||||
methods: {
|
||||
fetchEvents () {
|
||||
this.$store.dispatch('loadEvents')
|
||||
this.$store.dispatch('events/load')
|
||||
.then((events) => {
|
||||
this.events = events;
|
||||
}).catch(() => {
|
||||
|
||||
@@ -121,14 +121,14 @@
|
||||
},
|
||||
methods: {
|
||||
fetchTeamerData () {
|
||||
this.$store.dispatch('loadTeamerData')
|
||||
this.$store.dispatch('teamer/load')
|
||||
.then((data) => {
|
||||
this.teamerData = data;
|
||||
this.loaded = true;
|
||||
})
|
||||
},
|
||||
saveTeamerData () {
|
||||
this.$store.dispatch('saveTeamerData', this.teamerData)
|
||||
this.$store.dispatch('teamer/save', this.teamerData)
|
||||
.then(() => {
|
||||
this.message = 'Die Änderungen wurden gespeichert';
|
||||
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