Add cancelled member data
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2025-12-02 00:28:58 +01:00
parent 56af6f4cbf
commit 502ba20b6d
6 changed files with 44 additions and 3 deletions

View File

@ -20,7 +20,7 @@ class FormIndexAction
*/ */
public function handle(string $filter): LengthAwarePaginator public function handle(string $filter): LengthAwarePaginator
{ {
return FormFilterScope::fromRequest($filter)->getQuery()->query(fn ($query) => $query->withCount('participants'))->paginate(15); return FormFilterScope::fromRequest($filter)->getQuery()->query(fn ($query) => $query->withCount(['participants' => fn ($q) => $q->whereNull('cancelled_at')]))->paginate(15);
} }
public function asController(ActionRequest $request): Response public function asController(ActionRequest $request): Response

View File

@ -32,7 +32,8 @@ class ParticipantFilterScope extends ScoutFilter
public string $search = '', public string $search = '',
public array $options = [], public array $options = [],
public ?int $parent = null, public ?int $parent = null,
public ?Sorting $sort = null public ?Sorting $sort = null,
public bool $showCancelled = false,
) { ) {
} }
@ -54,7 +55,11 @@ class ParticipantFilterScope extends ScoutFilter
$filter->push('parent-id IS NULL'); $filter->push('parent-id IS NULL');
} }
$filter->push('cancelled_at IS NULL'); if ($this->showCancelled) {
$filter->push('cancelled_at IS NOT NULL');
} else {
$filter->push('cancelled_at IS NULL');
}
if ($this->parent !== null && $this->parent !== -1) { if ($this->parent !== null && $this->parent !== -1) {
$filter->push('parent-id = ' . $this->parent); $filter->push('parent-id = ' . $this->parent);

View File

@ -39,6 +39,10 @@ class ParticipantFactory extends Factory
return $this->state(['data' => $data]); return $this->state(['data' => $data]);
} }
public function cancelled(): self {
return $this->state(['cancelled_at' => now()->subWeek()]);
}
public function nr(int $number): self public function nr(int $number): self
{ {
return $this->state(['member_id' => $number]); return $this->state(['member_id' => $number]);

View File

@ -29,6 +29,7 @@
</template> </template>
<template #fields> <template #fields>
<f-switch id="show_cancelled" v-model="innerFilter.show_cancelled" label="Abgemeldete zeigen" size="sm" name="show_cancelled" />
<template v-for="(filter, index) in meta.filters"> <template v-for="(filter, index) in meta.filters">
<f-select v-if="filter.base_type === 'CheckboxField'" <f-select v-if="filter.base_type === 'CheckboxField'"
:id="`filter-field-${index}`" :id="`filter-field-${index}`"

View File

@ -98,6 +98,18 @@ it('testItDisplaysForms', function () {
->assertInertiaPath('data.meta.default.location', ''); ->assertInertiaPath('data.meta.default.location', '');
}); });
it('displays participants count', function () {
$this->login()->loginNami()->withoutExceptionHandling();
Form::factory()
->has(Participant::factory()->count(2))
->has(Participant::factory()->cancelled()->count(3))
->create();
sleep(1);
$this->get(route('form.index'))
->assertInertiaPath('data.data.0.participants_count', 2);
});
it('testFormtemplatesHaveData', function () { it('testFormtemplatesHaveData', function () {
$this->login()->loginNami()->withoutExceptionHandling(); $this->login()->loginNami()->withoutExceptionHandling();
Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')->fields([ Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')->fields([

View File

@ -78,6 +78,9 @@ it('testItShowsEmptyFilters', function () {
$this->callFilter('form.participant.index', ['data' => ['check' => null]], ['form' => $form])->assertHasJsonPath('meta.filter.data.check')->assertJsonPath('meta.filter.data.check', null); $this->callFilter('form.participant.index', ['data' => ['check' => null]], ['form' => $form])->assertHasJsonPath('meta.filter.data.check')->assertJsonPath('meta.filter.data.check', null);
$this->callFilter('form.participant.index', ['data' => ['check' => 'A']], ['form' => $form])->assertJsonPath('meta.filter.data.check', 'A'); $this->callFilter('form.participant.index', ['data' => ['check' => 'A']], ['form' => $form])->assertJsonPath('meta.filter.data.check', 'A');
$this->callFilter('form.participant.index', ['data' => []], ['form' => $form])->assertJsonPath('meta.filter.data.check', ParticipantFilterScope::$nan); $this->callFilter('form.participant.index', ['data' => []], ['form' => $form])->assertJsonPath('meta.filter.data.check', ParticipantFilterScope::$nan);
$this->callFilter('form.participant.index', ['data' => []], ['form' => $form])->assertJsonPath('meta.filter.show_cancelled', false);
$this->callFilter('form.participant.index', ['show_cancelled' => true], ['form' => $form])->assertJsonPath('meta.filter.show_cancelled', true);
$this->callFilter('form.participant.index', ['show_cancelled' => false], ['form' => $form])->assertJsonPath('meta.filter.show_cancelled', false);
}); });
it('sorts by active colums sorting by default', function (array $sorting, string $by, bool $direction) { it('sorts by active colums sorting by default', function (array $sorting, string $by, bool $direction) {
@ -186,6 +189,22 @@ it('testItFiltersParticipantsByRadioValue', function () {
->assertJsonCount(4, 'data'); ->assertJsonCount(4, 'data');
}); });
it('filters participants by cancelled at', function () {
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()
->has(Participant::factory()->count(1))
->has(Participant::factory()->cancelled()->count(2))
->create();
sleep(2);
$this->callFilter('form.participant.index', [], ['form' => $form])
->assertJsonCount(1, 'data');
$this->callFilter('form.participant.index', ['show_cancelled' => false], ['form' => $form])
->assertJsonCount(1, 'data');
$this->callFilter('form.participant.index', ['show_cancelled' => true], ['form' => $form])
->assertJsonCount(2, 'data');
});
it('testItPresentsNamiField', function () { it('testItPresentsNamiField', function () {
$this->login()->loginNami()->withoutExceptionHandling(); $this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory() $form = Form::factory()