Commit f0df71cf authored by Mahmoud Aglan's avatar Mahmoud Aglan

Improve sorting: default to name, add sortable columns

- ParticipantList: default sort by name_ar ASC, added sort headers for
  activity and membership columns
- EnrollmentList: added sort by participant name (join), group name,
  and payment_status columns
- GroupList: default sort by name_ar ASC instead of created_at
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent d0a15fc1
......@@ -104,8 +104,20 @@ public function render()
->when($this->status, fn ($q) => $q->where('status', $this->status))
->when($this->programFilter, fn ($q) => $q->where('training_program_id', $this->programFilter))
->when($this->groupFilter, fn ($q) => $q->where('training_group_id', $this->groupFilter))
->when($this->paymentFilter, fn ($q) => $q->where('payment_status', $this->paymentFilter))
->orderBy($this->sortBy, $this->sortDir);
->when($this->paymentFilter, fn ($q) => $q->where('payment_status', $this->paymentFilter));
if ($this->sortBy === 'name_ar') {
$query->join('participants', 'enrollments.participant_id', '=', 'participants.id')
->join('people', 'participants.person_id', '=', 'people.id')
->orderBy('people.name_ar', $this->sortDir)
->select('enrollments.*');
} elseif ($this->sortBy === 'group_name') {
$query->join('training_groups', 'enrollments.training_group_id', '=', 'training_groups.id')
->orderBy('training_groups.name_ar', $this->sortDir)
->select('enrollments.*');
} else {
$query->orderBy($this->sortBy, $this->sortDir);
}
$this->applyRoleScope($query);
......
......@@ -38,10 +38,10 @@ class GroupList extends Component
public string $programFilter = '';
#[Url]
public string $sortBy = 'created_at';
public string $sortBy = 'name_ar';
#[Url]
public string $sortDir = 'desc';
public string $sortDir = 'asc';
public function updatedSearch(): void
{
......
......@@ -30,6 +30,16 @@ class ParticipantList extends Component
public string $activity = '';
public string $skillLevel = '';
public function mount(): void
{
if (!request()->has('sortBy')) {
$this->sortBy = 'name_ar';
}
if (!request()->has('sortDir')) {
$this->sortDir = 'asc';
}
}
public function updatedSearch(): void
{
$this->resetPage();
......
......@@ -64,11 +64,11 @@ class="w-full px-3 py-2 text-sm border border-gray-300 rounded-lg focus:ring-2 f
<table class="w-full text-sm">
<thead class="bg-gray-50 border-b border-gray-200">
<tr>
<th class="px-4 py-3 text-start font-medium text-gray-600">{{ __('المشترك') }}</th>
<th class="px-4 py-3 text-start font-medium text-gray-600">{{ __('المجموعة') }}</th>
<x-ui.sort-header column="name_ar" :sortBy="$sortBy" :sortDir="$sortDir">{{ __('المشترك') }}</x-ui.sort-header>
<x-ui.sort-header column="group_name" :sortBy="$sortBy" :sortDir="$sortDir">{{ __('المجموعة') }}</x-ui.sort-header>
<th class="px-4 py-3 text-start font-medium text-gray-600">{{ __('البرنامج') }}</th>
<x-ui.sort-header column="status" :sortBy="$sortBy" :sortDir="$sortDir" align="center">{{ __('الحالة') }}</x-ui.sort-header>
<th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('الدفع') }}</th>
<x-ui.sort-header column="payment_status" :sortBy="$sortBy" :sortDir="$sortDir" align="center">{{ __('الدفع') }}</x-ui.sort-header>
<x-ui.sort-header column="enrollment_date" :sortBy="$sortBy" :sortDir="$sortDir" align="center">{{ __('تاريخ التسجيل') }}</x-ui.sort-header>
<th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('إجراءات') }}</th>
</tr>
......
......@@ -63,8 +63,8 @@ class="w-full px-3 sm:px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 f
<tr>
<x-ui.sort-header column="participant_number" :sortBy="$sortBy" :sortDir="$sortDir">{{ __('رقم المشترك') }}</x-ui.sort-header>
<x-ui.sort-header column="name_ar" :sortBy="$sortBy" :sortDir="$sortDir">{{ __('الاسم') }}</x-ui.sort-header>
<th class="px-4 py-3 text-start font-medium text-gray-600">{{ __('النشاط') }}</th>
<th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('العضوية') }}</th>
<x-ui.sort-header column="primary_activity_id" :sortBy="$sortBy" :sortDir="$sortDir">{{ __('النشاط') }}</x-ui.sort-header>
<x-ui.sort-header column="membership_type" :sortBy="$sortBy" :sortDir="$sortDir" align="center">{{ __('العضوية') }}</x-ui.sort-header>
<x-ui.sort-header column="status" :sortBy="$sortBy" :sortDir="$sortDir" align="center">{{ __('الحالة') }}</x-ui.sort-header>
<x-ui.sort-header column="created_at" :sortBy="$sortBy" :sortDir="$sortDir" align="center">{{ __('تاريخ التسجيل') }}</x-ui.sort-header>
<th class="px-4 py-3 text-center font-medium text-gray-600">{{ __('إجراءات') }}</th>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment