Mediathek in den Beitrags-Editor eingebunden, Version 0.18.0
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m26s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m58s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m0s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m27s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m26s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m38s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m9s
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m26s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m58s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m0s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m27s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m26s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m38s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m9s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2a11d8a47a
commit
629da715a9
139 changed files with 891 additions and 703 deletions
|
|
@ -7,6 +7,7 @@ import {
|
|||
EllipsisVertical,
|
||||
Eye,
|
||||
ImagePlus,
|
||||
Images,
|
||||
LoaderCircle,
|
||||
MessageSquareWarning,
|
||||
Monitor,
|
||||
|
|
@ -35,6 +36,9 @@ import BlockSettings from '@/pagebuilder/editor/BlockSettings.vue';
|
|||
import EditorBlockList from '@/pagebuilder/editor/EditorBlockList.vue';
|
||||
import { clone, createBlock, duplicate as duplicateBlock, locate, walk } from '@/pagebuilder/editor/tree';
|
||||
import { http } from '@/lib/http';
|
||||
import MediaPickerHost from '@/components/media/MediaPickerHost.vue';
|
||||
import { collectImagePaths, uploadWithProgress } from '@/components/media/api';
|
||||
import { useMediaPicker } from '@/components/media/useMediaPicker';
|
||||
|
||||
/**
|
||||
* Beitrag schreiben – mit demselben Baukasten wie die Seiten. Titelbild, Titel
|
||||
|
|
@ -70,6 +74,7 @@ const form = useForm({
|
|||
teaser: props.post?.teaser ?? '',
|
||||
category_id: props.post?.category_id ?? (props.categories.length === 1 ? props.categories[0].id : null),
|
||||
cover: null,
|
||||
cover_media: null,
|
||||
remove_cover: false,
|
||||
is_featured: props.post?.is_featured ?? false,
|
||||
published_at: localValue(props.post?.published_at),
|
||||
|
|
@ -155,18 +160,22 @@ function containsActive(item) {
|
|||
return candidates.some((block) => block.items?.includes(item) || locate(item.blocks, block.id));
|
||||
}
|
||||
|
||||
async function uploadImage(file) {
|
||||
const body = new FormData();
|
||||
body.append('image', file);
|
||||
|
||||
// Bilder landen zugleich in der Mediathek
|
||||
async function uploadImage(file, onProgress) {
|
||||
try {
|
||||
return await http.post('/redaktion/neuigkeiten/bilder', body);
|
||||
return await uploadWithProgress('/redaktion/neuigkeiten/bilder', file, { onProgress });
|
||||
} catch (error) {
|
||||
toast.error(error.fieldErrors?.image ?? error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const mediaPicker = useMediaPicker({
|
||||
upload: uploadImage,
|
||||
contextLabel: 'In diesem Beitrag',
|
||||
contextPaths: () => collectImagePaths(working.content),
|
||||
});
|
||||
|
||||
async function uploadFile() {
|
||||
toast.error('Dateien zum Herunterladen gehören in den Bereich „Downloads“ – dort hochladen und hier mit dem Downloads-Block verlinken.');
|
||||
throw new Error('not supported');
|
||||
|
|
@ -190,6 +199,7 @@ provide('pagebuilder:editor', {
|
|||
containsActive,
|
||||
uploadImage,
|
||||
uploadFile,
|
||||
pickMedia: (options) => mediaPicker.pick(options),
|
||||
imageUrl: (path) => `${props.uploadsUrl}/${path}`,
|
||||
});
|
||||
provide('pagebuilder:list', EditorBlockList);
|
||||
|
|
@ -339,12 +349,25 @@ function chooseCover(event) {
|
|||
if (!file) return;
|
||||
|
||||
form.cover = file;
|
||||
form.cover_media = null;
|
||||
form.remove_cover = false;
|
||||
coverPreview.value = URL.createObjectURL(file);
|
||||
}
|
||||
|
||||
async function pickCover() {
|
||||
const picked = await mediaPicker.pick({ title: 'Titelbild wählen' });
|
||||
|
||||
if (!picked?.length) return;
|
||||
|
||||
form.cover = null;
|
||||
form.cover_media = picked[0].path;
|
||||
form.remove_cover = false;
|
||||
coverPreview.value = picked[0].url;
|
||||
}
|
||||
|
||||
function removeCover() {
|
||||
form.cover = null;
|
||||
form.cover_media = null;
|
||||
form.remove_cover = true;
|
||||
coverPreview.value = null;
|
||||
}
|
||||
|
|
@ -519,20 +542,24 @@ function autoGrow(event) {
|
|||
<div v-if="coverPreview" class="group relative mb-6 overflow-hidden rounded-xl border" @click.stop>
|
||||
<img :src="coverPreview" alt="" class="aspect-video w-full object-cover" />
|
||||
<div class="absolute top-3 right-3 flex gap-2 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100">
|
||||
<Button size="sm" variant="outline" class="bg-card/95" @click="coverInput?.click()"><ImagePlus /> Ändern</Button>
|
||||
<Button size="sm" variant="outline" class="bg-card/95" @click="coverInput?.click()"><ImagePlus /> Hochladen</Button>
|
||||
<Button size="sm" variant="outline" class="bg-card/95" @click="pickCover"><Images /> Aus Mediathek</Button>
|
||||
<Button size="icon" variant="outline" class="size-8 bg-card/95" title="Titelbild entfernen" @click="removeCover"><X /></Button>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
<div
|
||||
v-else
|
||||
type="button"
|
||||
class="mb-6 flex aspect-[21/9] w-full flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed text-sm text-muted-foreground transition-colors hover:border-brand-300 hover:bg-brand-soft/40 hover:text-foreground"
|
||||
@click.stop="coverInput?.click()"
|
||||
class="mb-6 flex aspect-[21/9] w-full flex-col items-center justify-center gap-3 rounded-xl border-2 border-dashed text-sm text-muted-foreground"
|
||||
@click.stop
|
||||
>
|
||||
<ImagePlus class="size-7" />
|
||||
<span class="font-medium">Titelbild hinzufügen</span>
|
||||
<span class="font-medium text-foreground">Titelbild hinzufügen</span>
|
||||
<div class="flex gap-2">
|
||||
<Button size="sm" variant="outline" @click="coverInput?.click()"><ImagePlus /> Hochladen</Button>
|
||||
<Button size="sm" variant="outline" @click="pickCover"><Images /> Aus Mediathek</Button>
|
||||
</div>
|
||||
<span class="text-xs">Querformat, am besten 1600 × 900 Pixel</span>
|
||||
</button>
|
||||
</div>
|
||||
<input ref="coverInput" type="file" accept="image/jpeg,image/png,image/webp" class="hidden" @change="chooseCover" />
|
||||
<p v-if="form.errors.cover" class="-mt-4 mb-4 text-[13px] text-destructive">{{ form.errors.cover }}</p>
|
||||
|
||||
|
|
@ -620,7 +647,8 @@ function autoGrow(event) {
|
|||
<div class="grid gap-2 border-t pt-4">
|
||||
<span class="text-[13px] font-medium">Titelbild</span>
|
||||
<div class="flex gap-2">
|
||||
<Button variant="outline" size="sm" @click="coverInput?.click()"><ImagePlus /> {{ coverPreview ? 'Anderes Bild' : 'Bild hochladen' }}</Button>
|
||||
<Button variant="outline" size="sm" @click="coverInput?.click()"><ImagePlus /> Hochladen</Button>
|
||||
<Button variant="outline" size="sm" @click="pickCover"><Images /> Mediathek</Button>
|
||||
<Button v-if="coverPreview" variant="ghost" size="sm" @click="removeCover"><X /> Entfernen</Button>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground">Wird auf 16:9 zugeschnitten.</p>
|
||||
|
|
@ -670,5 +698,6 @@ function autoGrow(event) {
|
|||
</Dialog>
|
||||
</div>
|
||||
|
||||
<MediaPickerHost :picker="mediaPicker" />
|
||||
<Toaster position="bottom-left" />
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
namespace Inhaus\Plugins\News\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Media\MediaLibrary;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Pagebuilder\Blocks;
|
||||
use App\Pagebuilder\Content;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Images;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -109,15 +109,15 @@ class NewsEditorController extends Controller
|
|||
return to_route('editorial')->with('status', 'Beitrag gelöscht.');
|
||||
}
|
||||
|
||||
public function uploadImage(Request $request, Images $images): JsonResponse
|
||||
public function uploadImage(Request $request, MediaLibrary $library): JsonResponse
|
||||
{
|
||||
Gate::authorize('create', NewsPost::class);
|
||||
$request->validate(['image' => ['required', File::image()->types(['jpg', 'jpeg', 'png', 'webp', 'gif'])->max(15 * 1024)]]);
|
||||
|
||||
// Unter pagebuilder/, damit Bild-Blöcke den Pfad annehmen
|
||||
$path = $images->storeContentImage($request->file('image'), 'pagebuilder/news');
|
||||
// Landet zugleich in der Mediathek.
|
||||
$media = $library->store($request->file('image'), 'pagebuilder/news', $request->user());
|
||||
|
||||
return response()->json(['path' => $path, 'url' => Storage::disk('uploads')->url($path)]);
|
||||
return response()->json(['path' => $media->path, 'url' => Blocks::imageUrl($media->path), 'media' => $media->toLibraryArray()]);
|
||||
}
|
||||
|
||||
/** Vorschau dynamischer Blöcke (aktuelle Beiträge, Termine, Personen …) im Editor */
|
||||
|
|
@ -149,6 +149,8 @@ class NewsEditorController extends Controller
|
|||
'category_id' => [$user->can('news.manage') ? 'nullable' : 'required', 'integer', Rule::in($writable === true ? NewsCategory::query()->pluck('id')->all() : $writable)],
|
||||
'cover' => ['nullable', File::image()->types(['jpg', 'jpeg', 'png', 'webp'])->max(10 * 1024)],
|
||||
'remove_cover' => ['boolean'],
|
||||
// Titelbild aus der Mediathek
|
||||
'cover_media' => ['nullable', 'string', 'max:500', Rule::exists('media', 'path')],
|
||||
'is_featured' => ['boolean'],
|
||||
'comments_enabled' => ['boolean'],
|
||||
'published_at' => ['nullable', 'date'],
|
||||
|
|
@ -184,8 +186,12 @@ class NewsEditorController extends Controller
|
|||
$post->cover_path = null;
|
||||
}
|
||||
|
||||
if (filled($data['cover_media'] ?? null) && ! $request->hasFile('cover')) {
|
||||
$post->cover_path = $data['cover_media'];
|
||||
}
|
||||
|
||||
if ($request->hasFile('cover')) {
|
||||
$post->cover_path = $request->file('cover')->store('news', 'uploads');
|
||||
$post->cover_path = app(MediaLibrary::class)->store($request->file('cover'), 'news', $user)->path;
|
||||
}
|
||||
|
||||
if ($data['action'] === 'draft') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue