Initial commit: CABM-IT (ItGlue-style MSP documentation platform)
Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
use App\Models\FlexibleAsset;
|
||||
use App\Models\FlexibleAssetType;
|
||||
use App\Models\Organization;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public Organization $organization;
|
||||
public FlexibleAssetType $type;
|
||||
|
||||
#[Url]
|
||||
public string $search = '';
|
||||
|
||||
public function delete(int $assetId): void
|
||||
{
|
||||
$asset = $this->organization->flexibleAssets()->findOrFail($assetId);
|
||||
$asset->delete();
|
||||
|
||||
session()->flash('status', "\"{$asset->name}\" supprimé.");
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
$listFields = $this->type->fields()->where('show_in_list', true)->get();
|
||||
|
||||
return [
|
||||
'listFields' => $listFields,
|
||||
'assets' => $this->organization->flexibleAssets()
|
||||
->where('flexible_asset_type_id', $this->type->id)
|
||||
->when($this->search, fn ($query) => $query->where('name', 'like', "%{$this->search}%"))
|
||||
->orderBy('name')
|
||||
->paginate(15),
|
||||
];
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div>
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="text-2xl font-semibold text-slate-900">{{ $type->name }}</h1>
|
||||
</div>
|
||||
<a href="{{ route('organizations.assets.create', [$organization, $type]) }}"
|
||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||
+ Nouveau {{ $type->name }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<input type="text" wire:model.live.debounce.300ms="search" placeholder="Filtrer par nom..."
|
||||
class="mb-4 w-full max-w-sm rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
|
||||
<div class="overflow-x-auto rounded border border-slate-200 bg-white">
|
||||
<table class="min-w-full divide-y divide-slate-200 text-sm">
|
||||
<thead class="bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500">
|
||||
<tr>
|
||||
<th class="px-4 py-3">Nom</th>
|
||||
@foreach ($listFields as $field)
|
||||
<th class="px-4 py-3">{{ $field->label }}</th>
|
||||
@endforeach
|
||||
<th class="px-4 py-3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-100">
|
||||
@forelse ($assets as $asset)
|
||||
<tr wire:key="asset-{{ $asset->id }}">
|
||||
<td class="px-4 py-3">
|
||||
<a href="{{ route('organizations.assets.edit', [$organization, $type, $asset]) }}"
|
||||
class="font-medium text-slate-900 hover:underline">
|
||||
{{ $asset->name }}
|
||||
</a>
|
||||
</td>
|
||||
@foreach ($listFields as $field)
|
||||
<td class="px-4 py-3 text-slate-600">
|
||||
@php $value = $asset->data[$field->name] ?? null; @endphp
|
||||
@if ($field->field_type === 'password')
|
||||
<span class="tracking-widest text-slate-400">••••••••</span>
|
||||
@elseif ($field->field_type === 'checkbox')
|
||||
{{ $value ? 'Oui' : 'Non' }}
|
||||
@elseif ($field->field_type === 'related_asset')
|
||||
{{ $value ? ($field->relatedOptions($organization)->firstWhere('id', (int) $value)['label'] ?? '—') : '—' }}
|
||||
@elseif (is_array($value))
|
||||
{{ implode(', ', $value) }}
|
||||
@else
|
||||
{{ $value ?? '—' }}
|
||||
@endif
|
||||
</td>
|
||||
@endforeach
|
||||
<td class="px-4 py-3 text-right whitespace-nowrap">
|
||||
<a href="{{ route('organizations.assets.edit', [$organization, $type, $asset]) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
|
||||
<button type="button"
|
||||
wire:click="delete({{ $asset->id }})"
|
||||
wire:confirm="Supprimer cet actif ? Cette action est irréversible."
|
||||
class="ml-3 text-red-500 hover:text-red-700">
|
||||
Supprimer
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="{{ $listFields->count() + 2 }}" class="px-4 py-6 text-center text-slate-400">Aucun enregistrement pour le moment.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
{{ $assets->links() }}
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user