From c05434a7fbe18b8e9a23929a1eae15501e8db86c Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 12 Jul 2024 19:49:47 +0200 Subject: [PATCH] Add participant fields link --- app/Form/Actions/ParticipantFieldsAction.php | 22 ++++++++++++ app/Form/Resources/ParticipantResource.php | 3 +- routes/web.php | 2 ++ .../Form/ParticipantFieldsActionTest.php | 36 +++++++++++++++++++ .../Form/ParticipantIndexActionTest.php | 1 + 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 app/Form/Actions/ParticipantFieldsAction.php create mode 100644 tests/Feature/Form/ParticipantFieldsActionTest.php diff --git a/app/Form/Actions/ParticipantFieldsAction.php b/app/Form/Actions/ParticipantFieldsAction.php new file mode 100644 index 00000000..61e5515d --- /dev/null +++ b/app/Form/Actions/ParticipantFieldsAction.php @@ -0,0 +1,22 @@ +json([ + 'data' => [ + 'id' => $participant->id, + 'config' => $participant->getConfig(), + ] + ]); + } +} diff --git a/app/Form/Resources/ParticipantResource.php b/app/Form/Resources/ParticipantResource.php index 36c65dd6..9ad96f18 100644 --- a/app/Form/Resources/ParticipantResource.php +++ b/app/Form/Resources/ParticipantResource.php @@ -31,7 +31,8 @@ class ParticipantResource extends JsonResource 'links' => [ 'assign' => route('participant.assign', ['participant' => $this->getModel()]), 'destroy' => route('participant.destroy', ['participant' => $this->getModel()]), - 'children' => route('form.participant.index', ['form' => $this->form, 'parent' => $this->id]) + 'children' => route('form.participant.index', ['form' => $this->form, 'parent' => $this->id]), + 'fields' => route('participant.fields', ['participant' => $this->getModel()]), ] ]; } diff --git a/routes/web.php b/routes/web.php index d5d36ebf..7184b80b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -38,6 +38,7 @@ use App\Form\Actions\FormUpdateMetaAction; use App\Form\Actions\IsDirtyAction; use App\Form\Actions\ParticipantAssignAction; use App\Form\Actions\ParticipantDestroyAction; +use App\Form\Actions\ParticipantFieldsAction; use App\Form\Actions\ParticipantIndexAction; use App\Initialize\Actions\InitializeAction; use App\Initialize\Actions\InitializeFormAction; @@ -172,6 +173,7 @@ Route::group(['middleware' => 'auth:web'], function (): void { Route::post('/form/{form}/is-dirty', IsDirtyAction::class)->name('form.is-dirty'); Route::delete('/participant/{participant}', ParticipantDestroyAction::class)->name('participant.destroy'); Route::post('/participant/{participant}/assign', ParticipantAssignAction::class)->name('participant.assign'); + Route::get('/participant/{participant}/fields', ParticipantFieldsAction::class)->name('participant.fields'); // ------------------------------------ fileshare ----------------------------------- Route::post('/fileshare', FileshareStoreAction::class)->name('fileshare.store'); diff --git a/tests/Feature/Form/ParticipantFieldsActionTest.php b/tests/Feature/Form/ParticipantFieldsActionTest.php new file mode 100644 index 00000000..30db23fb --- /dev/null +++ b/tests/Feature/Form/ParticipantFieldsActionTest.php @@ -0,0 +1,36 @@ +login()->loginNami()->withoutExceptionHandling(); + $participant = Participant::factory()->data(['vorname' => 'Max', 'select' => ['A', 'B']]) + ->for(Form::factory()->sections([ + FormtemplateSectionRequest::new()->name('Sektion')->fields([ + $this->textField('vorname')->name('Vorname'), + $this->checkboxesField('select')->options(['A', 'B', 'C']), + ]) + + ])) + ->create(); + + $this->callFilter('participant.fields', [], ['participant' => $participant->id]) + ->assertOk() + ->assertJsonPath('data.id', $participant->id) + ->assertJsonPath('data.config.sections.0.name', 'Sektion') + ->assertJsonPath('data.config.sections.0.fields.0.key', 'vorname') + ->assertJsonPath('data.config.sections.0.fields.0.value', 'Max') + ->assertJsonPath('data.config.sections.0.fields.1.key', 'select') + ->assertJsonPath('data.config.sections.0.fields.1.value', ['A', 'B']); + } +} diff --git a/tests/Feature/Form/ParticipantIndexActionTest.php b/tests/Feature/Form/ParticipantIndexActionTest.php index c4948b54..d74507a5 100644 --- a/tests/Feature/Form/ParticipantIndexActionTest.php +++ b/tests/Feature/Form/ParticipantIndexActionTest.php @@ -48,6 +48,7 @@ class ParticipantIndexActionTest extends FormTestCase ->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('meta.columns.0.name', 'Vorname') ->assertJsonPath('meta.columns.0.base_type', class_basename(TextField::class)) ->assertJsonPath('meta.columns.0.id', 'vorname')