From 3cbb4768e852281d03cde15e90b6448c9d73a5da Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 21 Feb 2024 22:44:52 +0100 Subject: [PATCH] Add sorting and active_columns meta for form --- app/Form/Models/Form.php | 9 +++-- ...2_21_235228_create_formtemplates_table.php | 4 +- ..._02_02_002125_change_forms_description.php | 38 ------------------- ...02_04_032520_create_participants_table.php | 1 + ...create_participants_mitgliedsnr_column.php | 32 ---------------- resources/js/views/form/Participants.vue | 2 +- tests/Feature/Form/FormRegisterActionTest.php | 8 ---- tests/Feature/Form/FormStoreActionTest.php | 7 ---- tests/Feature/Form/FormTestCase.php | 8 ++++ tests/Feature/Form/FormUpdateActionTest.php | 7 ---- .../Form/ParticipantIndexActionTest.php | 3 +- 11 files changed, 20 insertions(+), 99 deletions(-) delete mode 100644 database/migrations/2024_02_02_002125_change_forms_description.php delete mode 100644 database/migrations/2024_02_20_002830_create_participants_mitgliedsnr_column.php diff --git a/app/Form/Models/Form.php b/app/Form/Models/Form.php index 85f038bb..7ac7e015 100644 --- a/app/Form/Models/Form.php +++ b/app/Form/Models/Form.php @@ -27,7 +27,7 @@ class Form extends Model implements HasMedia public $casts = [ 'config' => 'json', - 'active_columns' => 'json', + 'meta' => 'json', 'description' => 'json', ]; @@ -138,8 +138,11 @@ class Form extends Model implements HasMedia public static function booted(): void { static::saving(function (self $model) { - if (is_null($model->active_columns)) { - $model->setAttribute('active_columns', $model->getFields()->take(4)->pluck('key')->toArray()); + if (is_null($model->meta)) { + $model->setAttribute('meta', [ + 'active_columns' => $model->getFields()->take(4)->pluck('key')->toArray(), + 'sorting' => [$model->getFields()->first()['key'], 'asc'], + ]); } }); } diff --git a/database/migrations/2023_12_21_235228_create_formtemplates_table.php b/database/migrations/2023_12_21_235228_create_formtemplates_table.php index 37b27ac6..532c6a34 100644 --- a/database/migrations/2023_12_21_235228_create_formtemplates_table.php +++ b/database/migrations/2023_12_21_235228_create_formtemplates_table.php @@ -24,7 +24,7 @@ return new class extends Migration $table->id(); $table->string('name'); $table->string('slug'); - $table->text('description'); + $table->json('description'); $table->text('excerpt'); $table->json('config'); $table->date('from'); @@ -33,7 +33,7 @@ return new class extends Migration $table->dateTime('registration_until')->nullable(); $table->text('mail_top')->nullable(); $table->text('mail_bottom')->nullable(); - $table->json('active_columns'); + $table->json('meta'); $table->timestamps(); }); } diff --git a/database/migrations/2024_02_02_002125_change_forms_description.php b/database/migrations/2024_02_02_002125_change_forms_description.php deleted file mode 100644 index 642596d0..00000000 --- a/database/migrations/2024_02_02_002125_change_forms_description.php +++ /dev/null @@ -1,38 +0,0 @@ -dropColumn('description'); - }); - Schema::table('forms', function (Blueprint $table) { - $table->json('description')->after('name'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('forms', function (Blueprint $table) { - $table->dropColumn('description'); - }); - Schema::table('forms', function (Blueprint $table) { - $table->text('description')->after('name'); - }); - } -}; diff --git a/database/migrations/2024_02_04_032520_create_participants_table.php b/database/migrations/2024_02_04_032520_create_participants_table.php index 1a342bd3..2c747078 100644 --- a/database/migrations/2024_02_04_032520_create_participants_table.php +++ b/database/migrations/2024_02_04_032520_create_participants_table.php @@ -17,6 +17,7 @@ return new class extends Migration $table->id(); $table->json('data'); $table->foreignId('form_id'); + $table->string('mitgliedsnr')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2024_02_20_002830_create_participants_mitgliedsnr_column.php b/database/migrations/2024_02_20_002830_create_participants_mitgliedsnr_column.php deleted file mode 100644 index 8d10d26d..00000000 --- a/database/migrations/2024_02_20_002830_create_participants_mitgliedsnr_column.php +++ /dev/null @@ -1,32 +0,0 @@ -string('mitgliedsnr')->nullable(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::table('participants', function (Blueprint $table) { - $table->dropColumn('mitgliedsnr'); - }); - } -}; diff --git a/resources/js/views/form/Participants.vue b/resources/js/views/form/Participants.vue index 501b4dca..9e5b6ae1 100644 --- a/resources/js/views/form/Participants.vue +++ b/resources/js/views/form/Participants.vue @@ -39,5 +39,5 @@ var {meta, data, reload, reloadPage} = useApiIndex(props.url, 'participant'); await reload(); -const activeColumns = computed(() => meta.value.columns.filter((c) => meta.value.active_columns.includes(c.id))); +const activeColumns = computed(() => meta.value.columns.filter((c) => meta.value.form_meta.active_columns.includes(c.id))); diff --git a/tests/Feature/Form/FormRegisterActionTest.php b/tests/Feature/Form/FormRegisterActionTest.php index 4a9d9666..98d3bdb7 100644 --- a/tests/Feature/Form/FormRegisterActionTest.php +++ b/tests/Feature/Form/FormRegisterActionTest.php @@ -10,7 +10,6 @@ use App\Member\Member; use Carbon\Carbon; use Generator; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Support\Facades\Storage; use Illuminate\Testing\TestResponse; class FormRegisterActionTest extends FormTestCase @@ -18,13 +17,6 @@ class FormRegisterActionTest extends FormTestCase use DatabaseTransactions; - public function setUp(): void - { - parent::setUp(); - - Storage::fake('temp'); - } - public function testItSavesParticipantAsModel(): void { $this->login()->loginNami()->withoutExceptionHandling(); diff --git a/tests/Feature/Form/FormStoreActionTest.php b/tests/Feature/Form/FormStoreActionTest.php index 839b20ff..aca4fce1 100644 --- a/tests/Feature/Form/FormStoreActionTest.php +++ b/tests/Feature/Form/FormStoreActionTest.php @@ -16,13 +16,6 @@ class FormStoreActionTest extends FormTestCase use DatabaseTransactions; - public function setUp(): void - { - parent::setUp(); - - Storage::fake('temp'); - } - public function testItStoresForm(): void { Event::fake([Succeeded::class]); diff --git a/tests/Feature/Form/FormTestCase.php b/tests/Feature/Form/FormTestCase.php index e0c19ed8..888699b6 100644 --- a/tests/Feature/Form/FormTestCase.php +++ b/tests/Feature/Form/FormTestCase.php @@ -2,10 +2,18 @@ namespace Tests\Feature\Form; +use Illuminate\Support\Facades\Storage; use Tests\TestCase; use Tests\Lib\CreatesFormFields; class FormTestCase extends TestCase { use CreatesFormFields; + + public function setUp(): void + { + parent::setUp(); + + Storage::fake('temp'); + } } diff --git a/tests/Feature/Form/FormUpdateActionTest.php b/tests/Feature/Form/FormUpdateActionTest.php index f8d486e6..d2c4da71 100644 --- a/tests/Feature/Form/FormUpdateActionTest.php +++ b/tests/Feature/Form/FormUpdateActionTest.php @@ -11,13 +11,6 @@ class FormUpdateActionTest extends FormTestCase use DatabaseTransactions; - public function setUp(): void - { - parent::setUp(); - - Storage::fake('temp'); - } - public function testItSetsCustomAttributesOfFields(): void { $this->login()->loginNami()->withoutExceptionHandling(); diff --git a/tests/Feature/Form/ParticipantIndexActionTest.php b/tests/Feature/Form/ParticipantIndexActionTest.php index 3d381055..9a32460d 100644 --- a/tests/Feature/Form/ParticipantIndexActionTest.php +++ b/tests/Feature/Form/ParticipantIndexActionTest.php @@ -50,7 +50,8 @@ class ParticipantIndexActionTest extends FormTestCase ->assertJsonPath('meta.columns.0.id', 'vorname') ->assertJsonPath('meta.columns.6.display_attribute', 'birthday_display') ->assertJsonPath('meta.columns.0.display_attribute', 'vorname_display') - ->assertJsonPath('meta.active_columns', ['vorname', 'select', 'stufe', 'test1']); + ->assertJsonPath('meta.form_meta.active_columns', ['vorname', 'select', 'stufe', 'test1']) + ->assertJsonPath('meta.form_meta.sorting', ['vorname', 'asc']); } public function testItPresentsNamiField(): void