Ideenbox (0.33.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 9m16s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 9m12s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 9m52s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 9m47s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m6s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m6s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 56s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m56s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m53s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 13:09:05 +00:00
parent bd7536ab82
commit 858e248d26
160 changed files with 1543 additions and 348 deletions

View file

@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('ideas', function (Blueprint $table) {
$table->id();
$table->string('title', 160);
$table->text('body');
// Anonym eingereicht: keine Person gespeichert
$table->foreignId('author_id')->nullable()->constrained('users')->nullOnDelete();
$table->boolean('anonymous')->default(false);
// new | review | done | rejected
$table->string('status', 20)->default('new');
$table->text('status_note')->nullable();
$table->timestamp('status_changed_at')->nullable();
$table->unsignedInteger('supports_count')->default(0);
$table->unsignedInteger('comments_count')->default(0);
$table->timestamps();
$table->index(['status', 'created_at']);
});
Schema::create('idea_supports', function (Blueprint $table) {
$table->foreignId('idea_id')->constrained('ideas')->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->timestamp('created_at')->nullable();
$table->primary(['idea_id', 'user_id']);
});
Schema::create('idea_comments', function (Blueprint $table) {
$table->id();
$table->foreignId('idea_id')->constrained('ideas')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->text('body');
// Antwort des Gremiums (hervorgehoben)
$table->boolean('official')->default(false);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('idea_comments');
Schema::dropIfExists('idea_supports');
Schema::dropIfExists('ideas');
}
};

View file

@ -0,0 +1,14 @@
{
"slug": "ideen",
"name": "Ideenbox",
"version": "1.0.0",
"description": "Ideen und Verbesserungsvorschläge – für alle sichtbar, mit Unterstützen und Kommentaren. Ein Gremium prüft und setzt den Status (neu, in Prüfung, umgesetzt, abgelehnt). Einreichen auf Wunsch anonym.",
"author": "Inhaus",
"namespace": "Inhaus\\Plugins\\Ideen\\",
"class": "Inhaus\\Plugins\\Ideen\\IdeenPlugin",
"enabled_by_default": false,
"requires": {
"core": ">=0.32.0",
"php": ">=8.3"
}
}

View file

@ -0,0 +1,67 @@
<script setup>
import { watch } from 'vue';
import { useForm } from '@inertiajs/vue3';
import { LoaderCircle } from '@lucide/vue';
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 { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import FormField from '@/components/FormField.vue';
/**
* Idee einreichen bzw. (solange sie neu ist) bearbeiten.
*/
const props = defineProps({
idea: { type: Object, default: null },
});
const open = defineModel('open', { type: Boolean, default: false });
const form = useForm({ title: '', body: '', anonymous: false });
watch(open, (value) => {
if (!value) return;
form.clearErrors();
form.defaults({ title: props.idea?.title ?? '', body: props.idea?.body ?? '', anonymous: false });
form.reset();
});
function submit() {
const options = { preserveScroll: true, onSuccess: () => (open.value = false) };
props.idea ? form.put(`/ideen/${props.idea.id}`, options) : form.post('/ideen', options);
}
</script>
<template>
<Dialog v-model:open="open">
<DialogContent class="sm:max-w-xl">
<DialogHeader>
<DialogTitle>{{ idea ? 'Idee bearbeiten' : 'Idee einreichen' }}</DialogTitle>
<DialogDescription>Was ließe sich verbessern? Beschreiben Sie kurz das Problem und Ihren Vorschlag.</DialogDescription>
</DialogHeader>
<form id="idea-form" class="grid gap-5" @submit.prevent="submit">
<FormField id="idea-title" label="Titel" :error="form.errors.title">
<Input id="idea-title" v-model="form.title" maxlength="160" placeholder="z. B. Fahrradständer mit Überdachung" />
</FormField>
<FormField id="idea-body" label="Beschreibung" :error="form.errors.body">
<Textarea id="idea-body" v-model="form.body" rows="7" maxlength="5000" placeholder="Was ist heute schwierig? Was schlagen Sie vor? Wem würde es helfen?" />
</FormField>
<label v-if="!idea" class="flex items-start justify-between gap-4 rounded-md border p-3 text-sm">
<span>
<span class="font-medium">Anonym einreichen</span>
<span class="block text-xs text-muted-foreground">Ihr Name wird nicht gespeichert – auch nicht für das Gremium. Dann können Sie die Idee später nicht mehr bearbeiten und bekommen keine Rückmeldung per Benachrichtigung.</span>
</span>
<Switch v-model="form.anonymous" />
</label>
</form>
<DialogFooter>
<Button variant="ghost" @click="open = false">Abbrechen</Button>
<Button type="submit" form="idea-form" :disabled="form.processing">
<LoaderCircle v-if="form.processing" class="animate-spin" />
{{ idea ? 'Speichern' : 'Einreichen' }}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</template>

View file

@ -0,0 +1,17 @@
<script setup>
defineProps({
status: { type: String, required: true },
label: { type: String, required: true },
});
const styles = {
new: 'bg-brand-soft text-brand-text',
review: 'bg-accent2/15 text-accent2-text',
done: 'bg-brand text-brand-foreground',
rejected: 'bg-muted text-muted-foreground',
};
</script>
<template>
<span class="inline-flex shrink-0 items-center rounded px-1.5 py-0.5 text-[11px] font-medium" :class="styles[status]">{{ label }}</span>
</template>

View file

@ -0,0 +1,55 @@
<script setup>
import { ref, watch } from 'vue';
import { router } from '@inertiajs/vue3';
import { ThumbsUp } from '@lucide/vue';
/**
* „Unterstützen“ mit Zähler – schaltet sofort um, der Server bestätigt im Hintergrund.
*/
const props = defineProps({
idea: { type: Object, required: true },
disabled: { type: Boolean, default: false },
large: { type: Boolean, default: false },
});
const supported = ref(!!props.idea.supported);
const count = ref(props.idea.supports);
watch(() => [props.idea.supported, props.idea.supports], ([s, c]) => {
supported.value = !!s;
count.value = c;
});
function toggle() {
const next = !supported.value;
supported.value = next;
count.value += next ? 1 : -1;
router.visit(`/ideen/${props.idea.id}/unterstuetzen`, {
method: next ? 'post' : 'delete',
preserveScroll: true,
preserveState: true,
onError: () => {
supported.value = !next;
count.value += next ? -1 : 1;
},
});
}
</script>
<template>
<button
type="button"
:disabled="disabled"
:aria-pressed="supported"
:title="disabled ? 'Ihre eigene Idee' : supported ? 'Unterstützung zurücknehmen' : 'Idee unterstützen'"
class="flex shrink-0 flex-col items-center justify-center rounded-md border tabular-nums transition-colors disabled:cursor-default disabled:opacity-70"
:class="[
large ? 'min-w-20 gap-1 px-3 py-2.5' : 'size-14 gap-0.5',
supported ? 'border-brand bg-brand text-brand-foreground' : 'bg-card hover:border-brand/50 hover:bg-brand-soft',
]"
@click="toggle"
>
<ThumbsUp :class="[large ? 'size-5' : 'size-4', supported ? 'fill-current' : '']" />
<span class="text-sm font-semibold">{{ count }}</span>
<span v-if="large" class="text-[11px]">{{ supported ? 'Unterstützt' : 'Unterstützen' }}</span>
</button>
</template>

View file

@ -0,0 +1,30 @@
<script setup>
import { Link } from '@inertiajs/vue3';
import { MessageCircle, ThumbsUp } from '@lucide/vue';
import Panel from '@/components/Panel.vue';
import { formatRelative } from '@/lib/format';
import StatusBadge from '../components/StatusBadge.vue';
defineProps({
ideas: { type: Array, required: true },
});
</script>
<template>
<Panel title="Ideenbox – zu sichten" action-label="Alle Ideen" action-href="/ideen">
<ul v-if="ideas.length" class="-mx-5 divide-y border-t">
<li v-for="idea in ideas" :key="idea.id" class="flex items-center gap-3 px-5 py-2.5">
<div class="min-w-0 flex-1">
<Link :href="idea.url" class="block truncate text-sm font-medium hover:underline">{{ idea.title }}</Link>
<p class="truncate text-xs text-muted-foreground">{{ idea.author?.name ?? 'Anonym' }} · {{ formatRelative(idea.created_at) }}</p>
</div>
<span class="inline-flex shrink-0 items-center gap-2.5 text-xs text-muted-foreground tabular-nums">
<span class="inline-flex items-center gap-1"><ThumbsUp class="size-3.5" /> {{ idea.supports }}</span>
<span class="inline-flex items-center gap-1"><MessageCircle class="size-3.5" /> {{ idea.comments }}</span>
</span>
<StatusBadge :status="idea.status" :label="idea.status_label" />
</li>
</ul>
<p v-else class="text-sm text-muted-foreground">Keine offenen Ideen.</p>
</Panel>
</template>

View file

@ -0,0 +1,107 @@
<script setup>
import { ref, watch } from 'vue';
import { Link, router, usePage } from '@inertiajs/vue3';
import { Lightbulb, MessageCircle, Plus, Search } from '@lucide/vue';
import { toast } from 'vue-sonner';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import EmptyState from '@/components/EmptyState.vue';
import PageHeader from '@/components/PageHeader.vue';
import AppLayout from '@/layouts/AppLayout.vue';
import { formatRelative } from '@/lib/format';
import IdeaDialog from '../components/IdeaDialog.vue';
import StatusBadge from '../components/StatusBadge.vue';
import SupportButton from '../components/SupportButton.vue';
const props = defineProps({
ideas: { type: Array, required: true },
pagination: { type: Object, required: true },
filters: { type: Object, required: true },
statuses: { type: Object, required: true },
counts: { type: Object, default: () => ({}) },
});
const page = usePage();
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
const creating = ref(false);
const query = ref(props.filters.q);
function apply(changes) {
const params = { ...props.filters, ...changes };
router.get('/ideen', Object.fromEntries(Object.entries(params).filter(([key, value]) => value && !(key === 'sortierung' && value === 'neu'))), { preserveState: true, preserveScroll: true });
}
let timer;
watch(query, (value) => {
clearTimeout(timer);
timer = setTimeout(() => apply({ q: value }), 300);
});
const total = () => Object.values(props.counts).reduce((sum, n) => sum + n, 0);
const sorts = { neu: 'Neueste', beliebt: 'Meiste Unterstützung', diskutiert: 'Meiste Kommentare' };
</script>
<template>
<AppLayout title="Ideenbox">
<PageHeader title="Ideenbox" description="Gute Ideen machen den Alltag leichter. Reichen Sie Vorschläge ein, unterstützen Sie andere – das Gremium prüft und gibt Rückmeldung.">
<template #actions>
<Button @click="creating = true"><Plus /> Idee einreichen</Button>
</template>
</PageHeader>
<div class="mb-4 flex flex-wrap items-center gap-2">
<div class="flex flex-wrap gap-1 rounded-md bg-muted p-1" role="tablist" aria-label="Status">
<button type="button" role="tab" :aria-selected="!filters.status" class="rounded px-3 py-1 text-sm font-medium" :class="!filters.status ? 'bg-card shadow-xs' : 'text-muted-foreground hover:text-foreground'" @click="apply({ status: null })">
Alle <span class="text-xs text-muted-foreground tabular-nums">{{ total() }}</span>
</button>
<button
v-for="(label, key) in statuses"
:key="key"
type="button"
role="tab"
:aria-selected="filters.status === key"
class="rounded px-3 py-1 text-sm font-medium"
:class="filters.status === key ? 'bg-card shadow-xs' : 'text-muted-foreground hover:text-foreground'"
@click="apply({ status: key })"
>
{{ label }} <span class="text-xs text-muted-foreground tabular-nums">{{ counts[key] ?? 0 }}</span>
</button>
</div>
<span class="flex-1" />
<select :value="filters.sortierung" class="h-9 rounded-md border bg-card px-2 text-sm" aria-label="Sortierung" @change="apply({ sortierung: $event.target.value })">
<option v-for="(label, key) in sorts" :key="key" :value="key">{{ label }}</option>
</select>
<div class="relative w-full sm:w-56">
<Search class="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
<Input v-model="query" type="search" placeholder="Ideen durchsuchen" class="h-9 bg-card pl-8" aria-label="Ideen durchsuchen" />
</div>
</div>
<ul v-if="ideas.length" class="grid gap-3">
<li v-for="idea in ideas" :key="idea.id" class="flex gap-4 rounded-lg border bg-card p-4 shadow-xs">
<SupportButton :idea="idea" :disabled="idea.author?.id === page.props.auth.user.id" />
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-center gap-2">
<Link :href="idea.url" class="font-semibold hover:underline">{{ idea.title }}</Link>
<StatusBadge :status="idea.status" :label="idea.status_label" />
</div>
<p class="mt-1 line-clamp-2 text-sm text-muted-foreground">{{ idea.excerpt }}</p>
<p class="mt-2 flex flex-wrap items-center gap-x-3 text-xs text-muted-foreground">
<span>{{ idea.author?.name ?? 'Anonym' }} · {{ formatRelative(idea.created_at) }}</span>
<Link :href="`${idea.url}#kommentare`" class="inline-flex items-center gap-1 hover:text-foreground"><MessageCircle class="size-3.5" /> {{ idea.comments }}</Link>
</p>
</div>
</li>
</ul>
<EmptyState v-else :icon="Lightbulb" :title="filters.q || filters.status ? 'Keine passenden Ideen' : 'Noch keine Ideen'" text="Machen Sie den Anfang – jede Verbesserung zählt." class="rounded-lg border bg-card py-12" />
<nav v-if="pagination.last > 1" class="mt-6 flex items-center justify-between text-sm" aria-label="Seiten">
<Link v-if="pagination.prev" :href="pagination.prev" preserve-scroll class="font-medium text-brand-text hover:underline">← Zurück</Link><span v-else />
<span class="text-muted-foreground">Seite {{ pagination.current }} von {{ pagination.last }}</span>
<Link v-if="pagination.next" :href="pagination.next" preserve-scroll class="font-medium text-brand-text hover:underline">Weiter →</Link><span v-else />
</nav>
<IdeaDialog v-model:open="creating" />
</AppLayout>
</template>

View file

@ -0,0 +1,142 @@
<script setup>
import { ref, watch } from 'vue';
import { Link, router, useForm, usePage } from '@inertiajs/vue3';
import { BadgeCheck, LoaderCircle, PencilLine, Trash2 } from '@lucide/vue';
import { toast } from 'vue-sonner';
import { Button } from '@/components/ui/button';
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 PersonAvatar from '@/components/PersonAvatar.vue';
import AppLayout from '@/layouts/AppLayout.vue';
import { formatDate, formatRelative } from '@/lib/format';
import IdeaDialog from '../components/IdeaDialog.vue';
import StatusBadge from '../components/StatusBadge.vue';
import SupportButton from '../components/SupportButton.vue';
const props = defineProps({
idea: { type: Object, required: true },
statuses: { type: Object, required: true },
});
const page = usePage();
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
const editing = ref(false);
// Kommentare
const commentForm = useForm({ body: '', official: false });
function comment() {
commentForm.post(`/ideen/${props.idea.id}/kommentare`, { preserveScroll: true, onSuccess: () => commentForm.reset() });
}
function deleteComment(c) {
if (window.confirm('Kommentar löschen?')) router.delete(`/ideen/${props.idea.id}/kommentare/${c.id}`, { preserveScroll: true });
}
// Gremium
const statusForm = useForm({ status: props.idea.status, status_note: props.idea.status_note ?? '' });
function saveStatus() {
statusForm.put(`/ideen/${props.idea.id}/status`, { preserveScroll: true });
}
function remove() {
if (window.confirm(`Idee „${props.idea.title}“ löschen?`)) router.delete(`/ideen/${props.idea.id}`);
}
</script>
<template>
<AppLayout :title="idea.title">
<PageHeader :title="idea.title" :breadcrumbs="[{ label: 'Ideenbox', href: '/ideen' }]">
<template #description>
<span class="inline-flex flex-wrap items-center gap-2">
<StatusBadge :status="idea.status" :label="idea.status_label" />
eingereicht {{ formatRelative(idea.created_at) }}<template v-if="!idea.author"> · anonym</template>
</span>
</template>
<template v-if="idea.can_edit || idea.can_manage" #actions>
<Button v-if="idea.can_edit" variant="outline" size="sm" @click="editing = true"><PencilLine /> Bearbeiten</Button>
<Button variant="ghost" size="sm" class="text-destructive hover:text-destructive" @click="remove"><Trash2 /> Löschen</Button>
</template>
</PageHeader>
<div class="grid items-start gap-6 lg:grid-cols-12">
<div class="grid min-w-0 gap-6 lg:col-span-8">
<Panel>
<div class="flex gap-5">
<SupportButton :idea="idea" :disabled="idea.mine" large />
<div class="min-w-0 flex-1">
<p class="text-[15px] leading-relaxed whitespace-pre-line">{{ idea.body }}</p>
<div v-if="idea.author" class="mt-5 flex items-center gap-2.5 border-t pt-4 text-sm">
<PersonAvatar :person="idea.author" class="size-8" />
<Link :href="`/personen/${idea.author.id}`" class="font-medium hover:underline">{{ idea.author.name }}</Link>
</div>
</div>
</div>
</Panel>
<!-- Rückmeldung des Gremiums -->
<section v-if="idea.status_note" class="rounded-lg border border-brand/30 bg-brand-soft/60 p-5">
<h2 class="flex items-center gap-2 text-sm font-semibold text-brand-text"><BadgeCheck class="size-4" /> Rückmeldung: {{ idea.status_label }}</h2>
<p class="mt-2 text-sm leading-relaxed whitespace-pre-line">{{ idea.status_note }}</p>
<p v-if="idea.status_changed_at" class="mt-2 text-xs text-muted-foreground">{{ formatDate(idea.status_changed_at) }}</p>
</section>
<Panel id="kommentare" :title="`Kommentare (${idea.comment_list.length})`">
<ul v-if="idea.comment_list.length" class="-mx-5 mb-5 divide-y border-y">
<li v-for="c in idea.comment_list" :key="c.id" class="flex gap-3 px-5 py-4" :class="{ 'bg-brand-soft/40': c.official }">
<PersonAvatar v-if="c.author" :person="c.author" class="size-9" />
<div class="min-w-0 flex-1">
<p class="flex flex-wrap items-center gap-x-2 text-sm">
<span class="font-semibold">{{ c.author?.name ?? 'Gelöschtes Konto' }}</span>
<span v-if="c.official" class="inline-flex items-center gap-1 text-xs font-medium text-brand-text"><BadgeCheck class="size-3.5" /> Gremium</span>
<span class="text-xs text-muted-foreground">{{ formatRelative(c.created_at) }}</span>
</p>
<p class="mt-1 text-sm leading-relaxed whitespace-pre-line">{{ c.body }}</p>
</div>
<Button v-if="c.can_delete" variant="ghost" size="icon" class="size-7 shrink-0 text-muted-foreground hover:text-destructive" aria-label="Kommentar löschen" @click="deleteComment(c)"><Trash2 class="size-3.5" /></Button>
</li>
</ul>
<form class="grid gap-3" @submit.prevent="comment">
<Textarea v-model="commentForm.body" rows="3" maxlength="3000" placeholder="Ihre Meinung, Ergänzungen oder Erfahrungen …" aria-label="Kommentar" />
<p v-if="commentForm.errors.body" class="text-[13px] text-destructive">{{ commentForm.errors.body }}</p>
<div class="flex flex-wrap items-center justify-between gap-3">
<label v-if="idea.can_manage" class="flex items-center gap-2 text-sm"><Switch v-model="commentForm.official" /> Als Antwort des Gremiums</label>
<span v-else />
<Button type="submit" :disabled="commentForm.processing || !commentForm.body.trim()">
<LoaderCircle v-if="commentForm.processing" class="animate-spin" /> Kommentieren
</Button>
</div>
</form>
</Panel>
</div>
<aside class="grid gap-6 lg:col-span-4">
<Panel v-if="idea.can_manage" title="Bewertung (Gremium)">
<form class="grid gap-4" @submit.prevent="saveStatus">
<FormField id="idea-status" label="Status">
<select id="idea-status" v-model="statusForm.status" class="h-9 w-full rounded-md border bg-background px-2 text-sm">
<option v-for="(label, key) in statuses" :key="key" :value="key">{{ label }}</option>
</select>
</FormField>
<FormField id="idea-note" label="Rückmeldung (für alle sichtbar)" :error="statusForm.errors.status_note">
<Textarea id="idea-note" v-model="statusForm.status_note" rows="5" maxlength="3000" placeholder="z. B. Wird im Frühjahr umgesetzt. / Leider nicht möglich, weil …" />
</FormField>
<p class="text-xs text-muted-foreground">Bei einem neuen Status bekommen die einreichende Person und alle Unterstützenden Bescheid.</p>
<Button type="submit" :disabled="statusForm.processing || !statusForm.isDirty"><LoaderCircle v-if="statusForm.processing" class="animate-spin" /> Speichern</Button>
</form>
</Panel>
<Panel title="So funktioniert’s">
<ol class="grid list-decimal gap-2 pl-4 text-[13px] text-muted-foreground">
<li>Ideen sind für alle sichtbar und lassen sich unterstützen und kommentieren.</li>
<li>Das Gremium sichtet neue Ideen, prüft sie und gibt eine Rückmeldung.</li>
<li>Wer eine Idee eingereicht oder unterstützt hat, erfährt, wie es ausgeht.</li>
</ol>
</Panel>
</aside>
</div>
<IdeaDialog v-if="idea.can_edit" v-model:open="editing" :idea="idea" />
</AppLayout>
</template>

View file

@ -0,0 +1,24 @@
<script setup>
import { Link } from '@inertiajs/vue3';
import { ThumbsUp } from '@lucide/vue';
import Panel from '@/components/Panel.vue';
defineProps({
ideas: { type: Array, required: true },
});
</script>
<template>
<Panel title="Ideenbox" action-label="Alle Ideen" action-href="/ideen">
<ul class="-my-1 grid gap-1">
<li v-for="idea in ideas" :key="idea.id">
<Link :href="idea.url" class="group -mx-2 flex items-center gap-3 rounded-md p-2 hover:bg-accent/50">
<span class="flex size-10 shrink-0 flex-col items-center justify-center rounded-md bg-brand-soft text-brand-text tabular-nums">
<ThumbsUp class="size-3.5" /><span class="text-xs font-semibold">{{ idea.supports }}</span>
</span>
<span class="line-clamp-2 min-w-0 text-sm leading-snug font-medium group-hover:underline">{{ idea.title }}</span>
</Link>
</li>
</ul>
</Panel>
</template>

View file

@ -0,0 +1,14 @@
<?php
use Illuminate\Support\Facades\Route;
use Inhaus\Plugins\Ideen\Http\Controllers\IdeaController;
// /api/v1/ideas … (Token nötig, siehe docs/API.md)
Route::controller(IdeaController::class)->group(function () {
Route::get('/ideas', 'index');
Route::post('/ideas', 'store')->middleware('throttle:10,60');
Route::get('/ideas/{idea}', 'show')->whereNumber('idea');
Route::post('/ideas/{idea}/support', 'support')->whereNumber('idea')->middleware('throttle:60,1');
Route::delete('/ideas/{idea}/support', 'unsupport')->whereNumber('idea')->middleware('throttle:60,1');
Route::post('/ideas/{idea}/comments', 'comment')->whereNumber('idea')->middleware('throttle:20,1');
});

View file

@ -0,0 +1,17 @@
<?php
use Illuminate\Support\Facades\Route;
use Inhaus\Plugins\Ideen\Http\Controllers\IdeaController;
Route::middleware('auth')->prefix('ideen')->name('ideas.')->controller(IdeaController::class)->group(function () {
Route::get('/', 'index')->name('index');
Route::post('/', 'store')->middleware('throttle:10,60')->name('store');
Route::get('/{idea}', 'show')->name('show');
Route::put('/{idea}', 'update')->name('update');
Route::delete('/{idea}', 'destroy')->name('destroy');
Route::post('/{idea}/unterstuetzen', 'support')->middleware('throttle:60,1')->name('support');
Route::delete('/{idea}/unterstuetzen', 'unsupport')->middleware('throttle:60,1')->name('unsupport');
Route::post('/{idea}/kommentare', 'comment')->middleware('throttle:20,1')->name('comments.store');
Route::delete('/{idea}/kommentare/{comment}', 'deleteComment')->name('comments.destroy');
Route::put('/{idea}/status', 'status')->name('status');
});

View file

@ -0,0 +1,222 @@
<?php
namespace Inhaus\Plugins\Ideen\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Notifications\PortalNotification;
use App\Support\Audit;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Inertia\Inertia;
use Inertia\Response;
use Inhaus\Plugins\Ideen\Models\Idea;
use Inhaus\Plugins\Ideen\Models\IdeaComment;
use Inhaus\Plugins\Ideen\Presenter;
/**
* Ideenbox: einreichen, unterstützen, kommentieren – und die Bewertung durch das Gremium.
*/
class IdeaController extends Controller
{
public function index(Request $request): Response|JsonResponse
{
$data = $request->validate([
'status' => ['nullable', Rule::in(array_keys(Idea::STATUSES))],
'sortierung' => ['nullable', Rule::in(['neu', 'beliebt', 'diskutiert'])],
'q' => ['nullable', 'string', 'max:100'],
]);
$user = $request->user();
$ideas = Idea::query()->with('author')
->when($data['status'] ?? null, fn ($q, $status) => $q->where('status', $status))
->when($data['q'] ?? null, fn ($q, $term) => $q->where(fn ($q) => $q->where('title', 'like', '%'.addcslashes($term, '%_\\').'%')->orWhere('body', 'like', '%'.addcslashes($term, '%_\\').'%')))
->when(($data['sortierung'] ?? 'neu') === 'beliebt', fn ($q) => $q->orderByDesc('supports_count'))
->when(($data['sortierung'] ?? 'neu') === 'diskutiert', fn ($q) => $q->orderByDesc('comments_count'))
->latest()->latest('id')
->paginate(20)->withQueryString();
$supported = $user->belongsToMany(Idea::class, 'idea_supports')->whereIn('ideas.id', $ideas->modelKeys())->pluck('ideas.id')->all();
$items = collect($ideas->items())->map(fn (Idea $idea) => Presenter::card($idea, in_array($idea->id, $supported, true)))->all();
if ($this->wantsJson($request)) {
return response()->json(['data' => $items, 'meta' => ['current_page' => $ideas->currentPage(), 'last_page' => $ideas->lastPage(), 'total' => $ideas->total()]]);
}
return Inertia::render('ideen::Index', [
'ideas' => $items,
'pagination' => ['current' => $ideas->currentPage(), 'last' => $ideas->lastPage(), 'prev' => $ideas->previousPageUrl(), 'next' => $ideas->nextPageUrl()],
'filters' => ['status' => $data['status'] ?? null, 'sortierung' => $data['sortierung'] ?? 'neu', 'q' => $data['q'] ?? ''],
'statuses' => Idea::STATUSES,
'counts' => Idea::query()->selectRaw('status, count(*) as c')->groupBy('status')->pluck('c', 'status'),
]);
}
public function show(Request $request, Idea $idea): Response|JsonResponse
{
$detail = Presenter::detail($idea->load('author'), $request->user());
return $this->wantsJson($request)
? response()->json(['data' => $detail])
: Inertia::render('ideen::Show', ['idea' => $detail, 'statuses' => Idea::STATUSES]);
}
public function store(Request $request): RedirectResponse|JsonResponse
{
$data = $this->validated($request);
$anonymous = $request->boolean('anonymous');
$idea = Idea::query()->create([
'title' => $data['title'],
'body' => $data['body'],
'author_id' => $anonymous ? null : $request->user()->id,
'anonymous' => $anonymous,
])->refresh();
if ($this->wantsJson($request)) {
return response()->json(['data' => Presenter::detail($idea, $request->user())], 201);
}
return to_route('ideas.show', $idea)->with('status', 'Danke! Ihre Idee ist eingereicht.');
}
public function update(Request $request, Idea $idea): RedirectResponse
{
abort_unless(! $idea->anonymous && $idea->author_id === $request->user()->id && $idea->status === 'new', 403);
$idea->update($this->validated($request));
return back()->with('status', 'Idee gespeichert.');
}
public function destroy(Request $request, Idea $idea): RedirectResponse
{
$user = $request->user();
$own = ! $idea->anonymous && $idea->author_id === $user->id && $idea->status === 'new';
abort_unless($own || $user->can('ideas.manage'), 403);
$idea->delete();
if (! $own) {
Audit::log('idea.deleted', ['idea' => $idea->id, 'title' => $idea->title]);
}
return to_route('ideas.index')->with('status', 'Idee gelöscht.');
}
public function support(Request $request, Idea $idea): RedirectResponse|JsonResponse
{
abort_if(! $idea->anonymous && $idea->author_id === $request->user()->id, 422, 'Die eigene Idee lässt sich nicht unterstützen.');
$idea->supporters()->syncWithoutDetaching([$request->user()->id => ['created_at' => now()]]);
return $this->supportResponse($request, $idea, true);
}
public function unsupport(Request $request, Idea $idea): RedirectResponse|JsonResponse
{
$idea->supporters()->detach($request->user()->id);
return $this->supportResponse($request, $idea, false);
}
public function comment(Request $request, Idea $idea): RedirectResponse|JsonResponse
{
$data = $request->validate(['body' => ['required', 'string', 'max:'.IdeaComment::MAX_LENGTH], 'official' => ['boolean']], [], ['body' => 'Kommentar']);
$user = $request->user();
$official = ($data['official'] ?? false) && $user->can('ideas.manage');
$comment = $idea->comments()->create(['user_id' => $user->id, 'body' => trim($data['body']), 'official' => $official]);
$idea->refreshCounts();
// Die einreichende Person erfährt von neuen Kommentaren
if (! $idea->anonymous && $idea->author && $idea->author_id !== $user->id && $idea->author->is_active) {
$idea->author->notify(new PortalNotification(
($official ? 'Antwort zu Ihrer Idee: ' : 'Neuer Kommentar zu Ihrer Idee: ').$idea->title,
Str::limit($comment->body, 120),
route('ideas.show', $idea, false).'#kommentare',
'lightbulb',
));
}
return $this->wantsJson($request)
? response()->json(['data' => Presenter::detail($idea->fresh(), $user)], 201)
: back()->with('status', 'Kommentar veröffentlicht.');
}
public function deleteComment(Request $request, Idea $idea, IdeaComment $comment): RedirectResponse
{
abort_unless($comment->idea_id === $idea->id, 404);
$user = $request->user();
abort_unless($comment->user_id === $user->id || $user->can('ideas.manage'), 403);
$comment->delete();
$idea->refreshCounts();
return back()->with('status', 'Kommentar gelöscht.');
}
/** Gremium: Status und Rückmeldung */
public function status(Request $request, Idea $idea): RedirectResponse
{
Gate::authorize('ideas.manage');
$data = $request->validate([
'status' => ['required', Rule::in(array_keys(Idea::STATUSES))],
'status_note' => ['nullable', 'string', 'max:3000'],
]);
$changed = $data['status'] !== $idea->status;
$idea->update([
'status' => $data['status'],
'status_note' => filled($data['status_note'] ?? null) ? trim($data['status_note']) : null,
'status_changed_at' => $changed ? now() : $idea->status_changed_at,
]);
Audit::log('idea.status', ['idea' => $idea->id, 'status' => $idea->status]);
if ($changed) {
// Einreichende Person und alle Unterstützenden informieren
$recipients = $idea->supporters()->where('is_active', true)->get()
->when(! $idea->anonymous && $idea->author?->is_active, fn ($c) => $c->push($idea->author))
->unique('id')->reject(fn ($u) => $u->id === $request->user()->id);
Notification::send($recipients, new PortalNotification(
'Idee „'.Str::limit($idea->title, 60).'“: '.$idea->statusLabel(),
Str::limit((string) $idea->status_note, 120),
route('ideas.show', $idea, false),
'lightbulb',
));
}
return back()->with('status', 'Status gespeichert.');
}
/**
* @return array{title: string, body: string}
*/
private function validated(Request $request): array
{
$data = $request->validate([
'title' => ['required', 'string', 'max:160'],
'body' => ['required', 'string', 'max:5000'],
'anonymous' => ['boolean'],
], [], ['title' => 'Titel', 'body' => 'Beschreibung']);
return ['title' => trim($data['title']), 'body' => trim($data['body'])];
}
private function supportResponse(Request $request, Idea $idea, bool $supported): RedirectResponse|JsonResponse
{
$idea->refreshCounts();
return $this->wantsJson($request)
? response()->json(['data' => ['supported' => $supported, 'supports' => $idea->supports_count]])
: back();
}
private function wantsJson(Request $request): bool
{
return $request->expectsJson() && ! $request->header('X-Inertia');
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Inhaus\Plugins\Ideen;
use App\Dashboard\Widgets;
use App\Editorial\Editorial;
use App\Models\User;
use App\Plugins\Plugin;
use App\Support\Abilities;
use App\Support\Navigation;
use Inhaus\Plugins\Ideen\Models\Idea;
class IdeenPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('ideen', 'Ideenbox', '/ideen', active: 'ideas.*', sort: 76);
$this->app->make(Abilities::class)->define('ideas.manage', 'Ideen bewerten, beantworten und moderieren (Gremium)', 'Ideenbox', portal: true);
// Redaktion: was das Gremium noch sichten muss
$this->app->make(Editorial::class)->add('ideen', 'Ideenbox', 'ideen::EditorialIdeas', 34,
fn (User $user) => $user->can('ideas.manage'),
fn (User $user) => [
'ideas' => Idea::query()->with('author')->whereIn('status', ['new', 'review'])
->orderByRaw("status = 'new' DESC")->orderByDesc('supports_count')->latest()->limit(30)->get()
->map(fn (Idea $idea) => Presenter::card($idea))->all(),
]);
// Startseite: beliebteste offene Ideen
$this->app->make(Widgets::class)->add('ideen.popular', 'ideen::Popular', 'aside', sort: 28, props: function () {
$ideas = Idea::query()->with('author')->whereIn('status', ['new', 'review'])->where('created_at', '>=', now()->subDays(60))
->orderByDesc('supports_count')->latest()->limit(3)->get();
return $ideas->isEmpty() ? null : ['ideas' => $ideas->map(fn (Idea $idea) => Presenter::card($idea))->all()];
}, label: 'Ideenbox', mobileSort: 38);
}
}

View file

@ -0,0 +1,63 @@
<?php
namespace Inhaus\Plugins\Ideen\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['title', 'body', 'author_id', 'anonymous', 'status', 'status_note', 'status_changed_at'])]
class Idea extends Model
{
public const STATUSES = [
'new' => 'Neu',
'review' => 'In Prüfung',
'done' => 'Umgesetzt',
'rejected' => 'Abgelehnt',
];
protected function casts(): array
{
return ['anonymous' => 'boolean', 'status_changed_at' => 'datetime'];
}
/**
* @return BelongsTo<User, $this>
*/
public function author(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* @return BelongsToMany<User, $this>
*/
public function supporters(): BelongsToMany
{
return $this->belongsToMany(User::class, 'idea_supports')->withPivot('created_at');
}
/**
* @return HasMany<IdeaComment, $this>
*/
public function comments(): HasMany
{
return $this->hasMany(IdeaComment::class);
}
public function statusLabel(): string
{
return self::STATUSES[$this->status] ?? $this->status;
}
public function refreshCounts(): void
{
$this->forceFill([
'supports_count' => $this->supporters()->count(),
'comments_count' => $this->comments()->count(),
])->saveQuietly();
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Inhaus\Plugins\Ideen\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
#[Fillable(['idea_id', 'user_id', 'body', 'official'])]
class IdeaComment extends Model
{
public const MAX_LENGTH = 3000;
protected function casts(): array
{
return ['official' => 'boolean'];
}
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* @return BelongsTo<Idea, $this>
*/
public function idea(): BelongsTo
{
return $this->belongsTo(Idea::class);
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Inhaus\Plugins\Ideen;
use App\Models\User;
use Illuminate\Support\Str;
use Inhaus\Plugins\Ideen\Models\Idea;
use Inhaus\Plugins\Ideen\Models\IdeaComment;
class Presenter
{
/**
* @return array<string, mixed>
*/
public static function card(Idea $idea, ?bool $supported = null): array
{
return [
'id' => $idea->id,
'title' => $idea->title,
'excerpt' => Str::limit(preg_replace('/\s+/u', ' ', $idea->body), 180),
'status' => $idea->status,
'status_label' => $idea->statusLabel(),
'supports' => $idea->supports_count,
'comments' => $idea->comments_count,
'supported' => $supported,
'author' => self::author($idea),
'created_at' => $idea->created_at?->toIso8601String(),
'url' => route('ideas.show', $idea),
];
}
/**
* @return array<string, mixed>
*/
public static function detail(Idea $idea, User $user): array
{
$manager = $user->can('ideas.manage');
return [
...self::card($idea, $idea->supporters()->whereKey($user->id)->exists()),
'body' => $idea->body,
'anonymous' => $idea->anonymous,
'status_note' => $idea->status_note,
'status_changed_at' => $idea->status_changed_at?->toIso8601String(),
'mine' => ! $idea->anonymous && $idea->author_id === $user->id,
'can_edit' => ! $idea->anonymous && $idea->author_id === $user->id && $idea->status === 'new',
'can_manage' => $manager,
'comment_list' => $idea->comments()->with('user')->oldest()->oldest('id')->limit(500)->get()
->map(fn (IdeaComment $c) => [
'id' => $c->id,
'body' => $c->body,
'official' => $c->official,
'created_at' => $c->created_at?->toIso8601String(),
'author' => $c->user ? ['id' => $c->user->id, 'name' => $c->user->name, 'initials' => $c->user->initials, 'avatar_url' => $c->user->avatarUrl(64)] : null,
'can_delete' => $manager || $c->user_id === $user->id,
])->all(),
];
}
/**
* @return array{id: int, name: string, initials: string, avatar_url: ?string}|null
*/
private static function author(Idea $idea): ?array
{
$author = $idea->anonymous ? null : $idea->author;
return $author ? ['id' => $author->id, 'name' => $author->name, 'initials' => $author->initials, 'avatar_url' => $author->avatarUrl(64)] : null;
}
}