2023-05-05 10:08:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Shared\Storages;
|
2023-05-05 10:08:38 +00:00
|
|
|
|
2023-09-22 09:23:49 +00:00
|
|
|
use App\Models\LocalPersistentVolume;
|
2025-08-26 08:27:31 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2023-05-05 10:08:38 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class Show extends Component
|
|
|
|
|
{
|
2025-08-26 08:27:31 +00:00
|
|
|
use AuthorizesRequests;
|
|
|
|
|
|
2023-09-22 09:23:49 +00:00
|
|
|
public LocalPersistentVolume $storage;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-08-26 08:27:31 +00:00
|
|
|
public $resource;
|
|
|
|
|
|
2023-09-22 09:23:49 +00:00
|
|
|
public bool $isReadOnly = false;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-10-03 06:48:07 +00:00
|
|
|
public bool $isFirst = true;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-27 13:11:00 +00:00
|
|
|
public bool $isService = false;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-27 13:11:00 +00:00
|
|
|
public ?string $startedAt = null;
|
2023-09-22 09:23:49 +00:00
|
|
|
|
2025-10-13 13:38:59 +00:00
|
|
|
// Explicit properties
|
|
|
|
|
public string $name;
|
|
|
|
|
|
|
|
|
|
public string $mountPath;
|
|
|
|
|
|
|
|
|
|
public ?string $hostPath = null;
|
|
|
|
|
|
2026-03-16 13:54:22 +00:00
|
|
|
public bool $isPreviewSuffixEnabled = true;
|
|
|
|
|
|
2023-05-05 10:08:38 +00:00
|
|
|
protected $rules = [
|
2025-10-13 13:38:59 +00:00
|
|
|
'name' => 'required|string',
|
|
|
|
|
'mountPath' => 'required|string',
|
|
|
|
|
'hostPath' => 'string|nullable',
|
2026-03-16 13:54:22 +00:00
|
|
|
'isPreviewSuffixEnabled' => 'required|boolean',
|
2023-05-05 10:08:38 +00:00
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-06-16 10:35:40 +00:00
|
|
|
protected $validationAttributes = [
|
|
|
|
|
'name' => 'name',
|
2025-10-13 13:38:59 +00:00
|
|
|
'mountPath' => 'mount',
|
|
|
|
|
'hostPath' => 'host',
|
2023-06-16 10:35:40 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2025-10-13 13:38:59 +00:00
|
|
|
/**
|
|
|
|
|
* Sync data between component properties and model
|
|
|
|
|
*
|
|
|
|
|
* @param bool $toModel If true, sync FROM properties TO model. If false, sync FROM model TO properties.
|
|
|
|
|
*/
|
|
|
|
|
private function syncData(bool $toModel = false): void
|
|
|
|
|
{
|
|
|
|
|
if ($toModel) {
|
|
|
|
|
// Sync TO model (before save)
|
|
|
|
|
$this->storage->name = $this->name;
|
|
|
|
|
$this->storage->mount_path = $this->mountPath;
|
|
|
|
|
$this->storage->host_path = $this->hostPath;
|
2026-03-16 13:54:22 +00:00
|
|
|
$this->storage->is_preview_suffix_enabled = $this->isPreviewSuffixEnabled;
|
2025-10-13 13:38:59 +00:00
|
|
|
} else {
|
|
|
|
|
// Sync FROM model (on load/refresh)
|
|
|
|
|
$this->name = $this->storage->name;
|
|
|
|
|
$this->mountPath = $this->storage->mount_path;
|
|
|
|
|
$this->hostPath = $this->storage->host_path;
|
2026-03-16 13:54:22 +00:00
|
|
|
$this->isPreviewSuffixEnabled = $this->storage->is_preview_suffix_enabled ?? true;
|
2025-10-13 13:38:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 14:39:57 +00:00
|
|
|
public function mount()
|
|
|
|
|
{
|
2025-10-13 13:38:59 +00:00
|
|
|
$this->syncData(false);
|
2025-12-11 20:25:33 +00:00
|
|
|
$this->isReadOnly = $this->storage->shouldBeReadOnlyInUI();
|
2025-10-03 14:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 20:10:00 +00:00
|
|
|
public function instantSave(): void
|
2026-03-16 13:54:22 +00:00
|
|
|
{
|
|
|
|
|
$this->authorize('update', $this->resource);
|
2026-03-16 20:10:00 +00:00
|
|
|
$this->validate();
|
2026-03-16 13:54:22 +00:00
|
|
|
|
|
|
|
|
$this->syncData(true);
|
|
|
|
|
$this->storage->save();
|
|
|
|
|
$this->dispatch('success', 'Storage updated successfully');
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 10:08:38 +00:00
|
|
|
public function submit()
|
|
|
|
|
{
|
2025-08-26 08:27:31 +00:00
|
|
|
$this->authorize('update', $this->resource);
|
|
|
|
|
|
2023-05-05 10:08:38 +00:00
|
|
|
$this->validate();
|
2025-10-13 13:38:59 +00:00
|
|
|
$this->syncData(true);
|
2023-05-05 10:08:38 +00:00
|
|
|
$this->storage->save();
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('success', 'Storage updated successfully');
|
2023-05-05 10:08:38 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2026-03-11 14:04:45 +00:00
|
|
|
public function delete($password, $selectedActions = [])
|
2023-05-05 10:08:38 +00:00
|
|
|
{
|
2025-08-26 08:27:31 +00:00
|
|
|
$this->authorize('update', $this->resource);
|
|
|
|
|
|
2025-12-12 13:12:02 +00:00
|
|
|
if (! verifyPasswordConfirmation($password, $this)) {
|
2026-03-11 14:04:45 +00:00
|
|
|
return 'The provided password is incorrect.';
|
2024-09-04 20:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-05 10:08:38 +00:00
|
|
|
$this->storage->delete();
|
2024-08-05 18:00:57 +00:00
|
|
|
$this->dispatch('refreshStorages');
|
2026-03-11 14:04:45 +00:00
|
|
|
|
|
|
|
|
return true;
|
2023-05-05 10:08:38 +00:00
|
|
|
}
|
|
|
|
|
}
|