Termine im Portal bearbeiten (0.23.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m53s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m42s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m13s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m10s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m46s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m35s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m53s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m53s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m42s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m13s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m10s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m46s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m35s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m53s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
80a0f20447
commit
d7d09d6b9a
142 changed files with 917 additions and 315 deletions
|
|
@ -0,0 +1,45 @@
|
|||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { Plus } from '@lucide/vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import EventDateBlock from '../components/EventDateBlock.vue';
|
||||
|
||||
/**
|
||||
* „Redaktion → Termine“: kommende und kürzlich vergangene Termine.
|
||||
*/
|
||||
const props = defineProps({
|
||||
events: { type: Array, required: true },
|
||||
});
|
||||
|
||||
const showPast = ref(false);
|
||||
const list = computed(() => props.events.filter((event) => showPast.value || !event.is_past));
|
||||
const pastCount = computed(() => props.events.filter((event) => event.is_past).length);
|
||||
const time = new Intl.DateTimeFormat('de-DE', { weekday: 'short', day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' });
|
||||
const day = new Intl.DateTimeFormat('de-DE', { weekday: 'short', day: '2-digit', month: '2-digit', year: 'numeric' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Panel title="Termine">
|
||||
<template #actions>
|
||||
<Button size="sm" variant="outline" as-child><Link href="/redaktion/termine/neu"><Plus /> Neuer Termin</Link></Button>
|
||||
</template>
|
||||
<ul v-if="list.length" class="-mx-5 divide-y border-t">
|
||||
<li v-for="event in list" :key="event.id" class="flex items-center gap-3 px-5 py-2.5" :class="{ 'opacity-60': event.is_past }">
|
||||
<EventDateBlock :date="event.starts_at" class="w-11 shrink-0 py-1 text-xs" />
|
||||
<div class="min-w-0 flex-1">
|
||||
<Link :href="event.edit_url" class="block truncate text-sm font-medium hover:underline">{{ event.title }}</Link>
|
||||
<p class="truncate text-xs text-muted-foreground">
|
||||
{{ event.all_day ? `${day.format(new Date(event.starts_at))} · ganztägig` : `${time.format(new Date(event.starts_at))} Uhr` }}<template v-if="event.location"> · {{ event.location }}</template>
|
||||
</p>
|
||||
</div>
|
||||
<span v-if="!event.is_published" class="shrink-0 rounded bg-muted px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground">Entwurf</span>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="text-sm text-muted-foreground">Keine anstehenden Termine.</p>
|
||||
<button v-if="pastCount" type="button" class="mt-3 text-[13px] text-muted-foreground hover:text-foreground hover:underline" @click="showPast = !showPast">
|
||||
{{ showPast ? 'Vergangene ausblenden' : `Vergangene der letzten 30 Tage zeigen (${pastCount})` }}
|
||||
</button>
|
||||
</Panel>
|
||||
</template>
|
||||
161
plugins-core/events/resources/js/pages/Editor.vue
Normal file
161
plugins-core/events/resources/js/pages/Editor.vue
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
<script setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { Link, router, useForm } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, ImagePlus, LoaderCircle, Save, Trash2, Users, X } from '@lucide/vue';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import AudienceEditor from '@/components/AudienceEditor.vue';
|
||||
import FormField from '@/components/FormField.vue';
|
||||
import PageHeader from '@/components/PageHeader.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
import RichTextEditor from '@/components/RichTextEditor.vue';
|
||||
import MediaPickerHost from '@/components/media/MediaPickerHost.vue';
|
||||
import { uploadWithProgress } from '@/components/media/api';
|
||||
import { useMediaPicker } from '@/components/media/useMediaPicker';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
|
||||
/**
|
||||
* Termin anlegen oder bearbeiten (Redaktion im Portal).
|
||||
*/
|
||||
const props = defineProps({
|
||||
event: { type: Object, default: null },
|
||||
audienceOptions: { type: Object, required: true },
|
||||
});
|
||||
|
||||
const nextHour = () => {
|
||||
const date = new Date();
|
||||
date.setHours(date.getHours() + 1, 0, 0, 0);
|
||||
|
||||
return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().slice(0, 16);
|
||||
};
|
||||
|
||||
const e = props.event;
|
||||
const form = useForm({
|
||||
title: e?.title ?? '',
|
||||
all_day: e?.all_day ?? false,
|
||||
starts_at: e?.starts_at ?? nextHour(),
|
||||
ends_at: e?.ends_at ?? '',
|
||||
location: e?.location ?? '',
|
||||
online_url: e?.online_url ?? '',
|
||||
description: e?.description ?? '',
|
||||
image_path: e?.image_path ?? null,
|
||||
is_published: e?.is_published ?? true,
|
||||
audience: e?.audience ?? {},
|
||||
});
|
||||
|
||||
const previewUrl = ref(e?.image_url ?? null);
|
||||
|
||||
// Ganztägig: nur Datum bearbeiten
|
||||
const dateType = computed(() => (form.all_day ? 'date' : 'datetime-local'));
|
||||
watch(() => form.all_day, (allDay) => {
|
||||
form.starts_at = allDay ? form.starts_at.slice(0, 10) : `${form.starts_at.slice(0, 10)}T09:00`;
|
||||
form.ends_at = form.ends_at ? (allDay ? form.ends_at.slice(0, 10) : `${form.ends_at.slice(0, 10)}T17:00`) : '';
|
||||
});
|
||||
|
||||
const upload = (file, onProgress) => uploadWithProgress('/redaktion/termine/bilder', file, { onProgress });
|
||||
const picker = useMediaPicker({ upload, contextLabel: 'Bei diesem Termin', contextPaths: () => [form.image_path].filter(Boolean) });
|
||||
|
||||
async function chooseImage() {
|
||||
const items = await picker.pick({ title: 'Titelbild wählen' });
|
||||
|
||||
if (items?.[0]) {
|
||||
form.image_path = items[0].path;
|
||||
previewUrl.value = items[0].url;
|
||||
}
|
||||
}
|
||||
|
||||
const restricted = computed(() => Object.values(form.audience ?? {}).some((values) => values?.length));
|
||||
|
||||
function submit() {
|
||||
const options = { preserveScroll: true };
|
||||
e ? form.put(`/redaktion/termine/${e.id}`, options) : form.post('/redaktion/termine', options);
|
||||
}
|
||||
|
||||
function remove() {
|
||||
if (window.confirm(`Termin „${e.title}“ löschen?`)) {
|
||||
router.delete(`/redaktion/termine/${e.id}`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :title="e ? `Bearbeiten: ${e.title}` : 'Neuer Termin'">
|
||||
<PageHeader :title="e ? 'Termin bearbeiten' : 'Neuer Termin'" :breadcrumbs="[{ label: 'Termine', href: '/termine' }]">
|
||||
<template #actions>
|
||||
<Button v-if="e" variant="ghost" class="text-destructive hover:text-destructive" @click="remove"><Trash2 /> Löschen</Button>
|
||||
<Button :disabled="form.processing" @click="submit"><LoaderCircle v-if="form.processing" class="animate-spin" /><Save v-else /> Speichern</Button>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<form class="grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_20rem]" @submit.prevent="submit">
|
||||
<div class="grid min-w-0 gap-6">
|
||||
<Panel>
|
||||
<div class="grid gap-5">
|
||||
<FormField id="ev-title" label="Titel" :error="form.errors.title">
|
||||
<Input id="ev-title" v-model="form.title" maxlength="160" placeholder="z. B. Sommerfest 2026" class="text-base" />
|
||||
</FormField>
|
||||
|
||||
<label class="flex items-center gap-3 text-sm font-medium">
|
||||
<Switch v-model="form.all_day" /> Ganztägig
|
||||
</label>
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
<FormField id="ev-start" label="Beginn" :error="form.errors.starts_at">
|
||||
<Input id="ev-start" v-model="form.starts_at" :type="dateType" />
|
||||
</FormField>
|
||||
<FormField id="ev-end" label="Ende (optional)" :error="form.errors.ends_at">
|
||||
<Input id="ev-end" v-model="form.ends_at" :type="dateType" :min="form.starts_at" />
|
||||
</FormField>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
<FormField id="ev-location" label="Ort" :error="form.errors.location">
|
||||
<Input id="ev-location" v-model="form.location" maxlength="255" placeholder="z. B. Kantine, Haus A" />
|
||||
</FormField>
|
||||
<FormField id="ev-online" label="Online-Link" :error="form.errors.online_url">
|
||||
<Input id="ev-online" v-model="form.online_url" type="url" maxlength="500" placeholder="https://…" />
|
||||
</FormField>
|
||||
</div>
|
||||
|
||||
<FormField id="ev-description" label="Beschreibung" :error="form.errors.description">
|
||||
<RichTextEditor v-model="form.description" bordered min-height="12rem" placeholder="Worum geht es? Programm, Anmeldung, Mitbringen …" />
|
||||
</FormField>
|
||||
</div>
|
||||
</Panel>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-6">
|
||||
<Panel title="Veröffentlichung">
|
||||
<label class="flex items-center justify-between gap-3 text-sm">
|
||||
<span>
|
||||
<span class="font-medium">Veröffentlicht</span>
|
||||
<span class="block text-xs text-muted-foreground">Sonst nur für die Redaktion sichtbar.</span>
|
||||
</span>
|
||||
<Switch v-model="form.is_published" />
|
||||
</label>
|
||||
<Link v-if="e?.url && e.is_published" :href="e.url" class="mt-3 inline-flex items-center gap-1 text-[13px] text-brand-text hover:underline"><ArrowLeft class="size-3.5" /> Zum Termin</Link>
|
||||
</Panel>
|
||||
|
||||
<Panel title="Titelbild">
|
||||
<div v-if="form.image_path" class="relative overflow-hidden rounded-md border">
|
||||
<img :src="previewUrl" alt="" class="aspect-video w-full object-cover" />
|
||||
<button type="button" class="absolute top-2 right-2 grid size-7 place-items-center rounded-full bg-black/60 text-white hover:bg-black/80" aria-label="Bild entfernen" @click="form.image_path = null"><X class="size-4" /></button>
|
||||
</div>
|
||||
<Button type="button" variant="outline" class="w-full" :class="{ 'mt-3': form.image_path }" @click="chooseImage"><ImagePlus /> {{ form.image_path ? 'Anderes Bild' : 'Bild wählen oder hochladen' }}</Button>
|
||||
<p v-if="form.errors.image_path" class="mt-2 text-[13px] text-destructive">{{ form.errors.image_path }}</p>
|
||||
</Panel>
|
||||
|
||||
<Panel title="Wer sieht den Termin?">
|
||||
<p class="-mt-1 mb-3 flex items-start gap-2 text-[13px] text-muted-foreground">
|
||||
<Users class="mt-0.5 size-4 shrink-0" />
|
||||
{{ restricted ? 'Nur Personen, die mindestens eine Angabe erfüllen.' : 'Alle – oder unten eingrenzen.' }}
|
||||
</p>
|
||||
<AudienceEditor v-model="form.audience" :options="audienceOptions" exclude-hint="Sehen den Termin nie – auch wenn oben etwas passt." />
|
||||
</Panel>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<MediaPickerHost :picker="picker" />
|
||||
</AppLayout>
|
||||
</template>
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { CalendarDays, MapPin, Video } from '@lucide/vue';
|
||||
import { computed, watch } from 'vue';
|
||||
import { Link, usePage } from '@inertiajs/vue3';
|
||||
import { CalendarDays, MapPin, Plus, Video } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import EmptyState from '@/components/EmptyState.vue';
|
||||
import EventDateBlock from '../components/EventDateBlock.vue';
|
||||
import DashboardSidebar from '@/components/DashboardSidebar.vue';
|
||||
|
|
@ -12,8 +14,12 @@ import { formatEventRange, formatMonthYear } from '@/lib/format';
|
|||
const props = defineProps({
|
||||
events: { type: Object, required: true },
|
||||
sidebar: { type: Array, default: () => [] },
|
||||
canManage: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
|
||||
|
||||
// Nach Monaten gruppieren – laufende Termine erscheinen im aktuellen Monat.
|
||||
const groups = computed(() => {
|
||||
const result = [];
|
||||
|
|
@ -37,7 +43,11 @@ const groups = computed(() => {
|
|||
|
||||
<template>
|
||||
<AppLayout title="Termine">
|
||||
<PageHeader title="Termine" description="Veranstaltungen, Fortbildungen und Treffen." />
|
||||
<PageHeader title="Termine" description="Veranstaltungen, Fortbildungen und Treffen.">
|
||||
<template v-if="canManage" #actions>
|
||||
<Button as-child><Link href="/redaktion/termine/neu"><Plus /> Neuer Termin</Link></Button>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<div class="grid gap-6 lg:grid-cols-12">
|
||||
<div class="min-w-0" :class="sidebar.length ? 'lg:col-span-8 xl:col-span-9' : 'lg:col-span-12'">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<script setup>
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, CalendarPlus, Clock, MapPin, Video } from '@lucide/vue';
|
||||
import { watch } from 'vue';
|
||||
import { Link, usePage } from '@inertiajs/vue3';
|
||||
import { ArrowLeft, CalendarPlus, Clock, MapPin, PencilLine, Video } from '@lucide/vue';
|
||||
import { toast } from 'vue-sonner';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import EventDateBlock from '../components/EventDateBlock.vue';
|
||||
import Panel from '@/components/Panel.vue';
|
||||
|
|
@ -9,15 +11,22 @@ import { formatEventRange } from '@/lib/format';
|
|||
|
||||
defineProps({
|
||||
event: { type: Object, required: true },
|
||||
editUrl: { type: String, default: null },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
watch(() => page.props.flash.status, (status) => status && toast.success(status), { immediate: true });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :title="event.title">
|
||||
<div class="mx-auto max-w-4xl">
|
||||
<Link href="/termine" class="mb-6 inline-flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground">
|
||||
<ArrowLeft class="size-4" /> Alle Termine
|
||||
</Link>
|
||||
<div class="mb-6 flex items-center justify-between gap-3">
|
||||
<Link href="/termine" class="inline-flex items-center gap-1.5 text-sm font-medium text-muted-foreground hover:text-foreground">
|
||||
<ArrowLeft class="size-4" /> Alle Termine
|
||||
</Link>
|
||||
<Button v-if="editUrl" variant="outline" size="sm" as-child><Link :href="editUrl"><PencilLine /> Bearbeiten</Link></Button>
|
||||
</div>
|
||||
|
||||
<div class="flex items-start gap-4">
|
||||
<EventDateBlock :date="event.starts_at" class="w-16 py-2" />
|
||||
|
|
|
|||
|
|
@ -2,9 +2,20 @@
|
|||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inhaus\Plugins\Events\Http\Controllers\EventController;
|
||||
use Inhaus\Plugins\Events\Http\Controllers\EventEditorController;
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/termine', [EventController::class, 'index'])->name('events.index');
|
||||
|
||||
// Pflege im Portal (Recht „events.manage“)
|
||||
Route::prefix('redaktion/termine')->name('events.')->controller(EventEditorController::class)->group(function () {
|
||||
Route::get('/neu', 'create')->name('create');
|
||||
Route::post('/', 'store')->name('store');
|
||||
Route::post('/bilder', 'uploadImage')->name('images');
|
||||
Route::get('/{event}', 'edit')->name('edit');
|
||||
Route::put('/{event}', 'update')->name('update');
|
||||
Route::delete('/{event}', 'destroy')->name('destroy');
|
||||
});
|
||||
Route::get('/termine/{event}', [EventController::class, 'show'])->name('events.show');
|
||||
Route::get('/termine/{event}/kalender.ics', [EventController::class, 'ics'])->name('events.ics');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Inhaus\Plugins\Events;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Editorial\Editorial;
|
||||
use App\Media\ImagePaths;
|
||||
use App\Media\MediaUsages;
|
||||
use App\Models\User;
|
||||
|
|
@ -36,6 +37,24 @@ class EventsPlugin extends Plugin
|
|||
], fn (callable $each) => Event::query()->chunkById(100, fn ($events) => $events->each($each)));
|
||||
$usages->watch('events', Event::class, ['image_path', 'description_html', 'title', 'is_published']);
|
||||
|
||||
// Redaktion im Portal
|
||||
$this->app->make(Editorial::class)->add('events', 'Termine', 'events::EditorialEvents', 30,
|
||||
fn (User $user) => $user->can('events.manage'),
|
||||
fn (User $user) => [
|
||||
'events' => Event::query()->where(fn ($q) => $q->where('starts_at', '>=', now()->subDays(30))->orWhere('ends_at', '>=', now()))
|
||||
->orderBy('starts_at')->limit(100)->get()
|
||||
->map(fn (Event $event) => [
|
||||
'id' => $event->id,
|
||||
'title' => $event->title,
|
||||
'starts_at' => $event->starts_at->toIso8601String(),
|
||||
'all_day' => $event->all_day,
|
||||
'location' => $event->location,
|
||||
'is_published' => $event->is_published,
|
||||
'is_past' => ($event->ends_at ?? $event->starts_at->copy()->endOfDay())->isPast(),
|
||||
'edit_url' => route('events.edit', $event),
|
||||
])->all(),
|
||||
]);
|
||||
|
||||
$this->app->make(Widgets::class)->add('events.upcoming', 'events::Upcoming', 'aside', sort: 20, props: fn (User $user) => [
|
||||
'events' => EventResource::collection(Event::query()->upcoming()->visibleTo($user)->limit(4)->get())->resolve(),
|
||||
], label: 'Termine', mobileSort: 30);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class EventController extends Controller
|
|||
),
|
||||
// Seitenleiste der Startseite (ohne die Termin-Kachel selbst)
|
||||
'sidebar' => $widgets->sidebar($request->user(), $request, except: ['events.upcoming']),
|
||||
'canManage' => $request->user()->can('events.manage'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -35,6 +36,7 @@ class EventController extends Controller
|
|||
...(new EventResource($event))->resolve(),
|
||||
'description_html' => $event->description_html,
|
||||
],
|
||||
'editUrl' => request()->user()->can('update', $event) ? route('events.edit', $event) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Events\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Media\MediaLibrary;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Images;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Validation\Rules\File;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
|
||||
/**
|
||||
* Termine im Portal pflegen („Redaktion → Termine“) – dasselbe wie im Backend.
|
||||
*/
|
||||
class EventEditorController extends Controller
|
||||
{
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
Gate::authorize('create', Event::class);
|
||||
|
||||
return $this->editor(null);
|
||||
}
|
||||
|
||||
public function edit(Request $request, Event $event): Response
|
||||
{
|
||||
Gate::authorize('update', $event);
|
||||
|
||||
return $this->editor($event);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
Gate::authorize('create', Event::class);
|
||||
[$attributes, $audience] = $this->validated($request);
|
||||
|
||||
$event = Event::query()->create([...$attributes, 'author_id' => $request->user()->id]);
|
||||
Audiences::sync('event', $event->id, $audience);
|
||||
Audit::log('event.created', ['event' => $event->id, 'title' => $event->title]);
|
||||
|
||||
return to_route('events.show', $event)->with('status', 'Termin angelegt.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Event $event): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $event);
|
||||
[$attributes, $audience] = $this->validated($request);
|
||||
|
||||
$event->update($attributes);
|
||||
Audiences::sync('event', $event->id, $audience);
|
||||
Audit::log('event.updated', ['event' => $event->id, 'title' => $event->title]);
|
||||
|
||||
return ($event->is_published ? to_route('events.show', $event) : to_route('editorial'))->with('status', 'Termin gespeichert.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, Event $event): RedirectResponse
|
||||
{
|
||||
Gate::authorize('delete', $event);
|
||||
$event->delete();
|
||||
Audiences::sync('event', $event->id, []);
|
||||
Audit::log('event.deleted', ['event' => $event->id, 'title' => $event->title]);
|
||||
|
||||
return to_route('events.index')->with('status', 'Termin „'.$event->title.'“ gelöscht.');
|
||||
}
|
||||
|
||||
public function uploadImage(Request $request, MediaLibrary $library): JsonResponse
|
||||
{
|
||||
Gate::authorize('create', Event::class);
|
||||
$request->validate(['image' => ['required', File::image()->types(['jpg', 'jpeg', 'png', 'webp'])->max(15 * 1024)]]);
|
||||
|
||||
$media = $library->store($request->file('image'), 'events', $request->user());
|
||||
|
||||
return response()->json(['path' => $media->path, 'url' => app(Images::class)->url($media->path, null), 'media' => $media->toLibraryArray()]);
|
||||
}
|
||||
|
||||
private function editor(?Event $event): Response
|
||||
{
|
||||
return Inertia::render('events::Editor', [
|
||||
'event' => $event ? [
|
||||
'id' => $event->id,
|
||||
'title' => $event->title,
|
||||
'all_day' => $event->all_day,
|
||||
'starts_at' => $event->starts_at?->format('Y-m-d\TH:i'),
|
||||
'ends_at' => $event->ends_at?->format('Y-m-d\TH:i'),
|
||||
'location' => $event->location,
|
||||
'online_url' => $event->online_url,
|
||||
'description' => $event->description_html ?: $event->description,
|
||||
'image_path' => $event->image_path,
|
||||
'image_url' => $event->imageUrl('large'),
|
||||
'is_published' => $event->is_published,
|
||||
'audience' => Audiences::get('event', $event->id),
|
||||
'url' => route('events.show', $event),
|
||||
] : null,
|
||||
'audienceOptions' => Audiences::options(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: array<string, mixed>, 1: array<string, list<string>>}
|
||||
*/
|
||||
private function validated(Request $request): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'title' => ['required', 'string', 'max:160'],
|
||||
'all_day' => ['boolean'],
|
||||
'starts_at' => ['required', 'date'],
|
||||
'ends_at' => ['nullable', 'date', 'after_or_equal:starts_at'],
|
||||
'location' => ['nullable', 'string', 'max:255'],
|
||||
'online_url' => ['nullable', 'url:https,http', 'max:500'],
|
||||
'description' => ['nullable', 'string', 'max:100000'],
|
||||
'image_path' => ['nullable', 'string', 'max:500', 'regex:#^[A-Za-z0-9/_.-]+$#', 'not_regex:#\.\.#'],
|
||||
'is_published' => ['boolean'],
|
||||
'audience' => ['nullable', 'array'],
|
||||
'audience.*' => ['array'],
|
||||
'audience.*.*' => ['string', 'max:150'],
|
||||
], ['ends_at.after_or_equal' => 'Das Ende darf nicht vor dem Beginn liegen.'], [
|
||||
'title' => 'Titel', 'starts_at' => 'Beginn', 'ends_at' => 'Ende', 'location' => 'Ort', 'online_url' => 'Online-Link',
|
||||
]);
|
||||
|
||||
$allDay = (bool) ($data['all_day'] ?? false);
|
||||
$start = Carbon::parse($data['starts_at']);
|
||||
$end = filled($data['ends_at'] ?? null) ? Carbon::parse($data['ends_at']) : null;
|
||||
|
||||
return [[
|
||||
'title' => trim($data['title']),
|
||||
'all_day' => $allDay,
|
||||
'starts_at' => $allDay ? $start->startOfDay() : $start,
|
||||
'ends_at' => $allDay && $end ? $end->endOfDay() : $end,
|
||||
'location' => filled($data['location'] ?? null) ? trim($data['location']) : null,
|
||||
'online_url' => $data['online_url'] ?? null,
|
||||
'description' => filled($data['description'] ?? null) ? $data['description'] : null,
|
||||
'image_path' => $data['image_path'] ?? null,
|
||||
'is_published' => (bool) ($data['is_published'] ?? true),
|
||||
], array_intersect_key((array) ($data['audience'] ?? []), array_flip(['role', 'department', 'location', 'exclude_role']))];
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ use App\Notifications\PortalNotification;
|
|||
use App\Pagebuilder\Blocks;
|
||||
use App\Pagebuilder\Content;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -433,10 +434,6 @@ class PageEditorController extends Controller
|
|||
*/
|
||||
public static function audienceOptions(): array
|
||||
{
|
||||
return Cache::remember('pagebuilder.audience-options', 300, fn () => [
|
||||
'role' => Role::query()->orderBy('name')->get(['id', 'name'])->map(fn (Role $role) => ['value' => (string) $role->id, 'label' => $role->name])->all(),
|
||||
'department' => User::query()->active()->whereNotNull('department')->distinct()->orderBy('department')->pluck('department')->all(),
|
||||
'location' => User::query()->active()->whereNotNull('location')->distinct()->orderBy('location')->pluck('location')->all(),
|
||||
]);
|
||||
return Audiences::options();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue