Add AI photo import via Ollama Vision
Users can upload a photo of a nail polish bottle; a background queue job sends it to Ollama (llama3.2-vision at 192.168.30.172:11434), extracts name, number and manufacturer, then creates the nail polish and adds it to the user's collection automatically. - ProcessNailPolishImage job (180s timeout, 2 tries) - NailPolishImport model + migration (status tracking) - AiSetting model + migration (Ollama URL + model, admin-configurable) - NailPolishImportController: upload, status page (auto-refresh every 5s) - Admin\AiSettingController: configure Ollama connection - Views: drag-drop upload form, live status page, import history - Navbar: "Foto importieren" link for all users - Admin dropdown: "KI-Einstellungen" - neonail-worker.conf: Supervisor config for the queue worker Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
7a24e554b0
commit
f715bc4552
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiSetting;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AiSettingController extends Controller
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
$ai = AiSetting::get();
|
||||
return view('admin.ai.show', compact('ai'));
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'ollama_url' => 'required|url|max:255',
|
||||
'ollama_model' => 'required|string|max:100',
|
||||
]);
|
||||
|
||||
$ai = AiSetting::get();
|
||||
$ai->ollama_url = rtrim($request->ollama_url, '/');
|
||||
$ai->ollama_model = $request->ollama_model;
|
||||
$ai->save();
|
||||
|
||||
return redirect()->route('admin.ai.show')->with('success', 'KI-Einstellungen gespeichert.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\ProcessNailPolishImage;
|
||||
use App\Models\NailPolishImport;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class NailPolishImportController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$imports = NailPolishImport::where('user_id', auth()->id())
|
||||
->latest()
|
||||
->paginate(20);
|
||||
|
||||
return view('nail-polish-imports.index', compact('imports'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('nail-polish-imports.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'image' => 'required|image|mimes:jpeg,png,jpg,webp|max:10240',
|
||||
]);
|
||||
|
||||
$file = $request->file('image');
|
||||
$path = $file->store('nail-polish-imports', 'public');
|
||||
|
||||
$import = NailPolishImport::create([
|
||||
'user_id' => auth()->id(),
|
||||
'image_path' => $path,
|
||||
'status' => 'pending',
|
||||
]);
|
||||
|
||||
ProcessNailPolishImage::dispatch($import->id);
|
||||
|
||||
return redirect()->route('nail-polish-imports.show', $import)
|
||||
->with('success', 'Bild hochgeladen! Die KI analysiert es jetzt im Hintergrund.');
|
||||
}
|
||||
|
||||
public function show(NailPolishImport $nailPolishImport)
|
||||
{
|
||||
// Nur eigene Imports ansehen
|
||||
abort_if($nailPolishImport->user_id !== auth()->id(), 403);
|
||||
|
||||
return view('nail-polish-imports.show', ['import' => $nailPolishImport->load('nailPolish.manufacturer')]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\AiSetting;
|
||||
use App\Models\Manufacturer;
|
||||
use App\Models\NailPolish;
|
||||
use App\Models\NailPolishImport;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProcessNailPolishImage implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $timeout = 180;
|
||||
public int $tries = 2;
|
||||
|
||||
public function __construct(private int $importId) {}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$import = NailPolishImport::findOrFail($this->importId);
|
||||
$import->update(['status' => 'processing']);
|
||||
|
||||
try {
|
||||
$ai = AiSetting::get();
|
||||
$imageB64 = base64_encode(Storage::disk('public')->get($import->image_path));
|
||||
|
||||
$prompt = <<<PROMPT
|
||||
Analyze this nail polish bottle image carefully.
|
||||
Extract the following data and respond ONLY with valid JSON, no other text:
|
||||
{
|
||||
"name": "the nail polish color name",
|
||||
"number": "the product number or color code (often printed on bottle or cap)",
|
||||
"manufacturer": "the brand name printed on the bottle"
|
||||
}
|
||||
If a value is not visible or unclear, use null.
|
||||
PROMPT;
|
||||
|
||||
$response = Http::timeout(160)->post("{$ai->ollama_url}/api/generate", [
|
||||
'model' => $ai->ollama_model,
|
||||
'prompt' => $prompt,
|
||||
'images' => [$imageB64],
|
||||
'stream' => false,
|
||||
]);
|
||||
|
||||
if ($response->failed()) {
|
||||
throw new \RuntimeException('Ollama API Fehler: ' . $response->status());
|
||||
}
|
||||
|
||||
$raw = $response->json('response', '');
|
||||
$data = $this->parseJson($raw);
|
||||
|
||||
if (!$data) {
|
||||
throw new \RuntimeException('Ollama-Antwort konnte nicht als JSON geparst werden: ' . $raw);
|
||||
}
|
||||
|
||||
// Hersteller suchen oder anlegen
|
||||
$manufacturer = null;
|
||||
if (!empty($data['manufacturer'])) {
|
||||
$manufacturer = Manufacturer::firstOrCreate(
|
||||
['name' => trim($data['manufacturer'])]
|
||||
);
|
||||
}
|
||||
|
||||
// Nagellack-Nummer eindeutig machen falls nötig
|
||||
$number = $data['number'] ?? ('import-' . $this->importId);
|
||||
if (NailPolish::where('number', $number)->exists()) {
|
||||
$number .= '-' . $this->importId;
|
||||
}
|
||||
|
||||
$nailPolish = NailPolish::create([
|
||||
'name' => $data['name'] ?? 'Unbekannt',
|
||||
'number' => $number,
|
||||
'manufacturer_id' => $manufacturer?->id,
|
||||
'image_path' => $import->image_path,
|
||||
]);
|
||||
|
||||
// Zur Sammlung des Users hinzufügen
|
||||
$import->user->nailPolishes()->syncWithoutDetaching([$nailPolish->id]);
|
||||
|
||||
$import->update([
|
||||
'status' => 'done',
|
||||
'result' => $data,
|
||||
'nail_polish_id' => $nailPolish->id,
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('ProcessNailPolishImage fehlgeschlagen', [
|
||||
'import_id' => $this->importId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
$import->update([
|
||||
'status' => 'failed',
|
||||
'error_message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseJson(string $raw): ?array
|
||||
{
|
||||
// JSON aus der Antwort extrahieren (Ollama kann Text drumherum haben)
|
||||
if (preg_match('/\{.*\}/s', $raw, $matches)) {
|
||||
$decoded = json_decode($matches[0], true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AiSetting extends Model
|
||||
{
|
||||
protected $table = 'ai_settings';
|
||||
|
||||
protected $fillable = ['ollama_url', 'ollama_model'];
|
||||
|
||||
public static function get(): self
|
||||
{
|
||||
return static::firstOrCreate([], [
|
||||
'ollama_url' => 'http://192.168.30.172:11434',
|
||||
'ollama_model' => 'llama3.2-vision',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class NailPolishImport extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'image_path',
|
||||
'status',
|
||||
'result',
|
||||
'nail_polish_id',
|
||||
'error_message',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'result' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function nailPolish()
|
||||
{
|
||||
return $this->belongsTo(NailPolish::class);
|
||||
}
|
||||
|
||||
public function isPending(): bool
|
||||
{
|
||||
return in_array($this->status, ['pending', 'processing']);
|
||||
}
|
||||
|
||||
public function statusLabel(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'pending' => 'Warten',
|
||||
'processing' => 'Verarbeitung',
|
||||
'done' => 'Fertig',
|
||||
'failed' => 'Fehler',
|
||||
default => $this->status,
|
||||
};
|
||||
}
|
||||
|
||||
public function statusColor(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'pending' => 'warning',
|
||||
'processing' => 'info',
|
||||
'done' => 'success',
|
||||
'failed' => 'danger',
|
||||
default => 'secondary',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,11 @@ class User extends Authenticatable
|
||||
return $this->belongsToMany(NailPolish::class, 'user_nail_polishes', 'user_id', 'nail_polish_id');
|
||||
}
|
||||
|
||||
public function nailPolishImports()
|
||||
{
|
||||
return $this->hasMany(\App\Models\NailPolishImport::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob der User ein Admin ist
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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('nail_polish_imports', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('image_path');
|
||||
$table->enum('status', ['pending', 'processing', 'done', 'failed'])->default('pending');
|
||||
$table->json('result')->nullable();
|
||||
$table->foreignId('nail_polish_id')->nullable()->constrained('nail_polishes')->nullOnDelete();
|
||||
$table->text('error_message')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('nail_polish_imports');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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('ai_settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('ollama_url')->default('http://192.168.30.172:11434');
|
||||
$table->string('ollama_model')->default('llama3.2-vision');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
DB::table('ai_settings')->insert([
|
||||
'ollama_url' => 'http://192.168.30.172:11434',
|
||||
'ollama_model' => 'llama3.2-vision',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ai_settings');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
[program:neonail-worker]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=php /var/www/html/artisan queue:work --sleep=3 --tries=2 --timeout=180
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stopasgroup=true
|
||||
killasgroup=true
|
||||
user=www-data
|
||||
numprocs=1
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/www/html/storage/logs/worker.log
|
||||
stopwaitsecs=180
|
||||
@@ -0,0 +1,72 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'KI-Einstellungen – NeoNail DB')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero mb-4">
|
||||
<h1><i class="fas fa-robot me-2"></i>KI-Einstellungen</h1>
|
||||
<p>Ollama-Konfiguration für den automatischen Foto-Import</p>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<div class="col-lg-7">
|
||||
<div class="card">
|
||||
<div class="card-header"><i class="fas fa-cog me-2"></i>Ollama Verbindung</div>
|
||||
<div class="card-body p-4">
|
||||
<form method="POST" action="{{ route('admin.ai.update') }}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="ollama_url">Ollama URL <span class="text-danger">*</span></label>
|
||||
<input type="url" class="form-control @error('ollama_url') is-invalid @enderror"
|
||||
id="ollama_url" name="ollama_url"
|
||||
value="{{ old('ollama_url', $ai->ollama_url) }}"
|
||||
placeholder="http://192.168.30.172:11434">
|
||||
@error('ollama_url')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
<div class="form-text">URL des Ollama-Containers/Servers ohne abschließenden Slash.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label" for="ollama_model">Modell <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control @error('ollama_model') is-invalid @enderror"
|
||||
id="ollama_model" name="ollama_model"
|
||||
value="{{ old('ollama_model', $ai->ollama_model) }}"
|
||||
placeholder="llama3.2-vision">
|
||||
@error('ollama_model')
|
||||
<div class="invalid-feedback">{{ $message }}</div>
|
||||
@enderror
|
||||
<div class="form-text">Muss ein Vision-fähiges Modell sein (z.B. <code>llama3.2-vision</code>, <code>llava</code>).</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fas fa-save me-2"></i>Speichern
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-5">
|
||||
<div class="card">
|
||||
<div class="card-header"><i class="fas fa-info-circle me-2"></i>Queue Worker</div>
|
||||
<div class="card-body p-3">
|
||||
<p style="font-size:.83rem; color:#374151; margin-bottom:10px;">
|
||||
Jobs werden über die <strong>Datenbank-Queue</strong> verarbeitet. Auf dem Server muss dauerhaft ein Worker laufen:
|
||||
</p>
|
||||
<code style="display:block; background:#f3f4f6; padding:10px 12px; border-radius:8px; font-size:.78rem; white-space:pre-wrap;">php artisan queue:work \
|
||||
--timeout=180 \
|
||||
--tries=2 \
|
||||
--sleep=3</code>
|
||||
<p style="font-size:.78rem; color:#9ca3af; margin-top:10px; margin-bottom:0;">
|
||||
Empfohlen: Als Supervisor-Dienst einrichten, damit der Worker nach Crashes neu startet.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@@ -456,6 +456,12 @@
|
||||
<i class="fas fa-industry me-1"></i>Hersteller
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {{ request()->routeIs('nail-polish-imports.*') ? 'active' : '' }}"
|
||||
href="{{ route('nail-polish-imports.create') }}">
|
||||
<i class="fas fa-camera me-1"></i>Foto importieren
|
||||
</a>
|
||||
</li>
|
||||
@if(auth()->user()->isAdmin())
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle {{ request()->routeIs('admin.*') || request()->routeIs('nail-polishes.*') ? 'active' : '' }}"
|
||||
@@ -474,6 +480,8 @@
|
||||
<li><hr class="dropdown-divider" style="border-color:rgba(255,255,255,0.1);"></li>
|
||||
<li><a class="dropdown-item" href="{{ route('admin.sso.show') }}">
|
||||
<i class="fas fa-shield-alt me-2"></i>SSO-Konfiguration</a></li>
|
||||
<li><a class="dropdown-item" href="{{ route('admin.ai.show') }}">
|
||||
<i class="fas fa-robot me-2"></i>KI-Einstellungen</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@endif
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Foto importieren – NeoNail DB')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero mb-4">
|
||||
<h1><i class="fas fa-camera me-2"></i>Foto importieren</h1>
|
||||
<p>Lade ein Foto deines Nagellacks hoch – die KI erkennt Name, Nummer und Hersteller automatisch.</p>
|
||||
</div>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<div class="card">
|
||||
<div class="card-body p-4">
|
||||
<form method="POST" action="{{ route('nail-polish-imports.store') }}" enctype="multipart/form-data" id="importForm">
|
||||
@csrf
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Foto des Nagellacks</label>
|
||||
|
||||
<div id="dropzone"
|
||||
style="border: 2px dashed #d1d5db; border-radius: 16px; padding: 48px 20px;
|
||||
text-align: center; cursor: pointer; transition: all .2s;"
|
||||
onclick="document.getElementById('image').click()">
|
||||
<div id="dropzoneContent">
|
||||
<i class="fas fa-cloud-upload-alt" style="font-size: 2.5rem; color: #9ca3af; margin-bottom: 12px; display: block;"></i>
|
||||
<p style="color: #6b7280; margin: 0; font-weight: 500;">Foto hierher ziehen oder klicken</p>
|
||||
<p style="color: #9ca3af; font-size: .8rem; margin: 4px 0 0;">JPG, PNG, WebP – max. 10 MB</p>
|
||||
</div>
|
||||
<img id="preview" src="" alt="" style="display:none; max-height:280px; border-radius:10px; max-width:100%;">
|
||||
</div>
|
||||
|
||||
<input type="file" id="image" name="image" accept="image/*" class="d-none" required>
|
||||
|
||||
@error('image')
|
||||
<div class="text-danger mt-2" style="font-size:.85rem;">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-100 btn-lg" id="submitBtn">
|
||||
<i class="fas fa-magic me-2"></i>KI-Analyse starten
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center mt-3">
|
||||
<a href="{{ route('nail-polish-imports.index') }}" style="color: rgba(255,255,255,.65); font-size:.85rem;">
|
||||
<i class="fas fa-history me-1"></i>Meine Importe ansehen
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
<script>
|
||||
const dropzone = document.getElementById('dropzone');
|
||||
const input = document.getElementById('image');
|
||||
const preview = document.getElementById('preview');
|
||||
const content = document.getElementById('dropzoneContent');
|
||||
|
||||
input.addEventListener('change', e => showPreview(e.target.files[0]));
|
||||
|
||||
dropzone.addEventListener('dragover', e => { e.preventDefault(); dropzone.style.borderColor = '#7c3aed'; });
|
||||
dropzone.addEventListener('dragleave', () => { dropzone.style.borderColor = '#d1d5db'; });
|
||||
dropzone.addEventListener('drop', e => {
|
||||
e.preventDefault();
|
||||
dropzone.style.borderColor = '#d1d5db';
|
||||
const file = e.dataTransfer.files[0];
|
||||
if (file) { input.files = e.dataTransfer.files; showPreview(file); }
|
||||
});
|
||||
|
||||
function showPreview(file) {
|
||||
if (!file) return;
|
||||
const reader = new FileReader();
|
||||
reader.onload = e => {
|
||||
preview.src = e.target.result;
|
||||
preview.style.display = 'block';
|
||||
content.style.display = 'none';
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
document.getElementById('importForm').addEventListener('submit', () => {
|
||||
const btn = document.getElementById('submitBtn');
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Wird hochgeladen…';
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
@@ -0,0 +1,83 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Meine Importe – NeoNail DB')
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero d-flex align-items-center justify-content-between flex-wrap gap-3 mb-4">
|
||||
<div>
|
||||
<h1><i class="fas fa-history me-2"></i>Meine Importe</h1>
|
||||
<p>KI-Analysen deiner hochgeladenen Fotos</p>
|
||||
</div>
|
||||
<a href="{{ route('nail-polish-imports.create') }}" class="btn btn-glass">
|
||||
<i class="fas fa-camera me-2"></i>Neues Foto
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@if($imports->isEmpty())
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon"><i class="fas fa-camera"></i></div>
|
||||
<h4>Noch keine Importe</h4>
|
||||
<p>Lade ein Foto hoch und lass die KI deinen Nagellack erkennen.</p>
|
||||
<a href="{{ route('nail-polish-imports.create') }}" class="btn btn-primary">
|
||||
<i class="fas fa-camera me-2"></i>Jetzt importieren
|
||||
</a>
|
||||
</div>
|
||||
@else
|
||||
<div class="card">
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table mb-0" style="font-size:.875rem;">
|
||||
<thead style="background:#f9fafb; border-bottom:1px solid #f3f4f6;">
|
||||
<tr>
|
||||
<th style="padding:12px 16px; font-weight:600; color:#374151;">Bild</th>
|
||||
<th style="padding:12px 16px; font-weight:600; color:#374151;">Ergebnis</th>
|
||||
<th style="padding:12px 16px; font-weight:600; color:#374151;">Status</th>
|
||||
<th style="padding:12px 16px; font-weight:600; color:#374151;">Datum</th>
|
||||
<th style="padding:12px 16px;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($imports as $import)
|
||||
<tr style="border-bottom:1px solid #f3f4f6;">
|
||||
<td style="padding:12px 16px;">
|
||||
<img src="{{ Storage::url($import->image_path) }}"
|
||||
alt=""
|
||||
style="width:52px; height:52px; object-fit:cover; border-radius:10px;">
|
||||
</td>
|
||||
<td style="padding:12px 16px;">
|
||||
@if($import->result)
|
||||
<div style="font-weight:600; color:#111827;">{{ $import->result['name'] ?? '—' }}</div>
|
||||
<div style="color:#9ca3af; font-size:.78rem;">{{ $import->result['manufacturer'] ?? '' }}</div>
|
||||
@elseif($import->status === 'failed')
|
||||
<span style="color:#dc2626; font-size:.8rem;">{{ Str::limit($import->error_message, 60) }}</span>
|
||||
@else
|
||||
<span style="color:#9ca3af;">wird analysiert…</span>
|
||||
@endif
|
||||
</td>
|
||||
<td style="padding:12px 16px;">
|
||||
<span class="badge bg-{{ $import->statusColor() }}">{{ $import->statusLabel() }}</span>
|
||||
</td>
|
||||
<td style="padding:12px 16px; color:#9ca3af;">
|
||||
{{ $import->created_at->format('d.m.Y H:i') }}
|
||||
</td>
|
||||
<td style="padding:12px 16px; text-align:right;">
|
||||
<a href="{{ route('nail-polish-imports.show', $import) }}"
|
||||
class="btn btn-outline-secondary btn-sm">
|
||||
<i class="fas fa-eye"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ $imports->links() }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@endsection
|
||||
@@ -0,0 +1,115 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Import-Status – NeoNail DB')
|
||||
|
||||
@php $pending = $import->isPending(); @endphp
|
||||
|
||||
@if($pending)
|
||||
<meta http-equiv="refresh" content="5">
|
||||
@endif
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="page-hero mb-4">
|
||||
<h1><i class="fas fa-magic me-2"></i>KI-Analyse</h1>
|
||||
<p>
|
||||
<span class="badge bg-{{ $import->statusColor() }} fs-6">
|
||||
{{ $import->statusLabel() }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="row g-4 justify-content-center">
|
||||
|
||||
{{-- Bild --}}
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body p-3 text-center">
|
||||
<img src="{{ Storage::url($import->image_path) }}"
|
||||
alt="Importiertes Bild"
|
||||
style="max-width:100%; border-radius:12px; max-height:320px; object-fit:contain;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- Status / Ergebnis --}}
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
@if($pending)
|
||||
<i class="fas fa-spinner fa-spin me-2"></i>KI analysiert das Bild…
|
||||
@elseif($import->status === 'done')
|
||||
<i class="fas fa-check-circle text-success me-2"></i>Ergebnis
|
||||
@else
|
||||
<i class="fas fa-exclamation-circle text-danger me-2"></i>Fehler
|
||||
@endif
|
||||
</div>
|
||||
<div class="card-body p-4">
|
||||
|
||||
@if($pending)
|
||||
<p style="color:#6b7280;">
|
||||
Ollama verarbeitet das Bild gerade. Diese Seite aktualisiert sich automatisch alle 5 Sekunden.
|
||||
</p>
|
||||
<div class="progress" style="height:6px; border-radius:3px;">
|
||||
<div class="progress-bar progress-bar-striped progress-bar-animated"
|
||||
style="width:100%; background: linear-gradient(135deg,#7c3aed,#ec4899);"></div>
|
||||
</div>
|
||||
|
||||
@elseif($import->status === 'done')
|
||||
@php $result = $import->result; @endphp
|
||||
<table class="table table-borderless mb-0">
|
||||
<tr>
|
||||
<th style="width:130px; color:#6b7280; font-size:.85rem;">Name</th>
|
||||
<td style="font-weight:600;">{{ $result['name'] ?? '—' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="color:#6b7280; font-size:.85rem;">Nummer</th>
|
||||
<td>{{ $result['number'] ?? '—' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style="color:#6b7280; font-size:.85rem;">Hersteller</th>
|
||||
<td>{{ $result['manufacturer'] ?? '—' }}</td>
|
||||
</tr>
|
||||
@if($import->nailPolish)
|
||||
<tr>
|
||||
<th style="color:#6b7280; font-size:.85rem;">In Sammlung</th>
|
||||
<td>
|
||||
<span class="badge" style="background:linear-gradient(135deg,#7c3aed,#ec4899);">
|
||||
<i class="fas fa-check me-1"></i>Hinzugefügt
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</table>
|
||||
|
||||
@if($import->nailPolish)
|
||||
<div class="mt-3">
|
||||
<a href="{{ route('user-nail-polishes.index') }}" class="btn btn-primary btn-sm">
|
||||
<i class="fas fa-home me-1"></i>Zur Sammlung
|
||||
</a>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@else
|
||||
<div class="alert alert-danger mb-3">
|
||||
<i class="fas fa-exclamation-circle me-2"></i>
|
||||
{{ $import->error_message ?? 'Unbekannter Fehler' }}
|
||||
</div>
|
||||
<a href="{{ route('nail-polish-imports.create') }}" class="btn btn-primary btn-sm">
|
||||
<i class="fas fa-redo me-1"></i>Nochmal versuchen
|
||||
</a>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
<a href="{{ route('nail-polish-imports.index') }}" style="color:rgba(255,255,255,.65); font-size:.85rem;">
|
||||
<i class="fas fa-arrow-left me-1"></i>Alle Importe
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@@ -7,6 +7,8 @@ use App\Http\Controllers\AdminController;
|
||||
use App\Http\Controllers\Auth\LoginController;
|
||||
use App\Http\Controllers\Auth\SsoController;
|
||||
use App\Http\Controllers\Admin\SsoSettingController;
|
||||
use App\Http\Controllers\Admin\AiSettingController;
|
||||
use App\Http\Controllers\NailPolishImportController;
|
||||
use App\Http\Controllers\ManufacturerController;
|
||||
|
||||
// Startseite
|
||||
@@ -50,6 +52,8 @@ Route::middleware(['auth'])->group(function () {
|
||||
Route::get('/users/{user}/collection', [UserNailPolishController::class, 'showUserCollection'])->name('users.collection');
|
||||
Route::get('/sso', [SsoSettingController::class, 'show'])->name('sso.show');
|
||||
Route::put('/sso', [SsoSettingController::class, 'update'])->name('sso.update');
|
||||
Route::get('/ai', [AiSettingController::class, 'show'])->name('ai.show');
|
||||
Route::put('/ai', [AiSettingController::class, 'update'])->name('ai.update');
|
||||
});
|
||||
|
||||
// Nagellack-Verwaltung (nur für Admin)
|
||||
@@ -61,6 +65,10 @@ Route::middleware(['auth'])->group(function () {
|
||||
// Hersteller-Verwaltung (für alle eingeloggten User)
|
||||
Route::resource('manufacturers', ManufacturerController::class);
|
||||
Route::get('/manufacturers-search', [ManufacturerController::class, 'search'])->name('manufacturers.search');
|
||||
|
||||
// KI Foto-Import (für alle eingeloggten User)
|
||||
Route::resource('nail-polish-imports', NailPolishImportController::class)
|
||||
->only(['index', 'create', 'store', 'show']);
|
||||
});
|
||||
|
||||
// Fallback
|
||||
|
||||
Reference in New Issue
Block a user