diff --git a/src/components/EmissionManager.vue b/src/components/EmissionManager.vue index 63613ae62aa014ad896d44ee717842e9fb412ec2..125f631e459c4a57a2ae4c0bd7c2f49473cf94dc 100644 --- a/src/components/EmissionManager.vue +++ b/src/components/EmissionManager.vue @@ -269,6 +269,62 @@ export default { } }, + resolveEvent (toResolve, mode) { + this.$log.debug('resolveEvent', toResolve) + this.conflictCount -= toResolve.collisions.length + switch (mode) { + case 'theirs': + this.conflictSolutions[toResolve.hash] = 'theirs' + toResolve.className = 'discarded' + break + + default: + this.$log.error('EmissionManager.resolveEvent') + this.$log.error('toResolve:', toResolve) + this.$log.error('mode:', mode) + alert('Error: an undefined conflict resolution mode was chosen. See console for details') + break + } + }, + + // submit a conflict-resolved schedule to steering + resolveSubmit () { + // TODO: check why steering retourns undefined and null values here + if (this.resolveData.schedule.add_business_days_only === undefined) { this.resolveData.schedule.add_business_days_only = false } + if (this.resolveData.schedule.add_days_no === null) { this.resolveData.schedule.add_days_no = 0 } + if (this.resolveData.schedule.is_repetition === undefined) { this.resolveData.schedule.is_repetition = false } + if (this.resolveData.schedule.fallback_id === null) { this.resolveData.schedule.fallback_id = 0 } + if (this.resolveData.schedule.automation_id === null) { this.resolveData.schedule.automation_id = 0 } + if (this.resolveData.schedule.byweekday === undefined) { this.resolveData.schedule.byweekday = 0 } + // create the resolved schedule object including solutions + let resolvedSchedule = { + schedule: this.resolveData.schedule, + 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/' + axios.post(uri, resolvedSchedule, { + withCredentials: true, + headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token } + }).then(response => { + this.$log.debug('resolveSubmit: response:', response) + // 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) + } + }).catch(error => { + 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 = [] @@ -323,10 +379,6 @@ export default { alert('Error: could not load shows. See console for details.') }) }, - - updateSchedules () { - this.$log.debug(this.$refs.calendar.fireMethod('getView').start.format()) - } }, } </script> @@ -344,4 +396,8 @@ a.currentShow { .noconflict { background-color: #17a2b8; } +.discarded { + background-color: #eee; + text-decoration: line-through; +} </style> diff --git a/src/components/EmissionManagerModalResolve.vue b/src/components/EmissionManagerModalResolve.vue index 7adc0db8a69c40fd9c2631630a4aafbaeddfe67b..ee86359e7e679213702198419405b8f997ae6a03 100644 --- a/src/components/EmissionManagerModalResolve.vue +++ b/src/components/EmissionManagerModalResolve.vue @@ -52,6 +52,7 @@ v-if="toResolve.solutionChoices.indexOf('ours') >= 0" variant="danger" size="sm" + @click="resolve('ours')" > Create new,<br> delete existing. @@ -61,6 +62,7 @@ v-if="toResolve.solutionChoices.indexOf('theirs') >= 0" variant="success" size="sm" + @click="resolve('theirs')" > Discard new,<br> keep existing. @@ -70,6 +72,7 @@ v-if="toResolve.solutionChoices.indexOf('theirs-start') >= 0" variant="info" size="sm" + @click="notYetImplemented" > theirs-start<br> TODO: describe @@ -79,6 +82,7 @@ v-if="toResolve.solutionChoices.indexOf('theirs-end') >= 0" variant="info" size="sm" + @click="notYetImplemented" > theirs-end<br> TODO: describe @@ -88,6 +92,7 @@ v-if="toResolve.solutionChoices.indexOf('theirs-both') >= 0" variant="info" size="sm" + @click="notYetImplemented" > theirs-both<br> TODO: describe @@ -97,6 +102,7 @@ v-if="toResolve.solutionChoices.indexOf('ours-start') >= 0" variant="info" size="sm" + @click="notYetImplemented" > ours-start<br> TODO: describe @@ -106,6 +112,7 @@ v-if="toResolve.solutionChoices.indexOf('ours-end') >= 0" variant="info" size="sm" + @click="notYetImplemented" > ours-end<br> TODO: describe @@ -115,6 +122,7 @@ v-if="toResolve.solutionChoices.indexOf('ours-both') >= 0" variant="info" size="sm" + @click="notYetImplemented" > ours-both<br> TODO: describe @@ -147,13 +155,22 @@ export default { }, methods: { - resolve () { - + resolve (mode) { + switch (mode) { + case 'ours': + case 'theirs': + this.$parent.resolveEvent(this.toResolve, mode) + this.$refs.modalEmissionManagerResolve.hide() + break + + default: + this.notYetImplemented() + break + } }, // initialise properties and open the modal open (event) { - this.$log.debug(event) this.toResolve = event this.loaded = true this.$refs.modalEmissionManagerResolve.show() @@ -163,6 +180,10 @@ export default { openNotNeeded () { this.$refs.modalEmissionManagerResolveNotNeeded.show() }, + + notYetImplemented: function () { + alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.') + }, } } </script>