Add: Destroy formtemplate

This commit is contained in:
philipp lang 2024-02-19 03:01:18 +01:00
parent b86b2b6063
commit ebf7a1d5c9
6 changed files with 87 additions and 11 deletions

View File

@ -0,0 +1,27 @@
<?php
namespace App\Form\Actions;
use App\Form\Models\Formtemplate;
use App\Lib\Events\Succeeded;
use Illuminate\Http\JsonResponse;
use Lorisleiva\Actions\Concerns\AsAction;
class FormtemplateDestroyAction
{
use AsAction;
public function handle(Formtemplate $formtemplate): void
{
$formtemplate->delete();
}
public function asController(Formtemplate $formtemplate): JsonResponse
{
$this->handle($formtemplate);
Succeeded::message('Vorlage gelöscht.')->dispatch();
return response()->json([]);
}
}

View File

@ -29,6 +29,7 @@ class FormtemplateResource extends JsonResource
...parent::toArray($request),
'links' => [
'update' => route('formtemplate.update', ['formtemplate' => $this->getModel()]),
'destroy' => route('formtemplate.destroy', ['formtemplate' => $this->getModel()]),
]
];
}
@ -42,7 +43,7 @@ class FormtemplateResource extends JsonResource
'base_url' => url(''),
'groups' => Group::forSelect(),
'fields' => Field::asMeta(),
'namiFields' => NamiType::forSelect(),
'namiTypes' => NamiType::forSelect(),
'links' => [
'store' => route('formtemplate.store'),
'form_index' => route('form.index'),

View File

@ -2,12 +2,28 @@
<page-layout>
<template #toolbar>
<page-toolbar-button color="primary" icon="plus" @click="create">Vorlage erstellen</page-toolbar-button>
<page-toolbar-button :href="meta.links.form_index" color="primary"
icon="event">Veranstaltungen</page-toolbar-button>
<page-toolbar-button :href="meta.links.form_index" color="primary" icon="event">Veranstaltungen</page-toolbar-button>
</template>
<ui-popup v-if="single !== null" :heading="`Vorlage ${single.id ? 'bearbeiten' : 'erstellen'}`" full
@close="cancel">
<ui-popup v-if="deleting !== null" :heading="`Formular-Vorlage ${deleting.name} löschen?`" @close="deleting = null">
<div>
<p class="mt-4">Diese Formular-Vorlage löschen?</p>
<div class="grid grid-cols-2 gap-3 mt-6">
<a
href="#"
class="text-center btn btn-danger"
@click.prevent="
remove(deleting);
deleting = null;
"
>Formular-Vorlage löschen</a
>
<a href="#" class="text-center btn btn-primary" @click.prevent="deleting = null">Abbrechen</a>
</div>
</div>
</ui-popup>
<ui-popup v-if="single !== null" :heading="`Vorlage ${single.id ? 'bearbeiten' : 'erstellen'}`" full @close="cancel">
<form-builder v-model="single.config" :meta="meta">
<template #meta>
<f-text id="name" v-model="single.name" name="name" label="Name" required></f-text>
@ -31,8 +47,8 @@
<div v-text="formtemplate.name"></div>
</td>
<td>
<a v-tooltip="`Bearbeiten`" href="#" class="ml-2 inline-flex btn btn-warning btn-sm"
@click.prevent="edit(formtemplate)"><ui-sprite src="pencil"></ui-sprite></a>
<a v-tooltip="`Bearbeiten`" href="#" class="ml-2 inline-flex btn btn-warning btn-sm" @click.prevent="edit(formtemplate)"><ui-sprite src="pencil"></ui-sprite></a>
<a v-tooltip="`Löschen`" href="#" class="ml-2 inline-flex btn btn-danger btn-sm" @click.prevent="deleting = formtemplate"><ui-sprite src="trash"></ui-sprite></a>
</td>
</tr>
</table>
@ -43,11 +59,14 @@
</template>
<script setup>
import { indexProps, useIndex } from '../../composables/useInertiaApiIndex.js';
import {ref} from 'vue';
import {indexProps, useIndex} from '../../composables/useInertiaApiIndex.js';
import FormBuilder from './FormBuilder.vue';
const deleting = ref(null);
const props = defineProps(indexProps);
var { meta, data, reloadPage, create, single, edit, cancel, submit } = useIndex(props.data, 'invoice');
var {meta, data, reloadPage, create, remove, single, edit, cancel, submit} = useIndex(props.data, 'invoice');
function innerSubmit(payload) {
single.value = payload;

View File

@ -19,13 +19,12 @@ use App\Invoice\Actions\InvoiceStoreAction;
use App\Course\Actions\CourseUpdateAction;
use App\Dashboard\Actions\IndexAction as DashboardIndexAction;
use App\Efz\ShowEfzDocumentAction;
use App\Form\Actions\FormApiListAction;
use App\Form\Actions\FormDestroyAction;
use App\Form\Actions\FormIndexAction;
use App\Group\Actions\GroupApiIndexAction;
use App\Group\Actions\GroupBulkstoreAction;
use App\Group\Actions\GroupIndexAction;
use App\Form\Actions\FormStoreAction;
use App\Form\Actions\FormtemplateDestroyAction;
use App\Form\Actions\FormtemplateIndexAction;
use App\Form\Actions\FormtemplateStoreAction;
use App\Form\Actions\FormtemplateUpdateAction;
@ -156,6 +155,7 @@ Route::group(['middleware' => 'auth:web'], function (): void {
Route::delete('/form/{form}', FormDestroyAction::class)->name('form.destroy');
Route::post('/formtemplate', FormtemplateStoreAction::class)->name('formtemplate.store');
Route::patch('/formtemplate/{formtemplate}', FormtemplateUpdateAction::class)->name('formtemplate.update');
Route::delete('/formtemplate/{formtemplate}', FormtemplateDestroyAction::class)->name('formtemplate.destroy');
Route::post('/form', FormStoreAction::class)->name('form.store');
Route::get('/form/{form}/participants', ParticipantIndexAction::class)->name('form.participant.index');
});

View File

@ -0,0 +1,28 @@
<?php
namespace Tests\Feature\Form;
use App\Form\Models\Formtemplate;
use App\Lib\Events\Succeeded;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class FormtemplateDestroyActionTest extends TestCase
{
use DatabaseTransactions;
public function testItDestroysAFormtemplate(): void
{
Event::fake([Succeeded::class]);
$this->login()->loginNami()->withoutExceptionHandling();
$formtemplate = Formtemplate::factory()->create();
$this->deleteJson(route('formtemplate.destroy', ['formtemplate' => $formtemplate]))
->assertOk();
$this->assertDatabaseCount('formtemplates', 0);
Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage gelöscht.');
}
}

View File

@ -22,6 +22,7 @@ class FormtemplateIndexActionTest extends TestCase
$this->get(route('formtemplate.index'))
->assertInertiaPath('data.data.0.links', [
'update' => route('formtemplate.update', ['formtemplate' => $formtemplate]),
'destroy' => route('formtemplate.destroy', ['formtemplate' => $formtemplate]),
])
->assertInertiaPath('data.data.0.config.sections.0.name', 'sname')
->assertInertiaPath('data.meta.groups', [