Skip to content

Commit 09017c4

Browse files
authored
Merge pull request #15 from niladam/quickfix/fix-plugin-not-respecting-config
Fix plugin not respecting configuration
2 parents 0a0aaea + b2875a4 commit 09017c4

File tree

2 files changed

+52
-44
lines changed

2 files changed

+52
-44
lines changed

resources/views/main.blade.php

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
@auth
2-
<script src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('filament-auto-logout', 'niladam/filament-auto-logout') }}"></script>
3-
<form id="auto-logout-form"
4-
data-auto-logout-enabled="{{ $enabled }}"
5-
action="{{ $logout_url }}"
6-
data-duration="{{ $duration }}"
7-
data-warn-before="{{ $warn_before }}"
8-
data-show-timeleft="{{ $show_time_left }}"
9-
data-time-left-text="{{ $time_left_text }}"
10-
data-notification-title="{{ $notification_title }}"
11-
data-notification-body="{{ $notification_body }}"
12-
data-units='@json($units, JSON_THROW_ON_ERROR)'
13-
method="POST" style="display: none;">
14-
@csrf
15-
</form>
16-
17-
@if($show_time_left)
18-
<div id="idle-timeout-element"
19-
class="
20-
idle-timeout-element hidden sm:flex items-center h-9 px-3 text-sm font-medium
21-
rounded-lg shadow-sm ring-1
22-
ring-custom-600/20 bg-custom-50 text-custom-600
23-
dark:ring-custom-400/30 dark:bg-custom-400/10 dark:text-custom-400
24-
text-center
25-
"
26-
style="
27-
--c-50: {{ $color[50] }};
28-
--c-300: {{ $color[300] }};
29-
--c-400: {{ $color[400] }};
30-
--c-600: {{ $color[600] }};
31-
"
32-
>
33-
</div>
34-
@endif
35-
@endauth
1+
@if($enabled)
2+
@auth
3+
<script src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('filament-auto-logout', 'niladam/filament-auto-logout') }}"></script>
4+
<form id="auto-logout-form"
5+
data-auto-logout-enabled="{{ $enabled }}"
6+
action="{{ $logout_url }}"
7+
data-duration="{{ $duration }}"
8+
data-warn-before="{{ $warn_before }}"
9+
data-show-timeleft="{{ $show_time_left }}"
10+
data-time-left-text="{{ $time_left_text }}"
11+
data-notification-title="{{ $notification_title }}"
12+
data-notification-body="{{ $notification_body }}"
13+
data-units='@json($units, JSON_THROW_ON_ERROR)'
14+
method="POST" style="display: none;">
15+
@csrf
16+
</form>
17+
18+
@if($show_time_left)
19+
<div id="idle-timeout-element"
20+
class="
21+
idle-timeout-element hidden sm:flex items-center h-9 px-3 text-sm font-medium
22+
rounded-lg shadow-sm ring-1
23+
ring-custom-600/20 bg-custom-50 text-custom-600
24+
dark:ring-custom-400/30 dark:bg-custom-400/10 dark:text-custom-400
25+
text-center
26+
"
27+
style="
28+
--c-50: {{ $color[50] }};
29+
--c-300: {{ $color[300] }};
30+
--c-400: {{ $color[400] }};
31+
--c-600: {{ $color[600] }};
32+
"
33+
>
34+
</div>
35+
@endif
36+
@endauth
37+
@endif

src/AutoLogoutPlugin.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Niladam\FilamentAutoLogout;
44

5+
use Carbon\Carbon;
56
use Closure;
67
use Filament\Contracts\Plugin;
78
use Filament\Panel;
@@ -15,21 +16,21 @@ class AutoLogoutPlugin implements Plugin
1516
{
1617
use EvaluatesClosures;
1718

18-
public bool | Closure $enabled = true;
19+
public bool | Closure | null $enabled = null;
1920

2021
public bool | Closure $hasWarning = true;
2122

22-
public bool | Closure $showTimeLeft = true;
23+
public bool | Closure | null $showTimeLeft = null;
2324

24-
public int | Closure $duration = 900;
25+
public int | Closure | null $duration = null;
2526

26-
public int | Closure $warnBeforeSeconds = 30;
27+
public int | Closure | null $warnBeforeSeconds = null;
2728

2829
public array | Closure $color = Color::Zinc;
2930

3031
public ?string $timeleftText = null;
3132

32-
private string $location = PanelsRenderHook::GLOBAL_SEARCH_BEFORE;
33+
public string $location = PanelsRenderHook::GLOBAL_SEARCH_BEFORE;
3334

3435
public function getId(): string
3536
{
@@ -46,7 +47,14 @@ public function register(Panel $panel): void
4647

4748
public function boot(Panel $panel): void
4849
{
49-
$this->timeleftText = $this->timeleftText ?? config('filament-auto-logout.time_left_text');
50+
$this->enabled = $this->enabled ?? config('filament-auto-logout.enabled', true);
51+
$this->duration = $this->duration ?? config('filament-auto-logout.duration_in_seconds', Carbon::SECONDS_PER_MINUTE * 5);
52+
$this->warnBeforeSeconds = $this->warnBeforeSeconds ?? config('filament-auto-logout.warn_before_in_seconds', 30);
53+
$this->showTimeLeft = $this->showTimeLeft ?? config('filament-auto-logout.show_time_left', true);
54+
$this->timeleftText = $this->timeleftText ?? config('filament-auto-logout.time_left_text', 'Time left:');
55+
$this->location = $this->location === PanelsRenderHook::GLOBAL_SEARCH_BEFORE
56+
? config('filament-auto-logout.location', PanelsRenderHook::GLOBAL_SEARCH_BEFORE)
57+
: $this->location;
5058
}
5159

5260
protected function renderView(string $logoutUrl): ?string
@@ -73,7 +81,6 @@ public static function make(): static
7381

7482
public static function get(): static
7583
{
76-
/** @var static $plugin */
7784
$plugin = filament(app(static::class)->getId());
7885

7986
return $plugin;
@@ -90,7 +97,7 @@ public function enableIf(bool | Closure $enabled = true): static
9097

9198
public function disableIf(Closure $callback): static
9299
{
93-
return $this->enableif((bool) $this->evaluate($callback));
100+
return $this->enableIf((bool) $this->evaluate($callback));
94101
}
95102

96103
public function withoutWarning(): static
@@ -156,7 +163,6 @@ public function location(string $location = PanelsRenderHook::GLOBAL_SEARCH_BEFO
156163
protected function isValidPanelHook(string $location): bool
157164
{
158165
static $validLocations = null;
159-
160166
if ($validLocations === null) {
161167
$reflection = new ReflectionClass(PanelsRenderHook::class);
162168
$validLocations = array_values($reflection->getConstants());

0 commit comments

Comments
 (0)