Add: Destroy formtemplate
This commit is contained in:
parent
b86b2b6063
commit
ebf7a1d5c9
|
@ -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([]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ class FormtemplateResource extends JsonResource
|
||||||
...parent::toArray($request),
|
...parent::toArray($request),
|
||||||
'links' => [
|
'links' => [
|
||||||
'update' => route('formtemplate.update', ['formtemplate' => $this->getModel()]),
|
'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(''),
|
'base_url' => url(''),
|
||||||
'groups' => Group::forSelect(),
|
'groups' => Group::forSelect(),
|
||||||
'fields' => Field::asMeta(),
|
'fields' => Field::asMeta(),
|
||||||
'namiFields' => NamiType::forSelect(),
|
'namiTypes' => NamiType::forSelect(),
|
||||||
'links' => [
|
'links' => [
|
||||||
'store' => route('formtemplate.store'),
|
'store' => route('formtemplate.store'),
|
||||||
'form_index' => route('form.index'),
|
'form_index' => route('form.index'),
|
||||||
|
|
|
@ -2,12 +2,28 @@
|
||||||
<page-layout>
|
<page-layout>
|
||||||
<template #toolbar>
|
<template #toolbar>
|
||||||
<page-toolbar-button color="primary" icon="plus" @click="create">Vorlage erstellen</page-toolbar-button>
|
<page-toolbar-button color="primary" icon="plus" @click="create">Vorlage erstellen</page-toolbar-button>
|
||||||
<page-toolbar-button :href="meta.links.form_index" color="primary"
|
<page-toolbar-button :href="meta.links.form_index" color="primary" icon="event">Veranstaltungen</page-toolbar-button>
|
||||||
icon="event">Veranstaltungen</page-toolbar-button>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<ui-popup v-if="single !== null" :heading="`Vorlage ${single.id ? 'bearbeiten' : 'erstellen'}`" full
|
<ui-popup v-if="deleting !== null" :heading="`Formular-Vorlage ${deleting.name} löschen?`" @close="deleting = null">
|
||||||
@close="cancel">
|
<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">
|
<form-builder v-model="single.config" :meta="meta">
|
||||||
<template #meta>
|
<template #meta>
|
||||||
<f-text id="name" v-model="single.name" name="name" label="Name" required></f-text>
|
<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>
|
<div v-text="formtemplate.name"></div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a v-tooltip="`Bearbeiten`" href="#" class="ml-2 inline-flex btn btn-warning btn-sm"
|
<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>
|
||||||
@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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
@ -43,11 +59,14 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<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';
|
import FormBuilder from './FormBuilder.vue';
|
||||||
|
|
||||||
|
const deleting = ref(null);
|
||||||
|
|
||||||
const props = defineProps(indexProps);
|
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) {
|
function innerSubmit(payload) {
|
||||||
single.value = payload;
|
single.value = payload;
|
||||||
|
|
|
@ -19,13 +19,12 @@ use App\Invoice\Actions\InvoiceStoreAction;
|
||||||
use App\Course\Actions\CourseUpdateAction;
|
use App\Course\Actions\CourseUpdateAction;
|
||||||
use App\Dashboard\Actions\IndexAction as DashboardIndexAction;
|
use App\Dashboard\Actions\IndexAction as DashboardIndexAction;
|
||||||
use App\Efz\ShowEfzDocumentAction;
|
use App\Efz\ShowEfzDocumentAction;
|
||||||
use App\Form\Actions\FormApiListAction;
|
|
||||||
use App\Form\Actions\FormDestroyAction;
|
use App\Form\Actions\FormDestroyAction;
|
||||||
use App\Form\Actions\FormIndexAction;
|
use App\Form\Actions\FormIndexAction;
|
||||||
use App\Group\Actions\GroupApiIndexAction;
|
|
||||||
use App\Group\Actions\GroupBulkstoreAction;
|
use App\Group\Actions\GroupBulkstoreAction;
|
||||||
use App\Group\Actions\GroupIndexAction;
|
use App\Group\Actions\GroupIndexAction;
|
||||||
use App\Form\Actions\FormStoreAction;
|
use App\Form\Actions\FormStoreAction;
|
||||||
|
use App\Form\Actions\FormtemplateDestroyAction;
|
||||||
use App\Form\Actions\FormtemplateIndexAction;
|
use App\Form\Actions\FormtemplateIndexAction;
|
||||||
use App\Form\Actions\FormtemplateStoreAction;
|
use App\Form\Actions\FormtemplateStoreAction;
|
||||||
use App\Form\Actions\FormtemplateUpdateAction;
|
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::delete('/form/{form}', FormDestroyAction::class)->name('form.destroy');
|
||||||
Route::post('/formtemplate', FormtemplateStoreAction::class)->name('formtemplate.store');
|
Route::post('/formtemplate', FormtemplateStoreAction::class)->name('formtemplate.store');
|
||||||
Route::patch('/formtemplate/{formtemplate}', FormtemplateUpdateAction::class)->name('formtemplate.update');
|
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::post('/form', FormStoreAction::class)->name('form.store');
|
||||||
Route::get('/form/{form}/participants', ParticipantIndexAction::class)->name('form.participant.index');
|
Route::get('/form/{form}/participants', ParticipantIndexAction::class)->name('form.participant.index');
|
||||||
});
|
});
|
||||||
|
|
|
@ -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.');
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ class FormtemplateIndexActionTest extends TestCase
|
||||||
$this->get(route('formtemplate.index'))
|
$this->get(route('formtemplate.index'))
|
||||||
->assertInertiaPath('data.data.0.links', [
|
->assertInertiaPath('data.data.0.links', [
|
||||||
'update' => route('formtemplate.update', ['formtemplate' => $formtemplate]),
|
'update' => route('formtemplate.update', ['formtemplate' => $formtemplate]),
|
||||||
|
'destroy' => route('formtemplate.destroy', ['formtemplate' => $formtemplate]),
|
||||||
])
|
])
|
||||||
->assertInertiaPath('data.data.0.config.sections.0.name', 'sname')
|
->assertInertiaPath('data.data.0.config.sections.0.name', 'sname')
|
||||||
->assertInertiaPath('data.meta.groups', [
|
->assertInertiaPath('data.meta.groups', [
|
||||||
|
|
Loading…
Reference in New Issue