Loheide-eu-mitarbeiterplatt.../resources/js/components/EasyLanguageBar.vue
Friederich Loheide 268742983a
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m17s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m28s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 6m32s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 6m48s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 8m51s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 8m52s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 7m31s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 52s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 7m51s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m22s
KI-Assistent: OpenAI und Ollama als Anbieter (0.35.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 13:57:37 +00:00

118 lines
5.9 KiB
Vue
Raw Permalink 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 { ref, watch } from 'vue';
import { router } 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/RichTextEditor.vue';
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());
// 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>