Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front end fixes #187

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static function getNavigationItems(): array
return $lists
->map(fn(ChoiceList $choiceList) => NavigationItem::make($choiceList->list_name)
->group('Choice Lists')
->icon(fn() => HelperService::getCurrentOwner()?->hasCompletedLookupList($choiceList) ? 'heroicon-o-check' : 'heroicon-o-exclamation-circle')
->activeIcon(fn() => HelperService::getCurrentOwner()?->hasCompletedLookupList($choiceList) ? 'heroicon-o-check' : 'heroicon-o-exclamation-circle')
// ->icon(fn() => HelperService::getCurrentOwner()?->hasCompletedLookupList($choiceList) ? 'heroicon-o-check' : 'heroicon-o-exclamation-circle')
// ->activeIcon(fn() => HelperService::getCurrentOwner()?->hasCompletedLookupList($choiceList) ? 'heroicon-o-check' : 'heroicon-o-exclamation-circle')
->isActiveWhen(fn() => request()->routeIs(static::getRouteBaseName() . '.*')
&& request()->get('choiceListName') === $choiceList->list_name
)
Expand Down Expand Up @@ -183,7 +183,7 @@ public static function table(Table $table): Table
->label('Localised Entry')
->boolean(),
])
->recordClasses(fn(ChoiceListEntry $record) => $record->teamRemoved->contains(HelperService::getCurrentOwner()) ? 'opacity-50' : '');
->recordClasses(fn(ChoiceListEntry $record) => $record->isRemoved(HelperService::getCurrentOwner()) ? 'opacity-50' : '');
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function table(Table $table): Table
->form(fn(Form $form) => $form->schema(fn() => $this->getResource()::getFormSchema($this->choiceList))),
DeleteAction::make()->visible(fn(ChoiceListEntry $record) => !$record->is_global_entry),
\Filament\Tables\Actions\Action::make('Toggle Removed')
->label(fn(ChoiceListEntry $record) => $record->teamRemoved->contains(HelperService::getCurrentOwner()) ? 'Restore to Context' : 'Remove from Context')
->label(fn(ChoiceListEntry $record) => $record->isRemoved(HelperService::getCurrentOwner()) ? 'Restore to Context' : 'Remove from Context')
->visible(fn(ChoiceListEntry $record) => $record->is_global_entry)
->action(fn(ChoiceListEntry $record) => $record->toggleRemoved(HelperService::getCurrentOwner())),
]);
Expand All @@ -87,15 +87,15 @@ protected function getHeaderActions(): array
->form(fn(Form $form) => $form
->schema(fn() => $this->getResource()::getFormSchema($this->choiceList))),

Action::make('Mark as Complete')
->action(fn() => HelperService::getCurrentOwner()?->markLookupListAsComplete($this->choiceList))
->visible(fn() => !HelperService::getCurrentOwner()?->hasCompletedLookupList($this->choiceList))
->after(fn() => $this->redirect($this->getResource()::getUrl('index', ['choiceListName' => $this->choiceListName]))),

Action::make('Mark as Incomplete')
->action(fn() => HelperService::getCurrentOwner()?->markLookupListAsIncomplete($this->choiceList))
->visible(fn() => HelperService::getCurrentOwner()?->hasCompletedLookupList($this->choiceList))
->after(fn() => $this->redirect($this->getResource()::getUrl('index', ['choiceListName' => $this->choiceListName]))),
// Action::make('Mark as Complete')
// ->action(fn() => HelperService::getCurrentOwner()?->markLookupListAsComplete($this->choiceList))
// ->visible(fn() => !HelperService::getCurrentOwner()?->hasCompletedLookupList($this->choiceList))
// ->after(fn() => $this->redirect($this->getResource()::getUrl('index', ['choiceListName' => $this->choiceListName]))),
//
// Action::make('Mark as Incomplete')
// ->action(fn() => HelperService::getCurrentOwner()?->markLookupListAsIncomplete($this->choiceList))
// ->visible(fn() => HelperService::getCurrentOwner()?->hasCompletedLookupList($this->choiceList))
// ->after(fn() => $this->redirect($this->getResource()::getUrl('index', ['choiceListName' => $this->choiceListName]))),

];
}
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/TeamTranslationEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TeamTranslationEntry extends Component implements HasActions, HasForms, Ha

public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\View|\Illuminate\View\View|null
{
$this->selectedLocale = $this->team->locales()->wherePivot('language_id', $this->language->id)->first();
$this->selectedLocale = $this->team->locales()->where('language_id', $this->language->id)->first();

return view('livewire.team-translation-entry');
}
Expand Down
41 changes: 23 additions & 18 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,35 @@ public function xlsforms(): MorphMany
return $this->morphMany(Xlsform::class, 'owner');
}

/** @return MorphMany<ChoiceListEntry, $this> */
public function choiceListEntries(): MorphMany
public function choiceLists(): MorphMany
{
return $this->morphMany(ChoiceListEntry::class, 'owner');
}

public function markLookupListAsComplete(ChoiceList $choiceList): ?bool
{
$this->choiceLists()->sync([$choiceList->id => ['is_complete' => 1]], detaching: false);

return $this->hasCompletedLookupList($choiceList);
return $this->morphMany(ChoiceList::class, 'owner');
}

public function markLookupListAsInComplete(ChoiceList $choiceList): ?bool
/** @return MorphMany<ChoiceListEntry, $this> */
public function choiceListEntries(): MorphMany
{
$this->choiceLists()->detach($choiceList->id);

return $this->hasCompletedLookupList($choiceList);
return $this->morphMany(ChoiceListEntry::class, 'owner');
}

public function hasCompletedLookupList(ChoiceList $choiceList): ?bool
{
return $this->choiceLists()->where('choice_lists.id', $choiceList->id)->first()?->pivot->is_complete;
}
// public function markLookupListAsComplete(ChoiceList $choiceList): ?bool
// {
// $this->choiceLists()->sync([$choiceList->id => ['is_complete' => 1]], detaching: false);
//
// return $this->hasCompletedLookupList($choiceList);
// }
//
// public function markLookupListAsInComplete(ChoiceList $choiceList): ?bool
// {
// $this->choiceLists()->detach($choiceList->id);
//
// return $this->hasCompletedLookupList($choiceList);
// }
//
// public function hasCompletedLookupList(ChoiceList $choiceList): ?bool
// {
// return $this->choiceLists()->where('choice_lists.id', $choiceList->id)->first()?->pivot->is_complete;
// }


// Customisations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function up(): void
Schema::create('choice_list_entries_removed', function (Blueprint $table) {
$table->id();
$table->foreignId('choice_list_entry_id')->constrained();
$table->foreignId('team_id')->constrained();
$table->morphs('owner');
$table->timestamps();
});
}
Expand Down
5 changes: 3 additions & 2 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Database\Seeders;

use Database\Seeders\TestMiniForms\DatasetsTableSeeder;
use Database\Seeders\TestRealForms\ChoiceListsTableSeeder;
use Illuminate\Database\Seeder;
use Stats4sd\FilamentOdkLink\Database\Seeders\PlatformSeeder;

Expand All @@ -23,7 +23,8 @@ public function run(): void
foreach (glob(database_path('seeders/Prep/*.php')) as $file) {
$class = 'Database\\Seeders\\Prep\\' . pathinfo($file, PATHINFO_FILENAME);
$this->call($class);
}
$this->call(ChoiceListsTableSeeder::class);
}

// Call the test seeders locally
if (app()->environment('local')) {
Expand Down
50 changes: 25 additions & 25 deletions database/seeders/TestRealForms/ChoiceListsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public function run()
'xlsform_module_version_id' => 1,
'list_name' => 'language',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:40:46',
'updated_at' => '2025-02-20 15:40:46',
Expand All @@ -39,10 +39,10 @@ public function run()
'xlsform_module_version_id' => 1,
'list_name' => 'district',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:40:46',
'updated_at' => '2025-02-20 15:40:46',
Expand All @@ -53,10 +53,10 @@ public function run()
'xlsform_module_version_id' => 1,
'list_name' => 'sub_district',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:40:46',
'updated_at' => '2025-02-20 15:40:46',
Expand All @@ -67,10 +67,10 @@ public function run()
'xlsform_module_version_id' => 1,
'list_name' => 'village',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:40:46',
'updated_at' => '2025-02-20 15:40:46',
Expand All @@ -81,10 +81,10 @@ public function run()
'xlsform_module_version_id' => 1,
'list_name' => 'farm',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:40:46',
'updated_at' => '2025-02-20 15:40:46',
Expand Down Expand Up @@ -207,7 +207,7 @@ public function run()
'xlsform_module_version_id' => 1,
'list_name' => 'occupation',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
Expand Down Expand Up @@ -389,7 +389,7 @@ public function run()
'xlsform_module_version_id' => 8,
'list_name' => 'area_unit',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
Expand Down Expand Up @@ -417,7 +417,7 @@ public function run()
'xlsform_module_version_id' => 9,
'list_name' => 'shocks',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
Expand Down Expand Up @@ -1033,7 +1033,7 @@ public function run()
'xlsform_module_version_id' => 18,
'list_name' => 'crops',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
Expand Down Expand Up @@ -1131,7 +1131,7 @@ public function run()
'xlsform_module_version_id' => 18,
'list_name' => 'yield_unit',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
Expand Down Expand Up @@ -1243,7 +1243,7 @@ public function run()
'xlsform_module_version_id' => 19,
'list_name' => 'fert_unit',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
Expand Down Expand Up @@ -1537,7 +1537,7 @@ public function run()
'xlsform_module_version_id' => 22,
'list_name' => 'fish',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
Expand Down Expand Up @@ -1929,10 +1929,10 @@ public function run()
'xlsform_module_version_id' => 28,
'list_name' => 'district',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:51:41',
'updated_at' => '2025-02-20 15:51:41',
Expand All @@ -1943,10 +1943,10 @@ public function run()
'xlsform_module_version_id' => 28,
'list_name' => 'sub_district',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:51:41',
'updated_at' => '2025-02-20 15:51:41',
Expand All @@ -1957,10 +1957,10 @@ public function run()
'xlsform_module_version_id' => 28,
'list_name' => 'village',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:51:41',
'updated_at' => '2025-02-20 15:51:41',
Expand All @@ -1971,10 +1971,10 @@ public function run()
'xlsform_module_version_id' => 28,
'list_name' => 'farm',
'description' => NULL,
'is_localisable' => 0,
'is_localisable' => 1,
'is_dataset' => 0,
'can_be_hidden_from_context' => 0,
'has_custom_handling' => 0,
'has_custom_handling' => 1,
'properties' => NULL,
'created_at' => '2025-02-20 15:51:41',
'updated_at' => '2025-02-20 15:51:41',
Expand Down