Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m29s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m38s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m7s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m24s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
105 lines
4.3 KiB
Vue
105 lines
4.3 KiB
Vue
<script setup>
|
||
import { ref, watch } from 'vue';
|
||
import { Search, X } from '@lucide/vue';
|
||
import { PopoverAnchor, PopoverContent, PopoverPortal, PopoverRoot } from 'reka-ui';
|
||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||
import { http } from '@/lib/http';
|
||
|
||
/**
|
||
* Eine Person auswählen – mit Live-Suche im Personenverzeichnis.
|
||
* v-model: ID; person: bereits bekannte Angaben ({ id, name, … }) für die Anzeige.
|
||
*/
|
||
const props = defineProps({
|
||
person: { type: Object, default: null },
|
||
placeholder: { type: String, default: 'Name oder E-Mail eingeben …' },
|
||
id: { type: String, default: null },
|
||
});
|
||
|
||
const model = defineModel({ type: [Number, null], default: null });
|
||
const selected = ref(props.person);
|
||
const query = ref('');
|
||
const results = ref([]);
|
||
const open = ref(false);
|
||
const active = ref(0);
|
||
let timer;
|
||
|
||
watch(() => props.person, (person) => (selected.value = person));
|
||
|
||
watch(query, (value) => {
|
||
clearTimeout(timer);
|
||
|
||
if (value.trim().length < 2) {
|
||
results.value = [];
|
||
open.value = false;
|
||
|
||
return;
|
||
}
|
||
|
||
timer = setTimeout(async () => {
|
||
const data = await http.get(`/personen/suche?q=${encodeURIComponent(value.trim())}`);
|
||
results.value = data.people;
|
||
active.value = 0;
|
||
open.value = true;
|
||
}, 200);
|
||
});
|
||
|
||
function choose(person) {
|
||
if (!person) return;
|
||
|
||
selected.value = person;
|
||
model.value = person.id;
|
||
query.value = '';
|
||
open.value = false;
|
||
}
|
||
|
||
function clear() {
|
||
selected.value = null;
|
||
model.value = null;
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div v-if="selected && model" class="flex h-9 items-center gap-2 rounded-md border border-input bg-card pr-1 pl-1.5 text-sm shadow-xs">
|
||
<PersonAvatar :person="selected" class="size-6 text-[10px]" />
|
||
<span class="min-w-0 flex-1 truncate">{{ selected.name }}<span v-if="selected.job_title" class="text-muted-foreground"> · {{ selected.job_title }}</span></span>
|
||
<button type="button" class="rounded-sm p-1 text-muted-foreground hover:text-foreground" aria-label="Auswahl entfernen" @click="clear"><X class="size-3.5" /></button>
|
||
</div>
|
||
<PopoverRoot v-else v-model:open="open">
|
||
<PopoverAnchor as-child>
|
||
<div class="relative">
|
||
<Search class="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
||
<input
|
||
:id="id"
|
||
v-model="query"
|
||
type="search"
|
||
autocomplete="off"
|
||
:placeholder="placeholder"
|
||
class="h-9 w-full rounded-md border border-input bg-card pr-3 pl-8 text-sm shadow-xs focus-visible:border-brand-400 focus-visible:ring-3 focus-visible:ring-ring/30 focus-visible:outline-none"
|
||
@keydown.down.prevent="active = Math.min(results.length - 1, active + 1)"
|
||
@keydown.up.prevent="active = Math.max(0, active - 1)"
|
||
@keydown.enter.prevent="choose(results[active])"
|
||
/>
|
||
</div>
|
||
</PopoverAnchor>
|
||
<PopoverPortal>
|
||
<PopoverContent align="start" :side-offset="4" class="z-50 w-(--reka-popover-trigger-width) min-w-64 overflow-hidden rounded-md border bg-popover p-1 shadow-md" @open-auto-focus.prevent>
|
||
<button
|
||
v-for="(person, index) in results"
|
||
:key="person.id"
|
||
type="button"
|
||
class="flex w-full items-center gap-2.5 rounded-sm px-2 py-1.5 text-left text-sm"
|
||
:class="index === active ? 'bg-accent' : ''"
|
||
@mousemove="active = index"
|
||
@click="choose(person)"
|
||
>
|
||
<PersonAvatar :person="person" class="size-7 text-[11px]" />
|
||
<span class="min-w-0">
|
||
<span class="block truncate font-medium">{{ person.name }}</span>
|
||
<span v-if="person.job_title || person.department" class="block truncate text-xs text-muted-foreground">{{ [person.job_title, person.department].filter(Boolean).join(' · ') }}</span>
|
||
</span>
|
||
</button>
|
||
<p v-if="!results.length" class="px-3 py-4 text-center text-sm text-muted-foreground">Niemand gefunden</p>
|
||
</PopoverContent>
|
||
</PopoverPortal>
|
||
</PopoverRoot>
|
||
</template>
|