Compare commits
16 Commits
da4d553ea6
...
58426c5537
Author | SHA1 | Date |
---|---|---|
philipp lang | 58426c5537 | |
philipp lang | 84cd13c085 | |
philipp lang | b8d2b37057 | |
philipp lang | 44eb3719b9 | |
philipp lang | c65a208e34 | |
philipp lang | 95a8d4d689 | |
philipp lang | e1e8669beb | |
philipp lang | a3ecfa756d | |
philipp lang | 70e085a49e | |
philipp lang | 1178b011e0 | |
philipp lang | 6a91e857d2 | |
philipp lang | 82baf67a73 | |
philipp lang | 36466420f6 | |
philipp lang | 54c37fccd1 | |
philipp lang | d03f036a2b | |
philipp lang | 75d11f9860 |
|
@ -22,8 +22,8 @@ class FormUpdateMetaAction
|
|||
|
||||
return [
|
||||
'sorting' => 'array',
|
||||
'sorting.0' => 'required|string',
|
||||
'sorting.1' => 'required|string|in:asc,desc',
|
||||
'sorting.by' => 'required|string',
|
||||
'sorting.direction' => 'required|boolean',
|
||||
'active_columns' => 'array',
|
||||
'active_columns.*' => ['string', Rule::in([...$form->getFields()->pluck('key')->toArray(), 'created_at', 'prevention'])]
|
||||
];
|
||||
|
|
|
@ -6,9 +6,8 @@ use App\Form\Models\Form;
|
|||
use App\Form\Models\Participant;
|
||||
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
|
||||
|
@ -16,29 +15,22 @@ class ParticipantIndexAction
|
|||
use AsAction;
|
||||
|
||||
/**
|
||||
* @return HasMany<Participant>
|
||||
* @return Builder<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,31 @@
|
|||
<?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
|
||||
{
|
||||
if (config('scout.driver') !== 'meilisearch') {
|
||||
return;
|
||||
}
|
||||
|
||||
$form->searchableUsing()->updateIndexSettings(
|
||||
$form->participantsSearchableAs(),
|
||||
[
|
||||
'filterableAttributes' => [...$form->getFields()->filterables()->getKeys(), 'parent-id'],
|
||||
'searchableAttributes' => $form->getFields()->searchables()->getKeys(),
|
||||
'sortableAttributes' => [...$form->getFields()->sortables()->getKeys(), 'id'],
|
||||
'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,27 @@ class FieldCollection extends Collection
|
|||
{
|
||||
return $this->first(fn ($field) => $field->specialType === $specialType);
|
||||
}
|
||||
|
||||
public function searchables(): self
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sortables(): 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 . '\'';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -180,4 +180,10 @@ abstract class Field extends Data
|
|||
{
|
||||
return app(SingleValueMatcher::class);
|
||||
}
|
||||
|
||||
/** @param mixed $value */
|
||||
public function filter($value): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,11 +2,13 @@
|
|||
|
||||
namespace App\Form\Models;
|
||||
|
||||
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
||||
use App\Form\Data\ExportData;
|
||||
use App\Form\Data\FieldCollection;
|
||||
use App\Form\Data\FormConfigData;
|
||||
use App\Lib\Editor\Condition;
|
||||
use App\Lib\Editor\EditorData;
|
||||
use App\Lib\Sorting;
|
||||
use Cviebrock\EloquentSluggable\Sluggable;
|
||||
use Database\Factories\Form\Models\FormFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
@ -14,7 +16,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;
|
||||
|
@ -159,7 +160,7 @@ class Form extends Model implements HasMedia
|
|||
if (is_null(data_get($model->meta, 'active_columns'))) {
|
||||
$model->setAttribute('meta', [
|
||||
'active_columns' => $model->getFields()->count() ? $model->getFields()->take(4)->pluck('key')->toArray() : null,
|
||||
'sorting' => $model->getFields()->count() ? [$model->getFields()->first()->key, 'asc'] : null,
|
||||
'sorting' => Sorting::by('id'),
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
@ -172,5 +173,19 @@ 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';
|
||||
}
|
||||
|
||||
public function defaultSorting(): Sorting
|
||||
{
|
||||
return Sorting::from($this->meta['sorting']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,15 @@ class Participant extends Model implements Preventable
|
|||
{
|
||||
return 'Nachweise erforderlich für deine Anmeldung zu ' . $this->form->name;
|
||||
}
|
||||
|
||||
public function searchableAs(): string
|
||||
{
|
||||
return $this->form->participantsSearchableAs();
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
return [...$this->data, 'parent-id' => $this->parent_id];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,32 +4,76 @@ 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 App\Lib\Sorting;
|
||||
use Illuminate\Support\Arr;
|
||||
use Laravel\Scout\Builder;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Attributes\MapOutputName;
|
||||
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
|
||||
|
||||
/**
|
||||
* @extends Filter<Participant>
|
||||
* @extends ScoutFilter<Participant>
|
||||
*/
|
||||
#[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
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
public function __construct(
|
||||
public array $data = [],
|
||||
public string $search = '',
|
||||
public array $options = [],
|
||||
public ?int $parent = null,
|
||||
public ?Sorting $sort = 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 ');
|
||||
|
||||
$options['sort'] = $this->sort->toMeilisearch();
|
||||
|
||||
return $engine->search($query, [...$this->options, ...$options]);
|
||||
})->within($this->form->participantsSearchableAs());
|
||||
}
|
||||
|
||||
public function setForm(Form $form): self
|
||||
{
|
||||
$this->form = $form;
|
||||
|
||||
if (is_null($this->sort)) {
|
||||
$this->sort = $this->form->defaultSorting();
|
||||
}
|
||||
|
||||
foreach ($form->getFields() as $field) {
|
||||
if (!Arr::has($this->data, $field->key)) {
|
||||
data_set($this->data, $field->key, static::$nan);
|
||||
|
@ -39,18 +83,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib;
|
||||
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class Sorting extends Data
|
||||
{
|
||||
public static function by(string $by): self
|
||||
{
|
||||
return static::factory()->withoutMagicalCreation()->from(['by' => $by]);
|
||||
}
|
||||
|
||||
public function __construct(public string $by, public bool $direction = false)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function toMeilisearch(): array
|
||||
{
|
||||
return [$this->by . ':' . ($this->direction ? 'desc' : 'asc')];
|
||||
}
|
||||
}
|
|
@ -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,31 @@
|
|||
<?php
|
||||
|
||||
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
||||
use App\Form\Models\Form;
|
||||
use App\Lib\Sorting;
|
||||
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();
|
||||
}
|
||||
$form->updateQuietly(['meta' => [...$form->meta, 'sorting' => Sorting::by('id')]]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
<template>
|
||||
<th @click="$emit('update:model-value')">
|
||||
<div class="flex justify-between items-center">
|
||||
<span v-text="label"></span>
|
||||
<ui-sprite v-if="value.by === column && value.direction === false" src="chevron" class="w-3 h-3 text-primaryfg ml-2">ASC</ui-sprite>
|
||||
<ui-sprite v-if="value.by === column && value.direction === true" src="chevron" class="rotate-180 w-3 h-3 text-primaryfg ml-2">DESC</ui-sprite>
|
||||
</div>
|
||||
</th>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineEmits(['update:model-value']);
|
||||
|
||||
defineProps({
|
||||
column: {
|
||||
type: String,
|
||||
default: () => '',
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
default: () => '',
|
||||
},
|
||||
value: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return {by: '', direction: false};
|
||||
},
|
||||
},
|
||||
sortable: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
</script>
|
|
@ -28,9 +28,9 @@ 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);
|
||||
await reload(false, p);
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
|
|
@ -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>
|
||||
|
@ -68,7 +69,15 @@
|
|||
</page-filter>
|
||||
<table cellspacing="0" cellpadding="0" border="0" class="custom-table custom-table-sm">
|
||||
<thead>
|
||||
<th v-for="column in activeColumns" :key="column.id" v-text="column.name"></th>
|
||||
<ui-th
|
||||
v-for="column in activeColumns"
|
||||
:key="column.id"
|
||||
:column="column.id"
|
||||
:label="column.name"
|
||||
:value="getSort"
|
||||
sortable
|
||||
@update:model-value="setSort(column.id, {filter: toFilterString(innerFilter)})"
|
||||
></ui-th>
|
||||
<th></th>
|
||||
</thead>
|
||||
|
||||
|
@ -117,7 +126,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>
|
||||
|
@ -173,6 +182,13 @@ var { meta, data, reload, reloadPage, axios, remove, toFilterString, url, update
|
|||
|
||||
const activeColumns = computed(() => meta.value.columns.filter((c) => meta.value.form_meta.active_columns.includes(c.id)));
|
||||
|
||||
const getSort = computed(() => innerFilter.value.sort);
|
||||
|
||||
async function setSort(column) {
|
||||
innerFilter.value.sort = getSort.value.by === column ? {by: column, direction: !getSort.value.direction} : {by: column, direction: false};
|
||||
sortingConfig.value = innerFilter.value.sort;
|
||||
}
|
||||
|
||||
const activeColumnsConfig = computed({
|
||||
get: () => meta.value.form_meta.active_columns,
|
||||
set: async (v) => {
|
||||
|
@ -185,6 +201,18 @@ const activeColumnsConfig = computed({
|
|||
},
|
||||
});
|
||||
|
||||
const sortingConfig = computed({
|
||||
get: () => meta.value.form_meta.sorting,
|
||||
set: async (v) => {
|
||||
const response = await axios.patch(meta.value.links.update_form_meta, {
|
||||
...meta.value.form_meta,
|
||||
sorting: v,
|
||||
});
|
||||
|
||||
meta.value.form_meta = response.data;
|
||||
},
|
||||
});
|
||||
|
||||
async function handleDelete() {
|
||||
await remove(deleting.value);
|
||||
deleting.value = null;
|
||||
|
|
|
@ -0,0 +1,306 @@
|
|||
<?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();
|
||||
|
||||
sleep(2);
|
||||
$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', ['by' => 'id', 'direction' => false])
|
||||
->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();
|
||||
|
||||
sleep(2);
|
||||
$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('sorts by active colums sorting by default', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([
|
||||
$this->checkboxField('check'),
|
||||
$this->checkboxField('vorname'),
|
||||
])->create();
|
||||
$form->update(['meta' => ['active_columns' => [], 'sorting' => ['by' => 'vorname', 'direction' => true]]]);
|
||||
|
||||
sleep(2);
|
||||
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||
->assertOk()
|
||||
->assertJsonPath('meta.filter.sort.by', 'vorname')
|
||||
->assertJsonPath('meta.filter.sort.direction', true);
|
||||
});
|
||||
|
||||
|
||||
it('testItDisplaysHasNamiField', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->fields([$this->namiField('mitglieder')])->create();
|
||||
sleep(2);
|
||||
$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();
|
||||
|
||||
sleep(2);
|
||||
$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();
|
||||
|
||||
sleep(2);
|
||||
$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();
|
||||
|
||||
sleep(2);
|
||||
$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();
|
||||
|
||||
sleep(2);
|
||||
$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();
|
||||
|
||||
sleep(2);
|
||||
$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();
|
||||
|
||||
sleep(2);
|
||||
$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();
|
||||
|
||||
sleep(2);
|
||||
$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');
|
||||
});
|
||||
|
||||
it('test it orders participants by value', function (array $values, array $sorting, array $expected) {
|
||||
list($key, $direction) = $sorting;
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()
|
||||
->fields([
|
||||
$this->textField('vorname')->name('Vorname'),
|
||||
$this->checkboxesField('select')->options(['Wölflinge', 'Pfadfinder']),
|
||||
]);
|
||||
foreach ($values as $value) {
|
||||
$form = $form->has(Participant::factory()->data(['vorname' => 'Max', 'select' => 'Pfadfinder', $key => $value]));
|
||||
}
|
||||
$form = $form->create();
|
||||
|
||||
sleep(2);
|
||||
$response = $this->callFilter('form.participant.index', ['sort' => ['by' => $key, 'direction' => $direction]], ['form' => $form]);
|
||||
$response->assertJsonPath('meta.filter.sort.by', $key);
|
||||
$response->assertJsonPath('meta.filter.sort.direction', $direction);
|
||||
|
||||
foreach ($expected as $index => $value) {
|
||||
$response->assertJsonPath("data.{$index}.{$key}", $value);
|
||||
}
|
||||
})->with([
|
||||
[
|
||||
['Anna', 'Sarah', 'Ben'],
|
||||
['vorname', false],
|
||||
['Anna', 'Ben', 'Sarah'],
|
||||
],
|
||||
[
|
||||
['Anna', 'Sarah', 'Ben'],
|
||||
['vorname', true],
|
||||
['Sarah', 'Ben', 'Anna'],
|
||||
],
|
||||
[
|
||||
['Wölflinge', 'Pfadfinder'],
|
||||
['select', false],
|
||||
['Pfadfinder', 'Wölflinge'],
|
||||
]
|
||||
]);
|
|
@ -59,6 +59,19 @@ class FormStoreActionTest extends FormTestCase
|
|||
$this->assertFrontendCacheCleared();
|
||||
}
|
||||
|
||||
public function testItStoresDefaultSorting(): void
|
||||
{
|
||||
Event::fake([Succeeded::class]);
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
FormRequest::new()->fields([$this->textField()])->fake();
|
||||
|
||||
$this->postJson(route('form.store'))->assertOk();
|
||||
|
||||
$form = Form::latest()->first();
|
||||
$this->assertEquals('id', $form->meta['sorting']['by']);
|
||||
$this->assertFalse(false, $form->meta['sorting']['direction']);
|
||||
}
|
||||
|
||||
public function testRegistrationDatesCanBeNull(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
|
|
|
@ -21,13 +21,13 @@ class FormUpdateMetaActionTest extends FormTestCase
|
|||
|
||||
$this->patchJson(route('form.update-meta', ['form' => $form]), [
|
||||
'active_columns' => ['textone'],
|
||||
'sorting' => ['textone', 'desc'],
|
||||
'sorting' => ['by' => 'textone', 'direction' => false],
|
||||
])->assertOk()
|
||||
->assertJsonPath('active_columns.0', 'textone')
|
||||
->assertJsonPath('sorting.1', 'desc');
|
||||
->assertJsonPath('sorting.by', 'textone');
|
||||
|
||||
$form = Form::latest()->first();
|
||||
$this->assertEquals(['textone', 'desc'], $form->meta['sorting']);
|
||||
$this->assertEquals(['by' => 'textone', 'direction' => false], $form->meta['sorting']);
|
||||
$this->assertEquals(['textone'], $form->meta['active_columns']);
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,11 @@ class FormUpdateMetaActionTest extends FormTestCase
|
|||
|
||||
$this->patchJson(route('form.update-meta', ['form' => $form]), [
|
||||
'active_columns' => ['created_at'],
|
||||
'sorting' => ['created_at', 'desc'],
|
||||
'sorting' => ['by' => 'textone', 'direction' => false],
|
||||
])->assertOk();
|
||||
|
||||
$form = Form::latest()->first();
|
||||
$this->assertEquals(['created_at', 'desc'], $form->fresh()->meta['sorting']);
|
||||
$this->assertEquals(['by' => 'textone', 'direction' => false], $form->fresh()->meta['sorting']);
|
||||
$this->assertEquals(['created_at'], $form->fresh()->meta['active_columns']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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