View.php
1 <?php 2 3 namespace App\Http\Livewire\Users; 4 5 use App\Http\Services\GpgService; 6 use App\Models\User; 7 use Illuminate\Support\Facades\Storage; 8 use Illuminate\Support\Str; 9 use Livewire\Component; 10 use Livewire\WithPagination; 11 use App\Http\Services\EntityService; 12 use App\Traits\WithPerPagePagination; 13 use App\Http\Livewire\Entities\Relations\Users; 14 use App\Http\Services\NormService; 15 use App\Http\Services\SkillService; 16 use Illuminate\Foundation\Auth\Access\AuthorizesRequests; 17 use Illuminate\Support\Facades\Auth; 18 use WireUi\Traits\Actions; 19 20 class View extends Component 21 { 22 use WithPagination, WithPerPagePagination, AuthorizesRequests, Actions; 23 24 public User $user; 25 26 public array $filters = [ 27 'created_at_since' => null, 28 'created_at_to' => null, 29 'norm_ids' => [], 30 'withTrashed' => false, 31 ]; 32 33 public bool $readyToLoad = false; 34 35 public string $search = ''; 36 37 public string $sortField = 'id'; 38 39 public string $sortDirection = 'asc'; 40 41 protected $rules = [ 42 'filters.created_at_since' => 'nullable|date', 43 'filters.created_at_to' => 'nullable|date|after:filters.created_at_since', 44 'filters.norm_ids' => 'nullable|array', 45 'filters.norm_ids.*' => 'nullable|integer', 46 'filters.withTrashed' => 'nullable|boolean', 47 ]; 48 49 50 public function mount() 51 { 52 $this->authorize('view', $this->user); 53 } 54 55 public function getGpgProperty() 56 { 57 return $this->user->activeKey; 58 } 59 60 protected function getListeners() 61 { 62 return ['refresh' => '$refresh']; 63 } 64 65 public function fetchData() 66 { 67 $this->readyToLoad = true; 68 } 69 70 public function updatingSearch(): void 71 { 72 $this->resetPage(); 73 } 74 75 public function getRowsQueryProperty() 76 { 77 return SkillService::searchSkills($this->search, $this->sortField, $this->sortDirection, $this->filters, $this->user->id); 78 } 79 80 public function getSkillsProperty() 81 { 82 return $this->readyToLoad ? $this->applyPagination($this->rowsQuery) : []; 83 } 84 85 public function getNormsProperty() 86 { 87 return NormService::getAllNormsSelectables(); 88 } 89 90 public function activateSecondFactor() 91 { 92 if (Auth::id() !== $this->user->id) { 93 return; 94 } 95 } 96 97 public function redirectChangePassword() 98 { 99 if (Auth::id() !== $this->user->id) { 100 return; 101 } 102 } 103 104 105 public function render() 106 { 107 return view('livewire.users.view') 108 ->layoutData([ 109 'title' => $this->user->fullname, 110 'entity' => $this->user, 111 'breadcrumb' => 'users.view', 112 ]); 113 } 114 }