Loheide-eu-mitarbeiterplatt.../resources/js/components/EasyLanguageBar.vue
Friederich Loheide b967c16b6d
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 8m49s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 8m47s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 8m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 9m24s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 11m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m4s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 10m37s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 45s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m12s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 10m41s
Einfache Ansicht für Klienten (0.57.0)
Rollen-Schalter simple_ui: größere Schrift, Leichte Sprache automatisch,
Startseite mit großen Kacheln; Hinweis in „Was sieht wer?“.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 16:34:14 +00:00

124 lines
6.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup>
import { onMounted, ref, watch } from 'vue';
import { router, usePage } from '@inertiajs/vue3';
import { BookOpenText, LoaderCircle, PencilLine, Sparkles, TriangleAlert } from '@lucide/vue';
import { toast } from 'vue-sonner';
import { Button } from '@/components/ui/button';
import { Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle } from '@/components/ui/sheet';
import RichTextEditor from '@/components/RichTextEditorAsync.js';
import ReadAloud from '@/components/ReadAloud.vue';
import { http } from '@/lib/http';
/**
* Leiste über einem Inhalt: Vorlesen, Umschalten auf Leichte Sprache und – für die
* Redaktion – Bearbeiten der Leichten Sprache mit optionalem KI-Vorschlag.
*/
const props = defineProps({
/** { type, id, html, can_edit, ai } oder null */
easy: { type: Object, default: null },
/** Element, dessen Text vorgelesen wird */
readSource: { type: [Object, Function], default: null },
});
const showEasy = defineModel({ type: Boolean, default: false });
const reader = ref(null);
watch(showEasy, () => reader.value?.stop());
// Einfache Ansicht (z. B. Klienten): Leichte Sprache von selbst, wo es sie gibt
const page = usePage();
onMounted(() => {
if (page.props.auth?.user?.simple && props.easy?.html) showEasy.value = true;
});
// Bearbeiten
const editing = ref(false);
const draft = ref('');
const aiAssisted = ref(false);
const suggesting = ref(false);
const saving = ref(false);
function openEditor() {
draft.value = props.easy?.html ?? '';
aiAssisted.value = false;
editing.value = true;
}
async function suggest() {
if (draft.value.trim() && !window.confirm('Den bisherigen Text durch einen neuen Vorschlag ersetzen?')) return;
suggesting.value = true;
try {
const { html } = await http.post(`/leichte-sprache/${props.easy.type}/${props.easy.id}/vorschlag`);
draft.value = html;
aiAssisted.value = true;
toast.success('Vorschlag erstellt – bitte prüfen und anpassen.');
} catch (error) {
toast.error(error.message);
} finally {
suggesting.value = false;
}
}
function save(html = draft.value) {
saving.value = true;
router.put(`/leichte-sprache/${props.easy.type}/${props.easy.id}`, { html, ai_assisted: aiAssisted.value }, {
preserveScroll: true,
onSuccess: () => {
editing.value = false;
showEasy.value = !!html;
},
onFinish: () => (saving.value = false),
});
}
function remove() {
if (window.confirm('Leichte Sprache für diesen Inhalt entfernen?')) save('');
}
</script>
<template>
<div class="flex flex-wrap items-center gap-2">
<ReadAloud ref="reader" :source="readSource" />
<div v-if="easy?.html" class="inline-flex rounded-md border bg-muted/50 p-0.5" role="group" aria-label="Sprachfassung">
<button type="button" class="rounded px-2.5 py-1 text-[13px] font-medium" :class="!showEasy ? 'bg-card shadow-xs' : 'text-muted-foreground hover:text-foreground'" :aria-pressed="!showEasy" @click="showEasy = false">Standard</button>
<button type="button" class="inline-flex items-center gap-1.5 rounded px-2.5 py-1 text-[13px] font-medium" :class="showEasy ? 'bg-card shadow-xs' : 'text-muted-foreground hover:text-foreground'" :aria-pressed="showEasy" @click="showEasy = true">
<BookOpenText class="size-3.5" /> Leichte Sprache
</button>
</div>
<Button v-if="easy?.can_edit" type="button" variant="ghost" size="sm" class="text-muted-foreground" @click="openEditor">
<PencilLine /> {{ easy.html ? 'Leichte Sprache bearbeiten' : 'Leichte Sprache ergänzen' }}
</Button>
<Sheet v-if="easy?.can_edit" v-model:open="editing">
<SheetContent class="flex w-full flex-col gap-0 sm:max-w-2xl">
<SheetHeader>
<SheetTitle>Leichte Sprache</SheetTitle>
<SheetDescription>Eine zweite, leicht verständliche Fassung. Lesende schalten oben am Inhalt zwischen „Standard“ und „Leichte Sprache“ um.</SheetDescription>
</SheetHeader>
<div class="grid flex-1 content-start gap-4 overflow-y-auto px-4 pb-4">
<div v-if="easy.ai" class="grid gap-2 rounded-md border bg-muted/40 p-3">
<Button type="button" variant="outline" size="sm" class="justify-self-start" :disabled="suggesting" @click="suggest">
<LoaderCircle v-if="suggesting" class="animate-spin" /><Sparkles v-else /> {{ suggesting ? 'Vorschlag wird erstellt …' : 'KI-Vorschlag erstellen' }}
</Button>
<p class="flex items-start gap-1.5 text-xs text-muted-foreground">
<TriangleAlert class="mt-0.5 size-3.5 shrink-0" />
<template v-if="easy.ai_external">Dafür wird der Text an den externen KI-Dienst übertragen, den die Administration eingerichtet hat.</template>
<template v-else>Der Text wird vom KI-Server im eigenen Netz verarbeitet.</template>
Nur Inhalte ohne Zielgruppen-Einschränkung. Den Vorschlag bitte immer prüfen.
</p>
</div>
<RichTextEditor v-model="draft" bordered min-height="20rem" :headings="[2]" placeholder="Kurze Sätze. Ein Gedanke pro Satz. Einfache Wörter." />
<p class="text-xs text-muted-foreground">Leichte Sprache sehen alle, die den Inhalt sehen dürfen. Nur Allgemeines aufnehmen, nichts aus Abschnitten für bestimmte Zielgruppen.</p>
</div>
<SheetFooter class="flex-row justify-between border-t">
<Button v-if="easy.html" type="button" variant="ghost" class="text-destructive hover:text-destructive" :disabled="saving" @click="remove">Entfernen</Button>
<span v-else />
<Button type="button" :disabled="saving || suggesting" @click="save()"><LoaderCircle v-if="saving" class="animate-spin" /> Speichern</Button>
</SheetFooter>
</SheetContent>
</Sheet>
</div>
</template>