revert register for sessions. photos with different settings, settings configurable
This commit is contained in:
DigitalInfinity committed 2026-06-07 21:30:34 +02:00
1 parent 5596437995
commit 858a451396
14 files changed
+71 -515

No files matched your search

+26 -52
View File
@@ -4,8 +4,6 @@ namespace App\Livewire;
use App\Jobs\ConvertToComic;
use App\Models\PhotoJob;
use App\Models\PhotoSession;
use App\Models\PhotoSetting;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Livewire\Component;
@@ -14,6 +12,17 @@ class CameraCapture extends Component
{
public string $status = '';
public function delete(int $jobId): void
{
$job = PhotoJob::find($jobId);
if (!$job) return;
Storage::disk('public')->delete($job->image_path);
$job->delete();
$this->status = "Job #{$jobId} deleted";
}
public function capture(string $imageData): void
{
if (!preg_match('/^data:image\/(\w+);base64,/', $imageData, $type)) {
@@ -22,66 +31,31 @@ class CameraCapture extends Component
}
$extension = strtolower($type[1]);
$filename = 'photos/' . Str::uuid() . '.' . $extension;
$raw = base64_decode(substr($imageData, strpos($imageData, ',') + 1));
$originalPath = 'photos/' . Str::uuid() . '.' . $extension;
Storage::disk('public')->put($originalPath, $raw);
Storage::disk('public')->put($filename, $raw);
$session = PhotoSession::create(['original_image_path' => $originalPath]);
$job = PhotoJob::create([
'image_path' => $filename,
'status' => 'processing',
]);
$settings = PhotoSetting::active()->get();
ConvertToComic::dispatch($job);
foreach ($settings as $setting) {
$variantPath = 'photos/' . Str::uuid() . '.' . $extension;
Storage::disk('public')->put($variantPath, $raw);
$job = PhotoJob::create([
'image_path' => $variantPath,
'status' => 'processing',
'photo_session_id' => $session->id,
'photo_setting_id' => $setting->id,
]);
ConvertToComic::dispatch($job);
}
$this->status = count($settings) . ' Varianten werden erstellt…';
}
public function selectVariant(int $sessionId, int $jobId): void
{
PhotoSession::where('id', $sessionId)->update(['selected_job_id' => $jobId]);
}
public function deleteSession(int $sessionId): void
{
$session = PhotoSession::with('jobs')->find($sessionId);
if (!$session) return;
foreach ($session->jobs as $job) {
Storage::disk('public')->delete($job->image_path);
$job->delete();
}
Storage::disk('public')->delete($session->original_image_path);
$session->delete();
$this->status = "Session #{$sessionId} gelöscht";
$this->status = "Processing photo…";
}
public function render()
{
$sessions = PhotoSession::latest()->take(10)->get();
$recentPhotos = PhotoJob::latest()->take(10)->get()->map(fn($job) => [
'id' => $job->id,
'url' => Storage::disk('public')->url($job->image_path) . '?v=' . $job->updated_at->timestamp,
'status' => $job->status,
]);
foreach ($sessions as $session) {
$session->setRelation('jobs', $session->jobs()->with('setting')->orderBy('photo_setting_id')->get());
}
$hasProcessing = $recentPhotos->contains('status', 'processing');
$currentSession = $sessions->first();
$previousSessions = $sessions->skip(1);
$hasProcessing = $currentSession && $currentSession->jobs->contains('status', 'processing');
return view('livewire.camera-capture', compact('currentSession', 'previousSessions', 'hasProcessing'));
return view('livewire.camera-capture', compact('recentPhotos', 'hasProcessing'));
}
}
-75
View File
@@ -1,75 +0,0 @@
<?php
namespace App\Livewire;
use App\Models\PhotoSetting;
use Livewire\Component;
class PhotoSettings extends Component
{
public array $editingId = [];
public array $editName = [];
public array $editCommand = [];
public bool $showForm = false;
public string $newName = '';
public string $newCommand = '';
public function toggleActive(int $id): void
{
$setting = PhotoSetting::findOrFail($id);
$setting->update(['is_active' => !$setting->is_active]);
}
public function startEdit(int $id, string $name, string $command): void
{
$this->editingId = [$id => true];
$this->editName[$id] = $name;
$this->editCommand[$id] = $command;
}
public function saveEdit(int $id): void
{
PhotoSetting::findOrFail($id)->update([
'name' => trim($this->editName[$id] ?? ''),
'gmic_command' => trim($this->editCommand[$id] ?? ''),
]);
unset($this->editingId[$id]);
}
public function cancelEdit(int $id): void
{
unset($this->editingId[$id]);
}
public function addSetting(): void
{
$name = trim($this->newName);
$command = trim($this->newCommand);
if (!$name || !$command) return;
$max = PhotoSetting::max('sort_order') ?? 0;
PhotoSetting::create([
'name' => $name,
'gmic_command' => $command,
'sort_order' => $max + 1,
'is_active' => true,
]);
$this->newName = '';
$this->newCommand = '';
$this->showForm = false;
}
public function delete(int $id): void
{
PhotoSetting::findOrFail($id)->delete();
}
public function render()
{
return view('livewire.photo-settings', [
'settings' => PhotoSetting::orderBy('sort_order')->get(),
]);
}
}