Code cleanup

This commit is contained in:
Björn Fromme
2019-09-28 22:40:29 +02:00
parent 5713c811cc
commit ebbebcca08
18 changed files with 319 additions and 442 deletions
@@ -1,11 +1,13 @@
<script> <script>
import WatchlistToggle from './WatchlistToggle.vue' import WatchlistToggle from './WatchlistToggle'
import BackLink from './BackLink'
import defaultFilterSettings from '../_filtersettings' import defaultFilterSettings from '../_filtersettings'
export default { export default {
components: { components: {
WatchlistToggle WatchlistToggle,
BackLink
}, },
props: { props: {
referringPageUrl: { referringPageUrl: {
@@ -47,7 +47,6 @@
}, },
data () { data () {
return { return {
watchlist: [],
teasers: {}, teasers: {},
total: 0, total: 0,
loading: false, loading: false,
@@ -65,7 +64,7 @@
return; return;
} }
let query = {}; let query = {};
query['tx_epproducts_ajax[watchlistUids]'] = this.userData.watchlist; query['tx_epproducts_ajax[watchlistUids]'] = this.userData.watchList;
this.loading = true; this.loading = true;
axios({ axios({
url: this.watchlistUri, url: this.watchlistUri,
@@ -30,7 +30,9 @@
} }
}, },
computed: { computed: {
...mapGetters(['onWatchlist']) onWatchlist () {
return this.$store.getters.onWatchlist(this.uid)
}
} }
} }
</script> </script>
@@ -1,7 +1,7 @@
<template> <template>
<div class="form-wrapper form--border" id="myep-main" v-show="!loading"> <div class="form-wrapper form--border" id="myep-main" v-show="!loading">
<h1>Adressdaten</h1> <h1>Adressdaten</h1>
<form @submit.prevent="saveAddress()"> <form @submit.prevent="save()">
<div class="row"> <div class="row">
<div class="col-xs-12 col-md-6"> <div class="col-xs-12 col-md-6">
<div class="form-group"> <div class="form-group">
@@ -68,7 +68,7 @@
Land: Land:
</label> </label>
<select id="country" v-model="userData.country" class="form-control"> <select id="country" v-model="userData.country" class="form-control">
<option v-for="country in $store.state.countries" <option v-for="country in countries"
:value="country['code']">{{ country['name'] }}</option> :value="country['code']">{{ country['name'] }}</option>
</select> </select>
<span class="help-block">{{ formErrors.country }}</span> <span class="help-block">{{ formErrors.country }}</span>
@@ -107,8 +107,8 @@
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import { mapState } from 'vuex' import { mapState, mapMutations } from 'vuex'
import $ from 'jquery' import axios from 'axios'
import flatpickr from 'flatpickr' import flatpickr from 'flatpickr'
import { German } from 'flatpickr/dist/l10n/de' import { German } from 'flatpickr/dist/l10n/de'
@@ -116,29 +116,32 @@
data () { data () {
return { return {
picker: null, picker: null,
formErrors: {} formErrors: {},
countries: []
} }
}, },
created () { created () {
this.initFormErrors(); this.initFormErrors();
this.$store.dispatch('address/load') this.loadFormOptions();
this.$store.dispatch('loadAddress')
.then(() => { .then(() => {
this.picker.setDate(new Date(this.userData.dateOfBirth), true); this.picker.setDate(new Date(this.userData.dateOfBirth), true);
}); });
}, },
mounted () { mounted () {
Vue.nextTick(() => { Vue.nextTick(() => {
this.picker = $(this.$refs.picker).flatpickr({ this.picker = flatpickr(this.$refs.picker, {
dateFormat: 'd.m.Y', dateFormat: 'd.m.Y',
locale: German, locale: German,
inline: true, inline: true,
onChange: (selectedDates) => { onChange: selectedDates => {
this.userData.dateOfBirth = flatpickr.formatDate(selectedDates[0], 'Y-m-d') this.userData.dateOfBirth = flatpickr.formatDate(selectedDates[0], 'Y-m-d')
} }
}); });
}) })
}, },
methods: { methods: {
...mapMutations(['alert', 'beginLoading', 'endLoading']),
initFormErrors () { initFormErrors () {
this.formErrors = { this.formErrors = {
lastName: null, lastName: null,
@@ -152,15 +155,26 @@
country: null country: null
} }
}, },
saveAddress () { loadFormOptions () {
this.beginLoading();
return axios({
url: '/api/countries',
}).then(response => {
this.countries = response.data
}).catch(error => {
}).finally(() => {
this.endLoading()
});
},
save () {
this.initFormErrors(); this.initFormErrors();
this.$store.dispatch('address/save', this.userData) this.$store.dispatch('saveAddress', this.userData)
.catch(error => { .catch(error => {
this.$store.commit('alert', { this.alert({
message: 'Bitte überprüfe deine Eingaben.', message: 'Bitte überprüfe deine Eingaben.',
class: 'alert-danger' class: 'alert-danger'
}); });
const violations = error.response.data['violations']; const violations = error.response.data.violations;
for (let violation of violations) { for (let violation of violations) {
this.formErrors[violation.property_path] = violation.message; this.formErrors[violation.property_path] = violation.message;
} }
@@ -62,20 +62,15 @@
...mapGetters(['isLoggedIn', 'isTeamer']) ...mapGetters(['isLoggedIn', 'isTeamer'])
}, },
mounted () { mounted () {
this.$store.dispatch('initSession') this.$store.commit('initSession');
.then(()=> { if (this.isLoggedIn) {
if (this.isLoggedIn) { this.$router.push({ name: 'address' })
this.$router.push({ name: 'address' }) }
}
})
} }
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.nav-disabled {
opacity: 0.5;
}
#app { #app {
position: relative; position: relative;
} }
@@ -86,7 +81,7 @@
z-index: 10; z-index: 10;
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: rgba(255, 255, 255, 0.85); background-color: rgba(255, 255, 255, 0.75);
img { img {
position: absolute; position: absolute;
@@ -1,10 +1,10 @@
<template> <template>
<div id="myep-main" v-show="!loading"> <div id="myep-main" v-show="!loading">
<h1>Mein Profil</h1> <h1>Mein Profil</h1>
<form @submit.prevent="saveSelections()"> <form @submit.prevent="save()">
<div class="row"> <div class="row">
<div class="col-xs-12 col-md-6"> <div class="col-xs-12 col-md-6">
<template v-for="selectionGroup in this.crmData.selectionGroups" <template v-for="selectionGroup in crmData.selectionGroups"
v-if="hasVisibleSelections(selectionGroup)"> v-if="hasVisibleSelections(selectionGroup)">
<h3>{{ selectionGroup.name}}</h3> <h3>{{ selectionGroup.name}}</h3>
<div class="checkbox" v-for="selection in selectionGroup.selections" <div class="checkbox" v-for="selection in selectionGroup.selections"
@@ -19,7 +19,7 @@
</template> </template>
</div> </div>
<div class="col-xs-12 col-md-6"> <div class="col-xs-12 col-md-6">
<div class="checkbox" v-for="action in this.crmData.actions" <div class="checkbox" v-for="action in crmData.actions"
v-if="action.changeable === true"> v-if="action.changeable === true">
<label :class="{ disabled: !action.changeable}"> <label :class="{ disabled: !action.changeable}">
<input type="checkbox" class="form-control" <input type="checkbox" class="form-control"
@@ -44,7 +44,8 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapState, mapMutations } from 'vuex'
import axios from 'axios'
export default { export default {
data () { data () {
@@ -55,36 +56,67 @@
} }
}, },
created () { created () {
this.fetchSelections(); this.load()
}, },
methods: { methods: {
fetchSelections () { ...mapMutations(['beginLoading', 'endLoading', 'alert']),
this.$store.dispatch('crmdata/load') getClient () {
.then((data) => { return axios.create({
this.crmData = data; headers: {
}).catch(error => {}); 'Authorization': 'Bearer ' + this.authToken
}
});
}, },
saveSelections () { load () {
this.$store.dispatch('crmdata/save', this.crmData) this.beginLoading();
.catch(error => {});
return this.getClient().get('/api/crm-selections')
.then(response => {
this.crmData = response.data
}).catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
})
}).finally(() => {
this.endLoading()
});
},
save () {
this.beginLoading();
return this.getClient().put('/api/crm-selections', this.crmData)
.then(() => {
this.alert({
message: 'Die Änderungen wurden gespeichert',
class: 'alert-success'
});
}).catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
});
}).finally(() => {
this.endLoading();
});
}, },
hasVisibleSelections (group) { hasVisibleSelections (group) {
if (this.hiddenSelectionGroups.indexOf(group.id) !== -1) { if (this.hiddenSelectionGroups.indexOf(group.id) !== -1) {
return false; return false
} }
for (let selection of group.selections) { for (let selection of group.selections) {
if (this.hiddenSelections.indexOf(selection.id) === -1 && selection.changeable === true) { if (this.hiddenSelections.indexOf(selection.id) === -1 && selection.changeable === true) {
return true; return true
} }
} }
return false; return false
}, },
isSelectionVisible (selection) { isSelectionVisible (selection) {
return this.hiddenSelections.indexOf(selection.id) === -1; return this.hiddenSelections.indexOf(selection.id) === -1
} }
}, },
computed: { computed: {
...mapState(['loading']) ...mapState(['loading', 'authToken'])
} }
} }
</script> </script>
@@ -42,7 +42,8 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapState, mapMutations } from 'vuex'
import axios from 'axios'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import 'dayjs/locale/de' import 'dayjs/locale/de'
@@ -56,25 +57,40 @@
'O': 'Option', 'O': 'Option',
'U': 'Umbuchung', 'U': 'Umbuchung',
}, },
events: [] events: []
} }
}, },
created () { created () {
this.fetchEvents(); this.load()
}, },
methods: { methods: {
fetchEvents () { ...mapMutations(['beginLoading', 'endLoading', 'alert']),
this.$store.dispatch('events/load') load () {
.then((events) => { this.beginLoading();
this.events = events;
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + this.authToken
}
});
return client.get('/api/events')
.then(response => {
this.events = response.data;
}).catch(error => { }).catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
});
}).finally(() => {
this.endLoading();
}); });
}, },
formatBookingDate (date) { formatBookingDate (date) {
if (!date) { if (!date) {
return '-'; return '-'
} }
return dayjs(date).format('DD.MM.YYYY'); return dayjs(date).format('DD.MM.YYYY')
}, },
getDownloadUrl (event, type) { getDownloadUrl (event, type) {
return this.config.myEpApiBaseUrl return this.config.myEpApiBaseUrl
@@ -42,7 +42,7 @@
</template> </template>
<script> <script>
import { mapState, mapGetters } from 'vuex' import { mapState, mapGetters, mapMutations } from 'vuex'
export default { export default {
data () { data () {
@@ -53,25 +53,26 @@
} }
}, },
methods: { methods: {
...mapMutations(['alert']),
toggleMode () { toggleMode () {
this.mode = this.mode === 'login' ? 'reset' : 'login'; this.mode = this.mode === 'login' ? 'reset' : 'login';
this.password = ''; this.password = ''
}, },
submit () { submit () {
this.message = ''; this.message = '';
if (this.mode === 'login') { if (this.mode === 'login') {
this.login(); this.login()
} else { } else {
this.resetPassword(); this.resetPassword()
} }
}, },
login () { login () {
if (!this.email || !this.password) { if (!this.email || !this.password) {
this.$store.commit('alert', { this.alert({
message: 'Bitte E-Mail und Passwort eingeben', message: 'Bitte E-Mail und Passwort eingeben',
class: 'alert-danger' class: 'alert-danger'
}); });
return; return
} }
this.$store.dispatch('login', { this.$store.dispatch('login', {
email: this.email, email: this.email,
@@ -83,7 +84,7 @@
}, },
resetPassword () { resetPassword () {
if (!this.email) { if (!this.email) {
this.$store.commit('alert', { this.alert({
message: 'Bitte die E-Mail Adresse angeben', message: 'Bitte die E-Mail Adresse angeben',
class: 'alert-danger' class: 'alert-danger'
}); });
@@ -91,18 +92,18 @@
} }
this.$store.dispatch('resetPassword', this.$store.dispatch('resetPassword',
this.email this.email
).then((response) => { ).then(response => {
this.email = ''; this.email = '';
if (response.data.success) { if (response.data.success) {
this.$store.commit('alert', { this.alert({
message: 'Du erhältst in Kürze eine E-Mail mit einem Link zum (Zurück)setzen deines Passworts.', message: 'Du erhältst in Kürze eine E-Mail mit einem Link zum (Zurück)setzen deines Passworts.',
class: 'alert-success' class: 'alert-success'
}); })
} else { } else {
this.$store.commit('alert', { this.alert({
message: 'Diese E-Mail Adresse konnte nicht gefunden werden.', message: 'Diese E-Mail Adresse konnte nicht gefunden werden.',
class: 'alert-danger' class: 'alert-danger'
}); })
} }
}).catch(error => { }).catch(error => {
}); });
@@ -4,33 +4,59 @@
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<p v-html="statusMessage"></p> <p v-html="statusMessage"></p>
<button type="submit" class="button" :disabled="loading" @click.prevent="toggleReqistration()"> <div class="form-group">
{{ userData.newsletter ? 'Abmelden' : 'Anmelden' }} <button type="submit" class="button" :disabled="loading" @click.prevent="toggleReqistration()">
</button> {{ userData.newsletter ? 'Abmelden' : 'Anmelden' }}
</button>
</div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapState, mapMutations } from 'vuex'
import axios from 'axios'
export default { export default {
methods: { methods: {
...mapMutations(['beginLoding', 'endLoading', 'alert']),
toggleReqistration () { toggleReqistration () {
this.userData.newsletter = !this.userData.newsletter; this.userData.newsletter = !this.userData.newsletter;
const data = { const data = {
id: this.userData.id, id: this.userData.id,
email: this.userData.email, email: this.userData.email,
registration: this.userData.newsletter registration: this.userData.newsletter
}; };
this.$store.dispatch('newsletter/registration', data)
this.beginLoding();
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + this.authToken
}
});
return client.put('/api/newsletter', data)
.then(() => {
this.alert({
message: 'Die Änderungen wurden gespeichert',
class: 'alert-success'
});
})
.catch(error => { .catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
});
}).finally(() => {
this.endLoading();
}); });
} }
}, },
computed: { computed: {
...mapState(['loading', 'userData']), ...mapState(['loading', 'userData', 'authToken']),
statusMessage () { statusMessage () {
let message = 'Du bist aktuell'; let message = 'Du bist aktuell';
message += this.userData.newsletter ? ' ' : ' <strong>nicht</strong> '; message += this.userData.newsletter ? ' ' : ' <strong>nicht</strong> ';
@@ -13,12 +13,12 @@
</div> </div>
</div> </div>
<div class="col-xs-12 col-md-6"> <div class="col-xs-12 col-md-6">
<div class="form-group" :class="{'has-error': formErrors.name }"> <div class="form-group" :class="{'has-error': formErrors.lastName }">
<label for="name" class="control-label"> <label for="name" class="control-label">
Name Name
</label> </label>
<input id="name" type="text" v-model="userData.name" class="form-control"> <input id="name" type="text" v-model="userData.lastName" class="form-control">
<span class="help-block">{{ formErrors.name }}</span> <span class="help-block">{{ formErrors.lastName }}</span>
</div> </div>
</div> </div>
</div> </div>
@@ -65,7 +65,7 @@
</template> </template>
<script> <script>
import { mapState} from 'vuex' import { mapState, mapMutations } from 'vuex'
export default { export default {
data () { data () {
@@ -75,39 +75,38 @@
} }
}, },
methods: { methods: {
...mapMutations(['alert']),
submit () { submit () {
this.message = ''; this.message = '';
this.register(); this.register();
}, },
register () { register () {
this.initFormErrors(); this.initFormErrors();
this.$store.dispatch('register', this.$store.dispatch('register', this.userData)
this.userData .then(response => {
).then(() => { if (response.data.success) {
this.$store.dispatch('resetPassword', this.userData.email); this.alert({
this.$store.commit('alert', { message: 'Du erhältst in Kürze eine E-Mail mit einem Link zum (Zurück)setzen deines Passworts.',
message: 'Du erhältst in Kürze eine E-Mail mit einem Link zum (Zurück)setzen deines Passworts.', class: 'alert-success'
class: 'alert-success' });
}); this.initFormData();
this.initFormData(); this.initFormErrors();
this.initFormErrors(); } else {
}).catch(error => { this.alert({
if (error.response.data['@type'] === 'hydra:Error') { message: 'Du bist bereits registriert. Bitte nutze die Passwort vergessen Funktion.',
this.$store.commit('alert', { class: 'alert-danger'
message: 'Du bist bereits registriert. Bitte nutze die Passwort vergessen Funktion.', });
class: 'alert-danger'
});
} else {
const violations = error.response.data['violations'];
for (let violation of violations) {
this.formErrors[violation.propertyPath] = violation.message;
} }
} }).catch(error => {
}); const violations = error.response.data.violations;
for (let violation of violations) {
this.formErrors[violation.property_path] = violation.message;
}
});
}, },
initFormData () { initFormData () {
this.userData = { this.userData = {
name: '', lastName: '',
firstName: '', firstName: '',
email: '', email: '',
gender: 'M' gender: 'M'
@@ -115,7 +114,7 @@
}, },
initFormErrors () { initFormErrors () {
this.formErrors = { this.formErrors = {
name: null, lastName: null,
firstName: null, firstName: null,
email: null, email: null,
gender: null gender: null
@@ -1,7 +1,7 @@
<template> <template>
<div class="form-wrapper form--border" id="myep-main" v-show="!loading"> <div class="form-wrapper form--border" id="myep-main" v-show="!loading">
<h1>Teamer</h1> <h1>Teamer</h1>
<form @submit.prevent="saveTeamerData()"> <form @submit.prevent="save()">
<div class="row"> <div class="row">
<div class="col-xs-12 col-md-6"> <div class="col-xs-12 col-md-6">
<h4>Fährst du Ski oder Board?</h4> <h4>Fährst du Ski oder Board?</h4>
@@ -63,7 +63,7 @@
<h4>Verfügbarkeiten</h4> <h4>Verfügbarkeiten</h4>
<div class="checkbox" v-for="timeFrame in timeFrames"> <div class="checkbox" v-for="timeFrame in timeFrames">
<label> <label>
<input type="checkbox" class="form-control" v-model="userData.availableTimeframes" <input type="checkbox" class="form-control" v-model="userData.availableTimeFrames"
:value="timeFrame.id"/> :value="timeFrame.id"/>
<span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span> <span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
{{ timeFrame | period }} {{ timeFrame | period }}
@@ -92,7 +92,8 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import { mapState, mapMutations } from 'vuex'
import axios from 'axios'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import 'dayjs/locale/de' import 'dayjs/locale/de'
@@ -103,14 +104,35 @@
status: [ status: [
{ value: 'jr', label: 'Neuteamer' }, { value: 'jr', label: 'Neuteamer' },
{ value: 'sr', label: 'Bestandsteamer' } { value: 'sr', label: 'Bestandsteamer' }
] ],
abilities: [],
timeFrames: [],
jobProfiles: []
} }
}, },
methods: { methods: {
fetchTeamerData () { ...mapMutations(['beginLoading', 'endLoading', 'alert']),
this.$store.dispatch('teamer/loadSelectableValues'); getClient () {
return axios.create({
headers: {
'Authorization': 'Bearer ' + this.authToken
}
});
}, },
saveTeamerData () { load () {
this.beginLoading();
return this.getClient().get('/api/teamer-data')
.then(response => {
this.abilities = response.data.abilities;
this.timeFrames = response.data.timeFrames;
this.jobProfiles = response.data.jobProfiles;
}).catch(error => {
}).finally(() => {
this.endLoading();
});
},
save () {
const data = { const data = {
abilities: this.userData.abilities, abilities: this.userData.abilities,
jobProfiles: this.userData.jobProfiles, jobProfiles: this.userData.jobProfiles,
@@ -121,19 +143,30 @@
monthLong: this.userData.monthLong, monthLong: this.userData.monthLong,
notes: this.userData.notes, notes: this.userData.notes,
}; };
this.$store.dispatch('teamer/save', data)
.catch(error => { this.beginLoading();
return this.getClient().put('/api/teamer-data', data)
.then(() => {
this.alert({
message: 'Die Änderungen wurden gespeichert',
class: 'alert-success'
});
}).catch(error => {
this.alert({
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
});
}).finally(() => {
this.endLoading();
}); });
} }
}, },
created () { created () {
this.fetchTeamerData(); this.load()
}, },
computed: { computed: {
...mapState(['userData', 'loading']), ...mapState(['userData', 'loading', 'authToken'])
...mapState('teamer', [
'abilities', 'jobProfiles', 'timeFrames'
])
}, },
filters: { filters: {
period (timeFrame) { period (timeFrame) {
@@ -141,9 +174,9 @@
const end = dayjs(timeFrame.dateEnd); const end = dayjs(timeFrame.dateEnd);
let label = begin.format('DD.MM.YYYY') + ' - ' + end.format('DD.MM.YYYY'); let label = begin.format('DD.MM.YYYY') + ' - ' + end.format('DD.MM.YYYY');
if (timeFrame.label) { if (timeFrame.label) {
label += ' (' + timeFrame.label + ')'; label += ' (' + timeFrame.label + ')'
} }
return label; return label
} }
} }
} }
@@ -20,10 +20,12 @@ import Address from '../myep/Address'
import Events from '../myep/Events' import Events from '../myep/Events'
import Login from '../myep/Login' import Login from '../myep/Login'
import CrmData from '../myep/CrmData' import CrmData from '../myep/CrmData'
import Teamer from '../myep/Teamer'
import Newsletter from '../myep/Newsletter' import Newsletter from '../myep/Newsletter'
import Registration from '../myep/Registration' import Registration from '../myep/Registration'
// Lazy load teamer component when required
const Teamer = () => import('../myep/Teamer');
export default new VueRouter({ export default new VueRouter({
routes: [ routes: [
{ {
@@ -2,12 +2,6 @@ import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import axios from 'axios' import axios from 'axios'
import AddressStore from './modules/address'
import CrmDataStore from './modules/crmdata'
import TeamerStore from './modules/teamer'
import EventsStore from './modules/events'
import NewsletterStore from './modules/newsletter'
Vue.use(Vuex); Vue.use(Vuex);
const defaultUserData = { const defaultUserData = {
@@ -27,85 +21,73 @@ const defaultUserData = {
}; };
export default new Vuex.Store({ export default new Vuex.Store({
modules: {
address: AddressStore,
crmdata: CrmDataStore,
teamer: TeamerStore,
events: EventsStore,
newsletter: NewsletterStore
},
state: { state: {
config: {}, config: {},
loading: false, loading: false,
authToken: null, authToken: null,
userData: defaultUserData, userData: defaultUserData,
countries: [],
alert: { alert: {
message: '', message: '',
class: '' class: ''
} }
}, },
mutations: { mutations: {
initSession (state) { initSession(state) {
const authToken = sessionStorage.getItem('token'); const authToken = sessionStorage.getItem('token');
if (authToken) { if (authToken) {
state.authToken = authToken; state.authToken = authToken;
} }
}, },
initConfig (state) { initConfig(state) {
const configElement = document.getElementById('appconfig'); const configElement = document.getElementById('appconfig');
state.config = JSON.parse(configElement.innerHTML); state.config = JSON.parse(configElement.innerHTML);
axios.defaults.baseURL = state.config.myEpApiBaseUrl; axios.defaults.baseURL = state.config.myEpApiBaseUrl;
}, },
initWatchlist (state) { initWatchlist(state) {
if (!sessionStorage.getItem('watchList')) { if (!sessionStorage.getItem('watchList')) {
sessionStorage.setItem('watchList', JSON.stringify([])); sessionStorage.setItem('watchList', JSON.stringify([]));
} }
state.userData.watchList = JSON.parse(sessionStorage.getItem('watchList')); state.userData.watchList = JSON.parse(sessionStorage.getItem('watchList'));
}, },
setWatchlist (state, list) { setWatchlist(state, list) {
state.userData.watchList = list; state.userData.watchList = list;
sessionStorage.setItem('watchList', JSON.stringify(list)); sessionStorage.setItem('watchList', JSON.stringify(list));
}, },
setUserData (state, data) { setUserData(state, data) {
data.watchList = [...state.userData.watchList, ...data.watchList]; data.watchList = [...state.userData.watchList, ...data.watchList];
state.userData = data; state.userData = data;
}, },
login (state, token) { login(state, token) {
state.authToken = token; state.authToken = token;
sessionStorage.setItem('token', token); sessionStorage.setItem('token', token);
}, },
logout (state) { logout(state) {
state.authToken = null; state.authToken = null;
state.userData = defaultUserData; state.userData = defaultUserData;
sessionStorage.removeItem('token'); sessionStorage.removeItem('token');
sessionStorage.removeItem('watchlist'); sessionStorage.removeItem('watchlist');
}, },
alert (state, payload) { alert(state, payload) {
state.alert = payload; state.alert = payload;
}, },
loadingBegin (state) { beginLoading(state) {
state.loading = true; state.loading = true;
state.alert = { message: '', class: ''}; state.alert = {message: '', class: ''};
}, },
loadingFinish (state) { endLoading(state) {
state.loading = false; state.loading = false;
}, },
setCountries (state, countries) { setCountries(state, countries) {
state.countries = countries; state.countries = countries;
} }
}, },
actions: { actions: {
init({ commit }) { init({commit}) {
commit('initConfig'); commit('initConfig');
commit('initWatchlist'); commit('initWatchlist');
}, },
initSession({ commit, dispatch }) { login({commit, dispatch}, credentials) {
commit('initSession'); commit('beginLoading');
return dispatch('loadSelectableValues')
},
login({ commit, dispatch }, credentials) {
commit('loadingBegin');
return axios({ return axios({
url: '/api/login_check', url: '/api/login_check',
method: 'post', method: 'post',
@@ -124,11 +106,11 @@ export default new Vuex.Store({
}); });
throw error; throw error;
}).finally(() => { }).finally(() => {
commit('loadingFinish'); commit('endLoading');
}); });
}, },
logout({ commit, state }) { logout({commit, state}) {
commit('loadingBegin'); commit('beginLoading');
const client = axios.create({ const client = axios.create({
headers: { headers: {
'Authorization': 'Bearer ' + state.authToken, 'Authorization': 'Bearer ' + state.authToken,
@@ -136,57 +118,37 @@ export default new Vuex.Store({
}); });
return client({ return client({
url: '/api/logout' url: '/api/logout'
}).then(() => {
commit('logout');
}).catch(error => { }).catch(error => {
commit('alert', {
message: 'Der Logout ist fehlgeschlagen :(',
class: 'alert-danger'
});
throw error;
}).finally(() => { }).finally(() => {
commit('loadingFinish'); commit('logout');
commit('endLoading');
}); });
}, },
resetPassword({ commit }, email) { resetPassword({commit}, email) {
commit('loadingBegin'); commit('beginLoading');
return axios({ return axios({
url: '/api/reset-password', url: '/api/reset-password',
data: { email: email }, data: {email: email},
method: 'post' method: 'post'
}).then(response => { }).then(response => {
return response; return response;
}).catch(error => {
throw error;
}).finally(() => { }).finally(() => {
commit('loadingFinish'); commit('endLoading');
}); });
}, },
register({ commit }, userData) { register({commit}, userData) {
commit('loadingBegin'); commit('beginLoading');
return axios({ return axios({
url: '/api/register', url: '/api/register',
data: userData, data: userData,
method: 'post' method: 'post'
}).then(response => { }).then(response => {
return response; return response;
}).catch(error => {
throw error;
}).finally(() => { }).finally(() => {
commit('loadingFinish'); commit('endLoading');
}); });
}, },
loadSelectableValues ({ commit }) { watchlistToggle({commit, state}, uid) {
commit('loadingBegin');
return axios({
url: '/api/countries',
}).then(response => {
commit('setCountries', response.data);
}).finally(() => {
commit('loadingFinish');
});
},
watchlistToggle ({ commit, state }, uid) {
let list = state.userData.watchList; let list = state.userData.watchList;
let watchlistIndex = list.indexOf(uid); let watchlistIndex = list.indexOf(uid);
if (watchlistIndex === -1) { if (watchlistIndex === -1) {
@@ -199,6 +161,59 @@ export default new Vuex.Store({
axios.put('/api/watchlist', list) axios.put('/api/watchlist', list)
} }
}, },
loadAddress({commit, state}) {
commit('beginLoading');
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + state.authToken,
}
});
return client.get('/api/address')
.then(response => {
commit('setUserData', response.data);
if (response.data.watchlist) {
commit('setWatchlist', response.data.watchlist);
}
}).catch(() => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
});
}).finally(() => {
commit('endLoading');
});
},
saveAddress({commit, state}, data) {
commit('beginLoading');
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + state.authToken,
}
});
return client.put('/api/address', data)
.then(() => {
commit('alert', {
message: 'Die Änderungen wurden gespeichert',
class: 'alert-success'
});
})
.catch(error => {
if (error.config.status >= 500) {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
});
} else {
throw error;
}
}).finally(() => {
commit('endLoading');
});
}
}, },
getters: { getters: {
watchlistCount: state => state.userData.watchList.length, watchlistCount: state => state.userData.watchList.length,
@@ -1,59 +0,0 @@
import axios from 'axios';
export default {
namespaced: true,
state: {},
actions: {
load ({ commit, rootState }) {
commit('loadingBegin', null, { root: true });
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + rootState.authToken,
}
});
return client.get('/api/address')
.then(response => {
commit('setUserData', response.data, { root: true });
if (response.data.watchlist) {
commit('setWatchlist', response.data.watchlist, { root: true });
}
}).catch(() => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
}, { root: true });
commit('logout', null, { root: true });
}).finally(() => {
commit('loadingFinish', null, { root: true });
});
},
save ({ commit, rootState }, data) {
commit('loadingBegin', null, { root: true });
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + rootState.authToken,
}
});
return client.put('/api/address', data)
.then(() => {
commit('alert', {
message: 'Die Änderungen wurden gespeichert',
class: 'alert-success'
}, { root: true });
})
.catch(error => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
}, { root: true });
throw error;
}).finally(() => {
commit('loadingFinish', null, { root: true });
});
}
}
}
@@ -1,57 +0,0 @@
import axios from 'axios';
export default {
namespaced: true,
state: {},
actions: {
load ({ commit, rootState }) {
commit('loadingBegin', null, { root: true });
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + rootState.authToken
}
});
return client.get('/api/crm-selections')
.then((response) => {
commit('loadingFinish', null, { root: true });
return response.data;
}).catch((error) => {
commit('loadingFinish', null, { root: true });
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
}, { root: true });
commit('logout', null, { root: true });
throw error;
});
},
save ({ commit, rootState }, data) {
commit('loadingBegin', null, { root: true });
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + rootState.authToken
}
});
return client.put('/api/crm-selections', data)
.then(() => {
commit('loadingFinish', null, { root: true });
commit('alert', {
message: 'Die Änderungen wurden gespeichert',
class: 'alert-success'
}, { root: true });
}).catch((error) => {
commit('loadingFinish', null, { root: true });
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
}, { root: true });
commit('logout', null, { root: true });
throw error;
});
}
}
}
@@ -1,33 +0,0 @@
import EventBus from '../../_bus';
import axios from 'axios';
export default {
namespaced: true,
state: {},
actions: {
load ({ commit, rootState }) {
commit('loadingBegin', null, { root: true });
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + rootState.authToken
}
});
return client.get('/api/events')
.then((response) => {
commit('loadingFinish', null, { root: true });
return response.data;
}).catch((error) => {
commit('loadingFinish', null, { root: true });
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
}, { root: true });
commit('logout', null, { root: true });
EventBus.$emit('forcedLogout');
throw error;
});
}
}
}
@@ -1,37 +0,0 @@
import EventBus from '../../_bus';
import axios from 'axios';
export default {
namespaced: true,
state: {},
actions: {
registration ({ commit, rootState }, data) {
commit('loadingBegin', null, { root: true });
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + rootState.authToken
}
});
return client.put('/api/newsletter', data)
.then(() => {
commit('alert', {
message: 'Die Änderungen wurden gespeichert',
class: 'alert-success'
}, { root: true });
})
.catch((error) => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
}, { root: true });
commit('logout', null, { root: true });
EventBus.$emit('forcedLogout');
throw error;
}).finally(() => {
commit('loadingFinish', null, { root: true });
});
}
}
}
@@ -1,73 +0,0 @@
import axios from 'axios';
export default {
namespaced: true,
state: {
abilities: [],
timeFrames: [],
jobProfiles: []
},
mutations: {
setAbilities (state, abilities) {
state.abilities = abilities;
},
setTimeFrames (state, timeFrames) {
state.timeFrames = timeFrames;
},
setJobProfiles (state, jobProfiles) {
state.jobProfiles = jobProfiles;
}
},
actions: {
save ({ commit, rootState }, data) {
commit('loadingBegin', null, { root: true });
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + rootState.authToken
}
});
return client.put('/api/teamer-data', data)
.then(() => {
commit('alert', {
message: 'Die Änderungen wurden gespeichert',
class: 'alert-success'
}, { root: true });
}).catch(error => {
commit('alert', {
message: 'Es ist ein Fehler aufgetreten :(',
class: 'alert-danger'
}, { root: true });
commit('logout', null, { root: true });
throw error;
}).finally(() => {
commit('loadingFinish', null, { root: true });
});
},
loadSelectableValues ({ commit, rootState }) {
commit('loadingBegin', null, { root: true });
const client = axios.create({
headers: {
'Authorization': 'Bearer ' + rootState.authToken
}
});
return client.get('/api/teamer-data')
.then(response => {
commit('setAbilities', response.data.abilities);
commit('setTimeFrames', response.data.timeFrames);
commit('setJobProfiles', response.data.jobProfiles);
}).catch(error => {
}).finally(() => {
commit('loadingFinish', null, { root: true });
});
}
},
getters: {
abilities: state => state.abilities,
jobProfiles: state => state.jobProfiles,
timeFrames: state => state.timeFrames
}
}