Add filterable switch for activity
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2023-03-04 12:09:25 +01:00
parent 7db9e10200
commit b9c0abe49e
9 changed files with 29 additions and 13 deletions

View File

@ -21,6 +21,7 @@ class Activity extends Model
public $casts = [ public $casts = [
'nami_id' => 'integer', 'nami_id' => 'integer',
'is_filterable' => 'boolean',
]; ];
public function sluggable(): array public function sluggable(): array
@ -49,5 +50,4 @@ class Activity extends Model
{ {
return $this->belongsToMany(Subactivity::class); return $this->belongsToMany(Subactivity::class);
} }
} }

View File

@ -30,6 +30,7 @@ class ActivityStoreAction
{ {
return [ return [
'name' => 'required|max:255', 'name' => 'required|max:255',
'is_filterable' => 'present|boolean',
'subactivities' => 'present|array', 'subactivities' => 'present|array',
]; ];
} }

View File

@ -22,7 +22,7 @@ class ActivityUpdateAction
*/ */
public function handle(Activity $activity, array $payload): void public function handle(Activity $activity, array $payload): void
{ {
DB::transaction(function() use ($activity, $payload) { DB::transaction(function () use ($activity, $payload) {
$activity->update($payload); $activity->update($payload);
$activity->subactivities()->sync($payload['subactivities']); $activity->subactivities()->sync($payload['subactivities']);
}); });
@ -35,7 +35,8 @@ class ActivityUpdateAction
{ {
return [ return [
'name' => 'required|max:255', 'name' => 'required|max:255',
'subactivities' => 'present|array' 'is_filterable' => 'present|boolean',
'subactivities' => 'present|array',
]; ];
} }
@ -52,6 +53,7 @@ class ActivityUpdateAction
/** /**
* @todo handle this with a model event on the pivot model * @todo handle this with a model event on the pivot model
*
* @param Payload $payload * @param Payload $payload
*/ */
private function validateNami(Activity $activity, array $payload): void private function validateNami(Activity $activity, array $payload): void

View File

@ -2,7 +2,6 @@
namespace App\Activity\Actions; namespace App\Activity\Actions;
use App\Activity;
use App\Activity\Resources\ActivityResource; use App\Activity\Resources\ActivityResource;
use Inertia\Inertia; use Inertia\Inertia;
use Inertia\Response; use Inertia\Response;
@ -18,8 +17,9 @@ class CreateAction
'meta' => ActivityResource::meta(), 'meta' => ActivityResource::meta(),
'data' => [ 'data' => [
'name' => '', 'name' => '',
'is_filterable' => false,
'subactivities' => [], 'subactivities' => [],
] ],
]); ]);
} }
} }

View File

@ -28,11 +28,12 @@ class ActivityResource extends JsonResource
'name' => $this->name, 'name' => $this->name,
'id' => $this->id, 'id' => $this->id,
'subactivities' => $this->subactivities->pluck('id')->toArray(), 'subactivities' => $this->subactivities->pluck('id')->toArray(),
'is_filterable' => $this->is_filterable,
'links' => [ 'links' => [
'edit' => route('activity.edit', ['activity' => $this->getModel()]), 'edit' => route('activity.edit', ['activity' => $this->getModel()]),
'update' => route('activity.update', ['activity' => $this->getModel()]), 'update' => route('activity.update', ['activity' => $this->getModel()]),
'destroy' => route('activity.destroy', ['activity' => $this->getModel()]), 'destroy' => route('activity.destroy', ['activity' => $this->getModel()]),
] ],
]; ];
} }

View File

@ -1,6 +1,9 @@
<template> <template>
<form id="actionform" class="grow p-3" @submit.prevent="submit"> <form id="actionform" class="grow p-3" @submit.prevent="submit">
<f-text id="name" v-model="inner.name" label="Name" required></f-text> <div class="flex space-x-3">
<f-text id="name" v-model="inner.name" label="Name" required></f-text>
<f-switch v-model="inner.is_filterable" name="is_filterable" id="is_filterable" label="Filterbar"></f-switch>
</div>
<checkboxes-label class="mt-6">Untertätigkeiten</checkboxes-label> <checkboxes-label class="mt-6">Untertätigkeiten</checkboxes-label>
<div class="grid gap-2 sm:grid-cols-2 md:grid-cols-4"> <div class="grid gap-2 sm:grid-cols-2 md:grid-cols-4">
<f-switch <f-switch
@ -17,7 +20,7 @@
</div> </div>
<save-button form="actionform"></save-button> <save-button form="actionform"></save-button>
<new-subactivity @stored="reloadSubactivities" :activity-id="inner.id"></new-subactivity> <new-subactivity v-if="mode === 'edit'" @stored="reloadSubactivities" :activity-id="inner.id"></new-subactivity>
</form> </form>
</template> </template>

View File

@ -19,6 +19,7 @@ class CreateTest extends TestCase
$this->assertInertiaHas([ $this->assertInertiaHas([
'name' => '', 'name' => '',
'is_filterable' => false,
'subactivities' => [], 'subactivities' => [],
], $response, 'data'); ], $response, 'data');
$this->assertInertiaHas([ $this->assertInertiaHas([
@ -26,5 +27,4 @@ class CreateTest extends TestCase
'name' => 'Pupu', 'name' => 'Pupu',
], $response, 'meta.subactivities.0'); ], $response, 'meta.subactivities.0');
} }
} }

View File

@ -16,10 +16,11 @@ class EditTest extends TestCase
$this->login()->loginNami()->withoutExceptionHandling(); $this->login()->loginNami()->withoutExceptionHandling();
$activity = Activity::factory()->name('Asas')->hasAttached(Subactivity::factory()->name('Pupu'))->create(); $activity = Activity::factory()->name('Asas')->hasAttached(Subactivity::factory()->name('Pupu'))->create();
$response = $this->get(route('activity.edit', ['activity' => $activity])); $response = $this->get(route('activity.edit', ['activity' => $activity]));
$this->assertInertiaHas([ $this->assertInertiaHas([
'name' => 'Asas', 'name' => 'Asas',
'is_filterable' => false,
'subactivities' => [$activity->subactivities->first()->id], 'subactivities' => [$activity->subactivities->first()->id],
], $response, 'data'); ], $response, 'data');
$this->assertInertiaHas([ $this->assertInertiaHas([
@ -27,5 +28,4 @@ class EditTest extends TestCase
'name' => 'Pupu', 'name' => 'Pupu',
], $response, 'meta.subactivities.0'); ], $response, 'meta.subactivities.0');
} }
} }

View File

@ -18,6 +18,7 @@ class UpdateTest extends TestCase
$response = $this->patch(route('activity.update', ['activity' => $activity]), [ $response = $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'Lorem', 'name' => 'Lorem',
'is_filterable' => false,
'subactivities' => [], 'subactivities' => [],
]); ]);
@ -32,6 +33,7 @@ class UpdateTest extends TestCase
$this->patch(route('activity.update', ['activity' => $activity]), [ $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'abc', 'name' => 'abc',
'is_filterable' => false,
'subactivities' => [$subactivity->id], 'subactivities' => [$subactivity->id],
]); ]);
@ -45,6 +47,7 @@ class UpdateTest extends TestCase
$response = $this->patch(route('activity.update', ['activity' => $activity]), [ $response = $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'abc', 'name' => 'abc',
'is_filterable' => false,
'subactivities' => [], 'subactivities' => [],
]); ]);
@ -59,6 +62,7 @@ class UpdateTest extends TestCase
$response = $this->patch(route('activity.update', ['activity' => $activity]), [ $response = $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'abc', 'name' => 'abc',
'is_filterable' => false,
'subactivities' => [$subactivity->id], 'subactivities' => [$subactivity->id],
]); ]);
@ -73,6 +77,7 @@ class UpdateTest extends TestCase
$response = $this->patch(route('activity.update', ['activity' => $activity]), [ $response = $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'abc', 'name' => 'abc',
'is_filterable' => false,
'subactivities' => [$otherSubactivity->id], 'subactivities' => [$otherSubactivity->id],
]); ]);
@ -86,6 +91,7 @@ class UpdateTest extends TestCase
$response = $this->patch(route('activity.update', ['activity' => $activity]), [ $response = $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => '', 'name' => '',
'is_filterable' => true,
]); ]);
$response->assertSessionHasErrors(['name' => 'Name ist erforderlich.']); $response->assertSessionHasErrors(['name' => 'Name ist erforderlich.']);
@ -99,11 +105,12 @@ class UpdateTest extends TestCase
$response = $this->patch(route('activity.update', ['activity' => $activity]), [ $response = $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'Lorem', 'name' => 'Lorem',
'is_filterable' => true,
'subactivities' => [], 'subactivities' => [],
]); ]);
$response->assertRedirect('/activity'); $response->assertRedirect('/activity');
$this->assertDatabaseHas('activities', ['name' => 'Lorem']); $this->assertDatabaseHas('activities', ['name' => 'Lorem', 'is_filterable' => true]);
} }
public function testItSetsSubactivities(): void public function testItSetsSubactivities(): void
@ -114,6 +121,7 @@ class UpdateTest extends TestCase
$this->patch(route('activity.update', ['activity' => $activity]), [ $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'Lorem', 'name' => 'Lorem',
'is_filterable' => false,
'subactivities' => [$subactivity->id], 'subactivities' => [$subactivity->id],
]); ]);
@ -128,6 +136,7 @@ class UpdateTest extends TestCase
$this->patch(route('activity.update', ['activity' => $activity]), [ $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'Lorem', 'name' => 'Lorem',
'nami_id' => 66, 'nami_id' => 66,
'is_filterable' => false,
'subactivities' => [], 'subactivities' => [],
]); ]);
@ -143,10 +152,10 @@ class UpdateTest extends TestCase
$this->patch(route('activity.update', ['activity' => $activity]), [ $this->patch(route('activity.update', ['activity' => $activity]), [
'name' => 'Lorem', 'name' => 'Lorem',
'is_filterable' => false,
'subactivities' => [], 'subactivities' => [],
]); ]);
$this->assertDatabaseEmpty('activity_subactivity'); $this->assertDatabaseEmpty('activity_subactivity');
} }
} }