Primo commit

This commit is contained in:
Francesco Picone
2026-04-05 19:26:04 +02:00
commit 701f479b7f
135 changed files with 21445 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Livewire\Proclamatori;
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Proclamatore;
class ProclamatoreCestino extends Component
{
use WithPagination;
public function restore(int $id)
{
$proclamatore = Proclamatore::onlyTrashed()->findOrFail($id);
$proclamatore->restore();
activity()->causedBy(auth()->user())
->performedOn($proclamatore)
->log('restored');
session()->flash('success', "Proclamatore ripristinato.");
}
public function forceDelete(int $id)
{
$proclamatore = Proclamatore::onlyTrashed()->findOrFail($id);
if ($proclamatore->assegnazioni()->exists()) {
session()->flash('error', 'Impossibile eliminare definitivamente: il proclamatore ha assegnazioni nello storico.');
return;
}
activity()->causedBy(auth()->user())
->log('force_deleted_proclamatore');
$proclamatore->forceDelete();
session()->flash('success', 'Proclamatore eliminato definitivamente.');
}
public function render()
{
return view('livewire.proclamatori.proclamatore-cestino', [
'proclamatori' => Proclamatore::onlyTrashed()->orderByDesc('deleted_at')->paginate(20),
]);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Livewire\Proclamatori;
use Livewire\Component;
use App\Models\Proclamatore;
class ProclamatoreCreate extends Component
{
public string $nome = '';
public string $cognome = '';
public bool $attivo = true;
protected function rules(): array
{
return [
'nome' => 'required|string|max:100',
'cognome' => 'required|string|max:100',
'attivo' => 'boolean',
];
}
public function save()
{
$this->validate();
$proclamatore = Proclamatore::create([
'nome' => $this->nome,
'cognome' => $this->cognome,
'attivo' => $this->attivo,
]);
activity()->causedBy(auth()->user())
->performedOn($proclamatore)
->log('created');
session()->flash('success', "Proclamatore {$proclamatore->nome_completo} creato.");
return $this->redirect(route('proclamatori.index'), navigate: true);
}
public function render()
{
return view('livewire.proclamatori.proclamatore-form', [
'titolo' => 'Nuovo Proclamatore',
'btnLabel' => 'Crea Proclamatore',
]);
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Livewire\Proclamatori;
use Livewire\Component;
use App\Models\Proclamatore;
class ProclamatoreEdit extends Component
{
public Proclamatore $proclamatore;
public string $nome = '';
public string $cognome = '';
public bool $attivo = true;
public function mount(Proclamatore $proclamatore)
{
$this->proclamatore = $proclamatore;
$this->nome = $proclamatore->nome;
$this->cognome = $proclamatore->cognome;
$this->attivo = $proclamatore->attivo;
}
protected function rules(): array
{
return [
'nome' => 'required|string|max:100',
'cognome' => 'required|string|max:100',
'attivo' => 'boolean',
];
}
public function save()
{
$this->validate();
$this->proclamatore->update([
'nome' => $this->nome,
'cognome' => $this->cognome,
'attivo' => $this->attivo,
]);
session()->flash('success', "Proclamatore {$this->proclamatore->nome_completo} aggiornato.");
return $this->redirect(route('proclamatori.index'), navigate: true);
}
public function render()
{
return view('livewire.proclamatori.proclamatore-form', [
'titolo' => "Modifica {$this->proclamatore->nome_completo}",
'btnLabel' => 'Salva Modifiche',
]);
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace App\Livewire\Proclamatori;
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Proclamatore;
class ProclamatoreIndex extends Component
{
use WithPagination;
public string $search = '';
public string $filtroStato = '';
public string $sortField = 'cognome';
public string $sortDirection = 'asc';
protected $queryString = [
'search' => ['except' => ''],
'filtroStato' => ['except' => ''],
];
public function updatingSearch()
{
$this->resetPage();
}
public function updatingFiltroStato()
{
$this->resetPage();
}
public function sortBy(string $field)
{
if ($this->sortField === $field) {
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
} else {
$this->sortField = $field;
$this->sortDirection = 'asc';
}
}
public function toggleActive(int $id)
{
$proclamatore = Proclamatore::findOrFail($id);
$proclamatore->update(['attivo' => !$proclamatore->attivo]);
}
public function deleteProclamatore(int $id)
{
$proclamatore = Proclamatore::findOrFail($id);
if ($proclamatore->assegnazioni()->aperte()->exists()) {
session()->flash('error', "Il proclamatore {$proclamatore->nome_completo} ha assegnazioni aperte. Rientra prima i territori.");
return;
}
$proclamatore->delete();
session()->flash('success', "Proclamatore {$proclamatore->nome_completo} spostato nel cestino.");
}
public function anonimizza(int $id)
{
$proclamatore = Proclamatore::findOrFail($id);
$proclamatore->anonimizza();
session()->flash('success', "Dati personali del proclamatore anonimizzati (GDPR).");
}
public function render()
{
$query = Proclamatore::query();
if ($this->search !== '') {
// In-memory filter because nome/cognome are encrypted
$all = $query->get();
$filtered = $all->filter(function ($p) {
return str_contains(
mb_strtolower($p->nome . ' ' . $p->cognome),
mb_strtolower($this->search)
);
});
if ($this->filtroStato === 'attivo') {
$filtered = $filtered->where('attivo', true);
} elseif ($this->filtroStato === 'inattivo') {
$filtered = $filtered->where('attivo', false);
}
// Sort in-memory
$filtered = $filtered->sortBy(function ($p) {
return match ($this->sortField) {
'nome' => mb_strtolower($p->nome),
'cognome' => mb_strtolower($p->cognome),
default => mb_strtolower($p->cognome),
};
}, SORT_REGULAR, $this->sortDirection === 'desc');
// Manual pagination
$page = $this->getPage();
$perPage = 20;
$items = $filtered->slice(($page - 1) * $perPage, $perPage)->values();
$proclamatori = new \Illuminate\Pagination\LengthAwarePaginator(
$items, $filtered->count(), $perPage, $page,
['path' => request()->url()]
);
} else {
if ($this->filtroStato === 'attivo') {
$query->where('attivo', true);
} elseif ($this->filtroStato === 'inattivo') {
$query->where('attivo', false);
}
// cognome/nome encrypted, so sort in-memory
$all = $query->get()->sortBy(function ($p) {
return match ($this->sortField) {
'nome' => mb_strtolower($p->nome),
'cognome' => mb_strtolower($p->cognome),
default => mb_strtolower($p->cognome),
};
}, SORT_REGULAR, $this->sortDirection === 'desc');
$page = $this->getPage();
$perPage = 20;
$items = $all->slice(($page - 1) * $perPage, $perPage)->values();
$proclamatori = new \Illuminate\Pagination\LengthAwarePaginator(
$items, $all->count(), $perPage, $page,
['path' => request()->url()]
);
}
return view('livewire.proclamatori.proclamatore-index', [
'proclamatori' => $proclamatori,
]);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Livewire\Proclamatori;
use Livewire\Component;
use App\Models\Proclamatore;
use App\Models\Assegnazione;
class ProclamatoreShow extends Component
{
public Proclamatore $proclamatore;
public function mount(Proclamatore $proclamatore)
{
$this->proclamatore = $proclamatore;
}
public function render()
{
$assegnazioni = Assegnazione::where('proclamatore_id', $this->proclamatore->id)
->with(['territorio', 'annoTeocratico', 'campagna'])
->orderByDesc('assigned_at')
->get()
->groupBy(fn($a) => $a->annoTeocratico->label);
$stats = [
'totale_assegnazioni' => Assegnazione::where('proclamatore_id', $this->proclamatore->id)->count(),
'attualmente_assegnati' => Assegnazione::where('proclamatore_id', $this->proclamatore->id)->aperte()->count(),
'media_giorni' => round(
Assegnazione::where('proclamatore_id', $this->proclamatore->id)
->chiuse()
->get()
->avg(fn($a) => $a->giorni) ?? 0
),
];
return view('livewire.proclamatori.proclamatore-show', [
'assegnazioniPerAnno' => $assegnazioni,
'stats' => $stats,
]);
}
}