Commit 61ca1516 authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

move schedule submission from EmissionManager to store

parent a6a700ed
......@@ -136,7 +136,6 @@
</template>
<script>
import axios from 'axios'
import { FullCalendar } from 'vue-full-calendar'
import 'fullcalendar/dist/fullcalendar.css'
import modalEmissionManagerCreate from './EmissionManagerModalCreate.vue'
......@@ -164,12 +163,7 @@ export default {
seconds: 3
},
// flags for loading data
loaded: {
shows: false,
timeslots: false,
calendarSlots: false,
},
// flag for when submitting resolve data
submitting: false,
// this flag signifies if we are in conflict resolution mode
......@@ -211,6 +205,12 @@ export default {
computed: {
shows () { return this.$store.state.shows.shows },
timeslots () { return this.$store.state.shows.timeslots },
loaded () {
return {
shows: this.$store.state.shows.loaded['shows'],
timeslots: this.$store.state.shows.loaded['timeslots'],
}
},
},
created () {
......@@ -512,34 +512,26 @@ export default {
solutions: this.resolveData.solutions,
}
this.$log.debug('resolveSubmit: schedule:', resolvedSchedule)
// now generate the URL and POST it to steering
let uri = process.env.VUE_APP_API_STEERING_SHOWS + this.shows[this.currentShow].id + '/schedules/'
this.submitting = true
axios.post(uri, resolvedSchedule, {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
}).then(response => {
this.$log.debug('resolveSubmit: response:', response)
this.submitting = false
// if for some reason a new conflict arose, e.g. because in the meantime
// someone else inserted a conflicting schedule, we have to resolve.
if (response.data.projected === undefined) {
this.conflictMode = false
this.renderView(null)
} else {
this.resolve(response.data)
this.$store.dispatch('shows/submitSchedule', {
showId: this.shows[this.currentShow].id,
schedule: resolvedSchedule,
callback: (response) => {
this.submitting = false
if (response.data.projected === undefined) {
this.conflictMode = false
this.renderView(null)
} else {
this.resolve(response.data)
}
},
callbackCancel: () => {
this.submitting = false
}
}).catch(error => {
this.submitting = false
this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response)
alert('Error: could not submit final schedule. See console for details.')
// and we leave the modal open, so no call to its .hide function here
})
},
loadCalendarSlots () {
this.loaded.calendarSlots = false
this.calendarSlots = []
for (let i in this.timeslots) {
let highlighting = 'otherShow'
......@@ -554,28 +546,22 @@ export default {
className: highlighting
})
}
this.loaded.calendarSlots = true
},
loadTimeslots (start, end) {
this.loaded.timeslots = false
this.$store.dispatch('shows/fetchTimeslots', {
start: start,
end: end,
callback: () => {
this.$log.debug('loadTimeslots callback executed')
this.loaded.timeslots = true
this.loadCalendarSlots()
}
})
},
loadShows () {
this.loaded.shows = false
this.$store.dispatch('shows/fetchShows', {
callback: () => {
this.$log.debug('firing calendar method getView')
this.loaded.shows = true
let start = this.$refs.calendar.fireMethod('getView').start.format()
let end = this.$refs.calendar.fireMethod('getView').end.format()
this.loadTimeslots(start, end)
......
......@@ -7,7 +7,8 @@ const state = {
loaded: {
shows: false,
timeslots: false,
}
schedules: false,
},
}
const getters = {
......@@ -43,6 +44,7 @@ const actions = {
if (data && typeof(data.callback) === 'function') { data.callback() }
}).catch(error => {
handleApiError(this, error, 'could not load shows')
if (data && typeof(data.callbackCancel) === 'function') { data.callbackCancel() }
})
},
......@@ -58,8 +60,24 @@ const actions = {
if (data && typeof(data.callback) === 'function') { data.callback() }
}).catch(error => {
handleApiError(this, error, 'could not load timeslots')
if (data && typeof(data.callbackCancel) === 'function') { data.callbackCancel() }
})
},
submitSchedule (ctx, data) {
ctx.commit('loading', 'schedules')
let uri = process.env.VUE_APP_API_STEERING_SHOWS + data.showId + '/schedules/'
axios.post(uri, data.schedule, {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + ctx.rootState.auth.user.access_token }
}).then(response => {
ctx.commit('finishLoading', 'schedules')
if (data && typeof(data.callback) === 'function') { data.callback(response) }
}).catch(error => {
handleApiError(this, error, 'could not load timeslots')
if (data && typeof(data.callbackCancel) === 'function') { data.callbackCancel() }
})
}
}
export default {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment