Umfragen-Plugin (0.32.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m33s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 5m25s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 6m7s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m54s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m9s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m55s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 10m12s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 1m26s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 9m48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m52s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 12:54:17 +00:00
parent 08953d52cb
commit 3f67fde50b
153 changed files with 2075 additions and 329 deletions

View file

@ -0,0 +1,116 @@
<script setup>
import { computed } from 'vue';
import { useForm } from '@inertiajs/vue3';
import { CircleCheck, LoaderCircle, Lock } from '@lucide/vue';
import { Button } from '@/components/ui/button';
import { Textarea } from '@/components/ui/textarea';
import PollResults from './PollResults.vue';
/**
* Umfrage beantworten – oder, nach der Abstimmung, die Ergebnisse bzw. einen Hinweis.
*/
const props = defineProps({
poll: { type: Object, required: true },
compact: { type: Boolean, default: false },
disabled: { type: Boolean, default: false },
});
const form = useForm({
answers: Object.fromEntries(props.poll.questions.map((q) => [q.id, q.type === 'multiple' ? [] : null])),
});
function toggle(question, optionId) {
const list = form.answers[question.id];
const index = list.indexOf(optionId);
if (index >= 0) list.splice(index, 1);
else if (!question.max || list.length < question.max) list.push(optionId);
}
const complete = computed(() => props.poll.questions.every((q) => {
const value = form.answers[q.id];
return !q.required || (Array.isArray(value) ? value.length : value !== null && value !== '');
}));
function submit() {
form.post(`/umfragen/${props.poll.id}/abstimmen`, { preserveScroll: true });
}
const firstError = computed(() => form.errors.answers ?? null);
</script>
<template>
<div>
<form v-if="poll.can_vote" class="grid gap-6" @submit.prevent="submit">
<fieldset v-for="(question, index) in poll.questions" :key="question.id" class="grid gap-2.5" :disabled="disabled">
<legend class="mb-2.5 text-sm font-semibold">
<span v-if="poll.questions.length > 1" class="text-muted-foreground">{{ index + 1 }}. </span>{{ question.label }}
<span v-if="!question.required" class="font-normal text-muted-foreground"> (optional)</span>
<span v-if="question.type === 'multiple'" class="block text-xs font-normal text-muted-foreground">{{ question.max ? `Bis zu ${question.max} Antworten` : 'Mehrere Antworten möglich' }}</span>
</legend>
<template v-if="question.type === 'single' || question.type === 'multiple'">
<label
v-for="option in question.options"
:key="option.id"
class="flex cursor-pointer items-center gap-3 rounded-md border px-3.5 py-2.5 text-sm transition-colors hover:bg-accent/50 has-[:checked]:border-brand has-[:checked]:bg-brand-soft"
>
<input
v-if="question.type === 'single'"
v-model="form.answers[question.id]"
type="radio"
:name="`q-${poll.id}-${question.id}`"
:value="option.id"
class="size-4 accent-[var(--color-brand)]"
/>
<input
v-else
type="checkbox"
:checked="form.answers[question.id].includes(option.id)"
class="size-4 accent-[var(--color-brand)]"
@change="toggle(question, option.id)"
/>
{{ option.label }}
</label>
</template>
<div v-else-if="question.type === 'scale'" class="grid gap-1.5">
<div class="flex flex-wrap gap-1.5">
<label
v-for="n in question.scale"
:key="n"
class="grid size-10 cursor-pointer place-items-center rounded-md border text-sm font-medium tabular-nums transition-colors hover:bg-accent/50 has-[:checked]:border-brand has-[:checked]:bg-brand has-[:checked]:text-brand-foreground"
>
<input v-model="form.answers[question.id]" type="radio" :name="`q-${poll.id}-${question.id}`" :value="n" class="sr-only" />
{{ n }}
</label>
</div>
<div v-if="question.min_label || question.max_label" class="flex justify-between gap-3 text-xs text-muted-foreground" :style="{ maxWidth: `${question.scale * 2.5 + (question.scale - 1) * 0.375}rem` }">
<span>1 = {{ question.min_label }}</span><span>{{ question.scale }} = {{ question.max_label }}</span>
</div>
</div>
<Textarea v-else v-model="form.answers[question.id]" rows="3" maxlength="2000" />
<p v-if="form.errors[`answers.${question.id}`]" class="text-[13px] text-destructive">{{ form.errors[`answers.${question.id}`] }}</p>
</fieldset>
<p v-if="firstError" class="text-[13px] text-destructive">{{ firstError }}</p>
<div class="flex flex-wrap items-center gap-3">
<Button type="submit" :disabled="form.processing || !complete || disabled">
<LoaderCircle v-if="form.processing" class="animate-spin" />
Abstimmen
</Button>
<span v-if="poll.anonymous" class="inline-flex items-center gap-1.5 text-xs text-muted-foreground"><Lock class="size-3.5" /> Anonym – Ihre Antworten werden ohne Namen gespeichert.</span>
</div>
</form>
<template v-else>
<p v-if="poll.voted" class="mb-5 flex items-center gap-2 text-sm font-medium text-brand-text"><CircleCheck class="size-4" /> Sie haben teilgenommen – danke!</p>
<p v-else-if="!poll.open" class="mb-5 text-sm text-muted-foreground">Diese Umfrage ist beendet.</p>
<PollResults v-if="poll.results" :results="poll.results" :compact="compact" />
<p v-else-if="poll.results_note" class="text-sm text-muted-foreground">{{ poll.results_note }}</p>
</template>
</div>
</template>

View file

@ -0,0 +1,50 @@
<script setup>
/**
* Ergebnisse einer Umfrage: Balken je Antwort, Skalen mit Durchschnitt, Freitexte (nur Redaktion).
*/
defineProps({
results: { type: Object, required: true },
compact: { type: Boolean, default: false },
});
</script>
<template>
<div class="grid gap-6">
<p class="text-sm text-muted-foreground">{{ results.total }} {{ results.total === 1 ? 'Teilnahme' : 'Teilnahmen' }}</p>
<section v-for="(question, index) in results.questions" :key="question.id" class="grid gap-3">
<h3 class="text-sm font-semibold"><span v-if="results.questions.length > 1" class="text-muted-foreground">{{ index + 1 }}. </span>{{ question.label }}</h3>
<ul v-if="question.options" class="grid gap-2.5">
<li v-for="option in question.options" :key="option.id" class="grid gap-1">
<div class="flex items-baseline justify-between gap-3 text-sm">
<span class="min-w-0">{{ option.label }}</span>
<span class="shrink-0 text-muted-foreground tabular-nums">{{ option.percent }} %<span v-if="!compact" class="text-xs"> · {{ option.votes }}</span></span>
</div>
<div class="h-2 overflow-hidden rounded-full bg-muted">
<div class="h-full rounded-full bg-brand transition-[width] duration-500" :style="{ width: `${option.percent}%` }" />
</div>
</li>
</ul>
<div v-else-if="question.type === 'scale'" class="grid gap-2">
<p class="text-sm">Durchschnitt: <span class="font-semibold tabular-nums">{{ question.average === null ? '–' : question.average.toLocaleString('de-DE') }}</span> <span class="text-muted-foreground">von {{ question.scale }}</span></p>
<div class="flex h-20 items-end gap-1" role="img" :aria-label="`Verteilung der Antworten von 1 bis ${question.scale}`">
<div v-for="bar in question.distribution" :key="bar.value" class="flex flex-1 flex-col items-center gap-1">
<div class="w-full rounded-t-sm bg-brand/75" :style="{ height: `${question.answered ? Math.max(3, (bar.votes / Math.max(...question.distribution.map((d) => d.votes), 1)) * 56) : 3}px` }" :title="`${bar.value}: ${bar.votes}`" />
<span class="text-[11px] text-muted-foreground tabular-nums">{{ bar.value }}</span>
</div>
</div>
<div v-if="question.min_label || question.max_label" class="flex justify-between text-[11px] text-muted-foreground">
<span>{{ question.min_label }}</span><span>{{ question.max_label }}</span>
</div>
</div>
<template v-else-if="question.type === 'text'">
<p class="text-sm text-muted-foreground">{{ question.answered }} {{ question.answered === 1 ? 'Antwort' : 'Antworten' }}</p>
<ul v-if="question.texts?.length" class="grid max-h-80 gap-2 overflow-y-auto">
<li v-for="(text, i) in question.texts" :key="i" class="rounded-md bg-muted/60 px-3 py-2 text-sm whitespace-pre-line">{{ text }}</li>
</ul>
</template>
</section>
</div>
</template>