-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a178f60
commit 4f8a92b
Showing
6 changed files
with
163 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
use App\Concerns\Enums; | ||
use Filament\Support\Contracts\HasLabel; | ||
|
||
enum DashboardIntervalFilter: string implements HasLabel | ||
{ | ||
use Enums\HasLabel; | ||
use Enums\Comparable; | ||
use Enums\Arrayable; | ||
|
||
case TODAY = 'today'; | ||
case TOMORROW = 'tomorrow'; | ||
case ONE_WEEK = 'one_week'; | ||
|
||
protected function labelKeyPrefix(): ?string | ||
{ | ||
return 'enum.dashboard_interval_filter'; | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
app/Filament/Organizations/Widgets/DashboardInterventionsWidget.php
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,118 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Organizations\Widgets; | ||
|
||
use App\Enums\DashboardIntervalFilter; | ||
use App\Filament\Organizations\Resources\BeneficiaryResource; | ||
use App\Filament\Organizations\Resources\InterventionServiceResource; | ||
use App\Models\BeneficiaryIntervention; | ||
use App\Tables\Filters\SelectFilter; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Table; | ||
use Filament\Widgets\TableWidget as BaseWidget; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class DashboardInterventionsWidget extends BaseWidget | ||
{ | ||
protected int | string | array $columnSpan = 2; | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->query( | ||
fn () => BeneficiaryIntervention::query() | ||
->whereHas( | ||
'beneficiary', | ||
) | ||
->when( | ||
! auth()->user()->isNgoAdmin(), | ||
fn (Builder $query) => $query->where( | ||
fn (Builder $query) => $query | ||
->whereHas( | ||
'specialist', | ||
fn (Builder $query) => $query->where('user_id', auth()->id()) | ||
) | ||
->orWhereHas( | ||
'beneficiary.managerTeam', | ||
fn (Builder $query) => $query->where('user_id', auth()->id()) | ||
) | ||
) | ||
) | ||
->with([ | ||
'organizationServiceIntervention.serviceInterventionWithoutStatusCondition.service', | ||
'interventionService', | ||
'beneficiary', | ||
'specialist.user', | ||
]) | ||
) | ||
->heading(__('intervention_plan.headings.dashboard_intervention_table')) | ||
->searchPlaceholder(__('intervention_plan.placeholders.search_by_beneficiary_or_specialist')) | ||
->columns([ | ||
TextColumn::make('organizationServiceIntervention.serviceInterventionWithoutStatusCondition.name') | ||
->label(__('intervention_plan.labels.intervention')), | ||
|
||
TextColumn::make('organizationServiceIntervention.serviceInterventionWithoutStatusCondition.service.name') | ||
->label(__('intervention_plan.labels.service')), | ||
|
||
TextColumn::make('interval') | ||
->label(__('intervention_plan.labels.interval')), | ||
|
||
TextColumn::make('beneficiary.full_name') | ||
->label(__('intervention_plan.labels.beneficiary')) | ||
->url( | ||
fn ($record) => BeneficiaryResource::getUrl('view', [ | ||
'record' => $record->beneficiary, | ||
]) | ||
) | ||
->color('primary') | ||
->searchable(), | ||
|
||
TextColumn::make('specialist.user.full_name') | ||
->label(__('intervention_plan.labels.specialist')) | ||
->searchable(), | ||
]) | ||
->actions([ | ||
Tables\Actions\ViewAction::make() | ||
->label(__('intervention_plan.actions.view_intervention')) | ||
->url( | ||
fn (BeneficiaryIntervention $record) => InterventionServiceResource::getUrl('view_intervention', [ | ||
'parent' => $record->intervention_service_id, | ||
'record' => $record, | ||
]) | ||
), | ||
]) | ||
->recordUrl( | ||
fn (BeneficiaryIntervention $record) => InterventionServiceResource::getUrl('view_intervention', [ | ||
'parent' => $record->intervention_service_id, | ||
'record' => $record, | ||
]) | ||
) | ||
->actionsColumnLabel(__('intervention_plan.labels.actions')) | ||
->filters([ | ||
SelectFilter::make('selected_interval') | ||
->label(__('intervention_plan.labels.selected_interval')) | ||
->options(DashboardIntervalFilter::options()) | ||
->modifyQueryUsing(function (array $state, Builder $query) { | ||
if (DashboardIntervalFilter::isValue($state['value'], DashboardIntervalFilter::ONE_WEEK)) { | ||
return $query->where('start_date_interval', '<=', date('Y-m-d', strtotime('+1 week'))) | ||
->where('end_date_interval', '>=', date('Y-m-d')); | ||
} | ||
|
||
if (DashboardIntervalFilter::isValue($state['value'], DashboardIntervalFilter::TOMORROW)) { | ||
return $query->where('start_date_interval', '<=', date('Y-m-d', strtotime('+1 day'))) | ||
->where('end_date_interval', '>=', date('Y-m-d')); | ||
} | ||
|
||
return $query->where('start_date_interval', '<=', date('Y-m-d')) | ||
->where('end_date_interval', '>=', date('Y-m-d')); | ||
}), | ||
]) | ||
->paginationPageOptions([5, 10, 15]) | ||
->emptyStateHeading(__('intervention_plan.headings.dashboard_intervention_table_empty_state')) | ||
->emptyStateDescription('') | ||
->emptyStateIcon('heroicon-o-clipboard-document-check'); | ||
} | ||
} |
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
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