Add update of active columns in participants table
This commit is contained in:
parent
acec968963
commit
9d11294fde
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form\Actions;
|
||||||
|
|
||||||
|
use App\Form\Models\Form;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Lorisleiva\Actions\ActionRequest;
|
||||||
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
|
|
||||||
|
class FormUpdateMetaAction
|
||||||
|
{
|
||||||
|
use AsAction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
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<string, mixed> $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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,7 +35,10 @@ class ParticipantResource extends JsonResource
|
||||||
public static function meta(Form $form): array
|
public static function meta(Form $form): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'active_columns' => $form->active_columns,
|
'form_meta' => $form->meta,
|
||||||
|
'links' => [
|
||||||
|
'update_form_meta' => route('form.update-meta', ['form' => $form]),
|
||||||
|
],
|
||||||
'columns' => $form->getFields()
|
'columns' => $form->getFields()
|
||||||
->map(fn ($field) => Field::fromConfig($field))
|
->map(fn ($field) => Field::fromConfig($field))
|
||||||
->map(fn ($field) => [
|
->map(fn ($field) => [
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="mt-5">
|
<div class="mt-5">
|
||||||
|
<page-filter breakpoint="lg">
|
||||||
|
<f-multipleselect id="active_columns" v-model="activeColumnsConfig" :options="meta.columns" label="Aktive Spalten" size="sm" name="active_columns"></f-multipleselect>
|
||||||
|
</page-filter>
|
||||||
<table cellspacing="0" cellpadding="0" border="0" class="custom-table custom-table-sm">
|
<table cellspacing="0" cellpadding="0" border="0" class="custom-table custom-table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<th v-for="column in activeColumns" :key="column.id" v-text="column.name"></th>
|
<th v-for="column in activeColumns" :key="column.id" v-text="column.name"></th>
|
||||||
|
@ -25,7 +28,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import {ref, computed} from 'vue';
|
import {ref, computed} from 'vue';
|
||||||
import {useApiIndex} from '../../composables/useApiIndex.js';
|
import {useApiIndex} from '../../composables/useApiIndex.js';
|
||||||
import FormBuilder from '../formtemplate/FormBuilder.vue';
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
url: {
|
url: {
|
||||||
|
@ -35,9 +37,21 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var {meta, data, reload, reloadPage} = useApiIndex(props.url, 'participant');
|
var {meta, data, reload, reloadPage, axios} = useApiIndex(props.url, 'participant');
|
||||||
|
|
||||||
await reload();
|
|
||||||
|
|
||||||
const activeColumns = computed(() => meta.value.columns.filter((c) => meta.value.form_meta.active_columns.includes(c.id)));
|
const activeColumns = computed(() => meta.value.columns.filter((c) => meta.value.form_meta.active_columns.includes(c.id)));
|
||||||
|
|
||||||
|
const activeColumnsConfig = computed({
|
||||||
|
get: () => meta.value.form_meta.active_columns,
|
||||||
|
set: async (v) => {
|
||||||
|
const response = await axios.patch(meta.value.links.update_form_meta, {
|
||||||
|
...meta.value.form_meta,
|
||||||
|
active_columns: v,
|
||||||
|
});
|
||||||
|
|
||||||
|
meta.value.form_meta = response.data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await reload();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Form;
|
||||||
|
|
||||||
|
use App\Form\Models\Form;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class FormUpdateMetaActionTest extends FormTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function testItUpdatesMetaOfForm(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
$form = Form::factory()
|
||||||
|
->sections([FormtemplateSectionRequest::new()->fields([
|
||||||
|
$this->textField('textone'),
|
||||||
|
$this->dropdownField('texttwo'),
|
||||||
|
])])->create();
|
||||||
|
|
||||||
|
$this->patchJson(route('form.update-meta', ['form' => $form]), [
|
||||||
|
'active_columns' => ['textone'],
|
||||||
|
'sorting' => ['textone', 'desc'],
|
||||||
|
])->assertOk()
|
||||||
|
->assertJsonPath('active_columns.0', 'textone')
|
||||||
|
->assertJsonPath('sorting.1', 'desc');
|
||||||
|
|
||||||
|
$form = Form::latest()->first();
|
||||||
|
$this->assertEquals(['textone', 'desc'], $form->meta['sorting']);
|
||||||
|
$this->assertEquals(['textone'], $form->meta['active_columns']);
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,6 +50,7 @@ class ParticipantIndexActionTest extends FormTestCase
|
||||||
->assertJsonPath('meta.columns.6.display_attribute', 'birthday_display')
|
->assertJsonPath('meta.columns.6.display_attribute', 'birthday_display')
|
||||||
->assertJsonPath('meta.columns.0.display_attribute', 'vorname_display')
|
->assertJsonPath('meta.columns.0.display_attribute', 'vorname_display')
|
||||||
->assertJsonPath('meta.form_meta.active_columns', ['vorname', 'select', 'stufe', 'test1'])
|
->assertJsonPath('meta.form_meta.active_columns', ['vorname', 'select', 'stufe', 'test1'])
|
||||||
|
->assertJsonPath('meta.links.update_form_meta', route('form.update-meta', ['form' => $form]))
|
||||||
->assertJsonPath('meta.form_meta.sorting', ['vorname', 'asc']);
|
->assertJsonPath('meta.form_meta.sorting', ['vorname', 'asc']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue