Neues Modul Glossar (0.27.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m52s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m6s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m31s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m58s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 09:52:00 +00:00
parent d148f2fbe2
commit 0bd20a527e
121 changed files with 946 additions and 298 deletions

View file

@ -0,0 +1,32 @@
<?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('glossary_entries', function (Blueprint $table) {
$table->id();
$table->string('term', 150);
$table->string('aliases', 255)->nullable(); // Abkürzung, Synonyme
$table->text('description')->nullable(); // bereinigtes HTML
$table->string('link_url', 1000)->nullable();
$table->string('link_label', 100)->nullable();
$table->char('letter', 1); // A–Z oder #
$table->string('sort_key', 190);
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->index('sort_key');
});
}
public function down(): void
{
Schema::dropIfExists('glossary_entries');
}
};

View file

@ -0,0 +1,14 @@
{
"slug": "glossar",
"name": "Glossar",
"version": "1.0.0",
"description": "Begriffe und Abkürzungen mit Erklärung – alphabetisch, mit mitlaufender A–Z-Leiste, Suche und Pflege direkt im Portal.",
"author": "Inhaus",
"namespace": "Inhaus\\Plugins\\Glossar\\",
"class": "Inhaus\\Plugins\\Glossar\\GlossarPlugin",
"enabled_by_default": false,
"requires": {
"core": ">=0.26.0",
"php": ">=8.3"
}
}

View file

@ -0,0 +1,74 @@
<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 { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import FormField from '@/components/FormField.vue';
import RichTextEditor from '@/components/RichTextEditor.vue';
/**
* Begriff anlegen oder bearbeiten.
*/
const props = defineProps({
entry: { type: Object, default: null },
});
const open = defineModel('open', { type: Boolean, default: false });
const form = useForm({ term: '', aliases: '', description: '', link_url: '', link_label: '' });
watch(open, (value) => {
if (!value) return;
form.clearErrors();
form.defaults({
term: props.entry?.term ?? '',
aliases: props.entry?.aliases ?? '',
description: props.entry?.description ?? '',
link_url: props.entry?.link_url ?? '',
link_label: props.entry?.link_label ?? '',
});
form.reset();
});
function submit() {
const options = { preserveScroll: true, onSuccess: () => (open.value = false) };
props.entry ? form.put(`/glossar/${props.entry.id}`, options) : form.post('/glossar', options);
}
</script>
<template>
<Dialog v-model:open="open">
<DialogContent class="sm:max-w-xl">
<DialogHeader>
<DialogTitle>{{ entry ? 'Begriff bearbeiten' : 'Begriff hinzufügen' }}</DialogTitle>
</DialogHeader>
<form class="grid gap-4" @submit.prevent="submit">
<div class="grid gap-4 sm:grid-cols-[minmax(0,1fr)_12rem]">
<FormField id="gl-term" label="Begriff" :error="form.errors.term">
<Input id="gl-term" v-model="form.term" maxlength="150" autofocus placeholder="z. B. Dienstvereinbarung" />
</FormField>
<FormField id="gl-aliases" label="Abkürzung / Synonyme" :error="form.errors.aliases">
<Input id="gl-aliases" v-model="form.aliases" maxlength="255" placeholder="z. B. DV" />
</FormField>
</div>
<FormField id="gl-description" label="Erklärung" :error="form.errors.description">
<RichTextEditor v-model="form.description" bordered min-height="9rem" placeholder="Was bedeutet der Begriff? Wo spielt er eine Rolle?" />
</FormField>
<div class="grid gap-4 sm:grid-cols-2">
<FormField id="gl-link" label="Weiterlesen (optional)" :error="form.errors.link_url">
<Input id="gl-link" v-model="form.link_url" maxlength="1000" placeholder="https://… oder /seiten/…" />
</FormField>
<FormField id="gl-link-label" label="Linktext" :error="form.errors.link_label">
<Input id="gl-link-label" v-model="form.link_label" maxlength="100" placeholder="z. B. Zur Dienstvereinbarung" :disabled="!form.link_url" />
</FormField>
</div>
<DialogFooter>
<Button type="button" variant="outline" @click="open = false">Abbrechen</Button>
<Button type="submit" :disabled="form.processing || !form.term.trim()"><LoaderCircle v-if="form.processing" class="animate-spin" /> Speichern</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
</template>

View file

@ -0,0 +1,227 @@
<script setup>
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { router, usePage } from '@inertiajs/vue3';
import { BookOpen, ExternalLink, Link2, PencilLine, Plus, Search, Trash2, X } from '@lucide/vue';
import { toast } from 'vue-sonner';
import { Button } from '@/components/ui/button';
import EmptyState from '@/components/EmptyState.vue';
import PageHeader from '@/components/PageHeader.vue';
import AppLayout from '@/layouts/AppLayout.vue';
import EntryDialog from '../components/EntryDialog.vue';
/**
* Glossar: Begriffe alphabetisch, mit A–Z-Leiste, die beim Scrollen oben mitläuft.
*/
const props = defineProps({
entries: { type: Array, required: true },
canManage: { type: Boolean, default: false },
});
const page = usePage();
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
const LETTERS = [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '#'];
// Suche: Groß-/Kleinschreibung und Umlaute egal
const query = ref('');
const normalize = (text) => String(text ?? '').replace(/<[^>]+>/g, ' ').toLocaleLowerCase('de-DE').normalize('NFD').replace(/[̀-ͯ]/g, '').replace(/ß/g, 'ss');
const visible = computed(() => {
const term = normalize(query.value.trim());
if (!term) return props.entries;
return props.entries.filter((e) => normalize(`${e.term} ${e.aliases ?? ''} ${e.description ?? ''}`).includes(term));
});
const sections = computed(() => LETTERS.map((letter) => ({ letter, entries: visible.value.filter((e) => e.letter === letter) })).filter((s) => s.entries.length));
const available = computed(() => new Set(sections.value.map((s) => s.letter)));
// Aktueller Buchstabe beim Scrollen
const active = ref(null);
let jumpedTo = null;
function onScroll() {
// Nach einem Klick in der Leiste bleibt der Buchstabe markiert, bis selbst gescrollt wird –
// die letzten Buchstaben können am Seitenende nicht ganz nach oben rücken.
if (jumpedTo) {
active.value = jumpedTo;
return;
}
let current = sections.value[0]?.letter ?? null;
for (const section of sections.value) {
const el = document.getElementById(`buchstabe-${section.letter === '#' ? 'ziffern' : section.letter}`);
if (el && el.getBoundingClientRect().top <= 150) current = section.letter;
}
active.value = current;
}
function jump(letter) {
if (!available.value.has(letter)) return;
jumpedTo = letter;
active.value = letter;
document.getElementById(`buchstabe-${letter === '#' ? 'ziffern' : letter}`)?.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
// Direktlink auf einen Begriff (z. B. aus der Suche): hinscrollen und kurz hervorheben
const highlighted = ref(null);
function openHash() {
const match = window.location.hash.match(/^#begriff-(\d+)$/);
if (!match) return;
nextTick(() => {
document.getElementById(`begriff-${match[1]}`)?.scrollIntoView({ block: 'center' });
highlighted.value = Number(match[1]);
setTimeout(() => (highlighted.value = null), 2500);
});
}
const releaseJump = () => (jumpedTo = null);
// Auf schmalen Bildschirmen scrollt die Leiste selbst – aktiven Buchstaben sichtbar halten
const bar = ref(null);
watch(active, (letter) => {
const button = bar.value?.querySelector(`[data-letter="${letter}"]`);
const list = bar.value;
if (button && list && list.scrollWidth > list.clientWidth) {
list.scrollTo({ left: button.offsetLeft - list.clientWidth / 2 + button.clientWidth / 2, behavior: 'smooth' });
}
});
onMounted(() => {
window.addEventListener('scroll', onScroll, { passive: true });
['wheel', 'touchstart', 'keydown'].forEach((type) => window.addEventListener(type, releaseJump, { passive: true }));
onScroll();
openHash();
});
onBeforeUnmount(() => {
window.removeEventListener('scroll', onScroll);
['wheel', 'touchstart', 'keydown'].forEach((type) => window.removeEventListener(type, releaseJump));
});
watch(sections, () => nextTick(onScroll));
// Pflege
const dialog = ref({ open: false, entry: null });
function remove(entry) {
if (window.confirm(`„${entry.term}“ aus dem Glossar löschen?`)) {
router.delete(`/glossar/${entry.id}`, { preserveScroll: true });
}
}
async function copyLink(entry) {
try {
await navigator.clipboard.writeText(`${window.location.origin}/glossar#${entry.anchor}`);
toast.success('Link kopiert');
} catch {
toast.error('Kopieren nicht möglich');
}
}
const isExternal = (url) => /^https?:\/\//i.test(url ?? '');
</script>
<template>
<AppLayout title="Glossar">
<PageHeader title="Glossar" :description="`${entries.length} ${entries.length === 1 ? 'Begriff' : 'Begriffe'} und Abkürzungen – kurz erklärt.`">
<template #actions>
<div class="relative w-full sm:w-72">
<Search class="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
<input
v-model="query"
type="search"
placeholder="Begriff suchen …"
aria-label="Glossar durchsuchen"
class="h-10 w-full rounded-md border border-input bg-card pr-9 pl-9 text-sm shadow-xs focus-visible:border-brand-400 focus-visible:ring-3 focus-visible:ring-ring/30 focus-visible:outline-none [&::-webkit-search-cancel-button]:hidden"
/>
<button v-if="query" type="button" class="absolute top-1/2 right-2.5 -translate-y-1/2 text-muted-foreground hover:text-foreground" aria-label="Suche leeren" @click="query = ''"><X class="size-4" /></button>
</div>
<Button v-if="canManage" class="h-10" @click="dialog = { open: true, entry: null }"><Plus /> Begriff</Button>
</template>
</PageHeader>
<!-- A–Z-Leiste: klebt beim Scrollen unter der Kopfzeile -->
<nav class="sticky top-16 z-30 -mx-4 mb-6 border-y bg-background/95 px-4 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/80 lg:-mx-6 lg:px-6" aria-label="Alphabet">
<ol ref="bar" class="relative flex gap-1 overflow-x-auto [scrollbar-width:none] lg:justify-between [&::-webkit-scrollbar]:hidden">
<li v-for="letter in LETTERS" :key="letter" class="shrink-0">
<button
type="button"
class="grid size-8 place-items-center rounded-md text-sm font-semibold transition-colors"
:class="[
!available.has(letter) ? 'cursor-default text-muted-foreground/40' : active === letter ? 'bg-brand text-brand-foreground' : 'text-foreground hover:bg-accent',
]"
:disabled="!available.has(letter)"
:data-letter="letter"
:aria-current="active === letter ? 'location' : undefined"
:aria-label="letter === '#' ? 'Zahlen und Zeichen' : `Buchstabe ${letter}`"
@click="jump(letter)"
>
{{ letter }}
</button>
</li>
</ol>
</nav>
<div v-if="sections.length" class="grid gap-8">
<section
v-for="section in sections"
:id="`buchstabe-${section.letter === '#' ? 'ziffern' : section.letter}`"
:key="section.letter"
class="grid scroll-mt-32 gap-4 md:grid-cols-[4rem_minmax(0,1fr)]"
>
<h2 class="text-3xl leading-none font-semibold text-brand-text md:sticky md:top-36 md:self-start">{{ section.letter }}</h2>
<ul class="divide-y overflow-hidden rounded-lg border bg-card">
<li
v-for="entry in section.entries"
:id="entry.anchor"
:key="entry.id"
class="group scroll-mt-36 px-5 py-4 transition-colors"
:class="{ 'bg-brand-soft/60': highlighted === entry.id }"
>
<div class="flex items-start gap-3">
<h3 class="min-w-0 flex-1 text-base font-semibold break-words">
{{ entry.term }}
<span v-if="entry.aliases" class="ml-1.5 rounded bg-muted px-1.5 py-0.5 align-middle text-xs font-medium text-muted-foreground">{{ entry.aliases }}</span>
</h3>
<div class="flex shrink-0 items-center gap-0.5 opacity-100 transition-opacity md:opacity-0 md:group-focus-within:opacity-100 md:group-hover:opacity-100">
<Button size="icon" variant="ghost" class="size-8 text-muted-foreground" :aria-label="`Link zu ${entry.term} kopieren`" @click="copyLink(entry)"><Link2 /></Button>
<template v-if="canManage">
<Button size="icon" variant="ghost" class="size-8 text-muted-foreground" :aria-label="`${entry.term} bearbeiten`" @click="dialog = { open: true, entry }"><PencilLine /></Button>
<Button size="icon" variant="ghost" class="size-8 text-muted-foreground hover:text-destructive" :aria-label="`${entry.term} löschen`" @click="remove(entry)"><Trash2 /></Button>
</template>
</div>
</div>
<div v-if="entry.description" class="prose prose-sm mt-1.5 max-w-none break-words text-foreground/90 dark:prose-invert" v-html="entry.description" />
<a
v-if="entry.link_url"
:href="entry.link_url"
:target="isExternal(entry.link_url) ? '_blank' : undefined"
:rel="isExternal(entry.link_url) ? 'noopener' : undefined"
class="mt-2 inline-flex items-center gap-1 text-[13px] font-medium text-brand-text hover:underline"
>
{{ entry.link_label || 'Weiterlesen' }} <ExternalLink class="size-3.5" />
</a>
</li>
</ul>
</section>
</div>
<div v-else class="rounded-lg border border-dashed bg-card">
<EmptyState
:icon="BookOpen"
:title="query ? 'Nichts gefunden' : 'Noch keine Begriffe'"
:text="query ? `Kein Begriff passt zu „${query}“.` : canManage ? 'Mit „Begriff“ oben rechts den ersten Eintrag anlegen.' : 'Hier erscheinen bald Begriffe und Abkürzungen.'"
/>
</div>
<EntryDialog v-if="canManage" v-model:open="dialog.open" :entry="dialog.entry" />
</AppLayout>
</template>

View file

@ -0,0 +1,11 @@
<?php
use Illuminate\Support\Facades\Route;
use Inhaus\Plugins\Glossar\Http\Controllers\GlossaryController;
Route::middleware('auth')->prefix('glossar')->name('glossary.')->controller(GlossaryController::class)->group(function () {
Route::get('/', 'index')->name('index');
Route::post('/', 'store')->name('store');
Route::put('/{entry}', 'update')->whereNumber('entry')->name('update');
Route::delete('/{entry}', 'destroy')->whereNumber('entry')->name('destroy');
});

View file

@ -0,0 +1,18 @@
<?php
namespace Inhaus\Plugins\Glossar;
use App\Plugins\Plugin;
use App\Search\GlobalSearch;
use App\Support\Abilities;
use App\Support\Navigation;
class GlossarPlugin extends Plugin
{
public function register(): void
{
$this->app->make(Navigation::class)->add('glossar', 'Glossar', '/glossar', active: 'glossary.*', sort: 75);
$this->app->make(Abilities::class)->define('glossary.manage', 'Glossar pflegen', 'Glossar', portal: true);
$this->app->make(GlobalSearch::class)->add('glossar', 'Glossar', 'book-open', fn (...$args) => app(GlossarySearch::class)(...$args), sort: 45);
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Inhaus\Plugins\Glossar;
use App\Models\User;
use App\Search\GlobalSearch;
use Inhaus\Plugins\Glossar\Models\GlossaryEntry;
/** Suchquelle für die globale Suche */
class GlossarySearch
{
/**
* @return list<array<string, mixed>>
*/
public function __invoke(User $user, string $search, int $limit): array
{
$query = GlossaryEntry::query();
GlobalSearch::whereTerms($query, ['term', 'aliases', 'description'], $search);
return $query->orderBy('sort_key')->limit($limit)->get()->map(fn (GlossaryEntry $entry) => [
'title' => $entry->term.($entry->aliases ? ' ('.$entry->aliases.')' : ''),
'url' => '/glossar#'.$entry->anchor(),
'excerpt' => GlobalSearch::excerpt(strip_tags((string) $entry->description), $search),
'meta' => 'Glossar',
])->all();
}
}

View file

@ -0,0 +1,87 @@
<?php
namespace Inhaus\Plugins\Glossar\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Pagebuilder\Field;
use App\Support\Audit;
use App\Support\RichText;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Inertia\Inertia;
use Inertia\Response;
use Inhaus\Plugins\Glossar\Models\GlossaryEntry;
class GlossaryController extends Controller
{
public function index(Request $request): Response
{
return Inertia::render('glossar::Index', [
'entries' => GlossaryEntry::query()->orderBy('sort_key')->orderBy('term')->get()->map->toPortal(),
'canManage' => $request->user()->can('glossary.manage'),
]);
}
public function store(Request $request): RedirectResponse
{
$this->authorizeManage($request);
$entry = GlossaryEntry::query()->create([...$this->validated($request), 'created_by' => $request->user()->id, 'updated_by' => $request->user()->id]);
Audit::log('glossary.created', ['entry' => $entry->id, 'term' => $entry->term]);
return back()->with('status', '„'.$entry->term.'“ ist im Glossar.');
}
public function update(Request $request, GlossaryEntry $entry): RedirectResponse
{
$this->authorizeManage($request);
$entry->update([...$this->validated($request, $entry), 'updated_by' => $request->user()->id]);
Audit::log('glossary.updated', ['entry' => $entry->id, 'term' => $entry->term]);
return back()->with('status', 'Gespeichert.');
}
public function destroy(Request $request, GlossaryEntry $entry): RedirectResponse
{
$this->authorizeManage($request);
$entry->delete();
Audit::log('glossary.deleted', ['entry' => $entry->id, 'term' => $entry->term]);
return back()->with('status', '„'.$entry->term.'“ gelöscht.');
}
/**
* @return array<string, mixed>
*/
private function validated(Request $request, ?GlossaryEntry $entry = null): array
{
$data = $request->validate([
'term' => ['required', 'string', 'max:150'],
'aliases' => ['nullable', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:50000'],
'link_url' => ['nullable', 'string', 'max:1000'],
'link_label' => ['nullable', 'string', 'max:100'],
], [], ['term' => 'Begriff', 'aliases' => 'Abkürzung / Synonyme', 'description' => 'Erklärung', 'link_url' => 'Link']);
$term = trim($data['term']);
$duplicate = GlossaryEntry::query()->where('sort_key', GlossaryEntry::sortKey($term))->when($entry, fn ($q) => $q->whereKeyNot($entry->id))->exists();
if ($duplicate) {
throw ValidationException::withMessages(['term' => 'Diesen Begriff gibt es schon im Glossar.']);
}
$link = filled($data['link_url'] ?? null) ? Field::safeUrl($data['link_url']) : '';
return [
'term' => $term,
'aliases' => filled($data['aliases'] ?? null) ? trim($data['aliases']) : null,
'description' => filled($data['description'] ?? null) ? app(RichText::class)->sanitize($data['description']) : null,
'link_url' => $link !== '' ? $link : null,
'link_label' => $link !== '' && filled($data['link_label'] ?? null) ? trim($data['link_label']) : null,
];
}
private function authorizeManage(Request $request): void
{
abort_unless($request->user()->can('glossary.manage'), 403);
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace Inhaus\Plugins\Glossar\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
/**
* Ein Begriff im Glossar. Buchstabe und Sortierschlüssel entstehen beim Speichern:
* Umlaute zählen wie ihr Grundbuchstabe (Ä → A), Ziffern und Zeichen unter „#“.
*/
#[Fillable(['term', 'aliases', 'description', 'link_url', 'link_label', 'created_by', 'updated_by'])]
class GlossaryEntry extends Model
{
protected static function booted(): void
{
static::saving(function (GlossaryEntry $entry) {
$entry->sort_key = self::sortKey($entry->term);
$first = strtoupper(substr($entry->sort_key, 0, 1));
$entry->letter = $first !== '' && ctype_alpha($first) ? $first : '#';
});
}
public static function sortKey(string $term): string
{
$key = Str::lower(strtr(trim($term), ['Ä' => 'A', 'Ö' => 'O', 'Ü' => 'U', 'ä' => 'a', 'ö' => 'o', 'ü' => 'u', 'ß' => 'ss']));
$key = Str::ascii($key);
// Führende Anführungszeichen o. Ä. nicht mitsortieren
return mb_substr(ltrim($key, " \t\"'„“‚‘»«([-–"), 0, 190);
}
/** Anker für Direktlinks, z. B. /glossar#begriff-12 */
public function anchor(): string
{
return 'begriff-'.$this->id;
}
/**
* @return array<string, mixed>
*/
public function toPortal(): array
{
return [
'id' => $this->id,
'term' => $this->term,
'aliases' => $this->aliases,
'description' => $this->description,
'link_url' => $this->link_url,
'link_label' => $this->link_label,
'letter' => $this->letter,
'anchor' => $this->anchor(),
];
}
}