diff --git a/app/Form/FormSettings.php b/app/Form/FormSettings.php index 9f4cdb57..a68251ca 100644 --- a/app/Form/FormSettings.php +++ b/app/Form/FormSettings.php @@ -2,10 +2,8 @@ namespace App\Form; -use App\Form\Actions\SettingStoreAction; use App\Setting\Contracts\Storeable; use App\Setting\LocalSettings; -use Lorisleiva\Actions\ActionRequest; class FormSettings extends LocalSettings implements Storeable { @@ -33,10 +31,6 @@ class FormSettings extends LocalSettings implements Storeable ]; } - public function beforeSave(ActionRequest $request): void - { - } - /** * @inheritdoc */ @@ -44,10 +38,8 @@ class FormSettings extends LocalSettings implements Storeable { return [ 'data' => [ - 'data' => [ - 'registerUrl' => $this->registerUrl, - 'clearCacheUrl' => $this->clearCacheUrl, - ] + 'registerUrl' => $this->registerUrl, + 'clearCacheUrl' => $this->clearCacheUrl, ] ]; } diff --git a/app/Invoice/InvoiceSettings.php b/app/Invoice/InvoiceSettings.php index 23a30710..e1e0e4a2 100644 --- a/app/Invoice/InvoiceSettings.php +++ b/app/Invoice/InvoiceSettings.php @@ -77,10 +77,6 @@ class InvoiceSettings extends LocalSettings implements Storeable ]; } - public function beforeSave(ActionRequest $request): void - { - } - public static function title(): string { return 'Rechnung'; diff --git a/app/Module/ModuleSettings.php b/app/Module/ModuleSettings.php index 45556149..77a9db84 100644 --- a/app/Module/ModuleSettings.php +++ b/app/Module/ModuleSettings.php @@ -27,10 +27,6 @@ class ModuleSettings extends LocalSettings implements Storeable return in_array($module, $this->modules); } - public function beforeSave(ActionRequest $request): void - { - } - /** * @inheritdoc */ @@ -49,11 +45,9 @@ class ModuleSettings extends LocalSettings implements Storeable { return [ 'data' => [ - 'data' => [ - 'modules' => $this->modules, - ], - 'meta' => ['modules' => Module::forSelect()], - ] + 'modules' => $this->modules, + ], + 'meta' => ['modules' => Module::forSelect()], ]; } } diff --git a/app/Prevention/Actions/SettingApiAction.php b/app/Prevention/Actions/SettingApiAction.php deleted file mode 100644 index edcdd707..00000000 --- a/app/Prevention/Actions/SettingApiAction.php +++ /dev/null @@ -1,19 +0,0 @@ -json([ - 'data' => app(PreventionSettings::class)->toArray(), - ]); - } -} diff --git a/app/Prevention/Actions/SettingStoreAction.php b/app/Prevention/Actions/SettingStoreAction.php deleted file mode 100644 index cf72952c..00000000 --- a/app/Prevention/Actions/SettingStoreAction.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ - public function rules(): array - { - return [ - 'formmail' => 'array', - ]; - } - - public function handle(ActionRequest $request): void - { - $settings = app(PreventionSettings::class); - $settings->formmail = EditorData::from($request->formmail); - $settings->save(); - - Succeeded::message('Einstellungen gespeichert.')->dispatch(); - } -} diff --git a/app/Prevention/PreventionSettings.php b/app/Prevention/PreventionSettings.php index 01bfb1f2..acefe200 100644 --- a/app/Prevention/PreventionSettings.php +++ b/app/Prevention/PreventionSettings.php @@ -3,9 +3,11 @@ namespace App\Prevention; use App\Lib\Editor\EditorData; +use App\Setting\Contracts\Storeable; use App\Setting\LocalSettings; +use Lorisleiva\Actions\ActionRequest; -class PreventionSettings extends LocalSettings +class PreventionSettings extends LocalSettings implements Storeable { public EditorData $formmail; @@ -20,11 +22,32 @@ class PreventionSettings extends LocalSettings return 'Prävention'; } + /** + * @inheritdoc + */ + public function rules(): array + { + return [ + 'formmail' => 'required', + ]; + } + + public function saveAttributes(ActionRequest $request): array + { + return [ + 'formmail' => EditorData::from($request->formmail), + ]; + } + /** * @inheritdoc */ public function viewData(): array { - return []; + return [ + 'data' => [ + 'formmail' => $this->formmail, + ] + ]; } } diff --git a/app/Setting/Actions/StoreAction.php b/app/Setting/Actions/StoreAction.php index b7e66600..42ece5f4 100644 --- a/app/Setting/Actions/StoreAction.php +++ b/app/Setting/Actions/StoreAction.php @@ -2,7 +2,9 @@ namespace App\Setting\Actions; +use App\Lib\Events\Succeeded; use App\Setting\Contracts\Storeable; +use GrahamCampbell\ResultType\Success; use Illuminate\Http\RedirectResponse; use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\Concerns\AsAction; @@ -33,7 +35,9 @@ class StoreAction public function asController(ActionRequest $request, Storeable $settingGroup): RedirectResponse { $settingGroup->beforeSave($request); - $this->handle($settingGroup, $request->validated()); + $this->handle($settingGroup, $settingGroup->saveAttributes($request)); + + Succeeded::message('Einstellungen gespeichert')->dispatch(); return redirect()->back(); } diff --git a/app/Setting/Actions/ViewAction.php b/app/Setting/Actions/ViewAction.php index 459723b6..a20e3378 100644 --- a/app/Setting/Actions/ViewAction.php +++ b/app/Setting/Actions/ViewAction.php @@ -19,7 +19,8 @@ class ViewAction return Inertia::render('setting/' . ucfirst($settingGroup::group()), [ ...$settingGroup->viewData(), - 'setting_menu' => app(SettingFactory::class)->getShare(), + 'settingMenu' => app(SettingFactory::class)->getShare(), + 'storeUrl' => $settingGroup->storeUrl(), ]); } } diff --git a/app/Setting/Contracts/Storeable.php b/app/Setting/Contracts/Storeable.php index ee8ec324..ec255c90 100644 --- a/app/Setting/Contracts/Storeable.php +++ b/app/Setting/Contracts/Storeable.php @@ -24,4 +24,6 @@ interface Storeable public function rules(): array; public function beforeSave(ActionRequest $request): void; + + public function saveAttributes(ActionRequest $request): array; } diff --git a/app/Setting/LocalSettings.php b/app/Setting/LocalSettings.php index 46618f37..941c4e88 100644 --- a/app/Setting/LocalSettings.php +++ b/app/Setting/LocalSettings.php @@ -2,6 +2,7 @@ namespace App\Setting; +use Lorisleiva\Actions\ActionRequest; use Spatie\LaravelSettings\Settings; abstract class LocalSettings extends Settings @@ -13,8 +14,26 @@ abstract class LocalSettings extends Settings return route('setting.view', ['settingGroup' => $this->group()]); } + public function storeUrl(): string + { + return $this->url(); + } + /** * @return array */ abstract public function viewData(): array; + + public function beforeSave(ActionRequest $request): void + { + return; + } + + /** + * @return array + */ + public function saveAttributes(ActionRequest $request): array + { + return $request->validated(); + } } diff --git a/app/Setting/SettingFactory.php b/app/Setting/SettingFactory.php index 35424065..895320d3 100644 --- a/app/Setting/SettingFactory.php +++ b/app/Setting/SettingFactory.php @@ -2,8 +2,6 @@ namespace App\Setting; -use App\Invoice\InvoiceSettings; -use App\Setting\Contracts\Storeable; use Illuminate\Routing\Router; class SettingFactory diff --git a/resources/js/composables/useIndex.js b/resources/js/composables/useIndex.js index 487ed4d7..4d75bdca 100644 --- a/resources/js/composables/useIndex.js +++ b/resources/js/composables/useIndex.js @@ -2,9 +2,11 @@ import {ref, inject, computed, onBeforeUnmount} from 'vue'; import {router} from '@inertiajs/vue3'; import useQueueEvents from './useQueueEvents.js'; -export function useIndex(props, siteName) { +export function useIndex(props, siteName = null) { const axios = inject('axios'); - const {startListener, stopListener} = useQueueEvents(siteName, () => reload(false)); + if (siteName !== null) { + var {startListener, stopListener} = useQueueEvents(siteName, () => reload(false)); + } const rawProps = JSON.parse(JSON.stringify(props)); const inner = { data: ref(rawProps.data), @@ -56,8 +58,10 @@ export function useIndex(props, siteName) { reload(true); } - startListener(); - onBeforeUnmount(() => stopListener()); + if (siteName !== null) { + startListener(); + onBeforeUnmount(() => stopListener()); + } return { data: inner.data, diff --git a/resources/js/views/setting/Bill.vue b/resources/js/views/setting/Bill.vue index b6b71e1b..55f0f846 100644 --- a/resources/js/views/setting/Bill.vue +++ b/resources/js/views/setting/Bill.vue @@ -5,45 +5,26 @@
- - + +

Kontaktdaten

Diese Kontaktdaten stehen im Absender-Bereich auf der Rechnung.
- - - - - - - - - + + + + + + + + +
- diff --git a/resources/js/views/setting/Form.vue b/resources/js/views/setting/Form.vue index ff8a95af..ad3ebc9f 100644 --- a/resources/js/views/setting/Form.vue +++ b/resources/js/views/setting/Form.vue @@ -9,40 +9,16 @@

Hier kannst du Einstellungen für Anmeldeformulare setzen.

- - + +
- diff --git a/resources/js/views/setting/Layout.vue b/resources/js/views/setting/Layout.vue index b816ac9d..51ab5e92 100644 --- a/resources/js/views/setting/Layout.vue +++ b/resources/js/views/setting/Layout.vue @@ -1,6 +1,6 @@ @@ -9,7 +9,7 @@ export default { data: function () { return { - innerActive: this.$page.props.setting_menu.findIndex((menu) => menu.is_active), + innerActive: this.$page.props.settingMenu.findIndex((menu) => menu.is_active), }; }, computed: { @@ -19,7 +19,7 @@ export default { }, set(v) { var _self = this; - this.$inertia.visit(this.$page.props.setting_menu[v].url, { + this.$inertia.visit(this.$page.props.settingMenu[v].url, { onSuccess() { _self.innerActive = v; }, diff --git a/resources/js/views/setting/Mailman.vue b/resources/js/views/setting/Mailman.vue deleted file mode 100644 index b9d98ad9..00000000 --- a/resources/js/views/setting/Mailman.vue +++ /dev/null @@ -1,87 +0,0 @@ - - - diff --git a/resources/js/views/setting/Module.vue b/resources/js/views/setting/Module.vue index 099ca54e..89b7a9f6 100644 --- a/resources/js/views/setting/Module.vue +++ b/resources/js/views/setting/Module.vue @@ -4,48 +4,20 @@ -
+
-

Hier kannst du Funktionen innerhalb von Adrema (Module) aktivieren oder deaktivieren - und so den Funktionsumfang auf deine Bedürfnisse anpassen.

+

Hier kannst du Funktionen innerhalb von Adrema (Module) aktivieren oder deaktivieren und so den Funktionsumfang auf deine Bedürfnisse anpassen.

- +
- diff --git a/resources/js/views/setting/Nami.vue b/resources/js/views/setting/Nami.vue index d396325f..eb9c8c9e 100644 --- a/resources/js/views/setting/Nami.vue +++ b/resources/js/views/setting/Nami.vue @@ -8,40 +8,16 @@

Hier kannst du deine Zugangsdaten zu NaMi anpassen, falls sich z.B. dein Passwort geändert hat.

- - - + + + - diff --git a/resources/js/views/setting/Prevention.vue b/resources/js/views/setting/Prevention.vue index 9085ea2d..d0296edd 100644 --- a/resources/js/views/setting/Prevention.vue +++ b/resources/js/views/setting/Prevention.vue @@ -3,7 +3,7 @@ - +

Hier kannst du Einstellungen zu Prävention setzen.

@@ -16,22 +16,8 @@ - diff --git a/resources/js/views/setting/useSettings.js b/resources/js/views/setting/useSettings.js new file mode 100644 index 00000000..8ab758d3 --- /dev/null +++ b/resources/js/views/setting/useSettings.js @@ -0,0 +1,42 @@ +import {useIndex} from '../../composables/useIndex.js'; +import SettingLayout from './Layout.vue'; + +export function useSettings(props) { + const {data, meta, router} = useIndex(props); + + function submit() { + router.post(props.storeUrl, {...data.value}); + } + + return { + submit, + data, + meta, + props, + SettingLayout, + }; +} + +const props = { + data: { + type: Object, + required: true, + }, + storeUrl: { + type: String, + required: true, + }, + settingMenu: { + type: Object, + required: true, + }, + meta: { + type: Object, + required: false, + default: () => { + return {}; + }, + }, +}; + +export {props}; diff --git a/routes/api.php b/routes/api.php index 9e751f3a..2f417d6e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,13 +3,11 @@ use App\Contribution\Actions\GenerateApiAction as ContributionGenerateApiAction; use App\Form\Actions\FormApiListAction; use App\Form\Actions\RegisterAction; -use App\Prevention\Actions\SettingStoreAction as PreventionStoreAction; use App\Group\Actions\GroupApiIndexAction; -use App\Prevention\Actions\SettingApiAction; +use App\User\Actions\IndexAction as UserIndexAction; Route::post('/contribution-generate', ContributionGenerateApiAction::class)->name('api.contribution.generate')->middleware('client:contribution-generate'); Route::post('/form/{form}/register', RegisterAction::class)->name('form.register'); Route::get('/group/{group?}', GroupApiIndexAction::class)->name('api.group'); Route::get('/form', FormApiListAction::class)->name('api.form.index'); -Route::get('/prevention', SettingApiAction::class)->name('api.prevention.index'); -Route::post('/prevention', PreventionStoreAction::class)->name('api.prevention.store'); +Route::get('/user', UserIndexAction::class)->name('api.user.index'); diff --git a/tests/Feature/Prevention/SettingTest.php b/tests/Feature/Prevention/SettingTest.php index b67fd4b4..c4b4957c 100644 --- a/tests/Feature/Prevention/SettingTest.php +++ b/tests/Feature/Prevention/SettingTest.php @@ -16,25 +16,25 @@ class SettingTest extends TestCase { $this->login()->loginNami(); - $this->get('/setting/prevention')->assertComponent('setting/Prevention')->assertOk(); - } - - public function testItReceivesSettings(): void - { - $this->login()->loginNami(); - $text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->toData(); app(PreventionSettings::class)->fill(['formmail' => $text])->save(); - $this->get('/api/prevention') - ->assertJsonPath('data.formmail.blocks.0.data.text', 'lorem ipsum'); + $this->get(route('setting.view', ['settingGroup' => 'prevention'])) + ->assertOk() + ->assertComponent('setting/Prevention') + ->assertInertiaPath('data.formmail.blocks.0.data.text', 'lorem ipsum') + ->assertInertiaPath('store_url', route('setting.store', ['settingGroup' => 'prevention'])); } public function testItStoresSettings(): void { $this->login()->loginNami(); - $this->post('/api/prevention', ['formmail' => EditorRequestFactory::new()->text(50, 'new lorem')->create()])->assertOk(); + $route = route('setting.store', ['settingGroup' => 'prevention']); + $this + ->from($route) + ->post($route, ['formmail' => EditorRequestFactory::new()->text(50, 'new lorem')->create()]) + ->assertRedirect($route); $this->assertTrue(app(PreventionSettings::class)->formmail->hasAll(['new lorem'])); } }