From 9d11294fde33902c4733a7e5e024277d0b3db3fb Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 21 Feb 2024 23:18:31 +0100 Subject: [PATCH] Add update of active columns in participants table --- app/Form/Actions/FormUpdateMetaAction.php | 45 +++++++++++++++++++ app/Form/Resources/ParticipantResource.php | 5 ++- resources/js/views/form/Participants.vue | 22 +++++++-- .../Feature/Form/FormUpdateMetaActionTest.php | 33 ++++++++++++++ .../Form/ParticipantIndexActionTest.php | 1 + 5 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 app/Form/Actions/FormUpdateMetaAction.php create mode 100644 tests/Feature/Form/FormUpdateMetaActionTest.php diff --git a/app/Form/Actions/FormUpdateMetaAction.php b/app/Form/Actions/FormUpdateMetaAction.php new file mode 100644 index 00000000..825bfc12 --- /dev/null +++ b/app/Form/Actions/FormUpdateMetaAction.php @@ -0,0 +1,45 @@ + + */ + public function rules(): array + { + /** @var Form */ + $form = request()->route('form'); + + return [ + 'sorting' => 'array', + 'sorting.0' => 'required|string', + 'sorting.1' => 'required|string|in:asc,desc', + 'active_columns' => 'array', + 'active_columns.*' => ['string', Rule::in($form->getFields()->pluck('key')->toArray())] + ]; + } + + /** + * @param array $input + */ + public function handle(Form $form, array $input): void + { + $form->update(['meta' => $input]); + } + + public function asController(Form $form, ActionRequest $request) + { + $this->handle($form, $request->validated()); + + return response()->json($form->fresh()->meta); + } +} diff --git a/app/Form/Resources/ParticipantResource.php b/app/Form/Resources/ParticipantResource.php index 1d1bea24..577a41af 100644 --- a/app/Form/Resources/ParticipantResource.php +++ b/app/Form/Resources/ParticipantResource.php @@ -35,7 +35,10 @@ class ParticipantResource extends JsonResource public static function meta(Form $form): array { return [ - 'active_columns' => $form->active_columns, + 'form_meta' => $form->meta, + 'links' => [ + 'update_form_meta' => route('form.update-meta', ['form' => $form]), + ], 'columns' => $form->getFields() ->map(fn ($field) => Field::fromConfig($field)) ->map(fn ($field) => [ diff --git a/resources/js/views/form/Participants.vue b/resources/js/views/form/Participants.vue index 9e5b6ae1..ca4a68c7 100644 --- a/resources/js/views/form/Participants.vue +++ b/resources/js/views/form/Participants.vue @@ -1,5 +1,8 @@