Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Create Database btn on admin side #721

Merged
merged 24 commits into from
Dec 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7160fc9
Add Create Database btn on admin side
notAreYouScared Nov 20, 2024
6363b74
Remove unused function
notAreYouScared Nov 20, 2024
aba55ef
readd function
notAreYouScared Nov 20, 2024
01d7456
replace refreshform function
notAreYouScared Nov 20, 2024
96275e0
add authorize, remove database limit check
notAreYouScared Nov 20, 2024
1aeb017
add random words, use proper name function, catch exceptions on creation
notAreYouScared Nov 20, 2024
f18adda
add validation, match old client area more
notAreYouScared Nov 20, 2024
af3b87f
Merge remote-tracking branch 'origin/main' into feature/create-db
notAreYouScared Nov 22, 2024
ff2d059
Add more authorize to Database tab
notAreYouScared Nov 22, 2024
4592fde
Add confirmation to delete
notAreYouScared Nov 22, 2024
eb79fad
make password hidden / revealable
notAreYouScared Nov 22, 2024
c5e4488
better clarification
notAreYouScared Nov 22, 2024
9324da0
Set default and remove placeholder.
notAreYouScared Nov 22, 2024
203956b
Remove server import, add database model to auth
notAreYouScared Nov 22, 2024
f3c0e02
Make same changes for the database host page
notAreYouScared Nov 22, 2024
c55657f
Update app/Filament/Resources/ServerResource/Pages/EditServer.php
notAreYouScared Nov 23, 2024
0cf715e
Update app/Filament/Resources/DatabaseHostResource/RelationManagers/D…
notAreYouScared Nov 23, 2024
89955cc
Update app/Filament/Resources/DatabaseHostResource/RelationManagers/D…
notAreYouScared Nov 23, 2024
cca1999
Remove each hidden
notAreYouScared Nov 24, 2024
246c90a
Return nothing if user has no perms
notAreYouScared Nov 24, 2024
a9a5a2b
This is the way... Im done messing with it...
notAreYouScared Nov 26, 2024
fb9900c
Fix view permission for relationship manager
notAreYouScared Dec 1, 2024
3821837
Update app/Filament/Resources/DatabaseHostResource/RelationManagers/D…
rmartinoscar Dec 1, 2024
ea88a4a
Pint
rmartinoscar Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Create Database btn on admin side
notAreYouScared committed Nov 20, 2024
commit 7160fc9b4779be13234edb5022d716f377ab5d6d
44 changes: 42 additions & 2 deletions app/Filament/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
use App\Filament\Resources\ServerResource;
use App\Filament\Resources\ServerResource\RelationManagers\AllocationsRelationManager;
use App\Models\Database;
use App\Models\DatabaseHost;
use App\Models\Egg;
use App\Models\Mount;
use App\Models\Server;
@@ -609,6 +610,7 @@ public function form(Form $form): Form
]),
Tab::make('Databases')
->icon('tabler-database')
->columns(4)
->schema([
Repeater::make('databases')
->grid()
@@ -624,7 +626,10 @@ public function form(Form $form): Form
Action::make('Delete')
->color('danger')
->icon('tabler-trash')
->action(fn (DatabaseManagementService $databaseManagementService, $record) => $databaseManagementService->delete($record))
->action(function (DatabaseManagementService $databaseManagementService, $record) {
$databaseManagementService->delete($record);
$this->refreshForm();
})
),
TextInput::make('username')
->disabled()
@@ -659,7 +664,37 @@ public function form(Form $form): Form
->deletable(false)
->addable(false)
->columnSpan(4),
])->columns(4),
Forms\Components\Actions::make([
Action::make('createDatabase')
->disabled(fn (Server $server) => DatabaseHost::query()->count() < 1 || $server->databases()->count() >= $server->database_limit)
->label(fn (Server $server) => $server->databases()->count() >= $server->database_limit ? 'Database Limit Reached' : (DatabaseHost::query()->count() < 1 ? 'No Database Hosts' : 'Create Database'))
->color(fn (Server $server) => $server->databases()->count() >= $server->database_limit || DatabaseHost::query()->count() < 1 ? 'danger' : 'primary')
->modalSubmitActionLabel('Create')
->action(function (array $data, DatabaseManagementService $service, Server $server) {
if (empty($data['database'])) {
$data['database'] = str_random(12);
}
$data['database'] = 's'. $server->id . '_' . $data['database'];
$service->create($server, $data);
$this->refreshForm();
})
->form([
Select::make('database_host_id')
->label('Database Host')
->placeholder('Select Database Host')
->relationship('node.databaseHosts', 'name'),
TextInput::make('database')
->label('Database Name')
->prefix(fn (Server $server) => 's' . $server->id . '_')
->hintIcon('tabler-question-mark')
->hintIconTooltip('Leaving this blank will auto generate a random name'),
TextInput::make('remote')
->columnSpan(1)
->label('Connections From')
->default('%'),
]),
])->alignCenter()->columnSpanFull(),
]),
Tab::make('Actions')
->icon('tabler-settings')
->schema([
@@ -870,4 +905,9 @@ protected function rotatePassword(DatabasePasswordService $service, Database $re
$set('password', $newPassword);
$set('JDBC', $jdbcString);
}

public function refreshForm(): void
{
$this->fillForm();
}
}
5 changes: 5 additions & 0 deletions app/Models/Node.php
Original file line number Diff line number Diff line change
@@ -243,6 +243,11 @@ public function allocations(): HasMany
return $this->hasMany(Allocation::class);
}

public function databaseHosts(): HasMany
{
return $this->hasMany(DatabaseHost::class);
}

/**
* Returns a boolean if the node is viable for an additional server to be placed on it.
*/