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,344 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Organization;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public Organization $organization;
|
||||
|
||||
public string $newLogCategory = 'info';
|
||||
public string $newLogNote = '';
|
||||
|
||||
public int $activityPage = 1;
|
||||
|
||||
const ACTIVITY_PER_PAGE = 4;
|
||||
|
||||
public function addLogEntry(): void
|
||||
{
|
||||
$this->validate([
|
||||
'newLogCategory' => 'required|in:'.implode(',', array_keys(\App\Models\OrganizationLogEntry::CATEGORIES)),
|
||||
'newLogNote' => 'required|string',
|
||||
]);
|
||||
|
||||
$this->organization->logEntries()->create([
|
||||
'category' => $this->newLogCategory,
|
||||
'note' => $this->newLogNote,
|
||||
'created_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
$this->newLogNote = '';
|
||||
}
|
||||
|
||||
public function deleteLogEntry(int $entryId): void
|
||||
{
|
||||
$this->organization->logEntries()->findOrFail($entryId)->delete();
|
||||
}
|
||||
|
||||
public function toggleTodoDone(int $todoId): void
|
||||
{
|
||||
$todo = $this->organization->todos()->findOrFail($todoId);
|
||||
$todo->update([
|
||||
'is_done' => ! $todo->is_done,
|
||||
'completed_at' => $todo->is_done ? null : now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function previousActivityPage(): void
|
||||
{
|
||||
$this->activityPage = max(1, $this->activityPage - 1);
|
||||
}
|
||||
|
||||
public function nextActivityPage(): void
|
||||
{
|
||||
$this->activityPage++;
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
$expiringDomains = $this->organization->domains()
|
||||
->get()
|
||||
->filter(fn ($domain) => in_array($domain->expiryStatus(), ['soon', 'expired'], true))
|
||||
->sortBy(fn ($domain) => $domain->expiresInDays());
|
||||
|
||||
$recentDocuments = $this->organization->documents()
|
||||
->with('creator')
|
||||
->where('is_folder', false)
|
||||
->orderByDesc('updated_at')
|
||||
->limit(20)
|
||||
->get()
|
||||
->map(fn ($doc) => [
|
||||
'icon' => $doc->isOffice() ? ($doc->office_extension === 'xlsx' ? '📊' : '📘') : ($doc->isMarkdown() ? '📝' : '📄'),
|
||||
'label' => $doc->name,
|
||||
'kind' => 'Document',
|
||||
'url' => route('organizations.documents.edit', [$this->organization, $doc]),
|
||||
'creator' => $doc->creator?->name,
|
||||
'created' => $doc->created_at->equalTo($doc->updated_at),
|
||||
'at' => $doc->updated_at,
|
||||
]);
|
||||
|
||||
$recentAssets = $this->organization->flexibleAssets()
|
||||
->with(['type', 'creator'])
|
||||
->orderByDesc('updated_at')
|
||||
->limit(20)
|
||||
->get()
|
||||
->map(fn ($asset) => [
|
||||
'icon' => $asset->type?->icon ?: '🗂️',
|
||||
'label' => $asset->name,
|
||||
'kind' => $asset->type?->name ?? 'Actif',
|
||||
'url' => route('organizations.assets.edit', [$this->organization, $asset->type, $asset]),
|
||||
'creator' => $asset->creator?->name,
|
||||
'created' => $asset->created_at->equalTo($asset->updated_at),
|
||||
'at' => $asset->updated_at,
|
||||
]);
|
||||
|
||||
$recentVirtualMachines = $this->organization->virtualMachines()
|
||||
->with('creator')
|
||||
->orderByDesc('updated_at')
|
||||
->limit(20)
|
||||
->get()
|
||||
->map(fn ($vm) => [
|
||||
'icon' => '🖥️',
|
||||
'label' => $vm->name,
|
||||
'kind' => 'Machine virtuelle',
|
||||
'url' => route('organizations.virtual-machines.edit', [$this->organization, $vm]),
|
||||
'creator' => $vm->creator?->name,
|
||||
'created' => $vm->created_at->equalTo($vm->updated_at),
|
||||
'at' => $vm->updated_at,
|
||||
]);
|
||||
|
||||
$allActivity = $recentDocuments
|
||||
->concat($recentAssets)
|
||||
->concat($recentVirtualMachines)
|
||||
->sortByDesc('at')
|
||||
->values();
|
||||
|
||||
$activityPageCount = max(1, (int) ceil($allActivity->count() / self::ACTIVITY_PER_PAGE));
|
||||
$this->activityPage = min($this->activityPage, $activityPageCount);
|
||||
|
||||
$recentActivity = $allActivity->forPage($this->activityPage, self::ACTIVITY_PER_PAGE)->values();
|
||||
|
||||
$openTodos = $this->organization->todos()
|
||||
->with('assignee')
|
||||
->where('is_done', false)
|
||||
->orderByRaw("CASE criticality WHEN 'urgent' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 ELSE 3 END")
|
||||
->orderByRaw('due_date IS NULL')
|
||||
->orderBy('due_date')
|
||||
->limit(8)
|
||||
->get();
|
||||
|
||||
return [
|
||||
'counts' => [
|
||||
'contacts' => $this->organization->contacts()->count(),
|
||||
'locations' => $this->organization->locations()->count(),
|
||||
'domains' => $this->organization->domains()->count(),
|
||||
'documents' => $this->organization->documents()->where('is_folder', false)->count(),
|
||||
'virtualMachines' => $this->organization->virtualMachines()->count(),
|
||||
'assets' => $this->organization->flexibleAssets()->count(),
|
||||
'openTodos' => $this->organization->todos()->where('is_done', false)->count(),
|
||||
],
|
||||
'expiringDomains' => $expiringDomains,
|
||||
'recentActivity' => $recentActivity,
|
||||
'activityPageCount' => $activityPageCount,
|
||||
'openTodos' => $openTodos,
|
||||
'logEntries' => $this->organization->logEntries()->with('creator')->limit(20)->get(),
|
||||
'categories' => \App\Models\OrganizationLogEntry::CATEGORIES,
|
||||
];
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div>
|
||||
<div class="mb-6 flex items-start justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-slate-500">Tableau de bord</p>
|
||||
<h1 class="text-2xl font-semibold text-slate-900">{{ $organization->name }}</h1>
|
||||
</div>
|
||||
<img src="{{ $organization->logo_url }}" alt="Logo {{ $organization->name }}"
|
||||
class="h-20 w-20 shrink-0 rounded border border-slate-200 bg-white object-contain p-1">
|
||||
</div>
|
||||
|
||||
<div class="mb-6 flex divide-x divide-slate-200 overflow-x-auto rounded border border-slate-200 bg-white">
|
||||
<a href="{{ route('organizations.contacts.index', $organization) }}" class="flex flex-1 items-baseline gap-2 whitespace-nowrap px-4 py-3 hover:bg-slate-50">
|
||||
<span class="text-lg font-semibold text-slate-900">{{ $counts['contacts'] }}</span>
|
||||
<span class="text-xs text-slate-500">Contacts</span>
|
||||
</a>
|
||||
<a href="{{ route('organizations.locations.index', $organization) }}" class="flex flex-1 items-baseline gap-2 whitespace-nowrap px-4 py-3 hover:bg-slate-50">
|
||||
<span class="text-lg font-semibold text-slate-900">{{ $counts['locations'] }}</span>
|
||||
<span class="text-xs text-slate-500">Sites</span>
|
||||
</a>
|
||||
<a href="{{ route('organizations.domains.index', $organization) }}" class="flex flex-1 items-baseline gap-2 whitespace-nowrap px-4 py-3 hover:bg-slate-50">
|
||||
<span class="text-lg font-semibold text-slate-900">{{ $counts['domains'] }}</span>
|
||||
<span class="text-xs text-slate-500">Domaines</span>
|
||||
</a>
|
||||
<a href="{{ route('organizations.documents.index', $organization) }}" class="flex flex-1 items-baseline gap-2 whitespace-nowrap px-4 py-3 hover:bg-slate-50">
|
||||
<span class="text-lg font-semibold text-slate-900">{{ $counts['documents'] }}</span>
|
||||
<span class="text-xs text-slate-500">Documents</span>
|
||||
</a>
|
||||
<a href="{{ route('organizations.virtual-machines.index', $organization) }}" class="flex flex-1 items-baseline gap-2 whitespace-nowrap px-4 py-3 hover:bg-slate-50">
|
||||
<span class="text-lg font-semibold text-slate-900">{{ $counts['virtualMachines'] }}</span>
|
||||
<span class="text-xs text-slate-500">Machines virtuelles</span>
|
||||
</a>
|
||||
<a href="{{ route('organizations.assets.picker', $organization) }}" class="flex flex-1 items-baseline gap-2 whitespace-nowrap px-4 py-3 hover:bg-slate-50">
|
||||
<span class="text-lg font-semibold text-slate-900">{{ $counts['assets'] }}</span>
|
||||
<span class="text-xs text-slate-500">Actifs</span>
|
||||
</a>
|
||||
<a href="{{ route('organizations.todos.index', $organization) }}" class="flex flex-1 items-baseline gap-2 whitespace-nowrap px-4 py-3 hover:bg-slate-50">
|
||||
<span class="text-lg font-semibold text-slate-900">{{ $counts['openTodos'] }}</span>
|
||||
<span class="text-xs text-slate-500">Tâches ouvertes</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="mb-6 grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||
<div class="rounded border border-slate-200 bg-white p-4">
|
||||
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Domaines à surveiller</h2>
|
||||
@if ($expiringDomains->isEmpty())
|
||||
<p class="text-sm text-slate-400">Aucun domaine à surveiller.</p>
|
||||
@else
|
||||
<ul class="space-y-2">
|
||||
@foreach ($expiringDomains as $domain)
|
||||
<li class="flex items-center justify-between text-sm">
|
||||
<a href="{{ route('organizations.domains.edit', [$organization, $domain]) }}" class="text-slate-900 hover:underline">
|
||||
{{ $domain->name }}
|
||||
</a>
|
||||
<span class="rounded-full px-2 py-0.5 text-xs font-medium
|
||||
{{ $domain->expiryStatus() === 'expired' ? 'bg-red-100 text-red-700' : 'bg-amber-100 text-amber-700' }}">
|
||||
{{ $domain->expiryStatus() === 'expired' ? 'Expiré' : 'Expire dans '.$domain->expiresInDays().' j' }}
|
||||
</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="rounded border border-slate-200 bg-white p-4">
|
||||
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Activité récente</h2>
|
||||
<ul class="space-y-2.5 text-sm">
|
||||
@forelse ($recentActivity as $activity)
|
||||
<li>
|
||||
<div class="flex items-center justify-between">
|
||||
<a href="{{ $activity['url'] }}" class="text-slate-900 hover:underline">
|
||||
{{ $activity['icon'] }} {{ $activity['label'] }}
|
||||
</a>
|
||||
<span class="shrink-0 text-slate-400">{{ $activity['at']->diffForHumans() }}</span>
|
||||
</div>
|
||||
<p class="text-xs text-slate-500">
|
||||
{{ $activity['kind'] }} {{ $activity['created'] ? 'créé' : 'modifié' }}
|
||||
@if ($activity['creator'])
|
||||
par {{ $activity['creator'] }}
|
||||
@endif
|
||||
</p>
|
||||
</li>
|
||||
@empty
|
||||
<li class="text-slate-400">Aucune activité récente.</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
|
||||
@if ($activityPageCount > 1)
|
||||
<div class="mt-3 flex items-center justify-between border-t border-slate-100 pt-3 text-xs text-slate-500">
|
||||
<button type="button" wire:click="previousActivityPage" @disabled($activityPage <= 1)
|
||||
class="text-slate-600 hover:text-slate-900 disabled:cursor-not-allowed disabled:text-slate-300 disabled:hover:text-slate-300">
|
||||
← Précédent
|
||||
</button>
|
||||
<span>Page {{ $activityPage }} / {{ $activityPageCount }}</span>
|
||||
<button type="button" wire:click="nextActivityPage" @disabled($activityPage >= $activityPageCount)
|
||||
class="text-slate-600 hover:text-slate-900 disabled:cursor-not-allowed disabled:text-slate-300 disabled:hover:text-slate-300">
|
||||
Suivant →
|
||||
</button>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||
<div class="rounded border border-slate-200 bg-white p-4">
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<h2 class="text-sm font-semibold uppercase tracking-wide text-slate-500">Tâches ouvertes</h2>
|
||||
<a href="{{ route('organizations.todos.index', $organization) }}" class="text-xs text-slate-500 hover:text-slate-900">
|
||||
Voir toutes les tâches →
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="divide-y divide-slate-100">
|
||||
@forelse ($openTodos as $todo)
|
||||
<li wire:key="dash-todo-{{ $todo->id }}" class="flex items-center justify-between gap-4 py-2 text-sm">
|
||||
<div class="flex items-center gap-3">
|
||||
<input type="checkbox" wire:click="toggleTodoDone({{ $todo->id }})"
|
||||
class="rounded border-slate-300">
|
||||
<div>
|
||||
<a href="{{ route('organizations.todos.edit', [$organization, $todo]) }}" class="font-medium text-slate-900 hover:underline">
|
||||
{{ $todo->title }}
|
||||
</a>
|
||||
<p class="text-xs text-slate-500">
|
||||
{{ $todo->categoryLabel() }}
|
||||
@if ($todo->assignee)
|
||||
· {{ $todo->assignee->name }}
|
||||
@endif
|
||||
@if ($todo->due_date)
|
||||
· <span class="{{ $todo->isOverdue() ? 'font-medium text-red-600' : '' }}">{{ $todo->due_date->format('d/m/Y') }}</span>
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<span class="shrink-0 rounded-full px-2 py-0.5 text-xs font-medium
|
||||
{{ match($todo->criticality) {
|
||||
'urgent' => 'bg-red-100 text-red-700',
|
||||
'high' => 'bg-amber-100 text-amber-700',
|
||||
'medium' => 'bg-blue-100 text-blue-700',
|
||||
default => 'bg-slate-100 text-slate-600',
|
||||
} }}">
|
||||
{{ $todo->criticalityLabel() }}
|
||||
</span>
|
||||
</li>
|
||||
@empty
|
||||
<li class="py-2 text-sm text-slate-400">Aucune tâche ouverte.</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="rounded border border-slate-200 bg-white p-4">
|
||||
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Journal de bord</h2>
|
||||
|
||||
<form wire:submit="addLogEntry" class="mb-4 space-y-2 rounded border border-slate-100 bg-slate-50 p-3">
|
||||
<div class="flex items-start gap-2">
|
||||
<select wire:model="newLogCategory" class="rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@foreach ($categories as $value => $label)
|
||||
<option value="{{ $value }}">{{ $label }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<textarea wire:model="newLogNote" rows="2" placeholder="Projet en cours, point d'attention, intervention prévue..."
|
||||
class="flex-1 rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
||||
<button type="submit" class="rounded bg-slate-900 px-3 py-1.5 text-sm text-white hover:bg-slate-700">Ajouter</button>
|
||||
</div>
|
||||
@error('newLogNote') <p class="text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</form>
|
||||
|
||||
<div class="space-y-3">
|
||||
@forelse ($logEntries as $entry)
|
||||
<div wire:key="log-{{ $entry->id }}" class="flex items-start justify-between gap-4 border-b border-slate-100 pb-3 last:border-0 last:pb-0">
|
||||
<div>
|
||||
<span class="mb-1 inline-block rounded-full px-2 py-0.5 text-xs font-medium
|
||||
{{ match($entry->category) {
|
||||
'project' => 'bg-blue-100 text-blue-700',
|
||||
'attention' => 'bg-amber-100 text-amber-700',
|
||||
'intervention' => 'bg-purple-100 text-purple-700',
|
||||
default => 'bg-slate-100 text-slate-600',
|
||||
} }}">
|
||||
{{ $entry->categoryLabel() }}
|
||||
</span>
|
||||
<p class="whitespace-pre-line text-sm text-slate-900">{{ $entry->note }}</p>
|
||||
<p class="mt-1 text-xs text-slate-500">{{ $entry->creator?->name ?? 'système' }} · {{ $entry->created_at->diffForHumans() }}</p>
|
||||
</div>
|
||||
<button type="button" wire:click="deleteLogEntry({{ $entry->id }})"
|
||||
wire:confirm="Supprimer cette entrée ?"
|
||||
class="shrink-0 text-xs text-red-500 hover:text-red-700">
|
||||
Supprimer
|
||||
</button>
|
||||
</div>
|
||||
@empty
|
||||
<p class="text-sm text-slate-400">Aucune entrée dans le journal pour le moment.</p>
|
||||
@endforelse
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user