import FormInput from '../Form/Input.js'; import draggable from "../../directives/draggable.js"; import ApiCoursePicker from '../../api/factory/tempus/coursepicker.js'; export default { components: { FormInput }, directives: { draggable }, props: { stg: { type: [String, Number], default: null, }, studiensemester: { type: String, default: null }, }, emits: ['select-lecturer', 'select-kw'], data() { return { searchparam: '', allCourses: [], sortBy: null, multiWeekIds: new Set() } }, computed: { courses() { const query = (this.searchparam ?? '').trim().toLowerCase(); let result; if (query) { result = this.allCourses.filter(course => course.showname.toLowerCase().includes(query) || course.lektoren?.some(lektor => lektor.name.toLowerCase().includes(query) || lektor.kurzbz.toLowerCase().includes(query) ) ); } else result = this.allCourses; if (this.sortBy === 'lektor-asc' || this.sortBy === 'lektor-desc') { let dir = this.sortBy === 'lektor-asc' ? 1 : -1; return result.sort((a, b) => { let an = a.lektoren?.[0]?.kurzbz ?? ''; let bn = b.lektoren?.[0]?.kurzbz ?? ''; return an.localeCompare(bn) * dir; }); } else if (this.sortBy === 'kw-asc') { return result.sort((a, b) => (a.start_kw ?? 0) - (b.start_kw ?? 0)); } else if (this.sortBy === 'kw-desc') { return result.sort((a, b) => (b.start_kw ?? 0) - (a.start_kw ?? 0)); } else if (this.sortBy === 'stunden-asc') { return result.sort((a, b) => (a.offenestunden ?? 0) - (b.offenestunden ?? 0)); } else if (this.sortBy === 'stunden-desc') { return result.sort((a, b) => (b.offenestunden ?? 0) - (a.offenestunden ?? 0)); } return result; } }, watch: { stg(val) { this.searchparam = ''; this.loadCoursesByStg(val); }, studiensemester() { if (this.stg) this.loadCoursesByStg(this.stg); }, }, methods: { async loadCoursesByStg(stg) { if (!stg) { this.allCourses = []; return; } this.$api.call(ApiCoursePicker.getByStg(this.stg, this.studiensemester)) .then(result => { this.allCourses = result.data.map(e => ({ lehreinheit_id: e.lehreinheit_id, lektoren: e.lektoren, raumtyp: e.raumtyp, raumtypalternativ: e.raumtypalternativ, semesterstunden: e.planstunden, stundenblockung: e.stundenblockung, wochenrythmus: e.wochenrythmus, offenestunden: e.offenestunden, start_kw: e.start_kw, anmerkung: e.anmerkung, lehrfach: e.lehrfach, lehrform: e.lehrform, lehrfach_bez: e.lehrfach_bez, lehrfach_farbe: e.lehrfach_farbe, lehrverband: e.lehrverband, showname: `${e.lehrfach} ${e.lehrform}`, orig: { type: 'lehreinheit', lehreinheit_id: e.lehreinheit_id[0], blockung: e.stundenblockung, entry: e, } })); }) .catch(this.$fhcAlert.handleSystemError); }, dragLehreinheitCollection(course) { const orig = course.orig; return { type: 'lehreinheit', id: orig.lehreinheit_id, orig: orig, stundenblockung: course.stundenblockung, multiweek: this.isMultiWeek(course), }; }, courseStyle(course) { if (!course.lehrfach_farbe) return {}; return '--event-bg:#' + course.lehrfach_farbe; }, selectLecturer(lektor) { this.$emit('select-lecturer', lektor); }, setSort(field) { if (this.sortBy === `${field}-asc`) this.sortBy = `${field}-desc`; else if (this.sortBy === `${field}-desc`) this.sortBy = null; else this.sortBy = `${field}-asc`; }, sortIcon(field) { if (this.sortBy === `${field}-asc`) return 'fa-arrow-up'; if (this.sortBy === `${field}-desc`) return 'fa-arrow-down'; return 'fa-sort'; }, isSortActive(field) { return this.sortBy === `${field}-asc` || this.sortBy === `${field}-desc`; }, reload() { this.loadCoursesByStg(this.stg); }, toggleMultiWeek(course) { let id = course.lehreinheit_id[0]; let weekIds = new Set(this.multiWeekIds); if (weekIds.has(id)) weekIds.delete(id); else weekIds.add(id); this.multiWeekIds = weekIds; }, isMultiWeek(course) { return this.multiWeekIds.has(course.lehreinheit_id[0]); }, }, template: `