Compare commits
6 Commits
da4d553ea6
...
6a91e857d2
Author | SHA1 | Date |
---|---|---|
philipp lang | 6a91e857d2 | |
philipp lang | 82baf67a73 | |
philipp lang | 36466420f6 | |
philipp lang | 54c37fccd1 | |
philipp lang | d03f036a2b | |
philipp lang | 75d11f9860 |
|
@ -8,7 +8,7 @@ use App\Form\Resources\ParticipantResource;
|
|||
use App\Form\Scopes\ParticipantFilterScope;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Laravel\Scout\Builder;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class ParticipantIndexAction
|
||||
|
@ -18,27 +18,20 @@ class ParticipantIndexAction
|
|||
/**
|
||||
* @return HasMany<Participant>
|
||||
*/
|
||||
protected function getQuery(Form $form, ParticipantFilterScope $filter): HasMany
|
||||
protected function getQuery(Form $form, ParticipantFilterScope $filter): Builder
|
||||
{
|
||||
return $form->participants()->withFilter($filter)->withCount('children')->with('form');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LengthAwarePaginator<Participant>
|
||||
*/
|
||||
public function handle(Form $form, ParticipantFilterScope $filter): LengthAwarePaginator
|
||||
{
|
||||
return $this->getQuery($form, $filter)->paginate(15);
|
||||
return $filter->setForm($form)->getQuery()
|
||||
->query(fn ($q) => $q->withCount('children')->with('form'));
|
||||
}
|
||||
|
||||
public function asController(Form $form, ?int $parent = null): AnonymousResourceCollection
|
||||
{
|
||||
$filter = ParticipantFilterScope::fromRequest(request()->input('filter'));
|
||||
$filter = ParticipantFilterScope::fromRequest(request()->input('filter', ''))->parent($parent);
|
||||
|
||||
$data = match ($parent) {
|
||||
null => $this->handle($form, $filter),
|
||||
-1 => $this->getQuery($form, $filter)->where('parent_id', null)->paginate(15),
|
||||
default => $this->getQuery($form, $filter)->where('parent_id', $parent)->get(),
|
||||
null => $this->getQuery($form, $filter)->paginate(15), // initial all elements - paginate
|
||||
-1 => $this->getQuery($form, $filter)->paginate(15), // initial root elements - parinate
|
||||
default => $this->getQuery($form, $filter)->get(), // specific parent element - show all
|
||||
};
|
||||
|
||||
return ParticipantResource::collection($data)->additional(['meta' => ParticipantResource::meta($form)]);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Actions;
|
||||
|
||||
use App\Form\Models\Form;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class UpdateParticipantSearchIndexAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(Form $form): void
|
||||
{
|
||||
$form->searchableUsing()->updateIndexSettings(
|
||||
$form->participantsSearchableAs(),
|
||||
[
|
||||
'filterableAttributes' => [...$form->getFields()->filterables()->getKeys(), 'parent-id'],
|
||||
'searchableAttributes' => $form->getFields()->searchables()->getKeys(),
|
||||
'sortableAttributes' => [],
|
||||
'displayedAttributes' => [...$form->getFields()->filterables()->getKeys(), ...$form->getFields()->searchables()->getKeys(), 'id'],
|
||||
'pagination' => [
|
||||
'maxTotalHits' => 1000000,
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Contracts;
|
||||
|
||||
interface Filterable
|
||||
{
|
||||
/** @param mixed $value */
|
||||
public function filter($value): string;
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Form\Data;
|
||||
|
||||
use App\Form\Contracts\Filterable;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use App\Form\Fields\Field;
|
||||
use App\Form\Fields\NamiField;
|
||||
|
@ -117,4 +118,22 @@ class FieldCollection extends Collection
|
|||
{
|
||||
return $this->first(fn ($field) => $field->specialType === $specialType);
|
||||
}
|
||||
|
||||
public function searchables(): self
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filterables(): self
|
||||
{
|
||||
return $this->filter(fn ($field) => $field instanceof Filterable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function getKeys(): array
|
||||
{
|
||||
return $this->map(fn ($field) => $field->key)->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Form\Fields;
|
||||
|
||||
use App\Form\Contracts\Filterable;
|
||||
use App\Form\Matchers\BooleanMatcher;
|
||||
use App\Form\Matchers\Matcher;
|
||||
use App\Form\Models\Form;
|
||||
|
@ -9,9 +10,8 @@ use App\Form\Models\Participant;
|
|||
use App\Form\Presenters\BooleanPresenter;
|
||||
use App\Form\Presenters\Presenter;
|
||||
use Faker\Generator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CheckboxField extends Field
|
||||
class CheckboxField extends Field implements Filterable
|
||||
{
|
||||
public bool $required;
|
||||
public string $description;
|
||||
|
@ -86,4 +86,11 @@ class CheckboxField extends Field
|
|||
{
|
||||
return app(BooleanMatcher::class);
|
||||
}
|
||||
|
||||
public function filter($value): string
|
||||
{
|
||||
$asString = $value ? 'true' : 'false';
|
||||
|
||||
return "{$this->key} = $asString";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Form\Fields;
|
||||
|
||||
use App\Form\Contracts\Filterable;
|
||||
use App\Form\Matchers\Matcher;
|
||||
use App\Form\Matchers\SingleValueMatcher;
|
||||
use App\Form\Models\Form;
|
||||
|
@ -9,7 +10,7 @@ use App\Form\Models\Participant;
|
|||
use Faker\Generator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class DropdownField extends Field
|
||||
class DropdownField extends Field implements Filterable
|
||||
{
|
||||
public bool $required;
|
||||
/** @var array<int, string> */
|
||||
|
@ -87,4 +88,14 @@ class DropdownField extends Field
|
|||
{
|
||||
return app(SingleValueMatcher::class);
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function filter($value): string
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return "{$this->key} IS NULL";
|
||||
}
|
||||
|
||||
return $this->key . ' = \'' . $value . '\'';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Form\Fields;
|
||||
|
||||
use App\Form\Contracts\Filterable;
|
||||
use App\Form\Matchers\Matcher;
|
||||
use App\Form\Matchers\SingleValueMatcher;
|
||||
use App\Form\Models\Form;
|
||||
|
@ -9,7 +10,7 @@ use App\Form\Models\Participant;
|
|||
use Faker\Generator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class RadioField extends Field
|
||||
class RadioField extends Field implements Filterable
|
||||
{
|
||||
public bool $required;
|
||||
/** @var array<int, string> */
|
||||
|
@ -87,4 +88,13 @@ class RadioField extends Field
|
|||
{
|
||||
return app(SingleValueMatcher::class);
|
||||
}
|
||||
|
||||
public function filter($value): string
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return "{$this->key} IS NULL";
|
||||
}
|
||||
|
||||
return $this->key . ' = \'' . $value . '\'';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Form\Models;
|
||||
|
||||
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
||||
use App\Form\Data\ExportData;
|
||||
use App\Form\Data\FieldCollection;
|
||||
use App\Form\Data\FormConfigData;
|
||||
|
@ -14,7 +15,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Spatie\Image\Enums\Fit;
|
||||
use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
@ -172,5 +172,14 @@ class Form extends Model implements HasMedia
|
|||
return;
|
||||
}
|
||||
});
|
||||
|
||||
static::saved(function ($model) {
|
||||
UpdateParticipantSearchIndexAction::dispatch($model);
|
||||
});
|
||||
}
|
||||
|
||||
public function participantsSearchableAs(): string
|
||||
{
|
||||
return config('scout.prefix') . 'forms_' . $this->id . '_participants';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Laravel\Scout\Searchable;
|
||||
use stdClass;
|
||||
|
||||
class Participant extends Model implements Preventable
|
||||
|
@ -22,6 +23,7 @@ class Participant extends Model implements Preventable
|
|||
|
||||
/** @use HasFactory<ParticipantFactory> */
|
||||
use HasFactory;
|
||||
use Searchable;
|
||||
|
||||
public $guarded = [];
|
||||
|
||||
|
@ -46,15 +48,6 @@ class Participant extends Model implements Preventable
|
|||
return $this->hasMany(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<self> $query
|
||||
* @return Builder<self>
|
||||
*/
|
||||
public function scopeWithFilter(Builder $query, ParticipantFilterScope $filter): Builder
|
||||
{
|
||||
return $filter->apply($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Member, self>
|
||||
*/
|
||||
|
@ -110,4 +103,14 @@ class Participant extends Model implements Preventable
|
|||
{
|
||||
return 'Nachweise erforderlich für deine Anmeldung zu ' . $this->form->name;
|
||||
}
|
||||
|
||||
public function searchableAs()
|
||||
{
|
||||
return $this->form->participantsSearchableAs();
|
||||
}
|
||||
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
return [...$this->data, 'parent-id' => $this->parent_id];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@ namespace App\Form\Scopes;
|
|||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use App\Lib\Filter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Lib\ScoutFilter;
|
||||
use Illuminate\Support\Arr;
|
||||
use Laravel\Scout\Builder;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Attributes\MapOutputName;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
@ -16,20 +17,55 @@ use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
|||
*/
|
||||
#[MapInputName(SnakeCaseMapper::class)]
|
||||
#[MapOutputName(SnakeCaseMapper::class)]
|
||||
class ParticipantFilterScope extends Filter
|
||||
class ParticipantFilterScope extends ScoutFilter
|
||||
{
|
||||
|
||||
public static string $nan = 'deeb3ef4-d185-44b1-a4bc-0a4e7addebc3d8900c6f-a344-4afb-b54e-065ed483a7ba';
|
||||
private Form $form;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function __construct(
|
||||
public array $data = [],
|
||||
public string $search = '',
|
||||
public array $options = [],
|
||||
public ?int $parent = null
|
||||
) {
|
||||
}
|
||||
|
||||
public static string $nan = 'deeb3ef4-d185-44b1-a4bc-0a4e7addebc3d8900c6f-a344-4afb-b54e-065ed483a7ba';
|
||||
public function getQuery(): Builder
|
||||
{
|
||||
$this->search = $this->search ?: '';
|
||||
|
||||
return Participant::search($this->search, function ($engine, string $query, array $options) {
|
||||
$filter = collect([]);
|
||||
|
||||
foreach ($this->form->getFields()->filterables() as $field) {
|
||||
if ($this->data[$field->key] === static::$nan) {
|
||||
continue;
|
||||
}
|
||||
$filter->push($field->filter($this->data[$field->key]));
|
||||
}
|
||||
|
||||
if ($this->parent === -1) {
|
||||
$filter->push('parent-id IS NULL');
|
||||
}
|
||||
|
||||
if ($this->parent !== null && $this->parent !== -1) {
|
||||
$filter->push('parent-id = ' . $this->parent);
|
||||
}
|
||||
|
||||
$options['filter'] = $filter->map(fn ($expression) => "($expression)")->implode(' AND ');
|
||||
|
||||
return $engine->search($query, [...$this->options, ...$options]);
|
||||
})->within($this->form->participantsSearchableAs());
|
||||
}
|
||||
|
||||
public function setForm(Form $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
foreach ($form->getFields() as $field) {
|
||||
if (!Arr::has($this->data, $field->key)) {
|
||||
data_set($this->data, $field->key, static::$nan);
|
||||
|
@ -39,18 +75,10 @@ class ParticipantFilterScope extends Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function apply(Builder $query): Builder
|
||||
public function parent(?int $parent): self
|
||||
{
|
||||
foreach ($this->data as $key => $value) {
|
||||
if ($value === static::$nan) {
|
||||
continue;
|
||||
}
|
||||
$query = $query->where('data->' . $key, $value);
|
||||
}
|
||||
$this->parent = $parent;
|
||||
|
||||
return $query;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,3 +6,5 @@ echo "create database scoutrobot;" | sudo mysql
|
|||
ssh -l stammsilva zoomyboy.de "cd /usr/share/webapps/nami_silva && docker compose exec db mysqldump -udb -p$SCOUTROBOT_DB_PASSWORD db" > db.tmp
|
||||
sudo mysql scoutrobot < db.tmp
|
||||
rm db.tmp
|
||||
|
||||
echo 'app(\App\Form\FormSettings::class)->fill(["registerUrl" => "http://stammsilva.test/anmeldung/{slug}/register", "clearCacheUrl" => "http://stammsilva.test/adrema/clear-cache"])->save();' | php artisan tinker
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
||||
use App\Form\Models\Form;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
foreach (Form::get() as $form) {
|
||||
UpdateParticipantSearchIndexAction::run($form);
|
||||
foreach ($form->participants as $participant) {
|
||||
$participant->searchable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
|
@ -28,7 +28,7 @@ export function useApiIndex(firstUrl, siteName = null) {
|
|||
inner.meta.value = response.meta;
|
||||
}
|
||||
|
||||
async function reloadPage(page) {
|
||||
async function reloadPage(page, p = {}) {
|
||||
inner.meta.value.current_page = page;
|
||||
await reload(false);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
</ui-popup>
|
||||
<page-filter breakpoint="lg">
|
||||
<template #buttons>
|
||||
<f-text id="search" v-model="innerFilter.search" name="search" label="Suchen" size="sm"></f-text>
|
||||
<ui-icon-button icon="plus" @click="editing = {participant: null, preview: JSON.stringify(meta.form_config)}">Hinzufügen</ui-icon-button>
|
||||
<f-switch v-if="meta.has_nami_field" id="group_participants" v-model="groupParticipants" label="Gruppieren" size="sm" name="group_participants"></f-switch>
|
||||
<f-multipleselect id="active_columns" v-model="activeColumnsConfig" :options="meta.columns" label="Aktive Spalten" size="sm"></f-multipleselect>
|
||||
|
@ -117,7 +118,7 @@
|
|||
</template>
|
||||
</table>
|
||||
<div class="px-6">
|
||||
<ui-pagination class="mt-4" :value="meta" @reload="reloadPage"></ui-pagination>
|
||||
<ui-pagination class="mt-4" :value="meta" @reload="reloadPage($event, {filter: toFilterString(innerFilter)})"></ui-pagination>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
@ -0,0 +1,241 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Form\Fields\TextField;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use App\Form\Scopes\ParticipantFilterScope;
|
||||
use App\Group;
|
||||
use App\Member\Member;
|
||||
use Carbon\Carbon;
|
||||
use Tests\EndToEndTestCase;
|
||||
use Tests\Lib\CreatesFormFields;
|
||||
|
||||
uses(EndToEndTestCase::class);
|
||||
uses(CreatesFormFields::class);
|
||||
|
||||
it('testItShowsParticipantsAndColumns', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$group = Group::factory()->innerName('Stamm')->create();
|
||||
$form = Form::factory()
|
||||
->has(Participant::factory()->state(['member_id' => 55])->data(['vorname' => 'Max', 'select' => ['A', 'B'], 'stufe' => 'Pfadfinder', 'test1' => '', 'test2' => '', 'test3' => '', 'birthday' => '1991-04-20', 'bezirk' => $group->id]))
|
||||
->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
$this->checkboxesField('select')->options(['A', 'B', 'C']),
|
||||
$this->dropdownField('stufe')->options(['Wölfling', 'Jungpfadfinder', 'Pfadfinder']),
|
||||
$this->textField('test1')->name('Test 1'),
|
||||
$this->textField('test2')->name('Test 2'),
|
||||
$this->textField('test3')->name('Test 3'),
|
||||
$this->dateField('birthday')->name('Geburtsdatum'),
|
||||
$this->groupField('bezirk')->name('bezirk'),
|
||||
])
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.id', $form->participants->first()->id)
|
||||
->assertJsonPath('data.0.vorname', 'Max')
|
||||
->assertJsonPath('data.0.vorname_display', 'Max')
|
||||
->assertJsonPath('data.0.stufe', 'Pfadfinder')
|
||||
->assertJsonPath('data.0.bezirk', $group->id)
|
||||
->assertJsonPath('data.0.member_id', 55)
|
||||
->assertJsonPath('data.0.bezirk_display', 'Stamm')
|
||||
->assertJsonPath('data.0.birthday_display', '20.04.1991')
|
||||
->assertJsonPath('data.0.birthday', '1991-04-20')
|
||||
->assertJsonPath('data.0.select', ['A', 'B'])
|
||||
->assertJsonPath('data.0.select_display', 'A, B')
|
||||
->assertJsonPath('data.0.links.destroy', route('participant.destroy', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.assign', route('participant.assign', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.fields', route('participant.fields', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.update', route('participant.update', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('meta.columns.0.name', 'Vorname')
|
||||
->assertJsonPath('meta.columns.0.base_type', class_basename(TextField::class))
|
||||
->assertJsonPath('meta.columns.0.id', 'vorname')
|
||||
->assertJsonPath('meta.columns.6.display_attribute', 'birthday_display')
|
||||
->assertJsonPath('meta.columns.0.display_attribute', 'vorname_display')
|
||||
->assertJsonPath('meta.form_meta.active_columns', ['vorname', 'select', 'stufe', 'test1'])
|
||||
->assertJsonPath('meta.has_nami_field', false)
|
||||
->assertJsonPath('meta.links.update_form_meta', route('form.update-meta', ['form' => $form]))
|
||||
->assertJsonPath('meta.links.store_participant', route('form.participant.store', ['form' => $form]))
|
||||
->assertJsonPath('meta.form_meta.sorting', ['vorname', 'asc'])
|
||||
->assertJsonPath('meta.form_config.sections.0.fields.0.key', 'vorname');
|
||||
});
|
||||
|
||||
it('testItShowsEmptyFilters', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->checkboxField('check')->name('Checked')])->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertOk()
|
||||
->assertJsonPath('meta.filters.0.name', 'Checked')
|
||||
->assertJsonPath('meta.filters.0.key', 'check')
|
||||
->assertJsonPath('meta.filters.0.base_type', 'CheckboxField')
|
||||
->assertJsonPath('meta.default_filter_value', ParticipantFilterScope::$nan);
|
||||
|
||||
$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' => []], ['form' => $form])->assertJsonPath('meta.filter.data.check', ParticipantFilterScope::$nan);
|
||||
});
|
||||
|
||||
it('testItDisplaysHasNamiField', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->namiField('mitglieder')])->create();
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])->assertJsonPath('meta.has_nami_field', true);
|
||||
});
|
||||
|
||||
it('testItFiltersParticipantsByCheckboxValue', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->checkboxField('check')])
|
||||
->has(Participant::factory()->data(['check' => true])->count(1))
|
||||
->has(Participant::factory()->data(['check' => false])->count(2))
|
||||
->create();
|
||||
|
||||
sleep(2);
|
||||
$this->callFilter('form.participant.index', ['data' => []], ['form' => $form])
|
||||
->assertJsonCount(3, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['check' => ParticipantFilterScope::$nan]], ['form' => $form])
|
||||
->assertJsonCount(3, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['check' => true]], ['form' => $form])
|
||||
->assertJsonCount(1, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['check' => false]], ['form' => $form])
|
||||
->assertJsonCount(2, 'data');
|
||||
});
|
||||
|
||||
it('test it handles full text search', function (array $memberAttributes, string $search, bool $includes) {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()
|
||||
->has(Participant::factory()->data(['vorname' => 'Max', 'select' => 'Pfadfinder', ...$memberAttributes]))
|
||||
->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
$this->checkboxesField('select')->options(['Wölflinge', 'Pfadfinder']),
|
||||
])
|
||||
->create();
|
||||
|
||||
sleep(2);
|
||||
$this->callFilter('form.participant.index', ['search' => $search], ['form' => $form])
|
||||
->assertJsonCount($includes ? 1 : 0, 'data');
|
||||
})->with([
|
||||
[['vorname' => 'Max'], 'Max', true],
|
||||
[['vorname' => 'Jane'], 'Max', false],
|
||||
[['select' => 'Pfadfinder'], 'Pfadfinder', true],
|
||||
[['select' => 'Pfadfinder'], 'Rov', false],
|
||||
[['select' => 'Wölflinge'], 'Wölflinge', true],
|
||||
[['select' => 'Wölflinge'], 'Wölf', true],
|
||||
[['vorname' => 'Max', 'nachname' => 'Muster'], 'Max Muster', true],
|
||||
[['vorname' => 'Max', 'nachname' => 'Muster'], 'Jane Doe', false],
|
||||
]);
|
||||
|
||||
it('testItFiltersParticipantsByDropdownValue', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->dropdownField('drop')->options(['A', 'B'])])
|
||||
->has(Participant::factory()->data(['drop' => null])->count(1))
|
||||
->has(Participant::factory()->data(['drop' => 'A'])->count(2))
|
||||
->has(Participant::factory()->data(['drop' => 'B'])->count(4))
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => ParticipantFilterScope::$nan]], ['form' => $form])
|
||||
->assertJsonCount(7, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => null]], ['form' => $form])
|
||||
->assertJsonCount(1, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'A']], ['form' => $form])
|
||||
->assertJsonCount(2, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'B']], ['form' => $form])
|
||||
->assertJsonCount(4, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'Z*Z']], ['form' => $form])
|
||||
->assertJsonCount(0, 'data');
|
||||
});
|
||||
|
||||
it('testItFiltersParticipantsByRadioValue', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->radioField('drop')->options(['A', 'B'])])
|
||||
->has(Participant::factory()->data(['drop' => null])->count(1))
|
||||
->has(Participant::factory()->data(['drop' => 'A'])->count(2))
|
||||
->has(Participant::factory()->data(['drop' => 'B'])->count(4))
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => ParticipantFilterScope::$nan]], ['form' => $form])
|
||||
->assertJsonCount(7, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'A']], ['form' => $form])
|
||||
->assertJsonCount(2, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'B']], ['form' => $form])
|
||||
->assertJsonCount(4, 'data');
|
||||
});
|
||||
|
||||
it('testItPresentsNamiField', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()
|
||||
->has(Participant::factory()->data(['mitglieder' => [['id' => 393], ['id' => 394]]]))
|
||||
->has(Participant::factory()->nr(393)->data(['mitglieder' => []]))
|
||||
->has(Participant::factory()->nr(394)->data(['mitglieder' => []]))
|
||||
->fields([
|
||||
$this->namiField('mitglieder'),
|
||||
])
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertJsonPath('data.0.mitglieder_display', '393, 394');
|
||||
});
|
||||
|
||||
it('testItShowsRegisteredAtColumnAndAttribute', function () {
|
||||
Carbon::setTestNow(Carbon::parse('2023-03-05 06:00:00'));
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()
|
||||
->has(Participant::factory()->data(['vorname' => 'Max']))
|
||||
->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
])
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertJsonPath('data.0.vorname', 'Max')
|
||||
->assertJsonPath('data.0.vorname_display', 'Max')
|
||||
->assertJsonPath('data.0.created_at', '2023-03-05 06:00:00')
|
||||
->assertJsonPath('data.0.created_at_display', '05.03.2023')
|
||||
->assertJsonPath('meta.columns.1.name', 'Registriert am')
|
||||
->assertJsonPath('meta.columns.1.id', 'created_at')
|
||||
->assertJsonPath('meta.columns.1.display_attribute', 'created_at_display');
|
||||
});
|
||||
|
||||
it('testItShowsOnlyParentParticipantsWhenFilterEnabled', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
$participant = Participant::factory()
|
||||
->has(Participant::factory()->for($form)->count(2), 'children')
|
||||
->for($form)
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])->assertJsonCount(3, 'data');
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => -1])->assertJsonCount(1, 'data');
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonCount(2, 'data');
|
||||
});
|
||||
|
||||
it('testItShowsChildrenCount', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
$participant = Participant::factory()
|
||||
->has(Participant::factory()->for($form)->count(2), 'children')
|
||||
->for($form)
|
||||
->create();
|
||||
Participant::factory()->for($form)->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => -1])
|
||||
->assertJsonPath('data.0.children_count', 2)
|
||||
->assertJsonPath('data.1.children_count', 0)
|
||||
->assertJsonPath('data.0.links.children', route('form.participant.index', ['form' => $form, 'parent' => $participant->id]))
|
||||
->assertJsonPath('meta.current_page', 1);
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonPath('data.0.children_count', 0);
|
||||
});
|
||||
|
||||
it('testItShowsPreventionState', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$participant = Participant::factory()->data(['vorname' => 'Max'])
|
||||
->for(Member::factory()->defaults()->state(['efz' => null]))
|
||||
->for(Form::factory())
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $participant->form])
|
||||
->assertJsonPath('data.0.prevention_items.0.letter', 'F')
|
||||
->assertJsonPath('data.0.prevention_items.0.value', false)
|
||||
->assertJsonPath('data.0.prevention_items.0.tooltip', 'erweitertes Führungszeugnis nicht vorhanden');
|
||||
});
|
|
@ -1,225 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Form\Fields\TextField;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use App\Form\Scopes\ParticipantFilterScope;
|
||||
use App\Group;
|
||||
use App\Member\Member;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ParticipantIndexActionTest extends FormTestCase
|
||||
{
|
||||
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testItShowsParticipantsAndColumns(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$group = Group::factory()->innerName('Stamm')->create();
|
||||
$form = Form::factory()
|
||||
->has(Participant::factory()->state(['member_id' => 55])->data(['vorname' => 'Max', 'select' => ['A', 'B'], 'stufe' => 'Pfadfinder', 'test1' => '', 'test2' => '', 'test3' => '', 'birthday' => '1991-04-20', 'bezirk' => $group->id]))
|
||||
->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
$this->checkboxesField('select')->options(['A', 'B', 'C']),
|
||||
$this->dropdownField('stufe')->options(['Wölfling', 'Jungpfadfinder', 'Pfadfinder']),
|
||||
$this->textField('test1')->name('Test 1'),
|
||||
$this->textField('test2')->name('Test 2'),
|
||||
$this->textField('test3')->name('Test 3'),
|
||||
$this->dateField('birthday')->name('Geburtsdatum'),
|
||||
$this->groupField('bezirk')->name('bezirk'),
|
||||
])
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.id', $form->participants->first()->id)
|
||||
->assertJsonPath('data.0.vorname', 'Max')
|
||||
->assertJsonPath('data.0.vorname_display', 'Max')
|
||||
->assertJsonPath('data.0.stufe', 'Pfadfinder')
|
||||
->assertJsonPath('data.0.bezirk', $group->id)
|
||||
->assertJsonPath('data.0.member_id', 55)
|
||||
->assertJsonPath('data.0.bezirk_display', 'Stamm')
|
||||
->assertJsonPath('data.0.birthday_display', '20.04.1991')
|
||||
->assertJsonPath('data.0.birthday', '1991-04-20')
|
||||
->assertJsonPath('data.0.select', ['A', 'B'])
|
||||
->assertJsonPath('data.0.select_display', 'A, B')
|
||||
->assertJsonPath('data.0.links.destroy', route('participant.destroy', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.assign', route('participant.assign', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.fields', route('participant.fields', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('data.0.links.update', route('participant.update', ['participant' => $form->participants->first()]))
|
||||
->assertJsonPath('meta.columns.0.name', 'Vorname')
|
||||
->assertJsonPath('meta.columns.0.base_type', class_basename(TextField::class))
|
||||
->assertJsonPath('meta.columns.0.id', 'vorname')
|
||||
->assertJsonPath('meta.columns.6.display_attribute', 'birthday_display')
|
||||
->assertJsonPath('meta.columns.0.display_attribute', 'vorname_display')
|
||||
->assertJsonPath('meta.form_meta.active_columns', ['vorname', 'select', 'stufe', 'test1'])
|
||||
->assertJsonPath('meta.has_nami_field', false)
|
||||
->assertJsonPath('meta.links.update_form_meta', route('form.update-meta', ['form' => $form]))
|
||||
->assertJsonPath('meta.links.store_participant', route('form.participant.store', ['form' => $form]))
|
||||
->assertJsonPath('meta.form_meta.sorting', ['vorname', 'asc'])
|
||||
->assertJsonPath('meta.form_config.sections.0.fields.0.key', 'vorname');
|
||||
}
|
||||
|
||||
public function testItShowsEmptyFilters(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->checkboxField('check')->name('Checked')])->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertOk()
|
||||
->assertJsonPath('meta.filters.0.name', 'Checked')
|
||||
->assertJsonPath('meta.filters.0.key', 'check')
|
||||
->assertJsonPath('meta.filters.0.base_type', 'CheckboxField')
|
||||
->assertJsonPath('meta.default_filter_value', ParticipantFilterScope::$nan);
|
||||
|
||||
$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' => []], ['form' => $form])->assertJsonPath('meta.filter.data.check', ParticipantFilterScope::$nan);
|
||||
}
|
||||
|
||||
public function testItDisplaysHasNamiField(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->namiField('mitglieder')])->create();
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])->assertJsonPath('meta.has_nami_field', true);
|
||||
}
|
||||
|
||||
public function testItFiltersParticipantsByCheckboxValue(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->checkboxField('check')])
|
||||
->has(Participant::factory()->data(['check' => true])->count(1))
|
||||
->has(Participant::factory()->data(['check' => false])->count(2))
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', ['data' => ['check' => ParticipantFilterScope::$nan]], ['form' => $form])
|
||||
->assertJsonCount(3, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['check' => true]], ['form' => $form])
|
||||
->assertJsonCount(1, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['check' => false]], ['form' => $form])
|
||||
->assertJsonCount(2, 'data');
|
||||
}
|
||||
|
||||
public function testItFiltersParticipantsByDropdownValue(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->dropdownField('drop')->options(['A', 'B'])])
|
||||
->has(Participant::factory()->data(['drop' => null])->count(1))
|
||||
->has(Participant::factory()->data(['drop' => 'A'])->count(2))
|
||||
->has(Participant::factory()->data(['drop' => 'B'])->count(4))
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => ParticipantFilterScope::$nan]], ['form' => $form])
|
||||
->assertJsonCount(7, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => null]], ['form' => $form])
|
||||
->assertJsonCount(1, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'A']], ['form' => $form])
|
||||
->assertJsonCount(2, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'B']], ['form' => $form])
|
||||
->assertJsonCount(4, 'data');
|
||||
}
|
||||
|
||||
public function testItFiltersParticipantsByRadioValue(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->radioField('drop')->options(['A', 'B'])])
|
||||
->has(Participant::factory()->data(['drop' => null])->count(1))
|
||||
->has(Participant::factory()->data(['drop' => 'A'])->count(2))
|
||||
->has(Participant::factory()->data(['drop' => 'B'])->count(4))
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => ParticipantFilterScope::$nan]], ['form' => $form])
|
||||
->assertJsonCount(7, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'A']], ['form' => $form])
|
||||
->assertJsonCount(2, 'data');
|
||||
$this->callFilter('form.participant.index', ['data' => ['drop' => 'B']], ['form' => $form])
|
||||
->assertJsonCount(4, 'data');
|
||||
}
|
||||
|
||||
public function testItPresentsNamiField(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()
|
||||
->has(Participant::factory()->data(['mitglieder' => [['id' => 393], ['id' => 394]]]))
|
||||
->has(Participant::factory()->nr(393)->data(['mitglieder' => []]))
|
||||
->has(Participant::factory()->nr(394)->data(['mitglieder' => []]))
|
||||
->fields([
|
||||
$this->namiField('mitglieder'),
|
||||
])
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertJsonPath('data.0.mitglieder_display', '393, 394');
|
||||
}
|
||||
|
||||
public function testItShowsRegisteredAtColumnAndAttribute(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2023-03-05 06:00:00'));
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()
|
||||
->has(Participant::factory()->data(['vorname' => 'Max']))
|
||||
->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
])
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertJsonPath('data.0.vorname', 'Max')
|
||||
->assertJsonPath('data.0.vorname_display', 'Max')
|
||||
->assertJsonPath('data.0.created_at', '2023-03-05 06:00:00')
|
||||
->assertJsonPath('data.0.created_at_display', '05.03.2023')
|
||||
->assertJsonPath('meta.columns.1.name', 'Registriert am')
|
||||
->assertJsonPath('meta.columns.1.id', 'created_at')
|
||||
->assertJsonPath('meta.columns.1.display_attribute', 'created_at_display');
|
||||
}
|
||||
|
||||
public function testItShowsOnlyParentParticipantsWhenFilterEnabled(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
$participant = Participant::factory()
|
||||
->has(Participant::factory()->for($form)->count(2), 'children')
|
||||
->for($form)
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])->assertJsonCount(3, 'data');
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => -1])->assertJsonCount(1, 'data');
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonCount(2, 'data');
|
||||
}
|
||||
|
||||
public function testItShowsChildrenCount(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
$participant = Participant::factory()
|
||||
->has(Participant::factory()->for($form)->count(2), 'children')
|
||||
->for($form)
|
||||
->create();
|
||||
Participant::factory()->for($form)->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => -1])
|
||||
->assertJsonPath('data.0.children_count', 2)
|
||||
->assertJsonPath('data.1.children_count', 0)
|
||||
->assertJsonPath('data.0.links.children', route('form.participant.index', ['form' => $form, 'parent' => $participant->id]))
|
||||
->assertJsonPath('meta.current_page', 1);
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonPath('data.0.children_count', 0);
|
||||
}
|
||||
|
||||
public function testItShowsPreventionState(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$participant = Participant::factory()->data(['vorname' => 'Max'])
|
||||
->for(Member::factory()->defaults()->state(['efz' => null]))
|
||||
->for(Form::factory())
|
||||
->create();
|
||||
|
||||
$this->callFilter('form.participant.index', [], ['form' => $participant->form])
|
||||
->assertJsonPath('data.0.prevention_items.0.letter', 'F')
|
||||
->assertJsonPath('data.0.prevention_items.0.value', false)
|
||||
->assertJsonPath('data.0.prevention_items.0.tooltip', 'erweitertes Führungszeugnis nicht vorhanden');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue