import ApiKalender from '../../api/factory/tempus/kalender.js'; import BsModal from '../../../js/components/Bootstrap/Modal.js'; export default { components: { BsModal, }, props: { show: { type: Boolean, default: false }, lehreinheitId: { type: [String, Number], default: null }, ortKurzbz: { type: String, default: null }, startTime: { type: String, default: null }, endTime: { type: String, default: null }, }, emits: ['close', 'confirmed'], data() { return { loading: false, plan: [], skippedWeeks: [], errors: [], restOffen: 0, }; }, watch: { show(val) { if (val) { this.loadPlan(); this.$refs.bsModal.show(); } else { this.$refs.bsModal.hide(); } }, }, computed: { countTermin() { return (this.plan.filter(termin => termin.planen).length); }, formattedSkippedWeeks() { return this.skippedWeeks.map(week => luxon.DateTime.fromISO(week).toFormat('dd.MM.yyyy')).join('\n'); } }, methods: { async loadPlan() { this.loading = true; this.plan = []; this.errors = []; this.skippedWeeks = []; this.restOffen = 0; await this.$api.call( ApiKalender.calculateMultiWeekPlan( this.lehreinheitId, this.ortKurzbz, this.startTime, this.endTime )) .then(result => result.data) .then(result => { this.plan = (result.plan || []).map(termin => ({ ...termin, selected_ort_kurzbz: termin.raum_vorschlaege?.[0]?.ort_kurzbz ?? termin.ort_kurzbz, planen: (termin.collisions && termin.collisions.length > 0) ? false : true, })); this.skippedWeeks = result.skipped_weeks || []; this.errors = result.errors || []; this.restOffen = result.rest_offen || 0; this.loading = false; }) .catch(error => { this.$fhcAlert.handleSystemError(error); this.close(); }); }, async confirm() { this.loading = true; await this.$api.call( ApiKalender.confirmMultiWeekPlan(this.plan.filter(termin => termin.planen), this.lehreinheitId) ); this.$emit('confirmed'); this.close(); }, close() { this.loading = false; this.$emit('close'); }, hasCollision(termin) { return termin.collisions && termin.collisions.length > 0; }, roomOptions(termin) { return termin.raum_vorschlaege || []; }, formatDate(date) { return luxon.DateTime.fromISO(date).toFormat('dd.MM.yyyy'); } }, template: `
Wird berechnet...
Achtung: {{ restOffen }} Stunden konnten nicht verplant werden (Semesterende erreicht).
Übersprungende Ferienwochen:
{{ formattedSkippedWeeks }}
{{ err.message }}
Datum Zeit Collisions Raum Planen?
{{ formatDate(termin.datum) }} {{ termin.start.split(' ')[1] }} - {{ termin.ende.split(' ')[1] }}
{{ termin.collisions.map(c => c.message).join('\\n') }}
---
Kein Raum verfügbar
` }