diff --git a/app/Prevention/Actions/SettingApiAction.php b/app/Prevention/Actions/SettingApiAction.php index edcdd707..211c8737 100644 --- a/app/Prevention/Actions/SettingApiAction.php +++ b/app/Prevention/Actions/SettingApiAction.php @@ -13,7 +13,7 @@ class SettingApiAction public function handle(): JsonResponse { return response()->json([ - 'data' => app(PreventionSettings::class)->toArray(), + 'data' => app(PreventionSettings::class)->toFrontend(), ]); } } diff --git a/app/Prevention/Actions/SettingStoreAction.php b/app/Prevention/Actions/SettingStoreAction.php index 18586524..d7173f9e 100644 --- a/app/Prevention/Actions/SettingStoreAction.php +++ b/app/Prevention/Actions/SettingStoreAction.php @@ -20,6 +20,9 @@ class SettingStoreAction return [ 'formmail' => '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->formmail = EditorData::from($request->formmail); $settings->yearlymail = EditorData::from($request->yearlymail); + $settings->weeks = $request->weeks; + $settings->freshRememberInterval = $request->freshRememberInterval; + $settings->active = $request->active; $settings->save(); Succeeded::message('Einstellungen gespeichert.')->dispatch(); diff --git a/app/Prevention/PreventionSettings.php b/app/Prevention/PreventionSettings.php index 1a3cebcb..186502d0 100644 --- a/app/Prevention/PreventionSettings.php +++ b/app/Prevention/PreventionSettings.php @@ -12,6 +12,7 @@ class PreventionSettings extends LocalSettings public EditorData $yearlymail; public int $weeks; public int $freshRememberInterval; + public bool $active; public static function group(): string { @@ -30,4 +31,17 @@ class PreventionSettings extends LocalSettings { return []; } + + /** + * @todo return int value here and handle this in vue with a number field that only expects integers + * @return array + */ + public function toFrontend(): array + { + return [ + ...$this->toArray(), + 'weeks' => (string) $this->weeks, + 'freshRememberInterval' => (string) $this->freshRememberInterval, + ]; + } } diff --git a/database/settings/2025_05_24_202013_create_prevention_yearly_mail_settings.php b/database/settings/2025_05_24_202013_create_prevention_yearly_mail_settings.php index 078bd548..bbf5ac9e 100644 --- a/database/settings/2025_05_24_202013_create_prevention_yearly_mail_settings.php +++ b/database/settings/2025_05_24_202013_create_prevention_yearly_mail_settings.php @@ -9,5 +9,6 @@ return new class extends SettingsMigration $this->migrator->add('prevention.yearlymail', ['time' => 1, 'blocks' => [], 'version' => '1.0']); $this->migrator->add('prevention.weeks', 8); $this->migrator->add('prevention.freshRememberInterval', 12); + $this->migrator->add('prevention.active', false); } }; diff --git a/resources/js/views/setting/Prevention.vue b/resources/js/views/setting/Prevention.vue index 9085ea2d..12bc7352 100644 --- a/resources/js/views/setting/Prevention.vue +++ b/resources/js/views/setting/Prevention.vue @@ -3,13 +3,23 @@ +

Hier kannst du Einstellungen zu Prävention setzen.

-
- + +
+ +
+
+ +
+ + +
+
@@ -21,6 +31,12 @@ import { ref } from 'vue'; import { useApiIndex } from '../../composables/useApiIndex.js'; 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 loaded = ref(false); diff --git a/tests/Feature/Prevention/SettingTest.php b/tests/Feature/Prevention/SettingTest.php index 1c61da8d..f0508fc5 100644 --- a/tests/Feature/Prevention/SettingTest.php +++ b/tests/Feature/Prevention/SettingTest.php @@ -20,11 +20,14 @@ it('receives settings', function () { $text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->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') ->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 () { @@ -32,7 +35,10 @@ it('testItStoresSettings', function () { $formmail = EditorRequestFactory::new()->text(50, 'new lorem')->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)->yearlymail->hasAll(['lala dd'])); + test()->assertEquals(9, app(PreventionSettings::class)->weeks); + test()->assertEquals(11, app(PreventionSettings::class)->freshRememberInterval); + test()->assertTrue(app(PreventionSettings::class)->active); });