-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathPasteFoxSettings.php
More file actions
154 lines (134 loc) · 4.9 KB
/
PasteFoxSettings.php
File metadata and controls
154 lines (134 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
namespace FlexKleks\PasteFoxShare\Filament\Admin\Pages;
use App\Traits\EnvironmentWriterTrait;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Notifications\Notification;
use Filament\Pages\Concerns\InteractsWithFormActions;
use Filament\Pages\Page;
use Filament\Schemas\Components\Component;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
/**
* @property Schema $form
*/
class PasteFoxSettings extends Page
{
use EnvironmentWriterTrait;
use InteractsWithFormActions;
use InteractsWithForms;
protected static string|\BackedEnum|null $navigationIcon = 'tabler-share';
protected string $view = 'filament.server.pages.server-form-page';
/** @var array<mixed>|null */
public ?array $data = [];
public function getTitle(): string
{
return 'PasteFox Settings';
}
public static function getNavigationLabel(): string
{
return 'PasteFox';
}
public static function getNavigationGroup(): ?string
{
return trans('admin/dashboard.advanced');
}
public function mount(): void
{
$this->form->fill([
'api_key' => config('pastefox-share.api_key'),
'visibility' => config('pastefox-share.visibility', 'PUBLIC'),
'effect' => config('pastefox-share.effect', 'NONE'),
'password' => config('pastefox-share.password'),
'theme' => config('pastefox-share.theme', 'dark'),
]);
}
/**
* @return Component[]
*/
public function getFormSchema(): array
{
return [
Section::make('API Configuration')
->description('Without API key, pastes expire after 7 days and are always public.')
->schema([
TextInput::make('api_key')
->label('API Key')
->password()
->revealable()
->helperText('Optional - Get your API key from https://pastefox.com/dashboard'),
]),
Section::make('Paste Settings')
->schema([
Select::make('visibility')
->label('Visibility')
->options([
'PUBLIC' => 'Public',
'PRIVATE' => 'Private (requires API key)',
])
->default('PUBLIC')
->helperText('Private pastes require an API key'),
Select::make('effect')
->label('Visual Effect')
->options([
'NONE' => 'None',
'MATRIX' => 'Matrix Rain',
'GLITCH' => 'Glitch',
'CONFETTI' => 'Confetti',
'SCRATCH' => 'Scratch Card',
'PUZZLE' => 'Puzzle Reveal',
'SLOTS' => 'Slot Machine',
'SHAKE' => 'Shake',
'FIREWORKS' => 'Fireworks',
'TYPEWRITER' => 'Typewriter',
'BLUR' => 'Blur Reveal',
])
->default('NONE'),
Select::make('theme')
->label('Theme')
->options([
'dark' => 'Dark',
'light' => 'Light',
])
->default('dark'),
TextInput::make('password')
->label('Password Protection')
->password()
->revealable()
->minLength(4)
->maxLength(100)
->helperText('Optional - 4-100 characters'),
]),
];
}
protected function getFormStatePath(): ?string
{
return 'data';
}
protected function getHeaderActions(): array
{
return [
Action::make('save')
->label(trans('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->action('save')
->keyBindings(['mod+s']),
];
}
public function save(): void
{
$data = $this->form->getState();
$this->writeToEnvironment([
'PASTEFOX_API_KEY' => $data['api_key'] ?? '',
'PASTEFOX_VISIBILITY' => $data['visibility'] ?? 'PUBLIC',
'PASTEFOX_EFFECT' => $data['effect'] ?? 'NONE',
'PASTEFOX_THEME' => $data['theme'] ?? 'dark',
'PASTEFOX_PASSWORD' => $data['password'] ?? '',
]);
Notification::make()
->title('Settings saved')
->success()
->send();
}
}