Add filterable switch for activity
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
7db9e10200
commit
b9c0abe49e
|
@ -21,6 +21,7 @@ class Activity extends Model
|
|||
|
||||
public $casts = [
|
||||
'nami_id' => 'integer',
|
||||
'is_filterable' => 'boolean',
|
||||
];
|
||||
|
||||
public function sluggable(): array
|
||||
|
@ -49,5 +50,4 @@ class Activity extends Model
|
|||
{
|
||||
return $this->belongsToMany(Subactivity::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ class ActivityStoreAction
|
|||
{
|
||||
return [
|
||||
'name' => 'required|max:255',
|
||||
'is_filterable' => 'present|boolean',
|
||||
'subactivities' => 'present|array',
|
||||
];
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class ActivityUpdateAction
|
|||
*/
|
||||
public function handle(Activity $activity, array $payload): void
|
||||
{
|
||||
DB::transaction(function() use ($activity, $payload) {
|
||||
DB::transaction(function () use ($activity, $payload) {
|
||||
$activity->update($payload);
|
||||
$activity->subactivities()->sync($payload['subactivities']);
|
||||
});
|
||||
|
@ -35,7 +35,8 @@ class ActivityUpdateAction
|
|||
{
|
||||
return [
|
||||
'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
|
||||
*
|
||||
* @param Payload $payload
|
||||
*/
|
||||
private function validateNami(Activity $activity, array $payload): void
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Activity\Actions;
|
||||
|
||||
use App\Activity;
|
||||
use App\Activity\Resources\ActivityResource;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
@ -18,8 +17,9 @@ class CreateAction
|
|||
'meta' => ActivityResource::meta(),
|
||||
'data' => [
|
||||
'name' => '',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [],
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,12 @@ class ActivityResource extends JsonResource
|
|||
'name' => $this->name,
|
||||
'id' => $this->id,
|
||||
'subactivities' => $this->subactivities->pluck('id')->toArray(),
|
||||
'is_filterable' => $this->is_filterable,
|
||||
'links' => [
|
||||
'edit' => route('activity.edit', ['activity' => $this->getModel()]),
|
||||
'update' => route('activity.update', ['activity' => $this->getModel()]),
|
||||
'destroy' => route('activity.destroy', ['activity' => $this->getModel()]),
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
<template>
|
||||
<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>
|
||||
<div class="grid gap-2 sm:grid-cols-2 md:grid-cols-4">
|
||||
<f-switch
|
||||
|
@ -17,7 +20,7 @@
|
|||
</div>
|
||||
<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>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ class CreateTest extends TestCase
|
|||
|
||||
$this->assertInertiaHas([
|
||||
'name' => '',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [],
|
||||
], $response, 'data');
|
||||
$this->assertInertiaHas([
|
||||
|
@ -26,5 +27,4 @@ class CreateTest extends TestCase
|
|||
'name' => 'Pupu',
|
||||
], $response, 'meta.subactivities.0');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,11 @@ class EditTest extends TestCase
|
|||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$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([
|
||||
'name' => 'Asas',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [$activity->subactivities->first()->id],
|
||||
], $response, 'data');
|
||||
$this->assertInertiaHas([
|
||||
|
@ -27,5 +28,4 @@ class EditTest extends TestCase
|
|||
'name' => 'Pupu',
|
||||
], $response, 'meta.subactivities.0');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ class UpdateTest extends TestCase
|
|||
|
||||
$response = $this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'Lorem',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [],
|
||||
]);
|
||||
|
||||
|
@ -32,6 +33,7 @@ class UpdateTest extends TestCase
|
|||
|
||||
$this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'abc',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [$subactivity->id],
|
||||
]);
|
||||
|
||||
|
@ -45,6 +47,7 @@ class UpdateTest extends TestCase
|
|||
|
||||
$response = $this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'abc',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [],
|
||||
]);
|
||||
|
||||
|
@ -59,6 +62,7 @@ class UpdateTest extends TestCase
|
|||
|
||||
$response = $this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'abc',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [$subactivity->id],
|
||||
]);
|
||||
|
||||
|
@ -73,6 +77,7 @@ class UpdateTest extends TestCase
|
|||
|
||||
$response = $this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'abc',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [$otherSubactivity->id],
|
||||
]);
|
||||
|
||||
|
@ -86,6 +91,7 @@ class UpdateTest extends TestCase
|
|||
|
||||
$response = $this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => '',
|
||||
'is_filterable' => true,
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors(['name' => 'Name ist erforderlich.']);
|
||||
|
@ -99,11 +105,12 @@ class UpdateTest extends TestCase
|
|||
|
||||
$response = $this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'Lorem',
|
||||
'is_filterable' => true,
|
||||
'subactivities' => [],
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/activity');
|
||||
$this->assertDatabaseHas('activities', ['name' => 'Lorem']);
|
||||
$this->assertDatabaseHas('activities', ['name' => 'Lorem', 'is_filterable' => true]);
|
||||
}
|
||||
|
||||
public function testItSetsSubactivities(): void
|
||||
|
@ -114,6 +121,7 @@ class UpdateTest extends TestCase
|
|||
|
||||
$this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'Lorem',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [$subactivity->id],
|
||||
]);
|
||||
|
||||
|
@ -128,6 +136,7 @@ class UpdateTest extends TestCase
|
|||
$this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'Lorem',
|
||||
'nami_id' => 66,
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [],
|
||||
]);
|
||||
|
||||
|
@ -143,10 +152,10 @@ class UpdateTest extends TestCase
|
|||
|
||||
$this->patch(route('activity.update', ['activity' => $activity]), [
|
||||
'name' => 'Lorem',
|
||||
'is_filterable' => false,
|
||||
'subactivities' => [],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseEmpty('activity_subactivity');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue