Add inactive forms

This commit is contained in:
philipp lang 2024-05-27 18:30:05 +02:00
parent e5008d127d
commit c4aa9b1051
10 changed files with 44 additions and 4 deletions

View File

@ -32,6 +32,7 @@ class FormStoreAction
'mail_bottom' => 'array',
'header_image' => 'required|exclude',
'mailattachments' => 'present|array|exclude',
'is_active' => 'boolean',
];
}

View File

@ -31,6 +31,7 @@ class FormUpdateAction
'registration_until' => 'present|nullable|date',
'mail_top' => 'array',
'mail_bottom' => 'array',
'is_active' => 'boolean',
];
}

View File

@ -31,6 +31,7 @@ class Form extends Model implements HasMedia
'description' => 'json',
'mail_top' => 'json',
'mail_bottom' => 'json',
'is_active' => 'boolean',
];
/** @var array<int, string> */
@ -133,6 +134,7 @@ class Form extends Model implements HasMedia
'from' => $this->from->timestamp,
'to' => $this->to->timestamp,
'name' => $this->name,
'is_active' => $this->is_active,
];
}

View File

@ -43,6 +43,7 @@ class FormResource extends JsonResource
'registration_until' => $this->registration_until?->format('Y-m-d H:i:s'),
'config' => $this->config,
'participants_count' => $this->participants_count,
'is_active' => $this->is_active,
'links' => [
'participant_index' => route('form.participant.index', ['form' => $this->getModel()]),
'update' => route('form.update', ['form' => $this->getModel()]),
@ -71,6 +72,7 @@ class FormResource extends JsonResource
'specialTypes' => SpecialType::forSelect(),
'default' => [
'description' => [],
'is_active' => true,
'name' => '',
'excerpt' => '',
'from' => null,

View File

@ -19,6 +19,7 @@ class FormFilterScope extends ScoutFilter
public function __construct(
public ?string $search = '',
public bool $past = false,
public bool $inactive = false,
) {
}
@ -35,6 +36,10 @@ class FormFilterScope extends ScoutFilter
$filters->push('to > ' . now()->timestamp);
}
if ($this->inactive === false) {
$filters->push('is_active = true');
}
$options['filter'] = $filters->implode(' AND ');
return $engine->search($query, $options);

View File

@ -146,9 +146,9 @@ return [
]
],
Form::class => [
'filterableAttributes' => ['to'],
'filterableAttributes' => ['to', 'is_active'],
'searchableAttributes' => ['name'],
'sortableAttributes' => ['from',],
'sortableAttributes' => ['from'],
'displayedAttributes' => ['from', 'name', 'id', 'to'],
'pagination' => [
'maxTotalHits' => 1000000,

View File

@ -39,7 +39,10 @@
<div class="flex flex-col mt-3">
<ui-tabs v-model="active" :entries="tabs"></ui-tabs>
<div v-show="active === 0" class="grid grid-cols-2 gap-3">
<f-text id="name" v-model="single.name" name="name" label="Name" required></f-text>
<div class="flex space-x-3">
<f-text id="name" v-model="single.name" class="grow" name="name" label="Name" required></f-text>
<f-switch id="is_active" v-model="single.is_active" name="is_active" label="Aktiv"></f-switch>
</div>
<f-singlefile
id="header_image"
v-model="single.header_image"
@ -120,6 +123,7 @@
<page-filter breakpoint="xl">
<f-text id="search" :model-value="getFilter('search')" name="search" label="Suchen …" size="sm" @update:model-value="setFilter('search', $event)"></f-text>
<f-switch id="past" :model-value="getFilter('past')" label="vergangene zeigen" size="sm" @update:model-value="setFilter('past', $event)"></f-switch>
<f-switch id="inactive" :model-value="getFilter('inactive')" label="inaktive zeigen" size="sm" @update:model-value="setFilter('inactive', $event)"></f-switch>
</page-filter>
<table cellspacing="0" cellpadding="0" border="0" class="custom-table custom-table-sm">

View File

@ -46,6 +46,7 @@ class FormIndexActionTest extends FormTestCase
->assertInertiaPath('data.data.0.from', '2023-05-05')
->assertInertiaPath('data.data.0.participants_count', 5)
->assertInertiaPath('data.data.0.to', '2023-06-07')
->assertInertiaPath('data.data.0.is_active', true)
->assertInertiaPath('data.data.0.registration_from', '2023-05-06 04:00:00')
->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05:00:00')
->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form]))
@ -56,6 +57,7 @@ class FormIndexActionTest extends FormTestCase
->assertInertiaPath('data.meta.default.name', '')
->assertInertiaPath('data.meta.default.description', [])
->assertInertiaPath('data.meta.default.excerpt', '')
->assertInertiaPath('data.meta.default.is_active', true)
->assertInertiaPath('data.meta.default.mailattachments', [])
->assertInertiaPath('data.meta.default.config', null)
->assertInertiaPath('data.meta.base_url', url(''))
@ -77,6 +79,18 @@ class FormIndexActionTest extends FormTestCase
->assertInertiaCount('data.data', 2);
}
public function testItDoesntReturnInactiveForms(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
Form::factory()->isActive(false)->count(1)->create();
Form::factory()->isActive(true)->count(2)->create();
sleep(1);
$this->callFilter('form.index', [])->assertInertiaCount('data.data', 2);
$this->callFilter('form.index', ['inactive' => true])->assertInertiaCount('data.data', 3);
$this->callFilter('form.index', ['inactive' => false])->assertInertiaCount('data.data', 2);
}
public function testItOrdersByStartDateDesc(): void
{
$this->withoutExceptionHandling()->login()->loginNami();

View File

@ -8,7 +8,6 @@ use App\Lib\Events\Succeeded;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Event;
use Generator;
use Illuminate\Support\Facades\Storage;
use Tests\RequestFactories\EditorRequestFactory;
class FormStoreActionTest extends FormTestCase
@ -42,6 +41,7 @@ class FormStoreActionTest extends FormTestCase
$this->assertEquals(json_decode('{"time":1,"blocks":[{"id":11,"type":"paragraph","data":{"text":"lala"},"tunes":{"condition":{"mode":"all","ifs":[]}}}],"version":"1.0"}', true), $form->mail_top);
$this->assertEquals(json_decode('{"time":1,"blocks":[{"id":12,"type":"paragraph","data":{"text":"lalab"},"tunes":{"condition":{"mode":"all","ifs":[]}}}],"version":"1.0"}', true), $form->mail_bottom);
$this->assertEquals('2023-05-04 01:00', $form->registration_from->format('Y-m-d H:i'));
$this->assertEquals(true, $form->is_active);
$this->assertEquals('2023-07-07 01:00', $form->registration_until->format('Y-m-d H:i'));
$this->assertEquals('2023-07-07', $form->from->format('Y-m-d'));
$this->assertEquals('2023-07-08', $form->to->format('Y-m-d'));

View File

@ -48,6 +48,17 @@ class FormUpdateActionTest extends FormTestCase
$this->assertEquals(['firstname'], $form->fresh()->meta['active_columns']);
}
public function testItUpdatesActiveState(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isActive(false)->create())->assertSessionDoesntHaveErrors()->assertOk();
$this->assertFalse($form->fresh()->is_active);
$this->patchJson(route('form.update', ['form' => $form]), FormRequest::new()->isActive(true)->create())->assertSessionDoesntHaveErrors()->assertOk();
$this->assertTrue($form->fresh()->is_active);
}
public function testItUpdatesActiveColumnsWhenFieldsAdded(): void
{
$this->login()->loginNami()->withoutExceptionHandling();