diff --git a/app/Bill/BillSettings.php b/app/Bill/BillSettings.php new file mode 100644 index 00000000..354e4aea --- /dev/null +++ b/app/Bill/BillSettings.php @@ -0,0 +1,49 @@ +put('menu', 'setting'); - session()->put('title', 'Einstellungen'); + session()->put('title', 'Rechnungs-Einstellungen'); - return Inertia::render('setting/Index', [ + return Inertia::render('setting/Bill', [ 'data' => $this->handle($settings), ]); } diff --git a/app/Bill/SettingSaveAction.php b/app/Bill/SettingSaveAction.php index fc862f02..32a18104 100644 --- a/app/Bill/SettingSaveAction.php +++ b/app/Bill/SettingSaveAction.php @@ -2,7 +2,6 @@ namespace App\Bill; -use App\Setting\BillSettings; use Illuminate\Http\RedirectResponse; use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\Concerns\AsAction; diff --git a/app/Mailman/Actions/SettingIndexAction.php b/app/Mailman/Actions/SettingIndexAction.php index d621bb80..51b6d2ed 100644 --- a/app/Mailman/Actions/SettingIndexAction.php +++ b/app/Mailman/Actions/SettingIndexAction.php @@ -28,7 +28,7 @@ class SettingIndexAction session()->put('menu', 'setting'); session()->put('title', 'Mailman-Einstellungen'); - return Inertia::render('setting/Index', [ + return Inertia::render('setting/Mailman', [ 'data' => $this->handle($settings), ]); } diff --git a/app/Mailman/MailmanSettings.php b/app/Mailman/MailmanSettings.php index bdfa8d01..6a70995c 100644 --- a/app/Mailman/MailmanSettings.php +++ b/app/Mailman/MailmanSettings.php @@ -2,9 +2,11 @@ namespace App\Mailman; -use Spatie\LaravelSettings\Settings; +use App\Mailman\Actions\SettingIndexAction; +use App\Mailman\Actions\SettingSaveAction; +use App\Setting\LocalSettings; -class MailmanSettings extends Settings +class MailmanSettings extends LocalSettings { public ?string $base_url; @@ -16,4 +18,24 @@ class MailmanSettings extends Settings { return 'mailman'; } + + public static function slug(): string + { + return 'mailman'; + } + + public static function indexAction(): string + { + return SettingIndexAction::class; + } + + public static function saveAction(): string + { + return SettingSaveAction::class; + } + + public static function title(): string + { + return 'Mailman'; + } } diff --git a/app/Mailman/Support/MailmanService.php b/app/Mailman/Support/MailmanService.php index 804f43ed..db519451 100644 --- a/app/Mailman/Support/MailmanService.php +++ b/app/Mailman/Support/MailmanService.php @@ -3,6 +3,7 @@ namespace App\Mailman\Support; use App\Mailman\Exceptions\MailmanServiceException; +use Illuminate\Http\Client\ConnectionException; use Illuminate\Http\Client\PendingRequest; use Illuminate\Support\Facades\Http; use Illuminate\Support\LazyCollection; @@ -25,9 +26,13 @@ class MailmanService public function check(): bool { - $response = $this->http()->get('/system/versions'); + try { + $response = $this->http()->get('/system/versions'); - return 200 === $response->status(); + return 200 === $response->status(); + } catch (ConnectionException $e) { + return false; + } } /** diff --git a/app/Setting/BillSettings.php b/app/Setting/BillSettings.php deleted file mode 100644 index 2f477365..00000000 --- a/app/Setting/BillSettings.php +++ /dev/null @@ -1,29 +0,0 @@ - [ - 'modules' => $generalSettings->moduleOptions(), - ], - 'general' => [ - 'modules' => $generalSettings->modules, - ], - ]); - } -} diff --git a/app/Setting/LocalSettings.php b/app/Setting/LocalSettings.php new file mode 100644 index 00000000..37a9f390 --- /dev/null +++ b/app/Setting/LocalSettings.php @@ -0,0 +1,27 @@ +> + */ + private array $settings = []; + + /** + * @param class-string $setting + */ + public function register(string $setting): void + { + $this->settings[] = $setting; + + app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->get($setting::url(), $setting::indexAction()); + app(Router::class)->middleware(['web', 'auth:web', SettingMiddleware::class])->post($setting::url(), $setting::saveAction()); + + if (1 === count($this->settings)) { + app(Router::class)->redirect('/setting', '/setting/'.$setting::slug()); + } + } + + /** + * @return array + */ + public function getShare(): array + { + return collect($this->settings)->map(fn ($setting) => [ + 'url' => $setting::url(), + 'is_active' => request()->fullUrlIs(url($setting::url())), + 'title' => $setting::title(), + ]) + ->toArray(); + } +} diff --git a/app/Setting/SettingMiddleware.php b/app/Setting/SettingMiddleware.php new file mode 100644 index 00000000..ab854b29 --- /dev/null +++ b/app/Setting/SettingMiddleware.php @@ -0,0 +1,26 @@ + app(SettingFactory::class)->getShare(), + ]); + + return $next($request); + } +} diff --git a/app/Setting/SettingServiceProvider.php b/app/Setting/SettingServiceProvider.php new file mode 100644 index 00000000..eda8489b --- /dev/null +++ b/app/Setting/SettingServiceProvider.php @@ -0,0 +1,31 @@ +singleton(SettingFactory::class, fn () => new SettingFactory()); + } + + /** + * Bootstrap services. + * + * @return void + */ + public function boot() + { + app(SettingFactory::class)->register(BillSettings::class); + app(SettingFactory::class)->register(MailmanSettings::class); + } +} diff --git a/config/app.php b/config/app.php index 29c6d832..2e396bdb 100644 --- a/config/app.php +++ b/config/app.php @@ -187,6 +187,7 @@ return [ App\Providers\TelescopeServiceProvider::class, App\Tex\TexServiceProvider::class, App\Dav\ServiceProvider::class, + App\Setting\SettingServiceProvider::class, ], /* diff --git a/resources/js/components/VTabs.vue b/resources/js/components/VTabs.vue index 1750f823..5bb76f3b 100644 --- a/resources/js/components/VTabs.vue +++ b/resources/js/components/VTabs.vue @@ -5,10 +5,9 @@ v-for="(item, index) in entries" :key="index" href="#" - :data-cy="`menu-${item.id}`" @click.prevent="openMenu(index)" class="rounded py-1 px-3 text-gray-400" - :class="index == value ? `bg-gray-600` : ''" + :class="index === value ? `bg-gray-600` : ''" v-text="item.title" > diff --git a/resources/js/views/setting/Bill.vue b/resources/js/views/setting/Bill.vue new file mode 100644 index 00000000..15983e36 --- /dev/null +++ b/resources/js/views/setting/Bill.vue @@ -0,0 +1,58 @@ + + + diff --git a/resources/js/views/setting/Index.vue b/resources/js/views/setting/Index.vue deleted file mode 100644 index 162149ae..00000000 --- a/resources/js/views/setting/Index.vue +++ /dev/null @@ -1,67 +0,0 @@ - - - diff --git a/resources/js/views/setting/Layout.vue b/resources/js/views/setting/Layout.vue new file mode 100644 index 00000000..34e85308 --- /dev/null +++ b/resources/js/views/setting/Layout.vue @@ -0,0 +1,38 @@ + + + diff --git a/resources/js/views/setting/Mailman.vue b/resources/js/views/setting/Mailman.vue new file mode 100644 index 00000000..494c9231 --- /dev/null +++ b/resources/js/views/setting/Mailman.vue @@ -0,0 +1,37 @@ + + + diff --git a/routes/web.php b/routes/web.php index 54c04493..322f60e4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,14 +1,10 @@ 'auth:web'], function (): void { Route::get('/sendpayment', [SendpaymentController::class, 'create'])->name('sendpayment.create'); Route::get('/sendpayment/pdf', [SendpaymentController::class, 'send'])->name('sendpayment.pdf'); Route::apiResource('member.membership', MembershipController::class); - Route::get('setting/bill', BillSettingIndexAction::class); - Route::post('setting/bill', BillSettingSaveAction::class); - Route::get('setting/mailman', MailmanSettingIndexAction::class); - Route::post('setting/mailman', MailmanSettingSaveAction::class); Route::resource('member.course', CourseController::class); Route::get('/member/{member}/efz', MemberEfzController::class)->name('efz'); Route::get('/member/{member}/resync', MemberResyncController::class)->name('member.resync'); diff --git a/tests/Feature/Setting/SettingTest.php b/tests/Feature/Bill/SettingTest.php similarity index 71% rename from tests/Feature/Setting/SettingTest.php rename to tests/Feature/Bill/SettingTest.php index 5273e10f..27d9ecf7 100644 --- a/tests/Feature/Setting/SettingTest.php +++ b/tests/Feature/Bill/SettingTest.php @@ -1,8 +1,8 @@ withoutExceptionHandling()->login()->loginNami(); + + $response = $this->get('/setting/bill'); + + /** @var array */ + $menus = $this->inertia($response, 'setting_menu'); + $this->assertTrue( + collect($menus) + ->pluck('url') + ->contains('/setting/bill') + ); + + $settingMenu = collect($menus)->first(fn ($menu) => '/setting/bill' === $menu['url']); + $this->assertTrue($settingMenu['is_active']); + $this->assertEquals('Rechnung', $settingMenu['title']); + } + public function testItCanChangeSettings(): void { $this->withoutExceptionHandling()->login()->loginNami();