Primo commit
This commit is contained in:
53
app/Livewire/Settings/SettingsEdit.php
Normal file
53
app/Livewire/Settings/SettingsEdit.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Settings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Setting;
|
||||
|
||||
class SettingsEdit extends Component
|
||||
{
|
||||
public string $congregazione_nome = '';
|
||||
public int $giorni_giacenza_prioritari = 180;
|
||||
public int $giorni_per_smarrito = 120;
|
||||
public int $audit_retention_days = 365;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$settings = Setting::instance();
|
||||
$this->congregazione_nome = $settings->congregazione_nome ?? '';
|
||||
$this->giorni_giacenza_prioritari = $settings->giorni_giacenza_prioritari ?? 180;
|
||||
$this->giorni_per_smarrito = $settings->giorni_per_smarrito ?? 120;
|
||||
$this->audit_retention_days = $settings->audit_retention_days ?? 365;
|
||||
}
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'congregazione_nome' => 'required|string|max:255',
|
||||
'giorni_giacenza_prioritari' => 'required|integer|min:1|max:730',
|
||||
'giorni_per_smarrito' => 'required|integer|min:30|max:365',
|
||||
'audit_retention_days' => 'required|integer|min:30|max:3650',
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$settings = Setting::instance();
|
||||
$settings->update([
|
||||
'congregazione_nome' => $this->congregazione_nome,
|
||||
'giorni_giacenza_prioritari' => $this->giorni_giacenza_prioritari,
|
||||
'giorni_per_smarrito' => $this->giorni_per_smarrito,
|
||||
'audit_retention_days' => $this->audit_retention_days,
|
||||
]);
|
||||
|
||||
session()->flash('success', 'Impostazioni aggiornate.');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.settings.settings-edit');
|
||||
}
|
||||
}
|
||||
68
app/Livewire/Settings/TipologieIndex.php
Normal file
68
app/Livewire/Settings/TipologieIndex.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Settings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Tipologia;
|
||||
|
||||
class TipologieIndex extends Component
|
||||
{
|
||||
public string $nuovaTipologia = '';
|
||||
public ?int $editingId = null;
|
||||
public string $editingNome = '';
|
||||
|
||||
public function addTipologia()
|
||||
{
|
||||
$this->validate(['nuovaTipologia' => 'required|string|max:100|unique:tipologie,nome']);
|
||||
Tipologia::create(['nome' => $this->nuovaTipologia, 'attivo' => true]);
|
||||
$this->nuovaTipologia = '';
|
||||
session()->flash('success', 'Tipologia aggiunta.');
|
||||
}
|
||||
|
||||
public function startEdit(int $id)
|
||||
{
|
||||
$tipo = Tipologia::findOrFail($id);
|
||||
$this->editingId = $id;
|
||||
$this->editingNome = $tipo->nome;
|
||||
}
|
||||
|
||||
public function saveEdit()
|
||||
{
|
||||
$this->validate(['editingNome' => "required|string|max:100|unique:tipologie,nome,{$this->editingId}"]);
|
||||
$tipo = Tipologia::findOrFail($this->editingId);
|
||||
$tipo->update(['nome' => $this->editingNome]);
|
||||
$this->editingId = null;
|
||||
$this->editingNome = '';
|
||||
session()->flash('success', 'Tipologia aggiornata.');
|
||||
}
|
||||
|
||||
public function cancelEdit()
|
||||
{
|
||||
$this->editingId = null;
|
||||
$this->editingNome = '';
|
||||
}
|
||||
|
||||
public function toggleActive(int $id)
|
||||
{
|
||||
$tipo = Tipologia::findOrFail($id);
|
||||
$tipo->update(['attivo' => !$tipo->attivo]);
|
||||
}
|
||||
|
||||
public function deleteTipologia(int $id)
|
||||
{
|
||||
$tipo = Tipologia::findOrFail($id);
|
||||
if ($tipo->territori()->exists()) {
|
||||
session()->flash('error', "Impossibile eliminare: la tipologia '{$tipo->nome}' ha territori associati.");
|
||||
return;
|
||||
}
|
||||
$tipo->delete();
|
||||
session()->flash('success', "Tipologia '{$tipo->nome}' eliminata.");
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.settings.tipologie-index', [
|
||||
'tipologie' => Tipologia::orderBy('nome')->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
68
app/Livewire/Settings/ZoneIndex.php
Normal file
68
app/Livewire/Settings/ZoneIndex.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Settings;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Zona;
|
||||
|
||||
class ZoneIndex extends Component
|
||||
{
|
||||
public string $nuovaZona = '';
|
||||
public ?int $editingId = null;
|
||||
public string $editingNome = '';
|
||||
|
||||
public function addZona()
|
||||
{
|
||||
$this->validate(['nuovaZona' => 'required|string|max:100|unique:zone,nome']);
|
||||
Zona::create(['nome' => $this->nuovaZona, 'attivo' => true]);
|
||||
$this->nuovaZona = '';
|
||||
session()->flash('success', 'Zona aggiunta.');
|
||||
}
|
||||
|
||||
public function startEdit(int $id)
|
||||
{
|
||||
$zona = Zona::findOrFail($id);
|
||||
$this->editingId = $id;
|
||||
$this->editingNome = $zona->nome;
|
||||
}
|
||||
|
||||
public function saveEdit()
|
||||
{
|
||||
$this->validate(['editingNome' => "required|string|max:100|unique:zone,nome,{$this->editingId}"]);
|
||||
$zona = Zona::findOrFail($this->editingId);
|
||||
$zona->update(['nome' => $this->editingNome]);
|
||||
$this->editingId = null;
|
||||
$this->editingNome = '';
|
||||
session()->flash('success', 'Zona aggiornata.');
|
||||
}
|
||||
|
||||
public function cancelEdit()
|
||||
{
|
||||
$this->editingId = null;
|
||||
$this->editingNome = '';
|
||||
}
|
||||
|
||||
public function toggleActive(int $id)
|
||||
{
|
||||
$zona = Zona::findOrFail($id);
|
||||
$zona->update(['attivo' => !$zona->attivo]);
|
||||
}
|
||||
|
||||
public function deleteZona(int $id)
|
||||
{
|
||||
$zona = Zona::findOrFail($id);
|
||||
if ($zona->territori()->exists()) {
|
||||
session()->flash('error', "Impossibile eliminare: la zona '{$zona->nome}' ha territori associati.");
|
||||
return;
|
||||
}
|
||||
$zona->delete();
|
||||
session()->flash('success', "Zona '{$zona->nome}' eliminata.");
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.settings.zone-index', [
|
||||
'zone' => Zona::orderBy('nome')->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user