import ApiDetailHeader from "../../api/factory/detailHeader.js"; import ApiHandleFoto from "../../api/factory/fotoHandling.js"; import ModalUploadFoto from "./Modal/UploadFoto.js"; import CoreTag from "../Tag/Tag.js"; import ApiTag from "../../api/factory/stv/tag.js"; import { idTagFormatter } from "../Tag/tagFormatter.js"; export default { name: 'DetailHeader', components: { ModalUploadFoto, CoreTag }, props: { headerData: { type: Object, required: false }, person_id: { type: Number, required: false }, mitarbeiter_uid: { type: String, required: false }, fotoEditable: { type: Boolean, required: false, default: false }, domain: { type: String, required: false }, typeHeader: { type: String, default: 'student', validator(value) { return [ 'student', 'mitarbeiter', ].includes(value) } } }, inject: { tagsEnabled: { from: 'configStvTagsEnabled', default: false }, currentSemester: { from: 'currentSemester', required: true }, lists: { from: 'lists', required: true }, }, computed: { appRoot() { return FHC_JS_DATA_STORAGE_OBJECT.app_root; }, validatedHeaderData() { if (this.typeHeader === 'student') return this.headerData; if (this.typeHeader === 'mitarbeiter') return this.person_id; return null; }, hasTileAlphaSlot() { return !!this.$slots.titleAlphaTile }, hasTileBetaSlot() { return !!this.$slots.titleBetaTile }, hasTileGammaSlot() { return !!this.$slots.titleGammaTile }, hasTileUIDSlot() { return !!this.$slots.uid }, prestudentIds() { if (this.headerData[0].prestudent_id) { return [this.headerData[0].prestudent_id]; } }, semesterDates(){ return this.lists.studiensemester?.find(item => item.studiensemester_kurzbz === this.currentSemester) || {}; } }, created(){ if (this.typeHeader === 'student') { if (!this.headerData) { throw new Error('[DetailHeader] "headerData" is required.') } if(this.tagsEnabled) { this.loadTagsAndRender(this.headerData[0].prestudent_id); } } else if (this.typeHeader === 'mitarbeiter') { if (!this.person_id || !this.mitarbeiter_uid || !this.domain) { throw new Error( '[DetailHeader] "person_id", "mitarbeiter_uid", and "domain" are required.' ) } this.loadHeaderData(this.person_id, this.mitarbeiter_uid); } }, watch: { person_id: { handler(newVal) { if (newVal) { this.loadHeaderData(newVal, this.mitarbeiter_uid); } }, deep: true, }, headerData: { handler(newVal) { if(this.tagsEnabled) { this.loadTagsAndRender(this.headerData[0].prestudent_id); } }, deep: true, }, }, data(){ return{ headerDataMa: {}, departmentData: {}, leitungData: {}, isFetchingIssues: false, tagEndpoint: ApiTag, tagData: null, rebuildData: null, }; }, methods: { loadHeaderData(person_id, mitarbeiter_uid){ this.getHeader(person_id); this.loadDepartmentData(mitarbeiter_uid) .then(() => { // Call getLeitungOrg only after departmentData is loaded this.getLeitungOrg(this.departmentData.oe_kurzbz); }) .catch((error) => { console.error("Error loading header data: ", error); }); }, getHeader(person_id) { return this.$api .call(ApiDetailHeader.getHeader(person_id)) .then(result => { this.headerDataMa = result.data; }) .catch(this.$fhcAlert.handleSystemError); }, loadDepartmentData(mitarbeiter_uid) { return this.$api .call(ApiDetailHeader.getPersonAbteilung(mitarbeiter_uid)) .then(result => { this.departmentData = result.data; }) .catch(this.$fhcAlert.handleSystemError); }, getLeitungOrg(oekurzbz){ return this.$api .call(ApiDetailHeader.getLeitungOrg(oekurzbz)) .then(result => { this.leitungData = result.data; }) .catch(this.$fhcAlert.handleSystemError); }, async goToLeitung() { this.loadHeaderData(this.leitungData.person_id, this.leitungData.uid); this.redirectToLeitung(); }, redirectToLeitung() { this.$emit('redirectToLeitung', { person_id: this.leitungData.person_id, uid: this.leitungData.uid }); }, showModal(person_id){ this.$refs.modalFoto.open(person_id); }, showDeleteModal(person_id){ this.$fhcAlert .confirmDelete() .then(result => result ? person_id : Promise.reject({handled: true})) .then(this.deleteFoto) .catch(this.$fhcAlert.handleSystemError); }, deleteFoto(person_id){ return this.$api .call(ApiHandleFoto.deleteFoto(person_id)) .then(result => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); }) .catch(this.$fhcAlert.handleSystemError) .finally(()=> { this.reload(); }); }, reload() { if(this.person_id) { this.loadHeaderData(this.person_id, this.mitarbeiter_uid); } else { this.$emit('reload'); } }, getFotoSrc(foto) { if(foto === null) { return FHC_JS_DATA_STORAGE_OBJECT.app_root + 'skin/images/profilbild_dummy.jpg'; } else { return 'data:image/jpeg;base64,' + foto; } }, //methods tags async loadTagsAndRender(prestudent_id) { await this.getAllTags(prestudent_id); const container = idTagFormatter( prestudent_id, this.tagData, this.$refs.tagComponent, 'prestudent_id', this.semesterDates.start, this.semesterDates.ende ); this.$refs.tagWrapper.innerHTML = ''; this.$refs.tagWrapper.appendChild(container); }, getAllTags(prestudent_id){ return this.$api .call(ApiTag.getAllTagsPrestudent({prestudent_id})) .then(result => { this.tagData = result.data; }) .catch(this.$fhcAlert.handleSystemError); }, addedTag(addedTag) { this.reload(); }, deletedTag(id) { this.reload(); }, updatedTag(updatedTag) { this.reload(); }, rebuildPrestudentTags(){ const params = { id : this.headerData[0].prestudent_id, typeId: 'prestudent_id', sem: this.currentSemester }; return this.$api .call(ApiTag.rebuildTagsforTypeId(params)) .then(result => { this.rebuildData = result.data; console.log("Rebuild manually triggered"); this.reload(); }) .catch(this.$fhcAlert.handleSystemError); }, }, template: `
Email {{ mitarbeiter_uid }}@{{ domain }} {{headerDataMa.alias}}@{{domain}} | DW {{headerDataMa?.telefonklappe}}