Add participant fields link
This commit is contained in:
parent
248499dc60
commit
c05434a7fb
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Actions;
|
||||
|
||||
use App\Form\Models\Participant;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class ParticipantFieldsAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(Participant $participant): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'id' => $participant->id,
|
||||
'config' => $participant->getConfig(),
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -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()]),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ParticipantFieldsActionTest extends FormTestCase
|
||||
{
|
||||
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testItShowsParticipantsFields(): void
|
||||
{
|
||||
$this->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']);
|
||||
}
|
||||
}
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue