diff --git a/app/Fileshare/Actions/FileshareIndexAction.php b/app/Fileshare/Actions/FileshareIndexAction.php deleted file mode 100644 index 53874994..00000000 --- a/app/Fileshare/Actions/FileshareIndexAction.php +++ /dev/null @@ -1,24 +0,0 @@ -put('menu', 'setting'); - session()->put('title', 'Datei-Verbindungen'); - - return Inertia::render('fileshare/Index', [ - 'data' => FileshareResource::collection(Fileshare::paginate(15)), - ]); - } -} diff --git a/app/Fileshare/FileshareSettings.php b/app/Fileshare/FileshareSettings.php index c8f9a292..b5332786 100644 --- a/app/Fileshare/FileshareSettings.php +++ b/app/Fileshare/FileshareSettings.php @@ -2,7 +2,8 @@ namespace App\Fileshare; -use App\Fileshare\Actions\FileshareIndexAction; +use App\Fileshare\Models\Fileshare; +use App\Fileshare\Resources\FileshareResource; use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; @@ -18,13 +19,18 @@ class FileshareSettings extends LocalSettings implements Viewable return 'fileshare'; } - public static function indexAction(): string - { - return FileshareIndexAction::class; - } - public static function title(): string { return 'Datei-Verbindungen'; } + + /** + * @inheritdoc + */ + public function viewData(): array + { + return [ + 'data' => FileshareResource::collection(Fileshare::paginate(15)) + ]; + } } diff --git a/app/Form/Actions/SettingIndexAction.php b/app/Form/Actions/SettingIndexAction.php deleted file mode 100644 index 009c48f7..00000000 --- a/app/Form/Actions/SettingIndexAction.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ - public function handle(FormSettings $settings): array - { - return [ - 'data' => [ - 'register_url' => $settings->registerUrl, - 'clear_cache_url' => $settings->clearCacheUrl, - ], - ]; - } - - public function asController(FormSettings $settings): Response - { - session()->put('menu', 'setting'); - session()->put('title', 'Module'); - - return Inertia::render('setting/Form', [ - 'data' => $this->handle($settings), - ]); - } -} diff --git a/app/Form/FormSettings.php b/app/Form/FormSettings.php index bacebde2..a07fb9c4 100644 --- a/app/Form/FormSettings.php +++ b/app/Form/FormSettings.php @@ -2,7 +2,6 @@ namespace App\Form; -use App\Form\Actions\SettingIndexAction; use App\Form\Actions\SettingStoreAction; use App\Setting\Contracts\Viewable; use App\Setting\Contracts\Storeable; @@ -28,13 +27,23 @@ class FormSettings extends LocalSettings implements Viewable, Storeable return 'Formulare'; } - public static function indexAction(): string - { - return SettingIndexAction::class; - } - public static function storeAction(): string { return SettingStoreAction::class; } + + /** + * @inheritdoc + */ + public function viewData(): array + { + return [ + 'data' => [ + 'data' => [ + 'register_url' => $this->registerUrl, + 'clear_cache_url' => $this->clearCacheUrl, + ] + ] + ]; + } } diff --git a/app/Invoice/InvoiceSettings.php b/app/Invoice/InvoiceSettings.php index 061ccfaa..8ee5bca5 100644 --- a/app/Invoice/InvoiceSettings.php +++ b/app/Invoice/InvoiceSettings.php @@ -40,9 +40,26 @@ class InvoiceSettings extends LocalSettings implements Viewable, Storeable return 'bill'; } - public static function indexAction(): string + /** + * @inheritdoc + */ + public function viewData(): array { - return SettingIndexAction::class; + return [ + 'data' => [ + 'from_long' => $this->from_long, + 'from' => $this->from, + 'mobile' => $this->mobile, + 'email' => $this->email, + 'website' => $this->website, + 'address' => $this->address, + 'place' => $this->place, + 'zip' => $this->zip, + 'iban' => $this->iban, + 'bic' => $this->bic, + 'remember_weeks' => $this->rememberWeeks, + ] + ]; } public static function storeAction(): string diff --git a/app/Invoice/SettingIndexAction.php b/app/Invoice/SettingIndexAction.php deleted file mode 100644 index 11341622..00000000 --- a/app/Invoice/SettingIndexAction.php +++ /dev/null @@ -1,42 +0,0 @@ - - */ - public function handle(InvoiceSettings $settings): array - { - return [ - 'from_long' => $settings->from_long, - 'from' => $settings->from, - 'mobile' => $settings->mobile, - 'email' => $settings->email, - 'website' => $settings->website, - 'address' => $settings->address, - 'place' => $settings->place, - 'zip' => $settings->zip, - 'iban' => $settings->iban, - 'bic' => $settings->bic, - 'remember_weeks' => $settings->rememberWeeks, - ]; - } - - public function asController(InvoiceSettings $settings): Response - { - session()->put('menu', 'setting'); - session()->put('title', 'Rechnungs-Einstellungen'); - - return Inertia::render('setting/Bill', [ - 'data' => $this->handle($settings), - ]); - } -} diff --git a/app/Mailgateway/Actions/IndexAction.php b/app/Mailgateway/Actions/IndexAction.php deleted file mode 100644 index 4c2e1ee7..00000000 --- a/app/Mailgateway/Actions/IndexAction.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ - public function handle(): Builder - { - return (new Mailgateway())->newQuery(); - } - - public function asController(): Response - { - session()->put('menu', 'setting'); - session()->put('title', 'E-Mail-Verbindungen'); - - return Inertia::render('mailgateway/Index', [ - 'data' => MailgatewayResource::collection($this->handle()->paginate(10)), - ]); - } -} diff --git a/app/Mailgateway/MailgatewaySettings.php b/app/Mailgateway/MailgatewaySettings.php index 6f73b645..5ce9e4c1 100644 --- a/app/Mailgateway/MailgatewaySettings.php +++ b/app/Mailgateway/MailgatewaySettings.php @@ -3,6 +3,8 @@ namespace App\Mailgateway; use App\Mailgateway\Actions\IndexAction; +use App\Mailgateway\Models\Mailgateway; +use App\Mailgateway\Resources\MailgatewayResource; use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; @@ -18,13 +20,18 @@ class MailgatewaySettings extends LocalSettings implements Viewable return 'mailgateway'; } - public static function indexAction(): string - { - return IndexAction::class; - } - public static function title(): string { return 'E-Mail-Verbindungen'; } + + /** + * @inheritdoc + */ + public function viewData(): array + { + return [ + 'data' => MailgatewayResource::collection(Mailgateway::paginate(10)), + ]; + } } diff --git a/app/Module/ModuleIndexAction.php b/app/Module/ModuleIndexAction.php deleted file mode 100644 index 7005e061..00000000 --- a/app/Module/ModuleIndexAction.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ - public function handle(ModuleSettings $settings): array - { - return [ - 'data' => [ - 'modules' => $settings->modules, - ], - 'meta' => ['modules' => Module::forSelect()], - ]; - } - - public function asController(ModuleSettings $settings): Response - { - session()->put('menu', 'setting'); - session()->put('title', 'Module'); - - return Inertia::render('setting/Module', [ - 'data' => $this->handle($settings), - ]); - } -} diff --git a/app/Module/ModuleSettings.php b/app/Module/ModuleSettings.php index a2bab236..cd454594 100644 --- a/app/Module/ModuleSettings.php +++ b/app/Module/ModuleSettings.php @@ -26,11 +26,6 @@ class ModuleSettings extends LocalSettings implements Viewable, Storeable return 'Module'; } - public static function indexAction(): string - { - return ModuleIndexAction::class; - } - public static function storeAction(): string { return ModuleStoreAction::class; @@ -40,4 +35,19 @@ class ModuleSettings extends LocalSettings implements Viewable, Storeable { return in_array($module, $this->modules); } + + /** + * @inheritdoc + */ + public function viewData(): array + { + return [ + 'data' => [ + 'data' => [ + 'modules' => $this->modules, + ], + 'meta' => ['modules' => Module::forSelect()], + ] + ]; + } } diff --git a/app/Nami/Actions/SettingIndexAction.php b/app/Nami/Actions/SettingIndexAction.php deleted file mode 100644 index fe007ea9..00000000 --- a/app/Nami/Actions/SettingIndexAction.php +++ /dev/null @@ -1,35 +0,0 @@ - - */ - public function handle(NamiSettings $settings): array - { - return [ - 'mglnr' => $settings->mglnr, - 'password' => '', - 'default_group_id' => $settings->default_group_id, - ]; - } - - public function asController(NamiSettings $settings): Response - { - session()->put('menu', 'setting'); - session()->put('title', 'NaMi-Settings'); - - return Inertia::render('setting/Nami', [ - 'data' => $this->handle($settings), - ]); - } -} diff --git a/app/Prevention/Actions/PreventionIndexAction.php b/app/Prevention/Actions/PreventionIndexAction.php deleted file mode 100644 index d0570c8b..00000000 --- a/app/Prevention/Actions/PreventionIndexAction.php +++ /dev/null @@ -1,20 +0,0 @@ -put('menu', 'setting'); - session()->put('title', 'Prävention'); - - return Inertia::render('setting/Prevention'); - } -} diff --git a/app/Prevention/PreventionSettings.php b/app/Prevention/PreventionSettings.php index 06dbd182..cd9e6bcb 100644 --- a/app/Prevention/PreventionSettings.php +++ b/app/Prevention/PreventionSettings.php @@ -3,7 +3,6 @@ namespace App\Prevention; use App\Lib\Editor\EditorData; -use App\Prevention\Actions\PreventionIndexAction; use App\Setting\Contracts\Viewable; use App\Setting\LocalSettings; @@ -22,13 +21,16 @@ class PreventionSettings extends LocalSettings implements Viewable return 'prevention'; } - public static function indexAction(): string - { - return PreventionIndexAction::class; - } - public static function title(): string { return 'Prävention'; } + + /** + * @inheritdoc + */ + public function viewData(): array + { + return []; + } } diff --git a/app/Setting/Actions/ViewAction.php b/app/Setting/Actions/ViewAction.php new file mode 100644 index 00000000..4a7e45c0 --- /dev/null +++ b/app/Setting/Actions/ViewAction.php @@ -0,0 +1,21 @@ +put('menu', 'setting'); + session()->put('title', $settingGroup::title()); + + return Inertia::render('setting/' . ucfirst($settingGroup::group()), $settingGroup->viewData()); + } +} diff --git a/app/Setting/Contracts/Viewable.php b/app/Setting/Contracts/Viewable.php index e531af0c..cd839134 100644 --- a/app/Setting/Contracts/Viewable.php +++ b/app/Setting/Contracts/Viewable.php @@ -4,8 +4,14 @@ namespace App\Setting\Contracts; interface Viewable { + public static function url(): string; + + public static function title(): string; + + public static function group(): string; + /** - * @return class-string + * @return array */ - public static function indexAction(): string; + public function viewData(): array; } diff --git a/app/Setting/NamiSettings.php b/app/Setting/NamiSettings.php index 77e890f4..2905bf30 100644 --- a/app/Setting/NamiSettings.php +++ b/app/Setting/NamiSettings.php @@ -41,11 +41,6 @@ class NamiSettings extends LocalSettings implements Viewable, Storeable return 'nami'; } - public static function indexAction(): string - { - return SettingIndexAction::class; - } - public static function storeAction(): string { return SettingSaveAction::class; @@ -55,4 +50,18 @@ class NamiSettings extends LocalSettings implements Viewable, Storeable { return 'NaMi-Login'; } + + /** + * @inheritdoc + */ + public function viewData(): array + { + return [ + 'data' => [ + 'mglnr' => $this->mglnr, + 'password' => '', + 'default_group_id' => $this->default_group_id, + ] + ]; + } } diff --git a/app/Setting/SettingFactory.php b/app/Setting/SettingFactory.php index 67caab24..482cb5aa 100644 --- a/app/Setting/SettingFactory.php +++ b/app/Setting/SettingFactory.php @@ -2,8 +2,9 @@ namespace App\Setting; -use App\Setting\Contracts\Viewable; +use App\Invoice\InvoiceSettings; use App\Setting\Contracts\Storeable; +use App\Setting\Contracts\Viewable; use Illuminate\Routing\Router; class SettingFactory @@ -20,10 +21,6 @@ class SettingFactory { $this->settings[] = $setting; - if (new $setting() instanceof Viewable) { - app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->get($setting::url(), $setting::indexAction()); - } - if (new $setting() instanceof Storeable) { app(Router::class)->middleware(['web', 'auth:web'])->post($setting::url(), $setting::storeAction()); } @@ -45,4 +42,11 @@ class SettingFactory ]) ->toArray(); } + + public function resolveGroupName(string $name): Viewable + { + $settingClass = collect($this->settings)->filter(fn ($setting) => new $setting() instanceof Viewable)->first(fn ($setting) => $setting::group() === $name); + + return app($settingClass); + } } diff --git a/app/Setting/SettingServiceProvider.php b/app/Setting/SettingServiceProvider.php index 9bd20912..95cb5dec 100644 --- a/app/Setting/SettingServiceProvider.php +++ b/app/Setting/SettingServiceProvider.php @@ -8,6 +8,8 @@ use App\Invoice\InvoiceSettings; use App\Mailgateway\MailgatewaySettings; use App\Module\ModuleSettings; use App\Prevention\PreventionSettings; +use App\Setting\Actions\ViewAction; +use Illuminate\Routing\Router; use Illuminate\Support\ServiceProvider; class SettingServiceProvider extends ServiceProvider @@ -20,6 +22,8 @@ class SettingServiceProvider extends ServiceProvider public function register() { app()->singleton(SettingFactory::class, fn () => new SettingFactory()); + app(Router::class)->bind('settingGroup', fn ($param) => app(SettingFactory::class)->resolveGroupName($param)); + app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->get('/setting/{settingGroup}', ViewAction::class); } /** diff --git a/resources/js/views/fileshare/Index.vue b/resources/js/views/setting/Fileshare.vue similarity index 100% rename from resources/js/views/fileshare/Index.vue rename to resources/js/views/setting/Fileshare.vue diff --git a/resources/js/views/mailgateway/Index.vue b/resources/js/views/setting/Mailgateway.vue similarity index 100% rename from resources/js/views/mailgateway/Index.vue rename to resources/js/views/setting/Mailgateway.vue