Skip to content

Commit

Permalink
Enable modern and legacy look and feel in user settings
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Dec 5, 2024
1 parent 82c1402 commit 2cf08e8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
40 changes: 35 additions & 5 deletions app/Feature/LookAndFeel/LookAndFeelServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Coyote\Feature\LookAndFeel;

use Coyote\Services\Guest;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider;
Expand All @@ -14,11 +15,40 @@ public function boot(): void
$view = $this->app['view'];

$view->composer('layout', function (View $view) {
/** @var Request $request */
$request = $this->app[Request::class];

$has = $request->query->has('lookAndFeel');
$view->with(['lookAndFeelModern' => $has]);
$view->with(['lookAndFeelModern' => $this->lookAndFeel() === 'modern']);
});
}

private function lookAndFeel(): string
{
return $this->requestOverride() ?? $this->userSetting() ?? 'legacy';
}

private function userSetting(): ?string
{
if (!auth()->check()) {
return null;
}
$guest = new Guest(auth()->user()->guest_id);
if ($guest->getSetting('lookAndFeel') === 'modern') {
return 'modern';
}
if ($guest->getSetting('lookAndFeel') === 'legacy') {
return 'legacy';
}
return null;
}

private function requestOverride(): ?string
{
/** @var Request $request */
$request = $this->app[Request::class];
if ($request->query->get('lookAndFeel') === 'legacy') {
return 'legacy';
}
if ($request->query->has('lookAndFeel')) {
return 'modern';
}
return null;
}
}
9 changes: 9 additions & 0 deletions app/Http/Controllers/Adm/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Coyote\Repositories\Criteria\WithTrashed;
use Coyote\Repositories\Eloquent\UserRepository;
use Coyote\Services\FormBuilder\Form;
use Coyote\Services\Guest;
use Coyote\Services\Stream\Activities\Update;
use Coyote\Services\Stream\Objects\Person;
use Coyote\User;
Expand Down Expand Up @@ -106,6 +107,14 @@ public function save(User $user): RedirectResponse
$user->groups()->sync((array)$data['groups']);
stream(Update::class, new Person($user));
event($user->deleted_at ? new UserDeleted($user) : new UserSaved($user));

if ($this->request->has('local-settings-action')) {
$guest = new Guest($user->guest_id);
match ($this->request->get('local-settings-action')) {
'laf-modern' => $guest->setSetting('lookAndFeel', 'modern'),
'laf-legacy' => $guest->setSetting('lookAndFeel', 'legacy'),
};
}
});

return back()->with('success', 'Zmiany zostały zapisane.');
Expand Down
4 changes: 4 additions & 0 deletions resources/views/adm/users/save.twig
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<p>
Lokalne ustawienia użytkownika:
</p>
<div class="mb-2">
<button class="btn btn-primary" type="submit" name="local-settings-action" value="laf-modern">LookAndFeel: modern</button>
<button class="btn btn-primary" type="submit" name="local-settings-action" value="laf-legacy">LookAndFeel: legacy</button>
</div>
<pre><code>{{ userSettings }}</code></pre>
</div>
</div>
Expand Down

0 comments on commit 2cf08e8

Please sign in to comment.