55use App \Contracts \Plugins \HasPluginSettings ;
66use App \Traits \EnvironmentWriterTrait ;
77use Filament \Contracts \Plugin ;
8+ use Filament \Forms \Components \TagsInput ;
89use Filament \Forms \Components \TextInput ;
910use Filament \Forms \Components \Toggle ;
1011use Filament \Notifications \Notification ;
1112use Filament \Panel ;
13+ use Filament \Schemas \Components \Section ;
1214
1315class UserCreatableServersPlugin implements HasPluginSettings, Plugin
1416{
@@ -33,36 +35,59 @@ public function boot(Panel $panel): void {}
3335 public function getSettingsForm (): array
3436 {
3537 return [
36- TextInput::make ('database_limit ' )
37- ->label ('Default database limit ' )
38- ->required ()
39- ->numeric ()
40- ->minValue (0 )
41- ->default (fn () => config ('user-creatable-servers.database_limit ' )),
42- TextInput::make ('allocation_limit ' )
43- ->label ('Default allocation limit ' )
44- ->required ()
45- ->numeric ()
46- ->minValue (0 )
47- ->default (fn () => config ('user-creatable-servers.allocation_limit ' )),
48- TextInput::make ('backup_limit ' )
49- ->label ('Default backup limit ' )
50- ->required ()
51- ->numeric ()
52- ->minValue (0 )
53- ->default (fn () => config ('user-creatable-servers.backup_limit ' )),
54- Toggle::make ('can_users_update_servers ' )
55- ->label ('Can users update servers? ' )
56- ->hintIcon ('tabler-question-mark ' )
57- ->hintIconTooltip ('If checked users can update the resource limits of theirs servers after creation. ' )
58- ->inline (false )
59- ->default (fn () => config ('user-creatable-servers.can_users_update_servers ' )),
60- Toggle::make ('can_users_delete_servers ' )
61- ->label ('Can users delete servers? ' )
62- ->hintIcon ('tabler-question-mark ' )
63- ->hintIconTooltip ('If checked users can delete their own servers. ' )
64- ->inline (false )
65- ->default (fn () => config ('user-creatable-servers.can_users_delete_servers ' )),
38+ Section::make ('Limits ' )
39+ ->columns (3 )
40+ ->schema ([
41+ TextInput::make ('database_limit ' )
42+ ->label ('Default database limit ' )
43+ ->required ()
44+ ->numeric ()
45+ ->minValue (0 )
46+ ->default (fn () => config ('user-creatable-servers.database_limit ' )),
47+ TextInput::make ('allocation_limit ' )
48+ ->label ('Default allocation limit ' )
49+ ->required ()
50+ ->numeric ()
51+ ->minValue (0 )
52+ ->default (fn () => config ('user-creatable-servers.allocation_limit ' )),
53+ TextInput::make ('backup_limit ' )
54+ ->label ('Default backup limit ' )
55+ ->required ()
56+ ->numeric ()
57+ ->minValue (0 )
58+ ->default (fn () => config ('user-creatable-servers.backup_limit ' )),
59+ ]),
60+ Section::make ('User Settings ' )
61+ ->columns ()
62+ ->schema ([
63+ Toggle::make ('can_users_update_servers ' )
64+ ->label ('Can users update servers? ' )
65+ ->hintIcon ('tabler-question-mark ' )
66+ ->hintIconTooltip ('If checked users can update the resource limits of their servers after creation. ' )
67+ ->inline (false )
68+ ->default (fn () => config ('user-creatable-servers.can_users_update_servers ' )),
69+ Toggle::make ('can_users_delete_servers ' )
70+ ->label ('Can users delete servers? ' )
71+ ->hintIcon ('tabler-question-mark ' )
72+ ->hintIconTooltip ('If checked users can delete their own servers. ' )
73+ ->inline (false )
74+ ->default (fn () => config ('user-creatable-servers.can_users_delete_servers ' )),
75+ ]),
76+ Section::make ('Deployment Settings ' )
77+ ->columns ()
78+ ->schema ([
79+ TagsInput::make ('deployment_tags ' )
80+ ->label ('Node tags ' )
81+ ->hintIcon ('tabler-question-mark ' )
82+ ->hintIconTooltip ('Only nodes with these tags will be used for deployment. Leave empty to allow all nodes. ' )
83+ ->default (fn () => array_filter (explode (', ' , config ('user-creatable-servers.deployment_tags ' )))),
84+ TagsInput::make ('deployment_ports ' )
85+ ->label ('Ports ' )
86+ ->placeholder ('New port or port range ' )
87+ ->hintIcon ('tabler-question-mark ' )
88+ ->hintIconTooltip ('These ports will be used for deployment. You can enter individual ports or port ranges. (e.g. 8000-8100) Leave empty to create servers with any allocations. ' )
89+ ->default (fn () => array_filter (explode (', ' , config ('user-creatable-servers.deployment_ports ' )))),
90+ ]),
6691 ];
6792 }
6893
@@ -74,6 +99,8 @@ public function saveSettings(array $data): void
7499 'UCS_DEFAULT_BACKUP_LIMIT ' => $ data ['backup_limit ' ],
75100 'UCS_CAN_USERS_UPDATE_SERVERS ' => $ data ['can_users_update_servers ' ] ? 'true ' : 'false ' ,
76101 'UCS_CAN_USERS_DELETE_SERVERS ' => $ data ['can_users_delete_servers ' ] ? 'true ' : 'false ' ,
102+ 'UCS_DEPLOYMENT_TAGS ' => implode (', ' , $ data ['deployment_tags ' ]),
103+ 'UCS_DEPLOYMENT_PORTS ' => implode (', ' , $ data ['deployment_ports ' ]),
77104 ]);
78105
79106 Notification::make ()
0 commit comments