'required|string|max:255|unique:device_models,name', 'label' => 'required|string|max:255', 'description' => 'required|string', 'width' => 'required|integer|min:1', 'height' => 'required|integer|min:1', 'colors' => 'required|integer|min:1', 'bit_depth' => 'required|integer|min:1', 'scale_factor' => 'required|numeric|min:0.1', 'rotation' => 'required|integer', 'mime_type' => 'required|string|max:255', 'offset_x' => 'required|integer', 'offset_y' => 'required|integer', 'published_at' => 'nullable|date', ]; public function mount() { $this->deviceModels = DeviceModel::all(); $this->devicePalettes = DevicePalette::all(); return view('livewire.device-models.index'); } public $editingDeviceModelId; public $viewingDeviceModelId; public function openDeviceModelModal(?string $deviceModelId = null, bool $viewOnly = false): void { if ($deviceModelId) { $deviceModel = DeviceModel::findOrFail($deviceModelId); if ($viewOnly) { $this->viewingDeviceModelId = $deviceModel->id; $this->editingDeviceModelId = null; } else { $this->editingDeviceModelId = $deviceModel->id; $this->viewingDeviceModelId = null; } $this->name = $deviceModel->name; $this->label = $deviceModel->label; $this->description = $deviceModel->description; $this->width = $deviceModel->width; $this->height = $deviceModel->height; $this->colors = $deviceModel->colors; $this->bit_depth = $deviceModel->bit_depth; $this->scale_factor = $deviceModel->scale_factor; $this->rotation = $deviceModel->rotation; $this->mime_type = $deviceModel->mime_type; $this->offset_x = $deviceModel->offset_x; $this->offset_y = $deviceModel->offset_y; $this->published_at = $deviceModel->published_at?->format('Y-m-d\TH:i'); $this->palette_id = $deviceModel->palette_id; } else { $this->editingDeviceModelId = null; $this->viewingDeviceModelId = null; $this->reset(['name', 'label', 'description', 'width', 'height', 'colors', 'bit_depth', 'scale_factor', 'rotation', 'mime_type', 'offset_x', 'offset_y', 'published_at', 'palette_id']); $this->mime_type = 'image/png'; $this->scale_factor = 1.0; $this->rotation = 0; $this->offset_x = 0; $this->offset_y = 0; } } public function saveDeviceModel(): void { $rules = [ 'name' => 'required|string|max:255', 'label' => 'required|string|max:255', 'description' => 'required|string', 'width' => 'required|integer|min:1', 'height' => 'required|integer|min:1', 'colors' => 'required|integer|min:1', 'bit_depth' => 'required|integer|min:1', 'scale_factor' => 'required|numeric|min:0.1', 'rotation' => 'required|integer', 'mime_type' => 'required|string|max:255', 'offset_x' => 'required|integer', 'offset_y' => 'required|integer', 'published_at' => 'nullable|date', 'palette_id' => 'nullable|exists:device_palettes,id', ]; if ($this->editingDeviceModelId) { $rules['name'] = 'required|string|max:255|unique:device_models,name,'.$this->editingDeviceModelId; } else { $rules['name'] = 'required|string|max:255|unique:device_models,name'; } $this->validate($rules); if ($this->editingDeviceModelId) { $deviceModel = DeviceModel::findOrFail($this->editingDeviceModelId); $deviceModel->update([ 'name' => $this->name, 'label' => $this->label, 'description' => $this->description, 'width' => $this->width, 'height' => $this->height, 'colors' => $this->colors, 'bit_depth' => $this->bit_depth, 'scale_factor' => $this->scale_factor, 'rotation' => $this->rotation, 'mime_type' => $this->mime_type, 'offset_x' => $this->offset_x, 'offset_y' => $this->offset_y, 'published_at' => $this->published_at, 'palette_id' => $this->palette_id ?: null, ]); $message = 'Device model updated successfully.'; } else { DeviceModel::create([ 'name' => $this->name, 'label' => $this->label, 'description' => $this->description, 'width' => $this->width, 'height' => $this->height, 'colors' => $this->colors, 'bit_depth' => $this->bit_depth, 'scale_factor' => $this->scale_factor, 'rotation' => $this->rotation, 'mime_type' => $this->mime_type, 'offset_x' => $this->offset_x, 'offset_y' => $this->offset_y, 'published_at' => $this->published_at, 'palette_id' => $this->palette_id ?: null, 'source' => 'manual', ]); $message = 'Device model created successfully.'; } $this->reset(['name', 'label', 'description', 'width', 'height', 'colors', 'bit_depth', 'scale_factor', 'rotation', 'mime_type', 'offset_x', 'offset_y', 'published_at', 'palette_id', 'editingDeviceModelId', 'viewingDeviceModelId']); Flux::modal('device-model-modal')->close(); $this->deviceModels = DeviceModel::all(); session()->flash('message', $message); } public function deleteDeviceModel(string $deviceModelId): void { $deviceModel = DeviceModel::findOrFail($deviceModelId); $deviceModel->delete(); $this->deviceModels = DeviceModel::all(); session()->flash('message', 'Device model deleted successfully.'); } public function duplicateDeviceModel(string $deviceModelId): void { $deviceModel = DeviceModel::findOrFail($deviceModelId); $this->editingDeviceModelId = null; $this->viewingDeviceModelId = null; $this->name = $deviceModel->name.' (Copy)'; $this->label = $deviceModel->label; $this->description = $deviceModel->description; $this->width = $deviceModel->width; $this->height = $deviceModel->height; $this->colors = $deviceModel->colors; $this->bit_depth = $deviceModel->bit_depth; $this->scale_factor = $deviceModel->scale_factor; $this->rotation = $deviceModel->rotation; $this->mime_type = $deviceModel->mime_type; $this->offset_x = $deviceModel->offset_x; $this->offset_y = $deviceModel->offset_y; $this->published_at = $deviceModel->published_at?->format('Y-m-d\TH:i'); $this->palette_id = $deviceModel->palette_id; $this->js('Flux.modal("device-model-modal").show()'); } } ?>

Device Models

Devices Device Palettes
Add Device Model
@if (session()->has('message'))
@endif
@if ($viewingDeviceModelId) View Device Model @elseif ($editingDeviceModelId) Edit Device Model @else Add Device Model @endif
image/png image/bmp
None @foreach ($devicePalettes as $palette) {{ $palette->description ?? $palette->name }} ({{ $palette->name }}) @endforeach
@if (!$viewingDeviceModelId)
{{ $editingDeviceModelId ? 'Update' : 'Create' }} Device Model
@else
Duplicate
@endif
@foreach ($deviceModels as $deviceModel) @endforeach
Description
Width
Height
Bit Depth
Actions
{{ $deviceModel->label }}
{{ Str::limit($deviceModel->name, 50) }}
{{ $deviceModel->width }} {{ $deviceModel->height }} {{ $deviceModel->bit_depth }}
@if ($deviceModel->source === 'api') @else @endif