Skip to content

Commit c697d86

Browse files
authored
Merge branch 'pelican-dev:main' into main
2 parents 0b04697 + a3f26b9 commit c697d86

18 files changed

Lines changed: 223 additions & 84 deletions

File tree

snowflakes/config/snowflakes.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22

33
return [
4-
'enabled' => env('SNOWFLAKES_ENABLED', true),
5-
'size' => env('SNOWFLAKES_SIZE', 1),
6-
'speed' => env('SNOWFLAKES_SPEED', 3),
4+
'size' => env('SNOWFLAKES_SIZE', 0.8),
5+
'speed' => env('SNOWFLAKES_SPEED', 1),
76
'opacity' => env('SNOWFLAKES_OPACITY', 0.5),
87
'density' => env('SNOWFLAKES_DENSITY', 1),
98
'quality' => env('SNOWFLAKES_QUALITY', 1),

snowflakes/lang/en/strings.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
return [
4+
'size' => 'Size',
5+
'size_help' => 'Size of the snowflakes.',
6+
'speed' => 'Speed',
7+
'speed_help' => 'Speed of the snowflakes falling.',
8+
'opacity' => 'Opacity',
9+
'opacity_help' => 'How well can you see through the snowflakes.',
10+
'density' => 'Density',
11+
'density_help' => 'Page density of the snowflakes. More density, more snowflakes.',
12+
'quality' => 'Quality',
13+
'quality_help' => 'Higher quality may impact performance on some devices.',
14+
];

snowflakes/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "snowflakes",
33
"name": "Snowflakes",
4-
"author": "Boy132",
4+
"author": "Boy132 & notCharles",
55
"version": "1.0.0",
66
"description": "Let it snow, let it snow, let it snow",
77
"category": "plugin",

snowflakes/src/Providers/SnowflakesPluginProvider.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,11 @@ class SnowflakesPluginProvider extends ServiceProvider
1111
{
1212
public function boot(): void
1313
{
14-
$enabled = config('snowflakes.enabled');
15-
$size = config('snowflakes.size');
16-
$speed = config('snowflakes.speed');
17-
$opacity = config('snowflakes.opacity');
18-
$density = config('snowflakes.density');
19-
$quality = config('snowflakes.quality');
20-
2114
FilamentView::registerRenderHook(
2215
PanelsRenderHook::PAGE_START,
2316
fn () => Blade::render(<<<'HTML'
2417
<script>
2518
window.SnowflakeConfig = {
26-
start: {{ $enabled }},
2719
size: {{ $size }},
2820
speed: {{ $speed }},
2921
opacity: {{ $opacity }},
@@ -34,14 +26,7 @@ public function boot(): void
3426
};
3527
</script>
3628
<script src="https://cdn.jsdelivr.net/gh/nextapps-de/snowflake@master/snowflake.min.js"></script>
37-
HTML, [
38-
'enabled' => $enabled,
39-
'size' => $size,
40-
'speed' => $speed,
41-
'opacity' => $opacity,
42-
'density' => $density,
43-
'quality' => $quality,
44-
])
29+
HTML, config('snowflakes'))
4530
);
4631
}
4732
}

snowflakes/src/SnowflakesPlugin.php

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use App\Traits\EnvironmentWriterTrait;
77
use Filament\Contracts\Plugin;
88
use Filament\Forms\Components\Slider;
9-
use Filament\Forms\Components\Toggle;
109
use Filament\Notifications\Notification;
1110
use Filament\Panel;
1211
use Filament\Schemas\Components\Group;
@@ -27,60 +26,50 @@ public function boot(Panel $panel): void {}
2726
public function getSettingsForm(): array
2827
{
2928
$schema = [
30-
Toggle::make('SNOWFLAKES_ENABLED')
31-
->label('Enable Snowflakes')
32-
->columnSpanFull()
33-
->live()
34-
->default(fn () => config('snowflakes.enabled')),
3529
Slider::make('SNOWFLAKES_SIZE')
30+
->label(trans('snowflakes::strings.size'))
3631
->range(minValue: 0.5, maxValue: 4)
3732
->decimalPlaces(1)
3833
->step(0.1)
39-
->label('Size')
4034
->tooltips()
4135
->hintIcon('tabler-question-mark')
42-
->hintIconTooltip('Size of the snowflakes.')
43-
->disabled(fn ($get) => !$get('SNOWFLAKES_ENABLED'))
36+
->hintIconTooltip(trans('snowflakes::strings.size_help'))
4437
->default(fn () => config('snowflakes.size')),
4538
Slider::make('SNOWFLAKES_SPEED')
46-
->label('Speed')
39+
->label(trans('snowflakes::strings.speed'))
4740
->range(minValue: 0.5, maxValue: 3)
4841
->decimalPlaces(1)
4942
->step(0.1)
5043
->tooltips()
5144
->hintIcon('tabler-question-mark')
52-
->hintIconTooltip('Speed of the snowflakes falling.')
53-
->disabled(fn ($get) => !$get('SNOWFLAKES_ENABLED'))
45+
->hintIconTooltip(trans('snowflakes::strings.speed_help'))
5446
->default(fn () => config('snowflakes.speed')),
5547
Slider::make('SNOWFLAKES_OPACITY')
56-
->label('Opacity')
48+
->label(trans('snowflakes::strings.opacity'))
5749
->range(minValue: 0.1, maxValue: 1)
5850
->decimalPlaces(1)
5951
->step(0.1)
6052
->tooltips()
6153
->hintIcon('tabler-question-mark')
62-
->hintIconTooltip('How well can you see through the snowflakes.')
63-
->disabled(fn ($get) => !$get('SNOWFLAKES_ENABLED'))
54+
->hintIconTooltip(trans('snowflakes::strings.opacity_help'))
6455
->default(fn () => config('snowflakes.opacity')),
6556
Slider::make('SNOWFLAKES_DENSITY')
66-
->label('Density')
57+
->label(trans('snowflakes::strings.density'))
6758
->range(minValue: 0.5, maxValue: 10)
6859
->decimalPlaces(1)
6960
->step(0.1)
7061
->tooltips()
7162
->hintIcon('tabler-question-mark')
72-
->hintIconTooltip('Page density of the snowflakes. More density, more snowflakes.')
73-
->disabled(fn ($get) => !$get('SNOWFLAKES_ENABLED'))
63+
->hintIconTooltip(trans('snowflakes::strings.density_help'))
7464
->default(fn () => config('snowflakes.density')),
7565
Slider::make('SNOWFLAKES_QUALITY')
76-
->label('Quality')
66+
->label(trans('snowflakes::strings.quality'))
7767
->range(minValue: 0.1, maxValue: 1)
7868
->decimalPlaces(1)
7969
->step(0.1)
8070
->tooltips()
8171
->hintIcon('tabler-question-mark')
82-
->hintIconTooltip('Higher quality may impact performance on some devices.')
83-
->disabled(fn ($get) => !$get('SNOWFLAKES_ENABLED'))
72+
->hintIconTooltip(trans('snowflakes::strings.quality_help'))
8473
->default(fn () => config('snowflakes.quality')),
8574
];
8675

@@ -93,11 +82,10 @@ public function getSettingsForm(): array
9382

9483
public function saveSettings(array $data): void
9584
{
96-
$data['SNOWFLAKES_ENABLED'] = $data['SNOWFLAKES_ENABLED'] ? 'true' : 'false';
9785
$this->writeToEnvironment($data);
9886

9987
Notification::make()
100-
->title('Settings saved')
88+
->title(trans('admin/setting.save_success'))
10189
->success()
10290
->send();
10391
}

subdomains/database/migrations/002_create_subdomains_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public function up(): void
1717
$table->unsignedInteger('domain_id');
1818
$table->foreign('domain_id')->references('id')->on('cloudflare_domains')->cascadeOnDelete();
1919

20-
$table->unsignedInteger('allocation_id');
21-
$table->foreign('allocation_id')->references('id')->on('allocations')->cascadeOnDelete();
20+
$table->unsignedInteger('server_id');
21+
$table->foreign('server_id')->references('id')->on('servers')->cascadeOnDelete();
2222

2323
$table->timestamps();
2424

subdomains/lang/de/strings.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
return [
4+
'no_domains' => 'Keine Domains',
5+
'domain' => 'Domain|Domains',
6+
7+
'no_subdomains' => 'Keine Subdomains',
8+
'subdomain' => 'Subdomain|Subdomains',
9+
'limit' => 'Limit',
10+
'change_limit' => 'Limit anpassen',
11+
'limit_changed' => 'Limit angepasst',
12+
'limit_reached' => 'Subdomain Limit erreicht',
13+
'create_subdomain' => 'Subdomain erstellen',
14+
15+
'name' => 'Name',
16+
17+
'api_token' => 'Cloudflare API Token',
18+
'api_token_help' => 'Der Token benötigt Leseberechtigung für Zone.Zone und Schreibberechtigung für Zone.Dns. Für eine verbesserte Sicherheit können mit "Zone Resources" bestimmte Domains ausgeschlossen werden und die Panel-IP zum "Client IP Adress Filtering" hinzugefügt werden.',
19+
];

subdomains/lang/en/strings.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66

77
'no_subdomains' => 'No Subdomains',
88
'subdomain' => 'Subdomain|Subdomains',
9-
'limit' => 'Subdomain Limit Reached',
9+
'limit' => 'Limit',
10+
'change_limit' => 'Change Limit',
11+
'limit_changed' => 'Limit changed',
12+
'limit_reached' => 'Subdomain Limit Reached',
1013
'create_subdomain' => 'Create Subdomain',
1114

1215
'name' => 'Name',
16+
17+
'api_token' => 'Cloudflare API Token',
18+
'api_token_help' => 'The token needs to have read permissions for Zone.Zone and write for Zone.Dns. For better security you can also set the "Zone Resources" to exclude certain domains and add the panel ip to the "Client IP Adress Filtering".',
1319
];

subdomains/src/Filament/Admin/Resources/CloudflareDomains/CloudflareDomainResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static function table(Table $table): Table
7171
public static function form(Schema $schema): Schema
7272
{
7373
return $schema
74+
->columns(1)
7475
->components([
7576
TextInput::make('name')
7677
->label(trans('subdomains::strings.name'))
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Boy132\Subdomains\Filament\Admin\Resources\Users\RelationManagers;
4+
5+
use App\Models\Server;
6+
use Boy132\Subdomains\Models\CloudflareDomain;
7+
use Boy132\Subdomains\Models\Subdomain;
8+
use Filament\Actions\Action;
9+
use Filament\Actions\CreateAction;
10+
use Filament\Actions\DeleteAction;
11+
use Filament\Actions\EditAction;
12+
use Filament\Forms\Components\Hidden;
13+
use Filament\Forms\Components\Select;
14+
use Filament\Forms\Components\TextInput;
15+
use Filament\Notifications\Notification;
16+
use Filament\Resources\RelationManagers\RelationManager;
17+
use Filament\Schemas\Schema;
18+
use Filament\Tables\Columns\TextColumn;
19+
use Filament\Tables\Table;
20+
21+
/**
22+
* @method Server getOwnerRecord()
23+
*/
24+
class SubdomainRelationManager extends RelationManager
25+
{
26+
protected static string $relationship = 'subdomains';
27+
28+
public function table(Table $table): Table
29+
{
30+
return $table
31+
->heading(fn () => trans_choice('subdomains::strings.subdomain', 2) . ' (' . trans('subdomains::strings.limit') .': ' . ($this->getOwnerRecord()->subdomain_limit ?? 0) . ')')
32+
->columns([
33+
TextColumn::make('label')
34+
->label(trans('subdomains::strings.name'))
35+
->state(fn (Subdomain $subdomain) => $subdomain->getLabel()),
36+
])
37+
->recordActions([
38+
EditAction::make(),
39+
DeleteAction::make(),
40+
])
41+
->headerActions([
42+
Action::make('change_limit')
43+
->label(trans('subdomains::strings.change_limit'))
44+
->schema([
45+
TextInput::make('limit')
46+
->label(trans('subdomains::strings.limit'))
47+
->numeric()
48+
->required()
49+
->default($this->getOwnerRecord()->subdomain_limit ?? 0)
50+
->minValue(0),
51+
])
52+
->action(function ($data) {
53+
$oldLimit = $this->getOwnerRecord()->subdomain_limit ?? 0;
54+
$newLimit = $data['limit'];
55+
56+
$this->getOwnerRecord()->update(['subdomain_limit' => $newLimit]);
57+
58+
Notification::make()
59+
->title(trans('subdomains::strings.limit_changed'))
60+
->body($oldLimit . ' -> ' . $newLimit)
61+
->success()
62+
->send();
63+
}),
64+
CreateAction::make()
65+
->visible(fn () => CloudflareDomain::count() > 0)
66+
->disabled(fn () => !$this->getOwnerRecord()->allocation || $this->getOwnerRecord()->allocation->ip === '0.0.0.0' || $this->getOwnerRecord()->allocation->ip === '::')
67+
->createAnother(false),
68+
]);
69+
}
70+
71+
public function form(Schema $schema): Schema
72+
{
73+
return $schema
74+
->components([
75+
TextInput::make('name')
76+
->label(trans('subdomains::strings.name'))
77+
->required()
78+
->unique(),
79+
Select::make('domain_id')
80+
->label(trans_choice('subdomains::strings.domain', 1))
81+
->disabledOn('edit')
82+
->required()
83+
->relationship('domain', 'name')
84+
->preload()
85+
->searchable(),
86+
Hidden::make('record_type')
87+
->default(fn () => is_ipv6($this->getOwnerRecord()->allocation->ip) ? 'AAAA' : 'A'),
88+
]);
89+
}
90+
}

0 commit comments

Comments
 (0)