Add new prevention settings to frontend
This commit is contained in:
parent
f9c4e32ba2
commit
4ed6375202
|
@ -13,7 +13,7 @@ class SettingApiAction
|
||||||
public function handle(): JsonResponse
|
public function handle(): JsonResponse
|
||||||
{
|
{
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'data' => app(PreventionSettings::class)->toArray(),
|
'data' => app(PreventionSettings::class)->toFrontend(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@ class SettingStoreAction
|
||||||
return [
|
return [
|
||||||
'formmail' => 'array',
|
'formmail' => 'array',
|
||||||
'yearlymail' => 'array',
|
'yearlymail' => 'array',
|
||||||
|
'weeks' => 'required|numeric|gte:0',
|
||||||
|
'freshRememberInterval' => 'required|numeric|gte:0',
|
||||||
|
'active' => 'boolean',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +31,9 @@ class SettingStoreAction
|
||||||
$settings = app(PreventionSettings::class);
|
$settings = app(PreventionSettings::class);
|
||||||
$settings->formmail = EditorData::from($request->formmail);
|
$settings->formmail = EditorData::from($request->formmail);
|
||||||
$settings->yearlymail = EditorData::from($request->yearlymail);
|
$settings->yearlymail = EditorData::from($request->yearlymail);
|
||||||
|
$settings->weeks = $request->weeks;
|
||||||
|
$settings->freshRememberInterval = $request->freshRememberInterval;
|
||||||
|
$settings->active = $request->active;
|
||||||
$settings->save();
|
$settings->save();
|
||||||
|
|
||||||
Succeeded::message('Einstellungen gespeichert.')->dispatch();
|
Succeeded::message('Einstellungen gespeichert.')->dispatch();
|
||||||
|
|
|
@ -12,6 +12,7 @@ class PreventionSettings extends LocalSettings
|
||||||
public EditorData $yearlymail;
|
public EditorData $yearlymail;
|
||||||
public int $weeks;
|
public int $weeks;
|
||||||
public int $freshRememberInterval;
|
public int $freshRememberInterval;
|
||||||
|
public bool $active;
|
||||||
|
|
||||||
public static function group(): string
|
public static function group(): string
|
||||||
{
|
{
|
||||||
|
@ -30,4 +31,17 @@ class PreventionSettings extends LocalSettings
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo return int value here and handle this in vue with a number field that only expects integers
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toFrontend(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
...$this->toArray(),
|
||||||
|
'weeks' => (string) $this->weeks,
|
||||||
|
'freshRememberInterval' => (string) $this->freshRememberInterval,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,6 @@ return new class extends SettingsMigration
|
||||||
$this->migrator->add('prevention.yearlymail', ['time' => 1, 'blocks' => [], 'version' => '1.0']);
|
$this->migrator->add('prevention.yearlymail', ['time' => 1, 'blocks' => [], 'version' => '1.0']);
|
||||||
$this->migrator->add('prevention.weeks', 8);
|
$this->migrator->add('prevention.weeks', 8);
|
||||||
$this->migrator->add('prevention.freshRememberInterval', 12);
|
$this->migrator->add('prevention.freshRememberInterval', 12);
|
||||||
|
$this->migrator->add('prevention.active', false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,13 +3,23 @@
|
||||||
<template #right>
|
<template #right>
|
||||||
<f-save-button form="preventionform"></f-save-button>
|
<f-save-button form="preventionform"></f-save-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<setting-layout v-if="loaded">
|
<setting-layout v-if="loaded">
|
||||||
<form id="preventionform" class="grow p-6" @submit.prevent="submit">
|
<form id="preventionform" class="grow p-6" @submit.prevent="submit">
|
||||||
<div class="col-span-full text-gray-100 mb-3">
|
<div class="col-span-full text-gray-100 mb-3">
|
||||||
<p class="text-sm">Hier kannst du Einstellungen zu Prävention setzen.</p>
|
<p class="text-sm">Hier kannst du Einstellungen zu Prävention setzen.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid gap-4 mt-2">
|
<ui-tabs v-model="active" class="mt-2" :entries="tabs"></ui-tabs>
|
||||||
<f-editor id="frommail" v-model="data.formmail" label="E-Mail für Veranstaltungs-TN"></f-editor>
|
<div v-if="active === 0">
|
||||||
|
<f-editor v-if="active === 0" id="formmail" v-model="data.formmail" label="E-Mail für Veranstaltungs-TN"></f-editor>
|
||||||
|
</div>
|
||||||
|
<div v-if="active === 1" class="grid gap-6">
|
||||||
|
<f-switch id="active" v-model="data.active" name="active" label="Regelmäßig an Präventionsunterlagen erinnern"></f-switch>
|
||||||
|
<div class="flex gap-6">
|
||||||
|
<f-text id="weeks" v-model="data.weeks" label="Vor Ablauf X Wochen vorher erinnern" type="number" />
|
||||||
|
<f-text id="fresh_remember_interval" v-model="data.freshRememberInterval" label="Bei Ablauf alle X Wochen erinnern" type="number" />
|
||||||
|
</div>
|
||||||
|
<f-editor v-if="active === 1" id="yearlymail" v-model="data.yearlymail" label="Jährliche Präventions-Erinnerung"></f-editor>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</setting-layout>
|
</setting-layout>
|
||||||
|
@ -21,6 +31,12 @@ import { ref } from 'vue';
|
||||||
import { useApiIndex } from '../../composables/useApiIndex.js';
|
import { useApiIndex } from '../../composables/useApiIndex.js';
|
||||||
import SettingLayout from '../setting/Layout.vue';
|
import SettingLayout from '../setting/Layout.vue';
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{ title: 'für Veranstaltungen' },
|
||||||
|
{ title: 'Jährlich' },
|
||||||
|
];
|
||||||
|
const active = ref(0);
|
||||||
|
|
||||||
const { axios, data, reload } = useApiIndex('/api/prevention', 'prevention');
|
const { axios, data, reload } = useApiIndex('/api/prevention', 'prevention');
|
||||||
const loaded = ref(false);
|
const loaded = ref(false);
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,14 @@ it('receives settings', function () {
|
||||||
|
|
||||||
$text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->toData();
|
$text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->toData();
|
||||||
$yearlyMail = EditorRequestFactory::new()->text(50, 'lala dd')->toData();
|
$yearlyMail = EditorRequestFactory::new()->text(50, 'lala dd')->toData();
|
||||||
app(PreventionSettings::class)->fill(['formmail' => $text, 'yearlymail' => $yearlyMail])->save();
|
app(PreventionSettings::class)->fill(['formmail' => $text, 'yearlymail' => $yearlyMail, 'weeks' => 9, 'freshRememberInterval' => 11, 'active' => true])->save();
|
||||||
|
|
||||||
test()->get('/api/prevention')
|
test()->get('/api/prevention')
|
||||||
->assertJsonPath('data.formmail.blocks.0.data.text', 'lorem ipsum')
|
->assertJsonPath('data.formmail.blocks.0.data.text', 'lorem ipsum')
|
||||||
->assertJsonPath('data.yearlymail.blocks.0.data.text', 'lala dd');
|
->assertJsonPath('data.yearlymail.blocks.0.data.text', 'lala dd')
|
||||||
|
->assertJsonPath('data.weeks', '9')
|
||||||
|
->assertJsonPath('data.active', true)
|
||||||
|
->assertJsonPath('data.freshRememberInterval', '11');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('testItStoresSettings', function () {
|
it('testItStoresSettings', function () {
|
||||||
|
@ -32,7 +35,10 @@ it('testItStoresSettings', function () {
|
||||||
|
|
||||||
$formmail = EditorRequestFactory::new()->text(50, 'new lorem')->create();
|
$formmail = EditorRequestFactory::new()->text(50, 'new lorem')->create();
|
||||||
$yearlyMail = EditorRequestFactory::new()->text(50, 'lala dd')->create();
|
$yearlyMail = EditorRequestFactory::new()->text(50, 'lala dd')->create();
|
||||||
test()->post('/api/prevention', ['formmail' => $formmail, 'yearlymail' => $yearlyMail])->assertOk();
|
test()->post('/api/prevention', ['formmail' => $formmail, 'yearlymail' => $yearlyMail, 'weeks' => 9, 'freshRememberInterval' => 11, 'active' => true])->assertOk();
|
||||||
test()->assertTrue(app(PreventionSettings::class)->formmail->hasAll(['new lorem']));
|
test()->assertTrue(app(PreventionSettings::class)->formmail->hasAll(['new lorem']));
|
||||||
test()->assertTrue(app(PreventionSettings::class)->yearlymail->hasAll(['lala dd']));
|
test()->assertTrue(app(PreventionSettings::class)->yearlymail->hasAll(['lala dd']));
|
||||||
|
test()->assertEquals(9, app(PreventionSettings::class)->weeks);
|
||||||
|
test()->assertEquals(11, app(PreventionSettings::class)->freshRememberInterval);
|
||||||
|
test()->assertTrue(app(PreventionSettings::class)->active);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue