Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 9m3s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 9m36s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 13m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 13m56s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 12m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 11m58s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 50s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m13s
- PageHeader: Kopfband (Standard, kompakt), Kopfband mit Symbol, mit Symbol, kräftiger Titel – Einstellung page_header im Erscheinungsbild - Symbol vom passenden Menüpunkt (aktiv oder per Adresse), Prop icon - In Spalten (z. B. Downloads) schlichte Form statt Band - Zurück-Links als breadcrumbs (IT-Service), Profil bearbeiten mit PageHeader - Plugin-Assets: Fingerabdruck berücksichtigt Änderungszeiten der Dateien Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
314 lines
15 KiB
Vue
314 lines
15 KiB
Vue
<script setup>
|
||
import { pluginComponent } from '@/lib/pluginComponents';
|
||
import { defineAsyncComponent, ref } from 'vue';
|
||
import { router, useForm } from '@inertiajs/vue3';
|
||
import { Camera, Image as ImageIcon, LoaderCircle, Mail, Trash2 } from '@lucide/vue';
|
||
import { toast } from 'vue-sonner';
|
||
import { Button } from '@/components/ui/button';
|
||
import { Input } from '@/components/ui/input';
|
||
import { Switch } from '@/components/ui/switch';
|
||
import { Textarea } from '@/components/ui/textarea';
|
||
import FormField from '@/components/FormField.vue';
|
||
import PageHeader from '@/components/PageHeader.vue';
|
||
import Panel from '@/components/Panel.vue';
|
||
import CoverBanner from '@/components/CoverBanner.vue';
|
||
import DevicesPanel from '@/components/profile/DevicesPanel.vue';
|
||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||
import AppLayout from '@/layouts/AppLayout.vue';
|
||
|
||
const props = defineProps({
|
||
profile: { type: Object, required: true },
|
||
managed: { type: Array, default: () => [] },
|
||
locked: { type: Array, default: () => [] },
|
||
customFields: { type: Array, default: () => [] },
|
||
sections: { type: Array, default: () => [] },
|
||
tokens: { type: Array, default: () => [] },
|
||
digest: { type: Object, default: null },
|
||
});
|
||
|
||
// Wochenüberblick per E-Mail
|
||
function setDigest(enabled) {
|
||
router.put('/profil/wochenueberblick', { enabled }, { preserveScroll: true, onSuccess: () => toast.success(enabled ? 'Wochenüberblick eingeschaltet' : 'Wochenüberblick ausgeschaltet') });
|
||
}
|
||
|
||
// Abschnitte aus Plugins (App\Profile\ProfileSections): „<plugin>::Name“ aus plugins-core/<plugin>/resources/js/profile
|
||
const sectionLoaders = import.meta.glob('../../../../plugins-core/*/resources/js/profile/*.vue');
|
||
const sectionComponents = Object.fromEntries(Object.entries(sectionLoaders).map(([path, loader]) => [
|
||
`${path.match(/plugins-core\/([^/]+)\//)[1]}::${path.split('/').pop().replace('.vue', '')}`,
|
||
defineAsyncComponent(loader),
|
||
]));
|
||
|
||
const isManaged = (field) => props.managed.includes(field);
|
||
const isLocked = (field) => isManaged(field) || props.locked.includes(field);
|
||
|
||
// Stammdaten
|
||
const form = useForm({
|
||
first_name: props.profile.first_name ?? '',
|
||
last_name: props.profile.last_name ?? '',
|
||
email: props.profile.email,
|
||
job_title: props.profile.job_title ?? '',
|
||
department: props.profile.department ?? '',
|
||
location: props.profile.location ?? '',
|
||
phone: props.profile.phone ?? '',
|
||
mobile: props.profile.mobile ?? '',
|
||
about: props.profile.about ?? '',
|
||
custom_fields: Object.fromEntries(props.customFields.map((field) => [field.key, field.value ?? ''])),
|
||
});
|
||
|
||
const inputTypes = { email: 'email', phone: 'tel', url: 'url', date: 'date' };
|
||
|
||
function customHint(field) {
|
||
const hints = [];
|
||
|
||
if (field.managed) hints.push('Wird aus Microsoft Entra ID übernommen.');
|
||
else if (field.readonly) hints.push('Wird von der Personalverwaltung gepflegt.');
|
||
if (field.restricted) hints.push('Nur für Sie und die Personalverwaltung sichtbar.');
|
||
if (field.help) hints.push(field.help);
|
||
|
||
return hints.join(' ');
|
||
}
|
||
|
||
function saveProfile() {
|
||
form.put('/profil', {
|
||
preserveScroll: true,
|
||
onSuccess: () => {
|
||
form.defaults();
|
||
toast.success('Profil gespeichert');
|
||
},
|
||
});
|
||
}
|
||
|
||
const fields = [
|
||
{ key: 'first_name', label: 'Vorname', autocomplete: 'given-name' },
|
||
{ key: 'last_name', label: 'Nachname', autocomplete: 'family-name' },
|
||
{ key: 'email', label: 'E-Mail-Adresse', type: 'email', autocomplete: 'email', wide: true },
|
||
{ key: 'job_title', label: 'Funktion', autocomplete: 'organization-title' },
|
||
{ key: 'department', label: 'Abteilung' },
|
||
{ key: 'location', label: 'Standort' },
|
||
{ key: 'phone', label: 'Telefon', type: 'tel', autocomplete: 'tel' },
|
||
{ key: 'mobile', label: 'Mobil', type: 'tel' },
|
||
];
|
||
|
||
// Profilbild
|
||
const avatarInput = ref(null);
|
||
const avatarForm = useForm({ avatar: null });
|
||
|
||
function uploadAvatar(event) {
|
||
const file = event.target.files?.[0];
|
||
|
||
if (!file) return;
|
||
|
||
avatarForm.avatar = file;
|
||
avatarForm.post('/profil/bild', {
|
||
preserveScroll: true,
|
||
forceFormData: true,
|
||
onSuccess: () => toast.success('Profilbild aktualisiert'),
|
||
onFinish: () => {
|
||
event.target.value = '';
|
||
},
|
||
});
|
||
}
|
||
|
||
function removeAvatar() {
|
||
router.delete('/profil/bild', {
|
||
preserveScroll: true,
|
||
onSuccess: () => toast.success('Profilbild entfernt'),
|
||
});
|
||
}
|
||
|
||
// Titelbild
|
||
const coverInput = ref(null);
|
||
const coverForm = useForm({ cover: null });
|
||
|
||
function uploadCover(event) {
|
||
const file = event.target.files?.[0];
|
||
|
||
if (!file) return;
|
||
|
||
coverForm.cover = file;
|
||
coverForm.post('/profil/titelbild', {
|
||
preserveScroll: true,
|
||
forceFormData: true,
|
||
onSuccess: () => toast.success('Titelbild aktualisiert'),
|
||
onFinish: () => {
|
||
event.target.value = '';
|
||
},
|
||
});
|
||
}
|
||
|
||
function removeCover() {
|
||
router.delete('/profil/titelbild', {
|
||
preserveScroll: true,
|
||
onSuccess: () => toast.success('Titelbild entfernt – es gilt wieder das Standardbild'),
|
||
});
|
||
}
|
||
|
||
// Passwort
|
||
const passwordForm = useForm({
|
||
current_password: '',
|
||
password: '',
|
||
password_confirmation: '',
|
||
});
|
||
|
||
function savePassword() {
|
||
passwordForm.put('/user/password', {
|
||
preserveScroll: true,
|
||
errorBag: 'updatePassword',
|
||
onSuccess: () => {
|
||
passwordForm.reset();
|
||
toast.success('Passwort geändert');
|
||
},
|
||
});
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<AppLayout title="Profil bearbeiten">
|
||
<PageHeader title="Profil bearbeiten" icon="user-round" description="Ihre Angaben im Personenverzeichnis, Profil- und Titelbild, Benachrichtigungen und Geräte." />
|
||
|
||
<div class="grid gap-6 lg:grid-cols-12">
|
||
<div class="lg:col-span-4">
|
||
<Panel title="Profilbild">
|
||
<div class="flex flex-col items-center text-center">
|
||
<PersonAvatar :person="profile" class="size-32 text-3xl" />
|
||
<input ref="avatarInput" type="file" accept="image/jpeg,image/png,image/webp" class="hidden" @change="uploadAvatar" />
|
||
<div class="mt-5 flex flex-wrap justify-center gap-2">
|
||
<Button variant="outline" :disabled="avatarForm.processing" @click="avatarInput?.click()">
|
||
<LoaderCircle v-if="avatarForm.processing" class="animate-spin" />
|
||
<Camera v-else />
|
||
{{ profile.avatar_url ? 'Bild ändern' : 'Bild hochladen' }}
|
||
</Button>
|
||
<Button v-if="profile.avatar_url" variant="ghost" class="text-destructive hover:text-destructive" @click="removeAvatar">
|
||
<Trash2 /> Entfernen
|
||
</Button>
|
||
</div>
|
||
<p v-if="avatarForm.errors.avatar" class="mt-3 text-[13px] text-destructive">{{ avatarForm.errors.avatar }}</p>
|
||
<p class="mt-3 text-[13px] text-muted-foreground">JPG, PNG oder WebP, höchstens 8 MB. Das Bild wird quadratisch zugeschnitten.</p>
|
||
</div>
|
||
</Panel>
|
||
|
||
<Panel title="Titelbild" class="mt-6">
|
||
<CoverBanner :image="profile.cover_url" class="h-24 rounded-md" />
|
||
<input ref="coverInput" type="file" accept="image/jpeg,image/png,image/webp" class="hidden" @change="uploadCover" />
|
||
<div class="mt-4 flex flex-wrap gap-2">
|
||
<Button variant="outline" :disabled="coverForm.processing" @click="coverInput?.click()">
|
||
<LoaderCircle v-if="coverForm.processing" class="animate-spin" />
|
||
<ImageIcon v-else />
|
||
{{ profile.cover_url ? 'Bild ändern' : 'Bild hochladen' }}
|
||
</Button>
|
||
<Button v-if="profile.cover_url" variant="ghost" class="text-destructive hover:text-destructive" @click="removeCover">
|
||
<Trash2 /> Entfernen
|
||
</Button>
|
||
</div>
|
||
<p v-if="coverForm.errors.cover" class="mt-3 text-[13px] text-destructive">{{ coverForm.errors.cover }}</p>
|
||
<p class="mt-3 text-[13px] text-muted-foreground">Erscheint oben in Ihrem Profil und in der Begrüßung auf der Startseite – mit einer Fläche in der Hausfarbe darüber. Querformat, höchstens 8 MB.</p>
|
||
</Panel>
|
||
|
||
<Panel v-if="digest" title="Wochenüberblick" class="mt-6">
|
||
<label class="flex items-start justify-between gap-4 text-sm">
|
||
<span class="flex gap-3">
|
||
<Mail class="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||
<span>
|
||
<span class="font-medium">Per E-Mail zusammenfassen</span>
|
||
<span class="block text-[13px] text-muted-foreground">Neuigkeiten, Termine und mehr aus der letzten Woche – {{ digest.schedule }} an {{ profile.email }}.</span>
|
||
</span>
|
||
</span>
|
||
<Switch :model-value="digest.enabled" aria-label="Wochenüberblick per E-Mail" @update:model-value="setDigest" />
|
||
</label>
|
||
</Panel>
|
||
|
||
<DevicesPanel :tokens="tokens" class="mt-6" />
|
||
</div>
|
||
|
||
<div class="grid content-start gap-6 lg:col-span-8">
|
||
<Panel title="Persönliche Angaben">
|
||
<form class="grid gap-5" @submit.prevent="saveProfile">
|
||
<div class="grid gap-5 sm:grid-cols-2">
|
||
<FormField
|
||
v-for="field in fields"
|
||
:id="field.key"
|
||
:key="field.key"
|
||
:label="field.label"
|
||
:error="form.errors[field.key]"
|
||
:hint="isManaged(field.key) ? 'Wird vom Anmeldedienst übernommen.' : isLocked(field.key) ? 'Ändert die Personalverwaltung bzw. Administration.' : ''"
|
||
:class="{ 'sm:col-span-2': field.wide }"
|
||
>
|
||
<Input
|
||
:id="field.key"
|
||
v-model="form[field.key]"
|
||
:type="field.type ?? 'text'"
|
||
:autocomplete="field.autocomplete"
|
||
:disabled="isLocked(field.key)"
|
||
:aria-invalid="!!form.errors[field.key]"
|
||
/>
|
||
</FormField>
|
||
<FormField id="about" label="Über mich" :error="form.errors.about" hint="Aufgaben, Themen, bei denen man Sie ansprechen kann." class="sm:col-span-2">
|
||
<Textarea id="about" v-model="form.about" rows="4" maxlength="2000" />
|
||
</FormField>
|
||
</div>
|
||
<div v-if="customFields.length" class="grid gap-5 border-t pt-5">
|
||
<h3 class="text-sm font-semibold">Weitere Angaben</h3>
|
||
<div class="grid gap-5 sm:grid-cols-2">
|
||
<FormField
|
||
v-for="field in customFields"
|
||
:id="`custom-${field.key}`"
|
||
:key="field.key"
|
||
:label="field.label"
|
||
:error="form.errors[`custom_fields.${field.key}`]"
|
||
:hint="customHint(field)"
|
||
:class="{ 'sm:col-span-2': field.type === 'textarea' }"
|
||
>
|
||
<Textarea
|
||
v-if="field.type === 'textarea'"
|
||
:id="`custom-${field.key}`"
|
||
v-model="form.custom_fields[field.key]"
|
||
rows="3"
|
||
:disabled="field.readonly"
|
||
/>
|
||
<Input
|
||
v-else
|
||
:id="`custom-${field.key}`"
|
||
v-model="form.custom_fields[field.key]"
|
||
:type="inputTypes[field.type] ?? 'text'"
|
||
:disabled="field.readonly"
|
||
:aria-invalid="!!form.errors[`custom_fields.${field.key}`]"
|
||
/>
|
||
</FormField>
|
||
</div>
|
||
</div>
|
||
<div class="flex justify-end border-t pt-5">
|
||
<Button type="submit" :disabled="form.processing || !form.isDirty">
|
||
<LoaderCircle v-if="form.processing" class="animate-spin" />
|
||
Speichern
|
||
</Button>
|
||
</div>
|
||
</form>
|
||
</Panel>
|
||
|
||
<component :is="sectionComponents[section.component] ?? pluginComponent(section.component, 'profile')" v-for="section in sections" :key="section.key" v-bind="section.props" />
|
||
|
||
<Panel v-if="profile.has_password" title="Passwort ändern">
|
||
<form class="grid gap-5" @submit.prevent="savePassword">
|
||
<FormField id="current_password" label="Aktuelles Passwort" :error="passwordForm.errors.current_password" class="sm:max-w-sm">
|
||
<Input id="current_password" v-model="passwordForm.current_password" type="password" autocomplete="current-password" />
|
||
</FormField>
|
||
<div class="grid gap-5 sm:grid-cols-2">
|
||
<FormField id="password" label="Neues Passwort" :error="passwordForm.errors.password" hint="Mindestens 10 Zeichen, mit Buchstaben und Ziffern.">
|
||
<Input id="password" v-model="passwordForm.password" type="password" autocomplete="new-password" />
|
||
</FormField>
|
||
<FormField id="password_confirmation" label="Neues Passwort wiederholen">
|
||
<Input id="password_confirmation" v-model="passwordForm.password_confirmation" type="password" autocomplete="new-password" />
|
||
</FormField>
|
||
</div>
|
||
<div class="flex justify-end border-t pt-5">
|
||
<Button type="submit" :disabled="passwordForm.processing">
|
||
<LoaderCircle v-if="passwordForm.processing" class="animate-spin" />
|
||
Passwort ändern
|
||
</Button>
|
||
</div>
|
||
</form>
|
||
</Panel>
|
||
</div>
|
||
</div>
|
||
</AppLayout>
|
||
</template>
|