diff --git a/app/Filament/App/Clusters/LocationLevels/Resources/LocationLevelResource.php b/app/Filament/App/Clusters/LocationLevels/Resources/LocationLevelResource.php index bc7514fd..1762750a 100644 --- a/app/Filament/App/Clusters/LocationLevels/Resources/LocationLevelResource.php +++ b/app/Filament/App/Clusters/LocationLevels/Resources/LocationLevelResource.php @@ -36,7 +36,9 @@ public static function getNavigationItems(): array $baseRoute = static::getUrl('index'); - $navItems = LocationLevel::all() + $navItems = LocationLevel::query() + ->orderBy('parent_id') + ->get() ->map(function ($level) use ($baseRoute) { return NavigationItem::make(Str::plural($level->name)) ->url($baseRoute . '/' . $level->slug) @@ -96,6 +98,7 @@ public static function table(Table $table): Table ->boolean() ->sortable(), ]) + ->defaultSort('parent_id', 'asc') ->filters([ // ]) diff --git a/app/Filament/App/Clusters/LocationLevels/Resources/LocationLevelResource/RelationManagers/LocationsRelationManager.php b/app/Filament/App/Clusters/LocationLevels/Resources/LocationLevelResource/RelationManagers/LocationsRelationManager.php index b5ba12db..932f1f09 100644 --- a/app/Filament/App/Clusters/LocationLevels/Resources/LocationLevelResource/RelationManagers/LocationsRelationManager.php +++ b/app/Filament/App/Clusters/LocationLevels/Resources/LocationLevelResource/RelationManagers/LocationsRelationManager.php @@ -3,13 +3,13 @@ namespace App\Filament\App\Clusters\LocationLevels\Resources\LocationLevelResource\RelationManagers; use Filament\Forms; -use Filament\Forms\Form; -use Filament\Resources\RelationManagers\RelationManager; use Filament\Tables; +use Filament\Forms\Form; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Builder; +use Filament\Resources\RelationManagers\RelationManager; class LocationsRelationManager extends RelationManager { @@ -22,18 +22,30 @@ public static function getTitle(Model $ownerRecord, string $pageClass): string public function isReadOnly(): bool { - return true; + return false; } public function form(Form $form): Form { return $form ->schema([ + Forms\Components\Select::make('parent_id') + ->label(fn () => $this->getOwnerRecord()->parent->name) + ->relationship('parent', 'name', function ($query) { + $parent_location_level_id = $this->getOwnerRecord()->parent->id; + $query->where('location_level_id', $parent_location_level_id); }) + ->required() + ->searchable() + ->preload() + ->visible(fn () => $this->getOwnerRecord()->parent !== null), Forms\Components\TextInput::make('name') - ->hintIcon('heroicon-o-information-circle') ->required() ->maxLength(255), - ]); + Forms\Components\TextInput::make('code') + ->required() + ->maxLength(255), + ]) + ->columns(1); } public function table(Table $table): Table @@ -44,6 +56,7 @@ public function table(Table $table): Table if ($this->getOwnerRecord()->parent) { $columns[] = Tables\Columns\TextColumn::make('parent.name')->label(fn () => $this->getOwnerRecord()->parent->name)->sortable(); $filters[] = Tables\Filters\SelectFilter::make('parent') + ->label(fn () => $this->getOwnerRecord()->parent->name) ->relationship('parent', 'name', fn (Builder $query) => $query->where('location_level_id', $this->getOwnerRecord()->parent->id)); } @@ -58,7 +71,8 @@ public function table(Table $table): Table ->columns($columns) ->filters($filters) ->headerActions([ - Tables\Actions\CreateAction::make(), + Tables\Actions\CreateAction::make() + ->label(fn () => 'Add new ' . $this->getOwnerRecord()->name), ]) ->actions([ Tables\Actions\EditAction::make(), diff --git a/app/Filament/App/Pages/LISP.php b/app/Filament/App/Pages/LISP.php index 92ea43a4..534e51ed 100644 --- a/app/Filament/App/Pages/LISP.php +++ b/app/Filament/App/Pages/LISP.php @@ -35,9 +35,9 @@ public function markCompleteAction(): Action ->label('MARK AS COMPLETE') ->extraAttributes(['class' => 'buttona mx-4 inline-block']) ->action(function () { - $team = Team::find(auth()->user()->latestTeam->id); - $team->lisp_progress = 'complete'; - $team->save(); + Team::find(auth()->user()->latestTeam->id)->update([ + 'lisp_complete' => 1, + ]); $this->dispatch('refreshPage'); }); @@ -49,9 +49,9 @@ public function markIncompleteAction(): Action ->label('MARK AS INCOMPLETE') ->extraAttributes(['class' => 'buttona mx-4 inline-block']) ->action(function () { - $team = Team::find(auth()->user()->latestTeam->id); - $team->lisp_progress = 'not_started'; - $team->save(); + Team::find(auth()->user()->latestTeam->id)->update([ + 'lisp_complete' => 0, + ]); $this->dispatch('refreshPage'); }); diff --git a/app/Filament/App/Pages/PlaceAdaptations.php b/app/Filament/App/Pages/PlaceAdaptations.php index 7d9229ad..8ace084b 100644 --- a/app/Filament/App/Pages/PlaceAdaptations.php +++ b/app/Filament/App/Pages/PlaceAdaptations.php @@ -36,9 +36,9 @@ public function markCompleteAction(): Action ->label('MARK AS COMPLETE') ->extraAttributes(['class' => 'buttona mx-4 inline-block']) ->action(function () { - $team = Team::find(auth()->user()->latestTeam->id); - $team->pba_progress = 'complete'; - $team->save(); + Team::find(auth()->user()->latestTeam->id)->update([ + 'pba_complete' => 1, + ]); $this->dispatch('refreshPage'); }); @@ -50,9 +50,9 @@ public function markIncompleteAction(): Action ->label('MARK AS INCOMPLETE') ->extraAttributes(['class' => 'buttona mx-4 inline-block']) ->action(function () { - $team = Team::find(auth()->user()->latestTeam->id); - $team->pba_progress = 'not_started'; - $team->save(); + Team::find(auth()->user()->latestTeam->id)->update([ + 'pba_complete' => 0, + ]); $this->dispatch('refreshPage'); }); diff --git a/app/Filament/App/Pages/Sampling.php b/app/Filament/App/Pages/Sampling.php index c12c3ec8..cc6031e6 100644 --- a/app/Filament/App/Pages/Sampling.php +++ b/app/Filament/App/Pages/Sampling.php @@ -36,9 +36,9 @@ public function markCompleteAction(): Action ->label('MARK AS COMPLETE') ->extraAttributes(['class' => 'buttona mx-4 inline-block']) ->action(function () { - $team = Team::find(auth()->user()->latestTeam->id); - $team->sampling_progress = 'complete'; - $team->save(); + Team::find(auth()->user()->latestTeam->id)->update([ + 'sampling_complete' => 1, + ]); $this->dispatch('refreshPage'); }); @@ -50,9 +50,9 @@ public function markIncompleteAction(): Action ->label('MARK AS INCOMPLETE') ->extraAttributes(['class' => 'buttona mx-4 inline-block']) ->action(function () { - $team = Team::find(auth()->user()->latestTeam->id); - $team->sampling_progress = 'not_started'; - $team->save(); + Team::find(auth()->user()->latestTeam->id)->update([ + 'sampling_complete' => 0, + ]); $this->dispatch('refreshPage'); }); diff --git a/app/Filament/App/Pages/SurveyDashboard.php b/app/Filament/App/Pages/SurveyDashboard.php index 6c35032b..05b5793f 100644 --- a/app/Filament/App/Pages/SurveyDashboard.php +++ b/app/Filament/App/Pages/SurveyDashboard.php @@ -21,7 +21,6 @@ class SurveyDashboard extends Page public function mount(): void { $this->team = Team::find(auth()->user()->latestTeam->id); - ray($this->team->sampling_progress); } public function getMaxContentWidth(): MaxWidth diff --git a/app/Filament/App/Pages/SurveyLanguages.php b/app/Filament/App/Pages/SurveyLanguages.php index c0c2a592..18ebef39 100644 --- a/app/Filament/App/Pages/SurveyLanguages.php +++ b/app/Filament/App/Pages/SurveyLanguages.php @@ -36,9 +36,9 @@ public function markCompleteAction(): Action ->label('MARK AS COMPLETE') ->extraAttributes(['class' => 'buttona mx-4 inline-block']) ->action(function () { - $team = Team::find(auth()->user()->latestTeam->id); - $team->languages_progress = 'complete'; - $team->save(); + Team::find(auth()->user()->latestTeam->id)->update([ + 'languages_complete' => 1, + ]); $this->dispatch('refreshPage'); }); @@ -50,9 +50,9 @@ public function markIncompleteAction(): Action ->label('MARK AS INCOMPLETE') ->extraAttributes(['class' => 'buttona mx-4 inline-block']) ->action(function () { - $team = Team::find(auth()->user()->latestTeam->id); - $team->languages_progress = 'not_started'; - $team->save(); + Team::find(auth()->user()->latestTeam->id)->update([ + 'languages_complete' => 0, + ]); $this->dispatch('refreshPage'); }); diff --git a/app/Models/Team.php b/app/Models/Team.php index 17af6946..84a2ba43 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Models\Language; use App\Models\Holpa\LocalIndicator; use App\Models\SampleFrame\Farm; use App\Models\SampleFrame\Location; @@ -10,13 +11,16 @@ use App\Models\Xlsforms\ChoiceList; use App\Models\Xlsforms\ChoiceListEntry; use App\Models\Xlsforms\Xlsform; +use App\Models\XlsformTemplates\ChoiceList; +use App\Models\XlsformTemplates\ChoiceListEntry; +use App\Models\XlsformTemplates\XlsformTemplate; use App\Models\Xlsforms\XlsformModule; use App\Models\Xlsforms\XlsformModuleVersion; use App\Models\Xlsforms\XlsformTemplate; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphMany; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; @@ -186,4 +190,56 @@ public function getXlsformFwModuleVersionAttribute() } return null; } + + public function getLispProgressAttribute() + { + if ($this->lisp_complete === 1) { + return 'complete'; + } + + return $this->localIndicators()->exists() ? 'in_progress' : 'not_started'; + } + + public function getSamplingProgressAttribute() + { + if ($this->sampling_complete === 1) { + return 'complete'; + } + + return $this->locationLevels()->exists() ? 'in_progress' : 'not_started'; + } + + public function getLanguagesProgressAttribute() + { + if ($this->languages_complete === 1) { + return 'complete'; + } + + // teams have English as a locale as default, check for others + $english_language_id = Language::where('name', 'English')->value('id'); + + $hasAddedLocales = $this->locales() + ->where('language_id', '!=', $english_language_id) + ->exists(); + + return $hasAddedLocales ? 'in_progress' : 'not_started'; + } + + public function getPbaProgressAttribute() + { + if ($this->pba_complete === 1) { + return 'complete'; + } + + if ( + $this->time_frame !== null || + $this->diet_diversity_module_version_id !== null || + $this->choiceListEntries()->exists() + ) { + return 'in_progress'; + } + + return 'not_started'; + } + } diff --git a/database/migrations/2025_01_06_091020_change_progress_columns_on_teams_table.php b/database/migrations/2025_01_06_091020_change_progress_columns_on_teams_table.php new file mode 100644 index 00000000..def49c58 --- /dev/null +++ b/database/migrations/2025_01_06_091020_change_progress_columns_on_teams_table.php @@ -0,0 +1,43 @@ +update([ + 'lisp_progress' => DB::raw("IF(lisp_progress = 'complete', 1, 0)"), + 'sampling_progress' => DB::raw("IF(sampling_progress = 'complete', 1, 0)"), + 'languages_progress' => DB::raw("IF(languages_progress = 'complete', 1, 0)"), + 'pba_progress' => DB::raw("IF(pba_progress = 'complete', 1, 0)"), + ]); + + Schema::table('teams', function (Blueprint $table) { + $table->renameColumn('lisp_progress', 'lisp_complete'); + $table->renameColumn('sampling_progress', 'sampling_complete'); + $table->renameColumn('languages_progress', 'languages_complete'); + $table->renameColumn('pba_progress', 'pba_complete'); + }); + + Schema::table('teams', function (Blueprint $table) { + $table->boolean('lisp_complete')->default(false)->change(); + $table->boolean('sampling_complete')->default(false)->change(); + $table->boolean('languages_complete')->default(false)->change(); + $table->boolean('pba_complete')->default(false)->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/resources/views/filament/app/pages/lisp.blade.php b/resources/views/filament/app/pages/lisp.blade.php index b80012e1..4ea9ac0f 100644 --- a/resources/views/filament/app/pages/lisp.blade.php +++ b/resources/views/filament/app/pages/lisp.blade.php @@ -48,7 +48,7 @@
- @if(auth()->user()->latestTeam->lisp_progress === 'complete') + @if(auth()->user()->latestTeam->lisp_complete === 1)
diff --git a/resources/views/filament/app/pages/place-adaptations.blade.php b/resources/views/filament/app/pages/place-adaptations.blade.php index 2e4b7e8f..8c1814da 100644 --- a/resources/views/filament/app/pages/place-adaptations.blade.php +++ b/resources/views/filament/app/pages/place-adaptations.blade.php @@ -56,7 +56,7 @@
- @if(auth()->user()->latestTeam->pba_progress === 'complete') + @if(auth()->user()->latestTeam->pba_complete === 1)
diff --git a/resources/views/filament/app/pages/sampling.blade.php b/resources/views/filament/app/pages/sampling.blade.php index b97ab66d..9b45eb85 100644 --- a/resources/views/filament/app/pages/sampling.blade.php +++ b/resources/views/filament/app/pages/sampling.blade.php @@ -39,7 +39,7 @@
- @if(auth()->user()->latestTeam->sampling_progress === 'complete') + @if(auth()->user()->latestTeam->sampling_complete === 1)
diff --git a/resources/views/filament/app/pages/survey-languages.blade.php b/resources/views/filament/app/pages/survey-languages.blade.php index edd017e5..6b7e7a0b 100644 --- a/resources/views/filament/app/pages/survey-languages.blade.php +++ b/resources/views/filament/app/pages/survey-languages.blade.php @@ -27,7 +27,7 @@
- @if(auth()->user()->latestTeam->languages_progress === 'complete') + @if(auth()->user()->latestTeam->languages_complete === 1)
diff --git a/resources/views/livewire/cover-page.blade.php b/resources/views/livewire/cover-page.blade.php index e630e1da..17a56ab2 100644 --- a/resources/views/livewire/cover-page.blade.php +++ b/resources/views/livewire/cover-page.blade.php @@ -16,7 +16,7 @@

HOLPA

-

Holistic Localised Performance Assessment

+

Holistic Localised Performance Assessment for Agroecology