-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from devajmeireles/feature/presence
Lista de Presença
- Loading branch information
Showing
50 changed files
with
1,487 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Enums\UserRole; | ||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class CreateDevelopmentUser extends Command | ||
{ | ||
protected $signature = 'make:dev'; | ||
|
||
protected $description = 'Create a random dev user'; | ||
|
||
public function handle(): int | ||
{ | ||
$name = fake()->name(); | ||
$nickname = fake()->userName(); | ||
|
||
User::create([ | ||
'role' => UserRole::Admin, | ||
'name' => $name, | ||
'username' => $nickname, | ||
'password' => Hash::make('password'), | ||
]); | ||
|
||
$this->table( | ||
['Name', 'Username', 'Password'], | ||
[[$name, $nickname, 'password']] | ||
); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Exports\Presence; | ||
|
||
use App\Models\Presence; | ||
use Illuminate\Support\Collection; | ||
use Maatwebsite\Excel\Concerns\{FromCollection, WithHeadings, WithMapping}; | ||
|
||
class PresenceExport implements FromCollection, WithMapping, WithHeadings | ||
{ | ||
public function collection(): Collection | ||
{ | ||
return Presence::with('signatures')->get(); | ||
} | ||
|
||
public function headings(): array | ||
{ | ||
return [ | ||
'#', | ||
'Nome', | ||
'Telefone', | ||
'Confirmado', | ||
'Assinatura', | ||
'Criado', | ||
'Atualizado', | ||
]; | ||
} | ||
|
||
public function map(mixed $row): array | ||
{ | ||
/** @var Presence $row */ | ||
return [ | ||
$row->id, | ||
$row->name, | ||
$row->phone, | ||
$row->is_confirmed ? 'Sim' : 'Não', | ||
$row->signatures?->first()->id ?? 'N/A', // @phpstan-ignore-line | ||
$row->created_at->format('d/m/Y H:i:s'), | ||
$row->updated_at->format('d/m/Y H:i:s'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Exports\Presence\PresenceExport; | ||
use Illuminate\Contracts\View\View; | ||
use Maatwebsite\Excel\Facades\Excel; | ||
use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
|
||
class PresenceController extends Controller | ||
{ | ||
public function index(): View | ||
{ | ||
return view('presences'); | ||
} | ||
|
||
public function export(): BinaryFileResponse | ||
{ | ||
$file = sprintf('presenças-%s.xlsx', now()->format('Y-m-d_H:i')); | ||
|
||
return Excel::download(new PresenceExport(), $file); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Presence; | ||
|
||
use App\Models\Presence; | ||
use Exception; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Validation\Rule; | ||
use Livewire\Component; | ||
use WireUi\Traits\Actions; | ||
|
||
class Create extends Component | ||
{ | ||
use Actions; | ||
|
||
public Presence $presence; | ||
|
||
public bool $modal = false; | ||
|
||
public bool $observation = false; | ||
|
||
protected array $validationAttributes = [ | ||
'presence.name' => 'nome', | ||
'presence.phone' => 'telefone', | ||
'presence.is_confirmed' => 'presença confirmada', | ||
'presence.observation' => 'observação', | ||
]; | ||
|
||
public function mount(): void | ||
{ | ||
$this->presence(); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.presence.create'); | ||
} | ||
|
||
public function rules(bool $observation = null): array | ||
{ | ||
$observation ??= $this->observation; | ||
|
||
return [ | ||
'presence.name' => ['required', 'string', 'max:255'], | ||
'presence.phone' => ['nullable', 'string', 'max:20'], | ||
'presence.is_confirmed' => ['required', 'boolean'], | ||
'presence.observation' => [Rule::when($observation, ['required', 'string', 'max:1024'], ['nullable'])], | ||
]; | ||
} | ||
|
||
public function create(): void | ||
{ | ||
$this->validate(); | ||
|
||
try { | ||
$this->presence->save(); | ||
|
||
$this->emitUp('presence::index::refresh'); | ||
|
||
session()->flash('response', [ | ||
'type' => 'green', | ||
'message' => 'Presença criada com sucesso!', | ||
]); | ||
|
||
return; | ||
} catch (Exception $e) { | ||
report($e); | ||
} finally { | ||
$this->presence(); | ||
} | ||
|
||
session()->flash('response', [ | ||
'type' => 'red', | ||
'message' => 'Erro ao criar a presença!', | ||
]); | ||
} | ||
|
||
private function presence(): void | ||
{ | ||
$this->presence = new Presence(['phone' => '', 'is_confirmed' => true]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Presence; | ||
|
||
use App\Models\Presence; | ||
use Exception; | ||
use Livewire\Component; | ||
use WireUi\Traits\Actions; | ||
|
||
class Delete extends Component | ||
{ | ||
use Actions; | ||
|
||
public Presence $presence; | ||
|
||
public function render(): string | ||
{ | ||
return <<<'blade' | ||
<x-button.circle primary | ||
icon="trash" | ||
wire:click="confirmation" | ||
/> | ||
blade; | ||
} | ||
|
||
public function confirmation(): void | ||
{ | ||
$this->dialog()->confirm([ | ||
'title' => 'Confirmação!', | ||
'description' => 'Deseja realmente deletar esta assinatura?', | ||
'icon' => 'error', | ||
'accept' => [ | ||
'label' => 'Sim!', | ||
'method' => 'delete', | ||
], | ||
]); | ||
} | ||
|
||
public function delete(): void | ||
{ | ||
try { | ||
$this->presence->delete(); | ||
|
||
$this->emitUp('presence::index::refresh'); | ||
$this->notification()->success('Presença deletada com sucesso!'); | ||
|
||
return; | ||
} catch (Exception $e) { | ||
report($e); | ||
} | ||
|
||
$this->notification()->error('Erro ao deletar presença!'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Presence; | ||
|
||
use App\Exports\Contracts\ShouldExport; | ||
use App\Http\Livewire\Traits\InteractWithExportation; | ||
use Illuminate\Contracts\View\View; | ||
use Livewire\Component; | ||
use WireUi\Traits\Actions; | ||
|
||
class Filter extends Component implements ShouldExport | ||
{ | ||
use Actions; | ||
use InteractWithExportation; | ||
|
||
public bool $modal = false; | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.presence.filter'); | ||
} | ||
|
||
public function clear(): void | ||
{ | ||
// | ||
} | ||
|
||
public function exportable(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Presence; | ||
|
||
use App\Http\Livewire\Traits\Table; | ||
use App\Models\Presence; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Pagination\LengthAwarePaginator; | ||
use Livewire\Component; | ||
|
||
class Index extends Component | ||
{ | ||
use Table; | ||
|
||
protected $listeners = [ | ||
'presence::index::refresh' => '$refresh', | ||
]; | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.presence.index', [ | ||
'presences' => $this->data(), | ||
]); | ||
} | ||
|
||
private function data(): LengthAwarePaginator | ||
{ | ||
return Presence::withCount('signatures') | ||
->search($this->search, 'name', 'phone') | ||
->orderBy($this->sort, $this->direction) | ||
->paginate($this->quantity); | ||
} | ||
|
||
public function update(Presence $presence): void | ||
{ | ||
$this->emitTo(Update::class, 'presence::update::load', $presence); | ||
} | ||
} |
Oops, something went wrong.