Compare commits

...

7 Commits

Author SHA1 Message Date
philipp lang d9adb526ce Remove Setting store actions
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is failing Details
2024-08-01 16:26:38 +02:00
philipp lang daf6e87814 Remove Middleware 2024-08-01 16:26:38 +02:00
philipp lang 2056e1ad6b Fixed tests 2024-08-01 16:26:38 +02:00
philipp lang a4eba23bff Remove viewable interface 2024-08-01 16:26:38 +02:00
philipp lang ad8cd58b4f Add SettingView action 2024-08-01 16:26:38 +02:00
philipp lang 3a4908f505 Move Indexable to Viewable 2024-08-01 16:26:38 +02:00
philipp lang 291eec3849 Update CHANGELOG
continuous-integration/drone/push Build is passing Details
2024-08-01 12:15:28 +02:00
34 changed files with 317 additions and 591 deletions

View File

@ -4,6 +4,7 @@
- Rechnungen und Erinnerungen werden nun automatisch täglich um 10 Uhr verschickt - Rechnungen und Erinnerungen werden nun automatisch täglich um 10 Uhr verschickt
- Es kann eingestellt werden, nach wie vielen Wochen an Rechnungen erinnert werden soll (Standard: 12) - Es kann eingestellt werden, nach wie vielen Wochen an Rechnungen erinnert werden soll (Standard: 12)
- Name und Profilbild des angemeldeten Benutzers wird nun oben rechts angezeigt
### 1.10.15 ### 1.10.15

View File

@ -1,24 +0,0 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\Fileshare;
use App\Fileshare\Resources\FileshareResource;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class FileshareIndexAction
{
use AsAction;
public function handle(): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Datei-Verbindungen');
return Inertia::render('fileshare/Index', [
'data' => FileshareResource::collection(Fileshare::paginate(15)),
]);
}
}

View File

@ -2,29 +2,29 @@
namespace App\Fileshare; namespace App\Fileshare;
use App\Fileshare\Actions\FileshareIndexAction; use App\Fileshare\Models\Fileshare;
use App\Setting\Contracts\Indexable; use App\Fileshare\Resources\FileshareResource;
use App\Setting\LocalSettings; use App\Setting\LocalSettings;
class FileshareSettings extends LocalSettings implements Indexable class FileshareSettings extends LocalSettings
{ {
public static function group(): string public static function group(): string
{ {
return 'fileshare'; return 'fileshare';
} }
public static function slug(): string
{
return 'fileshare';
}
public static function indexAction(): string
{
return FileshareIndexAction::class;
}
public static function title(): string public static function title(): string
{ {
return 'Datei-Verbindungen'; return 'Datei-Verbindungen';
} }
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => FileshareResource::collection(Fileshare::paginate(15))
];
}
} }

View File

@ -1,36 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\FormSettings;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
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),
]);
}
}

View File

@ -1,46 +0,0 @@
<?php
namespace App\Form\Actions;
use App\Form\FormSettings;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingStoreAction
{
use AsAction;
/**
* @param array<string, mixed> $input
*/
public function handle(array $input): void
{
$settings = app(FormSettings::class);
$settings->fill([
'registerUrl' => $input['register_url'],
'clearCacheUrl' => $input['clear_cache_url'],
]);
$settings->save();
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'register_url' => 'present|string',
'clear_cache_url' => 'present|string',
];
}
public function asController(ActionRequest $request): RedirectResponse
{
$this->handle($request->validated());
return redirect()->back();
}
}

View File

@ -2,13 +2,12 @@
namespace App\Form; namespace App\Form;
use App\Form\Actions\SettingIndexAction;
use App\Form\Actions\SettingStoreAction; use App\Form\Actions\SettingStoreAction;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable; use App\Setting\Contracts\Storeable;
use App\Setting\LocalSettings; use App\Setting\LocalSettings;
use Lorisleiva\Actions\ActionRequest;
class FormSettings extends LocalSettings implements Indexable, Storeable class FormSettings extends LocalSettings implements Storeable
{ {
public string $registerUrl; public string $registerUrl;
public string $clearCacheUrl; public string $clearCacheUrl;
@ -18,23 +17,38 @@ class FormSettings extends LocalSettings implements Indexable, Storeable
return 'form'; return 'form';
} }
public static function slug(): string
{
return 'form';
}
public static function title(): string public static function title(): string
{ {
return 'Formulare'; return 'Formulare';
} }
public static function indexAction(): string /**
* @inheritdoc
*/
public function rules(): array
{ {
return SettingIndexAction::class; return [
'registerUrl' => 'present|string',
'clearCacheUrl' => 'present|string',
];
} }
public static function storeAction(): string public function beforeSave(ActionRequest $request): void
{ {
return SettingStoreAction::class; }
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => [
'data' => [
'registerUrl' => $this->registerUrl,
'clearCacheUrl' => $this->clearCacheUrl,
]
]
];
} }
} }

View File

@ -2,11 +2,11 @@
namespace App\Invoice; namespace App\Invoice;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable; use App\Setting\Contracts\Storeable;
use App\Setting\LocalSettings; use App\Setting\LocalSettings;
use Lorisleiva\Actions\ActionRequest;
class InvoiceSettings extends LocalSettings implements Indexable, Storeable class InvoiceSettings extends LocalSettings implements Storeable
{ {
public string $from_long; public string $from_long;
@ -35,19 +35,50 @@ class InvoiceSettings extends LocalSettings implements Indexable, Storeable
return 'bill'; return 'bill';
} }
public static function slug(): string /**
* @inheritdoc
*/
public function viewData(): array
{ {
return 'bill'; 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,
'rememberWeeks' => $this->rememberWeeks,
]
];
} }
public static function indexAction(): string /**
* @inheritdoc
*/
public function rules(): array
{ {
return SettingIndexAction::class; return [
'from_long' => '',
'from' => '',
'mobile' => '',
'email' => '',
'website' => '',
'address' => '',
'place' => '',
'zip' => '',
'iban' => '',
'bic' => '',
'rememberWeeks' => '',
];
} }
public static function storeAction(): string public function beforeSave(ActionRequest $request): void
{ {
return SettingSaveAction::class;
} }
public static function title(): string public static function title(): string

View File

@ -1,42 +0,0 @@
<?php
namespace App\Invoice;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
* @return array<string, string>
*/
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),
]);
}
}

View File

@ -1,43 +0,0 @@
<?php
namespace App\Invoice;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingSaveAction
{
use AsAction;
/**
* @param array<string, string> $input
*/
public function handle(array $input): void
{
$settings = app(InvoiceSettings::class);
$settings->fill([
'from_long' => $input['from_long'] ?? '',
'from' => $input['from'] ?? '',
'mobile' => $input['mobile'] ?? '',
'email' => $input['email'] ?? '',
'website' => $input['website'] ?? '',
'address' => $input['address'] ?? '',
'place' => $input['place'] ?? '',
'zip' => $input['zip'] ?? '',
'iban' => $input['iban'] ?? '',
'bic' => $input['bic'] ?? '',
'rememberWeeks' => $input['remember_weeks'] ?? 1,
]);
$settings->save();
}
public function asController(ActionRequest $request): RedirectResponse
{
$this->handle($request->all());
return redirect()->back();
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace App\Mailgateway\Actions;
use App\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Resources\MailgatewayResource;
use Illuminate\Database\Eloquent\Builder;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class IndexAction
{
use AsAction;
/**
* @return Builder<Mailgateway>
*/
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)),
]);
}
}

View File

@ -2,29 +2,29 @@
namespace App\Mailgateway; namespace App\Mailgateway;
use App\Mailgateway\Actions\IndexAction; use App\Mailgateway\Models\Mailgateway;
use App\Setting\Contracts\Indexable; use App\Mailgateway\Resources\MailgatewayResource;
use App\Setting\LocalSettings; use App\Setting\LocalSettings;
class MailgatewaySettings extends LocalSettings implements Indexable class MailgatewaySettings extends LocalSettings
{ {
public static function group(): string public static function group(): string
{ {
return 'mailgateway'; return 'mailgateway';
} }
public static function slug(): string
{
return 'mailgateway';
}
public static function indexAction(): string
{
return IndexAction::class;
}
public static function title(): string public static function title(): string
{ {
return 'E-Mail-Verbindungen'; return 'E-Mail-Verbindungen';
} }
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => MailgatewayResource::collection(Mailgateway::paginate(10)),
];
}
} }

View File

@ -1,35 +0,0 @@
<?php
namespace App\Module;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class ModuleIndexAction
{
use AsAction;
/**
* @return array<string, mixed>
*/
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),
]);
}
}

View File

@ -2,11 +2,12 @@
namespace App\Module; namespace App\Module;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable; use App\Setting\Contracts\Storeable;
use App\Setting\LocalSettings; use App\Setting\LocalSettings;
use Illuminate\Validation\Rule;
use Lorisleiva\Actions\ActionRequest;
class ModuleSettings extends LocalSettings implements Indexable, Storeable class ModuleSettings extends LocalSettings implements Storeable
{ {
/** @var array<int, string> */ /** @var array<int, string> */
public array $modules; public array $modules;
@ -16,28 +17,43 @@ class ModuleSettings extends LocalSettings implements Indexable, Storeable
return 'module'; return 'module';
} }
public static function slug(): string
{
return 'module';
}
public static function title(): string public static function title(): string
{ {
return 'Module'; return 'Module';
} }
public static function indexAction(): string
{
return ModuleIndexAction::class;
}
public static function storeAction(): string
{
return ModuleStoreAction::class;
}
public function hasModule(string $module): bool public function hasModule(string $module): bool
{ {
return in_array($module, $this->modules); return in_array($module, $this->modules);
} }
public function beforeSave(ActionRequest $request): void
{
}
/**
* @inheritdoc
*/
public function rules(): array
{
return [
'modules' => 'present|array',
'modules.*' => ['string', Rule::in(Module::values())],
];
}
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => [
'data' => [
'modules' => $this->modules,
],
'meta' => ['modules' => Module::forSelect()],
]
];
}
} }

View File

@ -1,45 +0,0 @@
<?php
namespace App\Module;
use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\Rule;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class ModuleStoreAction
{
use AsAction;
/**
* @param array<string, mixed> $input
*/
public function handle(array $input): void
{
$settings = app(ModuleSettings::class);
$settings->fill([
'modules' => $input['modules'],
]);
$settings->save();
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'modules' => 'present|array',
'modules.*' => ['string', Rule::in(Module::values())],
];
}
public function asController(ActionRequest $request): RedirectResponse
{
$this->handle($request->validated());
return redirect()->back();
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace App\Nami\Actions;
use App\Setting\NamiSettings;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingIndexAction
{
use AsAction;
/**
* @return array<string, string>
*/
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),
]);
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace App\Nami\Actions;
use App\Initialize\Actions\NamiLoginCheckAction;
use App\Setting\NamiSettings;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class SettingSaveAction
{
use AsAction;
/**
* @param array<string, string> $input
*/
public function handle(array $input): void
{
$settings = app(NamiSettings::class);
$settings->fill([
'mglnr' => $input['mglnr'] ?? '',
'password' => $input['password'] ?? '',
'default_group_id' => $input['default_group_id'] ?? '',
]);
$settings->save();
}
public function asController(ActionRequest $request): RedirectResponse
{
NamiLoginCheckAction::run([
'mglnr' => $request->mglnr,
'password' => $request->password,
]);
$this->handle($request->all());
return redirect()->back();
}
}

View File

@ -1,20 +0,0 @@
<?php
namespace App\Prevention\Actions;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class PreventionIndexAction
{
use AsAction;
public function handle(): Response
{
session()->put('menu', 'setting');
session()->put('title', 'Prävention');
return Inertia::render('setting/Prevention');
}
}

View File

@ -3,11 +3,9 @@
namespace App\Prevention; namespace App\Prevention;
use App\Lib\Editor\EditorData; use App\Lib\Editor\EditorData;
use App\Prevention\Actions\PreventionIndexAction;
use App\Setting\Contracts\Indexable;
use App\Setting\LocalSettings; use App\Setting\LocalSettings;
class PreventionSettings extends LocalSettings implements Indexable class PreventionSettings extends LocalSettings
{ {
public EditorData $formmail; public EditorData $formmail;
@ -17,18 +15,16 @@ class PreventionSettings extends LocalSettings implements Indexable
return 'prevention'; return 'prevention';
} }
public static function slug(): string
{
return 'prevention';
}
public static function indexAction(): string
{
return PreventionIndexAction::class;
}
public static function title(): string public static function title(): string
{ {
return 'Prävention'; return 'Prävention';
} }
/**
* @inheritdoc
*/
public function viewData(): array
{
return [];
}
} }

View File

@ -0,0 +1,40 @@
<?php
namespace App\Setting\Actions;
use App\Setting\Contracts\Storeable;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
class StoreAction
{
use AsAction;
/**
* @param array<string, mixed> $input
*/
public function handle(Storeable $settings, array $input): void
{
$settings->fill($input)->save();
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
/** @var Storeable */
$group = request()->route('settingGroup');
return $group->rules();
}
public function asController(ActionRequest $request, Storeable $settingGroup): RedirectResponse
{
$settingGroup->beforeSave($request);
$this->handle($settingGroup, $request->validated());
return redirect()->back();
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Setting\Actions;
use App\Setting\LocalSettings;
use App\Setting\SettingFactory;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class ViewAction
{
use AsAction;
public function handle(LocalSettings $settingGroup): Response
{
session()->put('menu', 'setting');
session()->put('title', $settingGroup::title());
return Inertia::render('setting/' . ucfirst($settingGroup::group()), [
...$settingGroup->viewData(),
'setting_menu' => app(SettingFactory::class)->getShare(),
]);
}
}

View File

@ -1,11 +0,0 @@
<?php
namespace App\Setting\Contracts;
interface Indexable
{
/**
* @return class-string
*/
public static function indexAction(): string;
}

View File

@ -2,10 +2,26 @@
namespace App\Setting\Contracts; namespace App\Setting\Contracts;
use App\Setting\LocalSettings;
use Lorisleiva\Actions\ActionRequest;
use Spatie\LaravelSettings\Settings;
/**
* @mixin LocalSettings
*/
interface Storeable interface Storeable
{ {
public function url(): string;
/** /**
* @return class-string * @param array<string, mixed> $input
*/ */
public static function storeAction(): string; public function fill(array $input): Settings;
/**
* @return array<string, mixed>
*/
public function rules(): array;
public function beforeSave(ActionRequest $request): void;
} }

View File

@ -6,12 +6,15 @@ use Spatie\LaravelSettings\Settings;
abstract class LocalSettings extends Settings abstract class LocalSettings extends Settings
{ {
abstract public static function slug(): string;
abstract public static function title(): string; abstract public static function title(): string;
public static function url(): string public function url(): string
{ {
return '/setting/'.static::slug(); return route('setting.view', ['settingGroup' => $this->group()]);
} }
/**
* @return array<string, mixed>
*/
abstract public function viewData(): array;
} }

View File

@ -3,14 +3,14 @@
namespace App\Setting; namespace App\Setting;
use App\Group; use App\Group;
use App\Nami\Actions\SettingIndexAction; use App\Initialize\Actions\NamiLoginCheckAction;
use App\Nami\Actions\SettingSaveAction; use App\Nami\Actions\SettingSaveAction;
use App\Setting\Contracts\Indexable;
use App\Setting\Contracts\Storeable; use App\Setting\Contracts\Storeable;
use Lorisleiva\Actions\ActionRequest;
use Zoomyboy\LaravelNami\Api; use Zoomyboy\LaravelNami\Api;
use Zoomyboy\LaravelNami\Nami; use Zoomyboy\LaravelNami\Nami;
class NamiSettings extends LocalSettings implements Indexable, Storeable class NamiSettings extends LocalSettings implements Storeable
{ {
public int $mglnr; public int $mglnr;
@ -31,28 +31,47 @@ class NamiSettings extends LocalSettings implements Indexable, Storeable
return Nami::login($this->mglnr, $this->password); return Nami::login($this->mglnr, $this->password);
} }
/**
* @inheritdoc
*/
public function rules(): array
{
return [
'mglnr' => 'required',
'password' => 'required',
'default_group_id' => 'required',
];
}
public function beforeSave(ActionRequest $request): void
{
NamiLoginCheckAction::run([
'mglnr' => $request->mglnr,
'password' => $request->password,
]);
}
public function localGroup(): ?Group public function localGroup(): ?Group
{ {
return Group::firstWhere('nami_id', $this->default_group_id); return Group::firstWhere('nami_id', $this->default_group_id);
} }
public static function slug(): string
{
return 'nami';
}
public static function indexAction(): string
{
return SettingIndexAction::class;
}
public static function storeAction(): string
{
return SettingSaveAction::class;
}
public static function title(): string public static function title(): string
{ {
return 'NaMi-Login'; return 'NaMi-Login';
} }
/**
* @inheritdoc
*/
public function viewData(): array
{
return [
'data' => [
'mglnr' => $this->mglnr,
'password' => '',
'default_group_id' => $this->default_group_id,
]
];
}
} }

View File

@ -2,7 +2,7 @@
namespace App\Setting; namespace App\Setting;
use App\Setting\Contracts\Indexable; use App\Invoice\InvoiceSettings;
use App\Setting\Contracts\Storeable; use App\Setting\Contracts\Storeable;
use Illuminate\Routing\Router; use Illuminate\Routing\Router;
@ -14,22 +14,14 @@ class SettingFactory
private array $settings = []; private array $settings = [];
/** /**
* @param class-string $setting * @param class-string<LocalSettings> $setting
*/ */
public function register(string $setting): void public function register(string $setting): void
{ {
$this->settings[] = $setting; $this->settings[] = $setting;
if (new $setting() instanceof Indexable) {
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', SettingMiddleware::class])->post($setting::url(), $setting::storeAction());
}
if (1 === count($this->settings)) { if (1 === count($this->settings)) {
app(Router::class)->redirect('/setting', '/setting/'.$setting::slug()); app(Router::class)->redirect('/setting', '/setting/' . $setting::group());
} }
} }
@ -39,10 +31,17 @@ class SettingFactory
public function getShare(): array public function getShare(): array
{ {
return collect($this->settings)->map(fn ($setting) => [ return collect($this->settings)->map(fn ($setting) => [
'url' => $setting::url(), 'url' => (new $setting)->url(),
'is_active' => '/'.request()->path() === $setting::url(), 'is_active' => url(request()->path()) === (new $setting)->url(),
'title' => $setting::title(), 'title' => $setting::title(),
]) ])
->toArray(); ->toArray();
} }
public function resolveGroupName(string $name): LocalSettings
{
$settingClass = collect($this->settings)->first(fn ($setting) => $setting::group() === $name);
return app($settingClass);
}
} }

View File

@ -1,26 +0,0 @@
<?php
namespace App\Setting;
use Closure;
use Illuminate\Http\Request;
use Inertia;
class SettingMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
*
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
Inertia::share([
'setting_menu' => app(SettingFactory::class)->getShare(),
]);
return $next($request);
}
}

View File

@ -8,6 +8,9 @@ use App\Invoice\InvoiceSettings;
use App\Mailgateway\MailgatewaySettings; use App\Mailgateway\MailgatewaySettings;
use App\Module\ModuleSettings; use App\Module\ModuleSettings;
use App\Prevention\PreventionSettings; use App\Prevention\PreventionSettings;
use App\Setting\Actions\StoreAction;
use App\Setting\Actions\ViewAction;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class SettingServiceProvider extends ServiceProvider class SettingServiceProvider extends ServiceProvider
@ -20,6 +23,10 @@ class SettingServiceProvider extends ServiceProvider
public function register() public function register()
{ {
app()->singleton(SettingFactory::class, fn () => new SettingFactory()); 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'])->name('setting.view')->get('/setting/{settingGroup}', ViewAction::class);
app(Router::class)->middleware(['web', 'auth:web'])->name('setting.data')->get('/setting/{settingGroup}/data', ViewAction::class);
app(Router::class)->middleware(['web', 'auth:web'])->name('setting.store')->post('/setting/{settingGroup}', StoreAction::class);
} }
/** /**

View File

@ -17,7 +17,7 @@
<f-text id="website" v-model="inner.website" label="Webseite"></f-text> <f-text id="website" v-model="inner.website" label="Webseite"></f-text>
<f-text id="iban" v-model="inner.iban" label="IBAN"></f-text> <f-text id="iban" v-model="inner.iban" label="IBAN"></f-text>
<f-text id="bic" v-model="inner.bic" label="BIC"></f-text> <f-text id="bic" v-model="inner.bic" label="BIC"></f-text>
<f-text id="remember_weeks" v-model="inner.remember_weeks" type="number" label="Erinnerung alle X Wochen versenden"></f-text> <f-text id="remember_weeks" v-model="inner.rememberWeeks" type="number" label="Erinnerung alle X Wochen versenden"></f-text>
</form> </form>
</setting-layout> </setting-layout>
</page-layout> </page-layout>

View File

@ -9,8 +9,8 @@
<p class="text-sm">Hier kannst du Einstellungen für Anmeldeformulare setzen.</p> <p class="text-sm">Hier kannst du Einstellungen für Anmeldeformulare setzen.</p>
</div> </div>
<div class="grid grid-cols-2 gap-4"> <div class="grid grid-cols-2 gap-4">
<f-text id="register_url" v-model="inner.register_url" label="Formular-Link"></f-text> <f-text id="register_url" v-model="inner.registerUrl" label="Formular-Link"></f-text>
<f-text id="clear_cache_url" v-model="inner.clear_cache_url" label="Frontend-Cache-Url"></f-text> <f-text id="clear_cache_url" v-model="inner.clearCacheUrl" label="Frontend-Cache-Url"></f-text>
</div> </div>
</form> </form>
</setting-layout> </setting-layout>

View File

@ -11,10 +11,8 @@ use App\Membership\Actions\MassStoreAction;
use App\Membership\Actions\MembershipDestroyAction; use App\Membership\Actions\MembershipDestroyAction;
use App\Membership\Actions\MembershipStoreAction; use App\Membership\Actions\MembershipStoreAction;
use App\Subactivity; use App\Subactivity;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Queue;
use Tests\EndToEndTestCase; use Tests\EndToEndTestCase;
use Tests\TestCase;
use Throwable; use Throwable;
use Zoomyboy\LaravelNami\Fakes\MembershipFake; use Zoomyboy\LaravelNami\Fakes\MembershipFake;

View File

@ -10,10 +10,19 @@ class SettingTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
public function testSettingIndex(): void public function testItDisplaysView(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();
InvoiceSettings::fake([
$this->get(route('setting.view', ['settingGroup' => 'bill']))
->assertOk()
->assertComponent('setting/Bill');
}
public function testDisplaySettings(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
app(InvoiceSettings::class)->fill([
'from_long' => 'DPSG Stamm Muster', 'from_long' => 'DPSG Stamm Muster',
'from' => 'Stamm Muster', 'from' => 'Stamm Muster',
'mobile' => '+49 176 55555', 'mobile' => '+49 176 55555',
@ -25,43 +34,33 @@ class SettingTest extends TestCase
'iban' => 'DE05', 'iban' => 'DE05',
'bic' => 'SOLSDE', 'bic' => 'SOLSDE',
'rememberWeeks' => 6 'rememberWeeks' => 6
]); ])->save();
$response = $this->get('/setting/bill'); $this->get(route('setting.data', ['settingGroup' => 'bill']))
->assertOk()
$response->assertOk(); ->assertComponent('setting/Bill')
$this->assertInertiaHas([ ->assertInertiaPath('data.from_long', 'DPSG Stamm Muster')
'from_long' => 'DPSG Stamm Muster', ->assertInertiaPath('data.from', 'Stamm Muster')
'from' => 'Stamm Muster', ->assertInertiaPath('data.mobile', '+49 176 55555')
'mobile' => '+49 176 55555', ->assertInertiaPath('data.email', 'max@muster.de')
'email' => 'max@muster.de', ->assertInertiaPath('data.website', 'https://example.com')
'website' => 'https://example.com', ->assertInertiaPath('data.address', 'Musterstr 4')
'address' => 'Musterstr 4', ->assertInertiaPath('data.place', 'Solingen')
'place' => 'Solingen', ->assertInertiaPath('data.zip', '12345')
'zip' => '12345', ->assertInertiaPath('data.iban', 'DE05')
'iban' => 'DE05', ->assertInertiaPath('data.bic', 'SOLSDE')
'bic' => 'SOLSDE', ->assertInertiaPath('data.rememberWeeks', 6);
'remember_weeks' => 6
], $response, 'data');
} }
public function testItReturnsTabs(): void public function testItReturnsTabs(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();
$response = $this->get('/setting/bill'); $this->get(route('setting.view', ['settingGroup' => 'bill']))
->assertInertiaPath('setting_menu.1.title', 'Rechnung')
/** @var array<int, array{url: string, title: string, is_active: bool}> */ ->assertInertiaPath('setting_menu.1.url', url('/setting/bill'))
$menus = $this->inertia($response, 'setting_menu'); ->assertInertiaPath('setting_menu.1.is_active', true)
$this->assertTrue( ->assertInertiaPath('setting_menu.0.is_active', false);
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 public function testItCanChangeSettings(): void
@ -79,7 +78,7 @@ class SettingTest extends TestCase
'zip' => '12345', 'zip' => '12345',
'iban' => 'DE05', 'iban' => 'DE05',
'bic' => 'SOLSDE', 'bic' => 'SOLSDE',
'remember_weeks' => 10 'rememberWeeks' => 10
]); ]);
$response->assertRedirect('/setting/bill'); $response->assertRedirect('/setting/bill');

View File

@ -42,6 +42,6 @@ class FileshareIndexActionTest extends FileshareTestCase
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();
$this->get('/setting/fileshare')->assertComponent('fileshare/Index'); $this->get('/setting/fileshare')->assertComponent('setting/Fileshare');
} }
} }