Files
lernapp/resources/views/admin/questions/index.blade.php
T

76 lines
4.0 KiB
PHP

@extends('layouts.admin')
@section('title','Fragen')
@section('content')
<div class="flex flex-wrap gap-3 items-center justify-between mb-6" x-data="{showImport:false}">
<form method="GET" class="flex gap-2">
<select name="subject" class="border border-slate-300 rounded-lg px-3 py-2 text-sm">
<option value="">Alle Fächer</option>
@foreach($subjects as $s)<option value="{{ $s->id }}" {{ request('subject')==$s->id?'selected':'' }}>{{ $s->icon }} {{ $s->name }}</option>@endforeach
</select>
<button class="bg-slate-700 text-white px-4 py-2 rounded-lg text-sm">Filtern</button>
</form>
<div class="flex gap-2 flex-wrap">
{{-- Export --}}
<a href="{{ route('admin.questions.export', request()->only('subject')) }}"
class="flex items-center gap-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-2 rounded-lg text-sm font-medium">
Export JSON
</a>
{{-- Import trigger --}}
<button @click="showImport=!showImport"
class="flex items-center gap-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-2 rounded-lg text-sm font-medium">
Import JSON
</button>
<a href="{{ route('admin.questions.create') }}" class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg text-sm font-medium">+ Neue Frage</a>
</div>
{{-- Import panel --}}
<div x-show="showImport" x-cloak class="w-full mt-1">
<div class="bg-amber-50 border border-amber-200 rounded-xl p-5">
<h3 class="font-semibold text-slate-800 mb-1">Fragen importieren</h3>
<p class="text-xs text-slate-500 mb-3">JSON-Datei im gleichen Format wie der Export. Bestehende Fragen bleiben erhalten.</p>
<form method="POST" action="{{ route('admin.questions.import') }}" enctype="multipart/form-data" class="flex items-center gap-3">
@csrf
<input type="file" name="file" accept=".json" required
class="flex-1 text-sm text-slate-600 file:mr-3 file:py-1.5 file:px-3 file:rounded-lg file:border-0 file:text-sm file:font-medium file:bg-violet-100 file:text-violet-700 hover:file:bg-violet-200">
<button type="submit" class="bg-violet-600 hover:bg-violet-700 text-white px-4 py-2 rounded-lg text-sm font-medium whitespace-nowrap">
Importieren
</button>
</form>
</div>
</div>
</div>
<div class="bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
<table class="w-full text-sm">
<thead class="bg-slate-50 border-b border-slate-200">
<tr>
<th class="text-left px-4 py-3 font-medium text-slate-600">Frage</th>
<th class="text-left px-4 py-3 font-medium text-slate-600">Fach</th>
<th class="text-center px-4 py-3 font-medium text-slate-600">Schwierigkeit</th>
<th class="text-center px-4 py-3 font-medium text-slate-600">Aktiv</th>
<th class="px-4 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@forelse($questions as $q)
<tr class="hover:bg-slate-50">
<td class="px-4 py-3 text-slate-700 max-w-xs truncate">{{ $q->question_text }}</td>
<td class="px-4 py-3"><span class="text-base">{{ $q->subject->icon }}</span> {{ $q->subject->name }}</td>
<td class="px-4 py-3 text-center">{{ $q->difficultyStars() }}</td>
<td class="px-4 py-3 text-center">{{ $q->active ? '✅' : '⏸️' }}</td>
<td class="px-4 py-3 text-right whitespace-nowrap">
<a href="{{ route('admin.questions.edit',$q) }}" class="text-violet-600 hover:underline mr-3">Bearbeiten</a>
<form method="POST" action="{{ route('admin.questions.destroy',$q) }}" class="inline" onsubmit="return confirm('Löschen?')">
@csrf @method('DELETE')
<button class="text-red-500 hover:underline">Löschen</button>
</form>
</td>
</tr>
@empty
<tr><td colspan="5" class="px-4 py-8 text-center text-slate-400">Keine Fragen vorhanden.</td></tr>
@endforelse
</tbody>
</table>
</div>
<div class="mt-4">{{ $questions->links() }}</div>
@endsection