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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue