QM-Texterkennung: Imagick nur mit Ghostscript als verfügbar melden
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 3m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 3m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 3m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 2m56s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 4m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 4m1s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 3m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 3m39s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m10s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 3m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 3m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 3m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 2m56s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 4m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 4m1s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 3m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 3m39s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m10s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5a360d3cc7
commit
b50d089946
117 changed files with 1747 additions and 2 deletions
|
|
@ -0,0 +1,35 @@
|
|||
<?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('gemeinsam_entries', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('section', 20); // welcome | transfer | jubilee | farewell | memoriam
|
||||
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete(); // Person aus dem Portal …
|
||||
$table->string('name', 150)->nullable(); // … oder freier Name
|
||||
$table->date('date'); // Eintritt, Wechsel ab, Jubiläum, letzter Tag, Todestag – bestimmt den Monat
|
||||
$table->date('born_on')->nullable(); // nur Gedenken
|
||||
$table->string('department', 150)->nullable();
|
||||
$table->string('location', 150)->nullable();
|
||||
$table->string('from', 150)->nullable(); // Wechsel: bisher
|
||||
$table->string('to', 150)->nullable(); // Wechsel: künftig
|
||||
$table->string('label', 150)->nullable(); // Jubiläum („25 Jahre“), Anlass („Ruhestand“)
|
||||
$table->string('text', 1000)->nullable();
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['date', 'section']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('gemeinsam_entries');
|
||||
}
|
||||
};
|
||||
14
plugins-core/gemeinsam/plugin.json
Normal file
14
plugins-core/gemeinsam/plugin.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"slug": "gemeinsam",
|
||||
"name": "Gemeinsam feiern, erinnern und willkommen heißen",
|
||||
"version": "1.0.0",
|
||||
"description": "Personalnachrichten auf einer Seite: neue Mitarbeitende, Wechsel des Einsatzorts, Geburtstage (aus dem Geburtstags-Plugin), Jubilare, Verabschiedungen und Gedenken – gepflegt von der Personalabteilung, nach Monaten.",
|
||||
"author": "Inhaus",
|
||||
"namespace": "Inhaus\\Plugins\\Gemeinsam\\",
|
||||
"class": "Inhaus\\Plugins\\Gemeinsam\\GemeinsamPlugin",
|
||||
"enabled_by_default": false,
|
||||
"requires": {
|
||||
"core": ">=0.12.0",
|
||||
"php": ">=8.3"
|
||||
}
|
||||
}
|
||||
139
plugins-core/gemeinsam/resources/js/components/EntryDialog.vue
Normal file
139
plugins-core/gemeinsam/resources/js/components/EntryDialog.vue
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import { LoaderCircle, X } from '@lucide/vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import FormField from '@/components/FormField.vue';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
import { http } from '@/lib/http';
|
||||
|
||||
const props = defineProps({
|
||||
open: { type: Boolean, default: false },
|
||||
section: { type: Object, default: null }, // { key, title }
|
||||
entry: { type: Object, default: null },
|
||||
month: { type: String, required: true },
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:open']);
|
||||
|
||||
// Feldbeschriftungen je Abschnitt
|
||||
const config = {
|
||||
welcome: { date: 'Eintritt am', fields: ['department', 'location', 'text'] },
|
||||
transfer: { date: 'Wechsel ab', fields: ['from', 'to', 'text'] },
|
||||
jubilee: { date: 'Jubiläum am', fields: ['label', 'department', 'text'], label: 'Jubiläum', labelPlaceholder: 'z. B. 25 Jahre' },
|
||||
farewell: { date: 'Letzter Arbeitstag', fields: ['department', 'label', 'text'], label: 'Anlass (optional)', labelPlaceholder: 'z. B. Ruhestand' },
|
||||
memoriam: { date: 'Verstorben am', fields: ['born_on', 'department', 'text'] },
|
||||
};
|
||||
|
||||
const current = computed(() => config[props.section?.key] ?? config.welcome);
|
||||
const has = (field) => current.value.fields.includes(field);
|
||||
|
||||
const form = useForm({ section: '', user_id: null, name: '', date: '', born_on: '', department: '', location: '', from: '', to: '', label: '', text: '' });
|
||||
const person = ref(null);
|
||||
const freeName = ref(false);
|
||||
const query = ref('');
|
||||
const results = ref([]);
|
||||
|
||||
watch(() => props.open, (open) => {
|
||||
if (!open) return;
|
||||
const e = props.entry;
|
||||
form.clearErrors();
|
||||
form.defaults({
|
||||
section: props.section.key,
|
||||
user_id: e?.user_id ?? null,
|
||||
name: e?.free_name ?? '',
|
||||
date: e?.date ?? `${props.month}-01`,
|
||||
born_on: e?.born_on ?? '',
|
||||
department: e?.raw?.department ?? '',
|
||||
location: e?.raw?.location ?? '',
|
||||
from: e?.from ?? '',
|
||||
to: e?.to ?? '',
|
||||
label: e?.label ?? '',
|
||||
text: e?.text ?? '',
|
||||
});
|
||||
form.reset();
|
||||
person.value = e?.person ?? null;
|
||||
freeName.value = !!e && !e.user_id;
|
||||
query.value = '';
|
||||
results.value = [];
|
||||
});
|
||||
|
||||
let timer;
|
||||
watch(query, (value) => {
|
||||
clearTimeout(timer);
|
||||
if (value.trim().length < 2) return (results.value = []);
|
||||
timer = setTimeout(async () => (results.value = (await http.get(`/personen/suche?q=${encodeURIComponent(value.trim())}`)).people), 250);
|
||||
});
|
||||
|
||||
function choose(p) {
|
||||
person.value = p;
|
||||
form.user_id = p.id;
|
||||
query.value = '';
|
||||
results.value = [];
|
||||
}
|
||||
|
||||
function clearPerson() {
|
||||
person.value = null;
|
||||
form.user_id = null;
|
||||
}
|
||||
|
||||
function submit() {
|
||||
if (freeName.value) form.user_id = null;
|
||||
const options = { preserveScroll: true, onSuccess: () => emit('update:open', false) };
|
||||
props.entry ? form.put(`/gemeinsam/eintraege/${props.entry.id}`, options) : form.post('/gemeinsam/eintraege', options);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog :open="open" @update:open="(v) => emit('update:open', v)">
|
||||
<DialogContent class="sm:max-w-lg">
|
||||
<DialogHeader><DialogTitle>{{ section?.title }}</DialogTitle></DialogHeader>
|
||||
<form class="grid gap-4" @submit.prevent="submit">
|
||||
<FormField id="g-person" label="Person" :error="form.errors.name || form.errors.user_id">
|
||||
<div v-if="!freeName">
|
||||
<div v-if="person" class="flex items-center gap-2 rounded-md border px-2 py-1.5">
|
||||
<PersonAvatar :person="person" class="size-7 text-[10px]" />
|
||||
<span class="min-w-0 flex-1 truncate text-sm">{{ person.name }}</span>
|
||||
<button type="button" class="grid size-6 place-items-center rounded hover:bg-accent" aria-label="Auswahl entfernen" @click="clearPerson"><X class="size-3.5" /></button>
|
||||
</div>
|
||||
<div v-else class="relative">
|
||||
<Input id="g-person" v-model="query" placeholder="Name im Portal suchen …" autocomplete="off" />
|
||||
<ul v-if="results.length" class="absolute inset-x-0 top-full z-30 mt-1 max-h-60 overflow-y-auto rounded-md border bg-popover p-1 shadow-md">
|
||||
<li v-for="p in results" :key="p.id">
|
||||
<button type="button" class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm hover:bg-accent" @click="choose(p)">
|
||||
<PersonAvatar :person="p" class="size-7 text-[10px]" /> <span class="truncate">{{ p.name }}</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<Input v-else id="g-person" v-model="form.name" maxlength="150" placeholder="Vor- und Nachname" />
|
||||
<button type="button" class="mt-1 justify-self-start text-xs text-brand-text hover:underline" @click="freeName = !freeName">
|
||||
{{ freeName ? 'Stattdessen Person aus dem Portal wählen' : 'Nicht im Portal? Namen frei eintragen' }}
|
||||
</button>
|
||||
</FormField>
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
<FormField id="g-date" :label="current.date" :error="form.errors.date"><Input id="g-date" v-model="form.date" type="date" /></FormField>
|
||||
<FormField v-if="has('born_on')" id="g-born" label="Geboren am (optional)" :error="form.errors.born_on"><Input id="g-born" v-model="form.born_on" type="date" /></FormField>
|
||||
<FormField v-if="has('label')" id="g-label" :label="current.label" :error="form.errors.label"><Input id="g-label" v-model="form.label" maxlength="150" :placeholder="current.labelPlaceholder" /></FormField>
|
||||
<FormField v-if="has('from')" id="g-from" label="Bisher" :error="form.errors.from"><Input id="g-from" v-model="form.from" maxlength="150" placeholder="z. B. Werkstatt Nord" /></FormField>
|
||||
<FormField v-if="has('to')" id="g-to" label="Künftig" :error="form.errors.to"><Input id="g-to" v-model="form.to" maxlength="150" placeholder="z. B. Verwaltung" /></FormField>
|
||||
<FormField v-if="has('department')" id="g-dep" label="Bereich" :error="form.errors.department"><Input id="g-dep" v-model="form.department" maxlength="150" :placeholder="person?.department || ''" /></FormField>
|
||||
<FormField v-if="has('location')" id="g-loc" label="Standort" :error="form.errors.location"><Input id="g-loc" v-model="form.location" maxlength="150" :placeholder="person?.location || ''" /></FormField>
|
||||
</div>
|
||||
<p v-if="person && (has('department') || has('location'))" class="-mt-2 text-xs text-muted-foreground">Leer gelassen, gilt die Angabe aus dem Profil.</p>
|
||||
|
||||
<FormField v-if="has('text')" id="g-text" label="Text (optional)" :error="form.errors.text"><Textarea id="g-text" v-model="form.text" rows="2" maxlength="1000" /></FormField>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" @click="emit('update:open', false)">Abbrechen</Button>
|
||||
<Button type="submit" :disabled="form.processing"><LoaderCircle v-if="form.processing" class="animate-spin" /> Speichern</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
|
||||
defineProps({
|
||||
entry: { type: Object, required: true },
|
||||
muted: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const initials = (name) => name.split(/\s+/).filter(Boolean).slice(0, 2).map((p) => p[0]).join('').toUpperCase();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<PersonAvatar :person="entry.person ?? { id: entry.name, name: entry.name, initials: initials(entry.name) }" class="size-9 shrink-0" :class="{ 'grayscale': muted }" />
|
||||
<div class="min-w-0">
|
||||
<Link v-if="entry.person?.url" :href="entry.person.url" class="block truncate text-sm font-medium hover:underline">{{ entry.name }}</Link>
|
||||
<span v-else class="block truncate text-sm font-medium">{{ entry.name }}</span>
|
||||
<span v-if="entry.person?.job_title" class="block truncate text-xs text-muted-foreground">{{ entry.person.job_title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
132
plugins-core/gemeinsam/resources/js/pages/Index.vue
Normal file
132
plugins-core/gemeinsam/resources/js/pages/Index.vue
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Link, router, usePage } from '@inertiajs/vue3';
|
||||
import { ArrowRightLeft, Award, Cake, ChevronLeft, ChevronRight, EllipsisVertical, Flower2, Hand, PencilLine, Plus, Sparkles, Trash2 } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import EmptyState from '@/components/EmptyState.vue';
|
||||
import PageHeader from '@/components/PageHeader.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import EntryDialog from '../components/EntryDialog.vue';
|
||||
import PersonCell from '../components/PersonCell.vue';
|
||||
|
||||
const props = defineProps({
|
||||
month: { type: String, required: true },
|
||||
monthLabel: { type: String, required: true },
|
||||
previous: { type: String, required: true },
|
||||
next: { type: String, required: true },
|
||||
isCurrent: { type: Boolean, default: true },
|
||||
sections: { 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 icons = { welcome: Sparkles, transfer: ArrowRightLeft, birthdays: Cake, jubilee: Award, farewell: Hand, memoriam: Flower2 };
|
||||
|
||||
// Spalten je Abschnitt (die Person steht immer vorne)
|
||||
const columns = {
|
||||
welcome: [['department', 'Bereich'], ['location', 'Standort'], ['date', 'Eintritt']],
|
||||
transfer: [['from', 'Bisher'], ['to', 'Künftig'], ['date', 'Ab']],
|
||||
birthdays: [['department', 'Bereich'], ['location', 'Standort'], ['date', 'Geburtstag']],
|
||||
jubilee: [['label', 'Jubiläum'], ['department', 'Bereich'], ['date', 'Datum']],
|
||||
farewell: [['department', 'Bereich'], ['label', 'Anlass'], ['date', 'Letzter Arbeitstag']],
|
||||
memoriam: [['lifespan', 'Lebensdaten'], ['department', 'Bereich']],
|
||||
};
|
||||
|
||||
const dateFormat = new Intl.DateTimeFormat('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' });
|
||||
const dayFormat = new Intl.DateTimeFormat('de-DE', { day: 'numeric', month: 'long' });
|
||||
const format = (iso, section) => (iso ? (section === 'birthdays' ? dayFormat : dateFormat).format(new Date(`${iso}T12:00:00`)) : '–');
|
||||
|
||||
function value(entry, key, section) {
|
||||
if (key === 'date') return format(entry.date, section);
|
||||
if (key === 'lifespan') return [entry.born_on && `* ${format(entry.born_on)}`, `† ${format(entry.date)}`].filter(Boolean).join(' ');
|
||||
|
||||
return entry[key] || '–';
|
||||
}
|
||||
|
||||
const visible = computed(() => props.sections.filter((s) => s.entries.length || (props.canManage && !s.automatic)));
|
||||
const empty = computed(() => props.sections.every((s) => !s.entries.length));
|
||||
|
||||
const dialog = ref({ open: false, section: null, entry: null });
|
||||
const add = (section) => (dialog.value = { open: true, section, entry: null });
|
||||
const edit = (section, entry) => (dialog.value = { open: true, section, entry });
|
||||
|
||||
function remove(entry) {
|
||||
if (window.confirm(`Eintrag „${entry.name}“ entfernen?`)) router.delete(`/gemeinsam/eintraege/${entry.id}`, { preserveScroll: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Gemeinsam feiern, erinnern und willkommen heißen">
|
||||
<PageHeader title="Gemeinsam feiern, erinnern und willkommen heißen" :description="monthLabel">
|
||||
<template #actions>
|
||||
<div class="flex items-center gap-1 rounded-md border bg-card p-0.5">
|
||||
<Button variant="ghost" size="icon" class="size-8" as-child><Link :href="`/gemeinsam?monat=${previous}`" aria-label="Vorheriger Monat" preserve-scroll><ChevronLeft /></Link></Button>
|
||||
<span class="min-w-32 text-center text-sm font-medium">{{ monthLabel }}</span>
|
||||
<Button variant="ghost" size="icon" class="size-8" as-child><Link :href="`/gemeinsam?monat=${next}`" aria-label="Nächster Monat" preserve-scroll><ChevronRight /></Link></Button>
|
||||
</div>
|
||||
<Button v-if="!isCurrent" variant="outline" as-child><Link href="/gemeinsam">Aktueller Monat</Link></Button>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<div v-if="visible.length && !(empty && !canManage)" class="grid max-w-5xl gap-6">
|
||||
<section
|
||||
v-for="section in visible"
|
||||
:key="section.key"
|
||||
class="overflow-hidden rounded-lg border bg-card"
|
||||
:class="section.key === 'memoriam' ? 'border-t-4 border-t-foreground/70' : 'border-t-4 border-t-brand'"
|
||||
>
|
||||
<header class="flex items-center justify-between gap-3 border-b px-5 py-3">
|
||||
<h2 class="flex items-center gap-2.5 text-base font-semibold" :class="{ 'text-foreground/85': section.key === 'memoriam' }">
|
||||
<component :is="icons[section.key]" class="size-5" :class="section.key === 'memoriam' ? 'text-muted-foreground' : 'text-brand-text'" />
|
||||
{{ section.title }}
|
||||
</h2>
|
||||
<Button v-if="canManage && !section.automatic" size="sm" variant="outline" @click="add(section)"><Plus /> Hinzufügen</Button>
|
||||
<span v-else-if="section.automatic && canManage" class="text-xs text-muted-foreground">aus dem Geburtstagskalender</span>
|
||||
</header>
|
||||
|
||||
<div v-if="section.entries.length" class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead class="bg-muted/40 text-left text-xs text-muted-foreground">
|
||||
<tr>
|
||||
<th class="px-5 py-2 font-medium">Name</th>
|
||||
<th v-for="[key, label] in columns[section.key]" :key="key" class="px-3 py-2 font-medium whitespace-nowrap">{{ label }}</th>
|
||||
<th v-if="canManage && !section.automatic" class="w-12"><span class="sr-only">Aktionen</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y">
|
||||
<template v-for="entry in section.entries" :key="entry.id">
|
||||
<tr>
|
||||
<td class="px-5 py-2.5"><PersonCell :entry="entry" :muted="section.key === 'memoriam'" /></td>
|
||||
<td v-for="[key] in columns[section.key]" :key="key" class="px-3 py-2.5 whitespace-nowrap" :class="{ 'tabular-nums': key === 'date' || key === 'lifespan' }">{{ value(entry, key, section.key) }}</td>
|
||||
<td v-if="canManage && !section.automatic" class="pr-3 text-right">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child><Button variant="ghost" size="icon" class="size-8 text-muted-foreground" :aria-label="`Aktionen für ${entry.name}`"><EllipsisVertical /></Button></DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem @select="edit(section, entry)"><PencilLine /> Bearbeiten</DropdownMenuItem>
|
||||
<DropdownMenuItem class="text-destructive" @select="remove(entry)"><Trash2 /> Entfernen</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="entry.text">
|
||||
<td :colspan="columns[section.key].length + 2" class="-mt-1 px-5 pb-3 text-[13px] text-muted-foreground" :class="{ italic: section.key === 'memoriam' }">{{ entry.text }}</td>
|
||||
</tr>
|
||||
</template>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p v-else class="px-5 py-4 text-[13px] text-muted-foreground">Noch keine Einträge in diesem Monat.</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div v-else class="max-w-5xl rounded-lg border bg-card">
|
||||
<EmptyState :icon="Sparkles" title="Keine Einträge in diesem Monat" text="Hier stehen neue Kolleginnen und Kollegen, Wechsel, Geburtstage, Jubiläen, Verabschiedungen und Gedenken." />
|
||||
</div>
|
||||
|
||||
<EntryDialog v-if="canManage" v-model:open="dialog.open" :section="dialog.section" :entry="dialog.entry" :month="month" />
|
||||
</AppLayout>
|
||||
</template>
|
||||
13
plugins-core/gemeinsam/routes/web.php
Normal file
13
plugins-core/gemeinsam/routes/web.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Gemeinsam\Http\Controllers\GemeinsamController;
|
||||
|
||||
Route::middleware('auth')->prefix('gemeinsam')->name('gemeinsam.')->controller(GemeinsamController::class)
|
||||
->where(['entry' => '[0-9]+'])
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::post('/eintraege', 'store')->name('store');
|
||||
Route::put('/eintraege/{entry}', 'update')->name('update');
|
||||
Route::delete('/eintraege/{entry}', 'destroy')->name('destroy');
|
||||
});
|
||||
16
plugins-core/gemeinsam/src/GemeinsamPlugin.php
Normal file
16
plugins-core/gemeinsam/src/GemeinsamPlugin.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Gemeinsam;
|
||||
|
||||
use App\Plugins\Plugin;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
|
||||
class GemeinsamPlugin extends Plugin
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('gemeinsam', 'Gemeinsam', '/gemeinsam', active: 'gemeinsam.*', sort: 65);
|
||||
$this->app->make(Abilities::class)->define('gemeinsam.manage', 'Personalnachrichten pflegen (Gemeinsam feiern …)', 'Gemeinsam');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Gemeinsam\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Plugins\PluginManager;
|
||||
use App\Support\Audit;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Birthdays\BirthdayList;
|
||||
use Inhaus\Plugins\Gemeinsam\Models\Entry;
|
||||
|
||||
class GemeinsamController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$month = $this->month((string) $request->query('monat', ''));
|
||||
$entries = Entry::query()->with('user')
|
||||
->whereBetween('date', [$month->copy()->startOfMonth()->toDateString(), $month->copy()->endOfMonth()->toDateString()])
|
||||
->orderBy('date')->orderBy('id')->get();
|
||||
|
||||
$sections = [];
|
||||
|
||||
foreach (Entry::SECTIONS as $key => $title) {
|
||||
if ($key === 'birthdays') {
|
||||
if (! app(PluginManager::class)->isLoaded('birthdays')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows = app(BirthdayList::class)->inMonth($month->year, $month->month);
|
||||
$sections[] = ['key' => $key, 'title' => $title, 'automatic' => true, 'entries' => array_map(fn ($row) => [
|
||||
'id' => 'b'.$row['person']['id'],
|
||||
'date' => $row['date'],
|
||||
'person' => $row['person'] + ['url' => '/personen/'.$row['person']['id']],
|
||||
'name' => $row['person']['name'],
|
||||
'department' => $row['person']['department'] ?? null,
|
||||
'location' => $row['person']['location'] ?? null,
|
||||
], $rows)];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$sections[] = [
|
||||
'key' => $key,
|
||||
'title' => $title,
|
||||
'automatic' => false,
|
||||
'entries' => $entries->where('section', $key)->values()->map(fn (Entry $entry) => $this->present($entry))->all(),
|
||||
];
|
||||
}
|
||||
|
||||
return Inertia::render('gemeinsam::Index', [
|
||||
'month' => $month->format('Y-m'),
|
||||
'monthLabel' => $month->locale('de')->isoFormat('MMMM YYYY'),
|
||||
'previous' => $month->copy()->subMonth()->format('Y-m'),
|
||||
'next' => $month->copy()->addMonth()->format('Y-m'),
|
||||
'isCurrent' => $month->isSameMonth(now()),
|
||||
'sections' => $sections,
|
||||
'canManage' => (bool) $request->user()->can('gemeinsam.manage'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->can('gemeinsam.manage'), 403);
|
||||
$entry = Entry::query()->create([...$this->validated($request), 'created_by' => $request->user()->id]);
|
||||
Audit::log('gemeinsam.created', ['section' => $entry->section, 'entry' => $entry->id]);
|
||||
|
||||
return redirect()->route('gemeinsam.index', ['monat' => $entry->date->format('Y-m')])->with('status', 'Eintrag gespeichert.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Entry $entry): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->can('gemeinsam.manage'), 403);
|
||||
$entry->update($this->validated($request));
|
||||
|
||||
return redirect()->route('gemeinsam.index', ['monat' => $entry->date->format('Y-m')])->with('status', 'Eintrag gespeichert.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Entry $entry): RedirectResponse
|
||||
{
|
||||
abort_unless($request->user()->can('gemeinsam.manage'), 403);
|
||||
$entry->delete();
|
||||
Audit::log('gemeinsam.deleted', ['section' => $entry->section, 'entry' => $entry->id]);
|
||||
|
||||
return back()->with('status', 'Eintrag entfernt.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function present(Entry $entry): array
|
||||
{
|
||||
$user = $entry->user;
|
||||
|
||||
return [
|
||||
'id' => $entry->id,
|
||||
'section' => $entry->section,
|
||||
'user_id' => $entry->user_id,
|
||||
'name' => $entry->displayName(),
|
||||
'free_name' => $entry->name,
|
||||
'person' => $user ? [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'initials' => $user->initials,
|
||||
'avatar_url' => $user->avatarUrl(96),
|
||||
'job_title' => $user->job_title,
|
||||
'url' => '/personen/'.$user->id,
|
||||
] : null,
|
||||
'date' => $entry->date->toDateString(),
|
||||
'born_on' => $entry->born_on?->toDateString(),
|
||||
// Leere Felder aus dem Profil ergänzen
|
||||
'department' => $entry->department ?? $user?->department,
|
||||
'location' => $entry->location ?? $user?->location,
|
||||
'from' => $entry->from,
|
||||
'to' => $entry->to,
|
||||
'label' => $entry->label,
|
||||
'text' => $entry->text,
|
||||
'raw' => [
|
||||
'department' => $entry->department,
|
||||
'location' => $entry->location,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validated(Request $request): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'section' => ['required', Rule::in(Entry::MANUAL)],
|
||||
'user_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
||||
'name' => ['required_without:user_id', 'nullable', 'string', 'max:150'],
|
||||
'date' => ['required', 'date'],
|
||||
'born_on' => ['nullable', 'date', 'before_or_equal:date'],
|
||||
'department' => ['nullable', 'string', 'max:150'],
|
||||
'location' => ['nullable', 'string', 'max:150'],
|
||||
'from' => ['nullable', 'string', 'max:150'],
|
||||
'to' => ['nullable', 'string', 'max:150'],
|
||||
'label' => ['nullable', 'string', 'max:150'],
|
||||
'text' => ['nullable', 'string', 'max:1000'],
|
||||
], ['name.required_without' => 'Bitte eine Person auswählen oder einen Namen eintragen.'], [
|
||||
'date' => 'Datum', 'born_on' => 'Geburtsdatum', 'department' => 'Bereich', 'location' => 'Standort', 'label' => 'Anlass',
|
||||
]);
|
||||
|
||||
if (! empty($data['user_id'])) {
|
||||
$data['name'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function month(string $value): Carbon
|
||||
{
|
||||
return preg_match('/^\d{4}-\d{2}$/', $value) && checkdate((int) substr($value, 5, 2), 1, (int) substr($value, 0, 4))
|
||||
? Carbon::createFromFormat('Y-m-d', $value.'-01')->startOfDay()
|
||||
: Carbon::today()->startOfMonth();
|
||||
}
|
||||
}
|
||||
44
plugins-core/gemeinsam/src/Models/Entry.php
Normal file
44
plugins-core/gemeinsam/src/Models/Entry.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Gemeinsam\Models;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable(['section', 'user_id', 'name', 'date', 'born_on', 'department', 'location', 'from', 'to', 'label', 'text', 'created_by'])]
|
||||
class Entry extends Model
|
||||
{
|
||||
protected $table = 'gemeinsam_entries';
|
||||
|
||||
/** Abschnitte in der Reihenfolge der Seite (Geburtstage kommen aus dem Geburtstags-Plugin). */
|
||||
public const SECTIONS = [
|
||||
'welcome' => 'Wir begrüßen die neuen Mitarbeitenden',
|
||||
'transfer' => 'Den Einsatzort wechseln',
|
||||
'birthdays' => 'Geburtstage',
|
||||
'jubilee' => 'Jubilare',
|
||||
'farewell' => 'Wir verabschieden',
|
||||
'memoriam' => 'In Gedenken an',
|
||||
];
|
||||
|
||||
public const MANUAL = ['welcome', 'transfer', 'jubilee', 'farewell', 'memoriam'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['date' => 'date', 'born_on' => 'date'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function displayName(): string
|
||||
{
|
||||
return $this->user?->name ?? (string) $this->name;
|
||||
}
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ class QmSettings extends Page
|
|||
.'<div>'.$ok($status['exec']).' Programme aufrufen erlaubt (PHP-Funktion proc_open)</div>'
|
||||
.'<div>'.$ok($status['tesseract'] !== null).' Tesseract: '.e($status['tesseract'] ?? 'nicht gefunden')
|
||||
.($status['languages'] ? ' · Sprachen: '.e(implode(', ', array_slice($status['languages'], 0, 8))) : '').'</div>'
|
||||
.'<div>'.$ok($status['rasterizer'] !== null).' PDF-Seiten in Bilder umwandeln: '.e($status['rasterizer'] ?? 'weder pdftoppm noch Imagick mit PDF-Unterstützung').'</div>'
|
||||
.'<div>'.$ok($status['rasterizer'] !== null).' PDF-Seiten in Bilder umwandeln: '.e($status['rasterizer'] ?? 'weder pdftoppm noch Imagick mit Ghostscript').'</div>'
|
||||
.'<div style="margin-top:4px">'.$pending.' eingescannte Datei(en) warten auf Texterkennung.</div>'
|
||||
.'<div style="margin-top:6px;opacity:.75">Einrichtung auf eigenem Server (Debian/Ubuntu): <code>apt install tesseract-ocr tesseract-ocr-deu poppler-utils</code>. Ein Apache-Modul gibt es dafür nicht; Tesseract ist ein eigenständiges Programm, das PHP aufruft.</div>'
|
||||
.'</div>'
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ class Ocr
|
|||
}
|
||||
|
||||
try {
|
||||
if (class_exists(Imagick::class) && in_array('PDF', Imagick::queryFormats('PDF'), true)) {
|
||||
// Imagick meldet PDF auch ohne Ghostscript – ohne „gs“ scheitert das Umwandeln aber.
|
||||
if ($exec && class_exists(Imagick::class) && in_array('PDF', Imagick::queryFormats('PDF'), true) && $this->run(['gs', '--version']) !== null) {
|
||||
return 'imagick';
|
||||
}
|
||||
} catch (Throwable) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?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('speiseplan_weeks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->date('week_start')->unique(); // Montag der Woche
|
||||
$table->string('path');
|
||||
$table->string('original_name')->nullable();
|
||||
$table->unsignedInteger('width')->nullable();
|
||||
$table->unsignedInteger('height')->nullable();
|
||||
$table->foreignId('uploaded_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('speiseplan_weeks');
|
||||
}
|
||||
};
|
||||
14
plugins-core/speiseplan/plugin.json
Normal file
14
plugins-core/speiseplan/plugin.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"slug": "speiseplan",
|
||||
"name": "Speiseplan",
|
||||
"version": "1.0.0",
|
||||
"description": "Speisepläne der Kantine als Bild je Woche – mehrere Wochen im Voraus, PDF wird automatisch zum Bild. Anzeige der aktuellen und der nächsten Woche, Allergie-Informationen als PDF und randloser A4-Druck.",
|
||||
"author": "Inhaus",
|
||||
"namespace": "Inhaus\\Plugins\\Speiseplan\\",
|
||||
"class": "Inhaus\\Plugins\\Speiseplan\\SpeiseplanPlugin",
|
||||
"enabled_by_default": false,
|
||||
"requires": {
|
||||
"core": ">=0.12.0",
|
||||
"php": ">=8.3"
|
||||
}
|
||||
}
|
||||
113
plugins-core/speiseplan/resources/js/components/ManagePanel.vue
Normal file
113
plugins-core/speiseplan/resources/js/components/ManagePanel.vue
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { router, useForm } from '@inertiajs/vue3';
|
||||
import { FileText, LoaderCircle, Trash2, Upload } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import FormField from '@/components/FormField.vue';
|
||||
import NativeSelect from '@/components/NativeSelect.vue';
|
||||
import { pdfToImage } from '../pdfToImage';
|
||||
|
||||
const props = defineProps({
|
||||
manage: { type: Object, required: true },
|
||||
allergens: { type: Object, default: null },
|
||||
});
|
||||
|
||||
const form = useForm({ week: props.manage.suggested, image: null });
|
||||
const converting = ref(false);
|
||||
const dragging = ref(false);
|
||||
const fileInput = ref(null);
|
||||
const allergenInput = ref(null);
|
||||
|
||||
async function upload(file) {
|
||||
if (!file) return;
|
||||
|
||||
let image = file;
|
||||
|
||||
if (file.type === 'application/pdf' || /\.pdf$/i.test(file.name)) {
|
||||
converting.value = true;
|
||||
try {
|
||||
image = await pdfToImage(file);
|
||||
} catch {
|
||||
toast.error('Das PDF ließ sich nicht umwandeln. Bitte als Bild hochladen.');
|
||||
|
||||
return;
|
||||
} finally {
|
||||
converting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
form.image = image;
|
||||
form.post('/speiseplan/wochen', {
|
||||
forceFormData: true,
|
||||
preserveScroll: true,
|
||||
onError: (errors) => toast.error(Object.values(errors)[0]),
|
||||
onSuccess: () => {
|
||||
form.image = null;
|
||||
form.week = props.manage.suggested;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function uploadAllergens(file) {
|
||||
if (!file) return;
|
||||
router.post('/speiseplan/allergene', { file }, { forceFormData: true, preserveScroll: true, onError: (e) => toast.error(Object.values(e)[0]) });
|
||||
}
|
||||
|
||||
function remove(plan) {
|
||||
if (window.confirm(`Speiseplan ${plan.label} entfernen?`)) router.delete(`/speiseplan/wochen/${plan.id}`, { preserveScroll: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="mt-10 rounded-lg border bg-card print:hidden">
|
||||
<h2 class="border-b px-5 py-3 text-base font-semibold">Speiseplan hochladen</h2>
|
||||
<div class="grid gap-6 p-5 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
|
||||
<div class="grid content-start gap-4">
|
||||
<FormField id="sp-week" label="Woche" :error="form.errors.week">
|
||||
<NativeSelect id="sp-week" v-model="form.week" :options="manage.options" />
|
||||
</FormField>
|
||||
<button
|
||||
type="button"
|
||||
class="grid place-items-center rounded-lg border-2 border-dashed px-6 py-10 text-center transition-colors"
|
||||
:class="dragging ? 'border-brand-400 bg-brand-soft/60' : 'hover:border-brand-300'"
|
||||
:disabled="form.processing || converting"
|
||||
@click="fileInput?.click()"
|
||||
@dragover.prevent="dragging = true"
|
||||
@dragleave.prevent="dragging = false"
|
||||
@drop.prevent="dragging = false; upload($event.dataTransfer.files[0])"
|
||||
>
|
||||
<LoaderCircle v-if="form.processing || converting" class="size-7 animate-spin text-muted-foreground" />
|
||||
<Upload v-else class="size-7 text-muted-foreground" />
|
||||
<span class="mt-2 text-sm font-medium">{{ converting ? 'PDF wird umgewandelt …' : form.processing ? 'Wird hochgeladen …' : 'PDF oder Bild hierher ziehen oder klicken' }}</span>
|
||||
<span class="mt-1 text-xs text-muted-foreground">Ein PDF wird automatisch zum Bild (erste Seite, A4). Ist für die Woche schon ein Plan da, wird er ersetzt.</span>
|
||||
</button>
|
||||
<input ref="fileInput" type="file" accept="application/pdf,image/jpeg,image/png,image/webp" class="hidden" @change="upload($event.target.files[0]); $event.target.value = ''" />
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3 rounded-md bg-muted/50 px-3 py-2.5 text-sm">
|
||||
<FileText class="size-4 text-muted-foreground" />
|
||||
<span class="min-w-0 flex-1 truncate">{{ allergens ? allergens.name : 'Noch keine Allergie-Informationen hinterlegt' }}</span>
|
||||
<Button size="sm" variant="outline" @click="allergenInput?.click()">{{ allergens ? 'Ersetzen' : 'PDF hochladen' }}</Button>
|
||||
<Button v-if="allergens" size="icon" variant="ghost" class="size-8" aria-label="Allergie-Informationen entfernen" @click="router.delete('/speiseplan/allergene', { preserveScroll: true })"><Trash2 /></Button>
|
||||
<input ref="allergenInput" type="file" accept="application/pdf" class="hidden" @change="uploadAllergens($event.target.files[0]); $event.target.value = ''" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p class="mb-2 text-sm font-medium">Hochgeladene Wochen</p>
|
||||
<ul v-if="manage.uploaded.length" class="grid grid-cols-[repeat(auto-fill,minmax(7rem,1fr))] gap-3">
|
||||
<li v-for="plan in manage.uploaded" :key="plan.id" class="group relative">
|
||||
<a :href="plan.image_url" target="_blank" class="block overflow-hidden rounded-md border bg-white" :class="{ 'opacity-60': plan.past }">
|
||||
<img :src="plan.image_url" :alt="plan.label" class="aspect-[210/297] w-full object-cover object-top" loading="lazy" />
|
||||
</a>
|
||||
<p class="mt-1 text-xs font-medium">KW {{ plan.week }}</p>
|
||||
<p class="text-[11px] text-muted-foreground">{{ plan.past ? 'vergangen' : plan.label.split('· ')[1] }}</p>
|
||||
<button type="button" class="absolute top-1 right-1 grid size-7 place-items-center rounded-md bg-card/90 text-destructive opacity-0 shadow-xs ring-1 ring-border group-hover:opacity-100 focus-visible:opacity-100" :aria-label="`KW ${plan.week} entfernen`" @click="remove(plan)"><Trash2 class="size-3.5" /></button>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="text-sm text-muted-foreground">Noch keine Pläne hochgeladen.</p>
|
||||
<p class="mt-3 text-xs text-muted-foreground">Vergangene Wochen werden nach {{ manage.keepWeeks }} Wochen automatisch gelöscht.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
61
plugins-core/speiseplan/resources/js/pages/Index.vue
Normal file
61
plugins-core/speiseplan/resources/js/pages/Index.vue
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<script setup>
|
||||
import { watch } from 'vue';
|
||||
import { usePage } from '@inertiajs/vue3';
|
||||
import { FileText, Printer, UtensilsCrossed } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import PageHeader from '@/components/PageHeader.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import ManagePanel from '../components/ManagePanel.vue';
|
||||
|
||||
const props = defineProps({
|
||||
weeks: { type: Array, required: true },
|
||||
allergens: { type: Object, default: null },
|
||||
canManage: { type: Boolean, default: false },
|
||||
manage: { type: Object, default: null },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
|
||||
|
||||
const printUrl = (ids) => `/speiseplan/druck${ids.length ? `?wochen=${ids.join(',')}` : ''}`;
|
||||
const available = () => props.weeks.filter((w) => w.plan).map((w) => w.plan.id);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout title="Speiseplan">
|
||||
<PageHeader title="Speiseplan" description="Unsere Kantine – diese und nächste Woche.">
|
||||
<template #actions>
|
||||
<Button v-if="allergens" variant="outline" as-child><a :href="allergens.url" target="_blank" rel="noopener"><FileText /> Allergie-Informationen</a></Button>
|
||||
<Button v-if="available().length" as-child><a :href="printUrl(available())" target="_blank" rel="noopener"><Printer /> Drucken</a></Button>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<div class="grid gap-6 lg:grid-cols-2">
|
||||
<section v-for="week in weeks" :key="week.week_start" class="overflow-hidden rounded-lg border bg-card">
|
||||
<header class="flex items-center justify-between gap-3 border-b px-4 py-2.5">
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold">{{ week.title }}</h2>
|
||||
<p class="text-xs text-muted-foreground">{{ week.label }}</p>
|
||||
</div>
|
||||
<Button v-if="week.plan" size="sm" variant="ghost" as-child><a :href="printUrl([week.plan.id])" target="_blank" rel="noopener"><Printer /> Nur diese Woche</a></Button>
|
||||
</header>
|
||||
<a v-if="week.plan" :href="week.plan.image_url" target="_blank" rel="noopener" class="block bg-muted/40 p-3" title="In voller Größe öffnen">
|
||||
<img :src="week.plan.image_url" :alt="`Speiseplan ${week.label}`" class="mx-auto w-full max-w-2xl rounded shadow-sm" />
|
||||
</a>
|
||||
<div v-else class="grid aspect-[210/297] max-h-[36rem] w-full place-items-center bg-muted/30 text-center">
|
||||
<div>
|
||||
<UtensilsCrossed class="mx-auto size-8 text-muted-foreground" :stroke-width="1.5" />
|
||||
<p class="mt-2 text-sm text-muted-foreground">Für diese Woche liegt noch kein Speiseplan vor.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<p v-if="allergens" class="mt-6 text-sm">
|
||||
<a :href="allergens.url" target="_blank" rel="noopener" class="inline-flex items-center gap-1.5 font-medium text-brand-text hover:underline"><FileText class="size-4" /> Allergie-Informationen (PDF)</a>
|
||||
</p>
|
||||
|
||||
<ManagePanel v-if="canManage && manage" :manage="manage" :allergens="allergens" />
|
||||
</AppLayout>
|
||||
</template>
|
||||
118
plugins-core/speiseplan/resources/js/pages/Print.vue
Normal file
118
plugins-core/speiseplan/resources/js/pages/Print.vue
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<script setup>
|
||||
import { onMounted } from 'vue';
|
||||
import { Head } from '@inertiajs/vue3';
|
||||
|
||||
/**
|
||||
* Druckansicht ohne Portal-Rahmen: jeder Plan füllt eine A4-Seite randlos.
|
||||
*/
|
||||
const props = defineProps({
|
||||
plans: { type: Array, required: true },
|
||||
});
|
||||
|
||||
function print() {
|
||||
window.print();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// Erst drucken, wenn alle Bilder geladen sind.
|
||||
await Promise.all([...document.querySelectorAll('.sp-page img')].map((img) => (img.complete ? null : new Promise((r) => (img.onload = img.onerror = r)))));
|
||||
if (props.plans.length) setTimeout(print, 150);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Head title="Speiseplan drucken" />
|
||||
<div class="sp-toolbar">
|
||||
<strong>Speiseplan drucken</strong>
|
||||
<span>{{ plans.length }} {{ plans.length === 1 ? 'Seite' : 'Seiten' }} · A4, randlos. Falls Adresse oder Datum mitgedruckt werden: im Druckdialog „Kopf- und Fußzeilen“ abschalten.</span>
|
||||
<button type="button" @click="print">Drucken</button>
|
||||
</div>
|
||||
<p v-if="!plans.length" class="sp-empty">Kein Speiseplan zum Drucken vorhanden.</p>
|
||||
<div v-for="plan in plans" :key="plan.id" class="sp-page">
|
||||
<img :src="plan.image_url" :alt="`Speiseplan ${plan.label}`" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
@page {
|
||||
size: A4 portrait;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.sp-toolbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
font: 14px/1.4 system-ui, sans-serif;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.sp-toolbar span {
|
||||
flex: 1;
|
||||
color: #6b7280;
|
||||
min-width: 240px;
|
||||
}
|
||||
|
||||
.sp-toolbar button {
|
||||
padding: 6px 14px;
|
||||
border-radius: 6px;
|
||||
background: #111827;
|
||||
color: #fff;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.sp-empty {
|
||||
padding: 24px;
|
||||
font: 14px system-ui, sans-serif;
|
||||
}
|
||||
|
||||
.sp-page {
|
||||
width: 210mm;
|
||||
height: 297mm;
|
||||
margin: 16px auto;
|
||||
box-shadow: 0 1px 6px rgb(0 0 0 / 0.15);
|
||||
background: #fff;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.sp-page img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: fill;
|
||||
}
|
||||
|
||||
@media print {
|
||||
html,
|
||||
body {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
background: #fff !important;
|
||||
}
|
||||
|
||||
.sp-toolbar,
|
||||
.sp-empty {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.sp-page {
|
||||
margin: 0;
|
||||
box-shadow: none;
|
||||
break-after: page;
|
||||
page-break-after: always;
|
||||
}
|
||||
|
||||
.sp-page:last-child {
|
||||
break-after: auto;
|
||||
page-break-after: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
28
plugins-core/speiseplan/resources/js/pdfToImage.js
Normal file
28
plugins-core/speiseplan/resources/js/pdfToImage.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* Erste Seite eines PDFs als JPEG in A4-Druckqualität (ca. 200 dpi) – im Browser,
|
||||
* damit der Server nichts umwandeln muss.
|
||||
*/
|
||||
export async function pdfToImage(file, targetWidth = 1654) {
|
||||
const [pdfjs, worker] = await Promise.all([import('pdfjs-dist'), import('pdfjs-dist/build/pdf.worker.min.mjs?url')]);
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = worker.default;
|
||||
|
||||
const pdf = await pdfjs.getDocument({ data: await file.arrayBuffer(), isEvalSupported: false, enableXfa: false }).promise;
|
||||
|
||||
try {
|
||||
const page = await pdf.getPage(1);
|
||||
const viewport = page.getViewport({ scale: targetWidth / page.getViewport({ scale: 1 }).width });
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = Math.round(viewport.width);
|
||||
canvas.height = Math.round(viewport.height);
|
||||
const context = canvas.getContext('2d');
|
||||
context.fillStyle = '#ffffff';
|
||||
context.fillRect(0, 0, canvas.width, canvas.height);
|
||||
await page.render({ canvasContext: context, viewport }).promise;
|
||||
|
||||
const blob = await new Promise((resolve) => canvas.toBlob(resolve, 'image/jpeg', 0.9));
|
||||
|
||||
return new File([blob], file.name.replace(/\.pdf$/i, '') + '.jpg', { type: 'image/jpeg' });
|
||||
} finally {
|
||||
pdf.destroy();
|
||||
}
|
||||
}
|
||||
19
plugins-core/speiseplan/routes/web.php
Normal file
19
plugins-core/speiseplan/routes/web.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Speiseplan\Http\Controllers\SpeiseplanController;
|
||||
|
||||
Route::middleware('auth')->prefix('speiseplan')->name('speiseplan.')->controller(SpeiseplanController::class)
|
||||
->where(['week' => '[0-9]+'])
|
||||
->group(function () {
|
||||
Route::get('/', 'index')->name('index');
|
||||
Route::get('/druck', 'print')->name('print');
|
||||
Route::get('/bild/{week}', 'image')->name('image');
|
||||
Route::get('/allergene', 'allergensFile')->name('allergens.show');
|
||||
|
||||
// Pflege (Recht „speiseplan.manage“)
|
||||
Route::post('/wochen', 'store')->name('store');
|
||||
Route::delete('/wochen/{week}', 'destroy')->name('destroy');
|
||||
Route::post('/allergene', 'storeAllergens')->name('allergens.store');
|
||||
Route::delete('/allergene', 'destroyAllergens')->name('allergens.destroy');
|
||||
});
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Speiseplan\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Speiseplan\Models\Week;
|
||||
use Inhaus\Plugins\Speiseplan\SpeiseplanPlugin;
|
||||
use Symfony\Component\HttpFoundation\Response as HttpResponse;
|
||||
|
||||
class SpeiseplanController extends Controller
|
||||
{
|
||||
private const ALLERGENS = 'speiseplan.allergens';
|
||||
|
||||
public function __construct(private readonly Settings $settings) {}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$monday = Week::mondayOf(now());
|
||||
$weeks = Week::query()->whereIn('week_start', [$monday->toDateString(), $monday->copy()->addWeek()->toDateString()])->get()->keyBy(fn (Week $w) => $w->week_start->toDateString());
|
||||
$canManage = (bool) $request->user()->can('speiseplan.manage');
|
||||
|
||||
$slot = fn ($start, string $title) => [
|
||||
'title' => $title,
|
||||
'label' => 'KW '.$start->isoWeek().' · '.$start->format('d.m.').' – '.$start->copy()->addDays(4)->format('d.m.Y'),
|
||||
'week_start' => $start->toDateString(),
|
||||
'plan' => ($w = $weeks->get($start->toDateString())) ? $w->present() : null,
|
||||
];
|
||||
|
||||
return Inertia::render('speiseplan::Index', [
|
||||
'weeks' => [$slot($monday, 'Diese Woche'), $slot($monday->copy()->addWeek(), 'Nächste Woche')],
|
||||
'allergens' => $this->allergens(),
|
||||
'canManage' => $canManage,
|
||||
'manage' => $canManage ? $this->manageData($monday) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Druckansicht: jeder Plan eine A4-Seite, randlos.
|
||||
*/
|
||||
public function print(Request $request): Response
|
||||
{
|
||||
$ids = array_filter(array_map('intval', explode(',', (string) $request->query('wochen', ''))));
|
||||
$monday = Week::mondayOf(now());
|
||||
$query = Week::query()->orderBy('week_start');
|
||||
$ids ? $query->whereIn('id', $ids) : $query->whereIn('week_start', [$monday->toDateString(), $monday->copy()->addWeek()->toDateString()]);
|
||||
|
||||
return Inertia::render('speiseplan::Print', ['plans' => $query->get()->map(fn (Week $w) => $w->present())->values()]);
|
||||
}
|
||||
|
||||
public function image(Week $week): HttpResponse
|
||||
{
|
||||
return Storage::disk(Week::DISK)->response($week->path, 'speiseplan-kw'.$week->week_start->isoWeek().'.'.pathinfo($week->path, PATHINFO_EXTENSION), [
|
||||
'Cache-Control' => 'private, max-age=86400',
|
||||
'X-Content-Type-Options' => 'nosniff',
|
||||
]);
|
||||
}
|
||||
|
||||
private function allergens(): ?array
|
||||
{
|
||||
$file = $this->settings->get(self::ALLERGENS);
|
||||
|
||||
return is_array($file) && ! empty($file['path']) ? ['name' => $file['name'], 'url' => route('speiseplan.allergens.show')] : null;
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$data = $request->validate([
|
||||
'week' => ['required', 'date'],
|
||||
'image' => ['required', 'file', 'max:20480', 'mimes:jpg,jpeg,png,webp'],
|
||||
], ['image.mimes' => 'Bitte ein Bild (JPG, PNG, WebP) oder ein PDF hochladen.'], ['week' => 'Woche', 'image' => 'Speiseplan']);
|
||||
|
||||
$monday = Week::mondayOf($data['week']);
|
||||
$file = $request->file('image');
|
||||
[$width, $height] = @getimagesize($file->getRealPath()) ?: [null, null];
|
||||
$path = $file->storeAs('speiseplan', $monday->toDateString().'-'.Str::random(12).'.'.strtolower($file->extension() ?: 'jpg'), Week::DISK);
|
||||
|
||||
$existing = Week::query()->where('week_start', $monday->toDateString())->first();
|
||||
$old = $existing?->path;
|
||||
Week::query()->updateOrCreate(['week_start' => $monday->toDateString()], [
|
||||
'path' => $path, 'original_name' => $file->getClientOriginalName(), 'width' => $width, 'height' => $height, 'uploaded_by' => $request->user()->id,
|
||||
]);
|
||||
|
||||
if ($old) {
|
||||
Storage::disk(Week::DISK)->delete($old);
|
||||
}
|
||||
|
||||
Audit::log('speiseplan.uploaded', ['week' => $monday->toDateString()]);
|
||||
|
||||
return back()->with('status', 'Speiseplan für KW '.$monday->isoWeek().($existing ? ' ersetzt.' : ' gespeichert.'));
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Week $week): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$week->delete();
|
||||
|
||||
return back()->with('status', 'Speiseplan für KW '.$week->week_start->isoWeek().' entfernt.');
|
||||
}
|
||||
|
||||
public function storeAllergens(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$request->validate(['file' => ['required', 'file', 'max:20480', 'mimes:pdf']], [], ['file' => 'Allergie-Informationen']);
|
||||
|
||||
$old = $this->settings->get(self::ALLERGENS);
|
||||
$path = $request->file('file')->storeAs('speiseplan', 'allergene-'.Str::random(12).'.pdf', Week::DISK);
|
||||
$this->settings->set(self::ALLERGENS, ['path' => $path, 'name' => $request->file('file')->getClientOriginalName()]);
|
||||
|
||||
if (is_array($old) && ! empty($old['path'])) {
|
||||
Storage::disk(Week::DISK)->delete($old['path']);
|
||||
}
|
||||
|
||||
return back()->with('status', 'Allergie-Informationen gespeichert.');
|
||||
}
|
||||
|
||||
public function destroyAllergens(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$old = $this->settings->get(self::ALLERGENS);
|
||||
|
||||
if (is_array($old) && ! empty($old['path'])) {
|
||||
Storage::disk(Week::DISK)->delete($old['path']);
|
||||
}
|
||||
|
||||
$this->settings->set(self::ALLERGENS, null);
|
||||
|
||||
return back()->with('status', 'Allergie-Informationen entfernt.');
|
||||
}
|
||||
|
||||
public function allergensFile(): HttpResponse
|
||||
{
|
||||
$file = $this->settings->get(self::ALLERGENS);
|
||||
abort_unless(is_array($file) && ! empty($file['path']) && Storage::disk(Week::DISK)->exists($file['path']), 404);
|
||||
|
||||
return Storage::disk(Week::DISK)->response($file['path'], $file['name'] ?? 'allergene.pdf', ['Content-Type' => 'application/pdf', 'X-Content-Type-Options' => 'nosniff']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function manageData($monday): array
|
||||
{
|
||||
$uploaded = Week::query()->where('week_start', '>=', $monday->copy()->subWeeks(SpeiseplanPlugin::KEEP_WEEKS)->toDateString())->orderBy('week_start')->get()->keyBy(fn (Week $w) => $w->week_start->toDateString());
|
||||
$options = [];
|
||||
|
||||
for ($i = 0; $i < 12; $i++) {
|
||||
$start = $monday->copy()->addWeeks($i);
|
||||
$options[] = [
|
||||
'value' => $start->toDateString(),
|
||||
'label' => 'KW '.$start->isoWeek().' · '.$start->format('d.m.').' – '.$start->copy()->addDays(4)->format('d.m.Y').($uploaded->has($start->toDateString()) ? ' (vorhanden)' : ''),
|
||||
'uploaded' => $uploaded->has($start->toDateString()),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'options' => $options,
|
||||
'suggested' => collect($options)->firstWhere('uploaded', false)['value'] ?? $options[0]['value'],
|
||||
'uploaded' => $uploaded->values()->map(fn (Week $w) => $w->present() + ['past' => $w->week_start->lt($monday)])->all(),
|
||||
'keepWeeks' => SpeiseplanPlugin::KEEP_WEEKS,
|
||||
];
|
||||
}
|
||||
|
||||
private function authorizeManage(Request $request): void
|
||||
{
|
||||
abort_unless($request->user()->can('speiseplan.manage'), 403);
|
||||
}
|
||||
}
|
||||
52
plugins-core/speiseplan/src/Models/Week.php
Normal file
52
plugins-core/speiseplan/src/Models/Week.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Speiseplan\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Speiseplan einer Kalenderwoche (ein Bild, A4 hoch).
|
||||
*/
|
||||
#[Fillable(['week_start', 'path', 'original_name', 'width', 'height', 'uploaded_by'])]
|
||||
class Week extends Model
|
||||
{
|
||||
public const DISK = 'local';
|
||||
|
||||
protected $table = 'speiseplan_weeks';
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleted(fn (Week $week) => Storage::disk(self::DISK)->delete($week->path));
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['week_start' => 'date'];
|
||||
}
|
||||
|
||||
public static function mondayOf(Carbon|string $date): Carbon
|
||||
{
|
||||
return Carbon::parse($date)->startOfWeek(Carbon::MONDAY)->startOfDay();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function present(): array
|
||||
{
|
||||
$end = $this->week_start->copy()->addDays(4);
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'week_start' => $this->week_start->toDateString(),
|
||||
'week' => (int) $this->week_start->isoWeek(),
|
||||
'label' => 'KW '.$this->week_start->isoWeek().' · '.$this->week_start->format('d.m.').' – '.$end->format('d.m.Y'),
|
||||
'image_url' => route('speiseplan.image', ['week' => $this->id, 'v' => $this->updated_at?->timestamp]),
|
||||
'width' => $this->width,
|
||||
'height' => $this->height,
|
||||
];
|
||||
}
|
||||
}
|
||||
35
plugins-core/speiseplan/src/SpeiseplanPlugin.php
Normal file
35
plugins-core/speiseplan/src/SpeiseplanPlugin.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Speiseplan;
|
||||
|
||||
use App\Plugins\Plugin;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
use Inhaus\Plugins\Speiseplan\Models\Week;
|
||||
|
||||
class SpeiseplanPlugin extends Plugin
|
||||
{
|
||||
/** Vergangene Wochen bleiben so lange erhalten, dann werden sie gelöscht. */
|
||||
public const KEEP_WEEKS = 2;
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('speiseplan', 'Speiseplan', '/speiseplan', active: 'speiseplan.*', sort: 70);
|
||||
$this->app->make(Abilities::class)->define('speiseplan.manage', 'Speiseplan hochladen', 'Speiseplan');
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
Schedule::call(fn () => self::purge())->dailyAt('03:30')->name('speiseplan-purge')->withoutOverlapping(10);
|
||||
}
|
||||
|
||||
public static function purge(): int
|
||||
{
|
||||
$cutoff = Week::mondayOf(now())->subWeeks(self::KEEP_WEEKS);
|
||||
$old = Week::query()->where('week_start', '<', $cutoff->toDateString())->get();
|
||||
$old->each->delete();
|
||||
|
||||
return $old->count();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue