IT-Service: Dateianhang beim Ticket
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m45s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m2s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m23s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m17s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m23s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 21:16:11 +00:00
parent e9283752c6
commit 011a421b29
111 changed files with 561 additions and 451 deletions

View file

@ -1,7 +1,7 @@
<script setup>
import { computed } from 'vue';
import { computed, ref } from 'vue';
import { Link, useForm } from '@inertiajs/vue3';
import { ArrowLeft, CircleAlert, HelpCircle, Laptop, LoaderCircle, Send } from '@lucide/vue';
import { ArrowLeft, CircleAlert, HelpCircle, Laptop, LoaderCircle, Paperclip, Send, X } from '@lucide/vue';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
@ -28,15 +28,48 @@ const form = useForm({
description: '',
category_id: null,
location_id: props.defaultLocation,
attachment: null,
});
// Anhang: eine Datei, höchstens 10 MB (wie OpenNIT erlaubt)
const MAX_BYTES = 10 * 1024 * 1024;
const fileInput = ref(null);
const dragging = ref(false);
const fileError = ref('');
function setFile(file) {
fileError.value = '';
if (!file) return;
if (file.size > MAX_BYTES) {
fileError.value = 'Die Datei ist zu groß (höchstens 10 MB).';
return;
}
form.attachment = file;
}
function onDrop(event) {
dragging.value = false;
setFile(event.dataTransfer?.files?.[0]);
}
function clearFile() {
form.attachment = null;
if (fileInput.value) fileInput.value.value = '';
}
const fileSize = (bytes) => (bytes > 1_048_576 ? `${(bytes / 1_048_576).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
function submit() {
form.transform((data) => ({
...data,
asset_id: data.asset_id || null,
category_id: data.category_id ? Number(data.category_id) : null,
location_id: data.location_id ? Number(data.location_id) : null,
})).post('/it-service/tickets');
})).post('/it-service/tickets', { forceFormData: true });
}
</script>
@ -92,6 +125,34 @@ function submit() {
<FormField id="description" label="Nachricht" :error="form.errors.description" hint="Was ist passiert? Seit wann? Gibt es eine Fehlermeldung? Was haben Sie schon versucht?">
<Textarea id="description" v-model="form.description" rows="14" maxlength="20000" class="min-h-72" required />
</FormField>
<div class="grid gap-1.5">
<span class="text-[13px] font-medium">Anhang (optional)</span>
<div
v-if="!form.attachment"
class="flex cursor-pointer flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed px-4 py-6 text-center text-sm text-muted-foreground transition-colors"
:class="dragging ? 'border-brand bg-brand-soft/50' : 'hover:border-brand-300 hover:bg-accent/40'"
role="button"
tabindex="0"
@click="fileInput?.click()"
@keydown.enter.prevent="fileInput?.click()"
@dragover.prevent="dragging = true"
@dragleave="dragging = false"
@drop.prevent="onDrop"
>
<Paperclip class="size-5" />
<span><span class="font-medium text-foreground">Datei auswählen</span> oder hierher ziehen</span>
<span class="text-xs">z. B. Screenshot oder Fehlermeldung – Bild, PDF, Text oder Word, höchstens 10 MB</span>
</div>
<div v-else class="flex items-center gap-3 rounded-lg border bg-muted/40 px-3 py-2.5 text-sm">
<Paperclip class="size-4 shrink-0 text-muted-foreground" />
<span class="min-w-0 flex-1 truncate">{{ form.attachment.name }}</span>
<span class="shrink-0 text-xs text-muted-foreground">{{ fileSize(form.attachment.size) }}</span>
<button type="button" class="grid size-7 place-items-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground" aria-label="Anhang entfernen" @click="clearFile"><X class="size-4" /></button>
</div>
<input ref="fileInput" type="file" class="hidden" accept="image/*,.pdf,.txt,.doc,.docx" @change="setFile($event.target.files?.[0])" />
<p v-if="fileError || form.errors.attachment" class="text-[13px] text-destructive">{{ fileError || form.errors.attachment }}</p>
</div>
<div class="flex justify-end border-t pt-4">
<Button type="submit" :disabled="form.processing">
<LoaderCircle v-if="form.processing" class="animate-spin" /><Send v-else /> Ticket absenden

View file

@ -96,9 +96,10 @@ class ItServiceController extends Controller
'category_id' => $categories ? ['required', 'integer', Rule::in($categories)] : ['nullable', 'integer'],
'location_id' => $locations ? ['required', 'integer', Rule::in($locations)] : ['nullable', 'integer'],
'asset_id' => ['nullable', 'integer'],
], [], ['subject' => 'Betreff', 'description' => 'Nachricht', 'category_id' => 'Kategorie', 'location_id' => 'Standort']);
'attachment' => ['nullable', 'file', 'max:10240', 'mimes:jpg,jpeg,png,gif,webp,pdf,txt,doc,docx'],
], ['attachment.mimes' => 'Bitte ein Bild, PDF, Text- oder Word-Dokument anhängen.'], ['subject' => 'Betreff', 'description' => 'Nachricht', 'category_id' => 'Kategorie', 'location_id' => 'Standort', 'attachment' => 'Anhang']);
$id = $this->orFail(fn () => $this->it->createTicket($request->user(), $data), 'subject');
$id = $this->orFail(fn () => $this->it->createTicket($request->user(), $data, $request->file('attachment')), 'subject');
return $id > 0
? to_route('it-service.tickets.show', $id)->with('status', 'Ticket erstellt – die IT meldet sich.')

View file

@ -3,8 +3,10 @@
namespace Inhaus\Plugins\ItService;
use App\Models\User;
use App\Support\Images;
use App\Support\RichText;
use Illuminate\Http\Client\Response;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Inhaus\Plugins\ItService\OpenNit\Client;
use Inhaus\Plugins\ItService\OpenNit\Settings;
@ -90,9 +92,9 @@ class ItService
/**
* @param array{subject: string, description?: ?string, category_id?: ?int, location_id?: ?int, asset_id?: ?int} $data
*/
public function createTicket(User $user, array $data): int
public function createTicket(User $user, array $data, ?UploadedFile $attachment = null): int
{
$response = $this->client->post('/tickets', array_filter([
$body = array_filter([
'subject' => $data['subject'],
'from_email' => $user->email,
'from_name' => $user->name,
@ -100,7 +102,17 @@ class ItService
'category_id' => $data['category_id'] ?? null,
'location_id' => $data['location_id'] ?? null,
'asset_id' => $data['asset_id'] ?? null,
], fn ($value) => $value !== null && $value !== ''));
], fn ($value) => $value !== null && $value !== '');
// Anhang wie im WordPress-Plugin von OpenNIT: Data-URL plus Name und Typ
if ($attachment) {
$mime = $attachment->getMimeType() ?: 'application/octet-stream';
$body['attachment_b64'] = Images::withLocalCopy($attachment, fn (string $path) => 'data:'.$mime.';base64,'.base64_encode((string) file_get_contents($path)));
$body['attachment_name'] = $attachment->getClientOriginalName();
$body['attachment_mime'] = $mime;
}
$response = $this->client->post('/tickets', $body);
return (int) ($response['id'] ?? $response['ticket_id'] ?? 0);
}