Skip to content

Commit

Permalink
Merge pull request #17 from liberu-genealogy/main
Browse files Browse the repository at this point in the history
Various
  • Loading branch information
curtisdelicata authored Jun 17, 2024
2 parents 0d285af + 963e087 commit 21c94b2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
5 changes: 0 additions & 5 deletions app/Filament/Admin/Resources/DnsSettingResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ public static function getRelations(): array {
];
}

public function __construct(protected DnsSettingService $dnsSettingService)
{
// ...
}

public static function getPages(): array {
return [
'index' => Pages\ListDnsSettings::route('/'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ public function __construct(protected DnsSettingService $dnsSettingService)
// ...
}

protected function create(array $data): DnsSetting
protected function getFormData(): array
{
return $this->form->getState();
}

public function create(bool $another = false): void
{
try {
$data = $this->getFormData();
$dnsSetting = DnsSetting::create($data);

$this->dnsSettingService->updateBindDnsRecord($dnsSetting);
Expand All @@ -29,8 +35,6 @@ protected function create(array $data): DnsSetting
->body('The DNS setting has been created and BIND records have been updated.')
->success()
->send();

return $dnsSetting;
} catch (\Exception $e) {
Notification::make()
->title('Error')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ protected function getHeaderActions(): array {
];
}

protected function save(array $data): DnsSetting
public function save(bool $shouldRedirect = true, bool $shouldSendSavedNotification = true): void
{
$data = $this->form->getState();
$this->record->update($data);

$this->dnsSettingService->updateBindDnsRecord($this->record);
Expand All @@ -34,6 +35,11 @@ protected function save(array $data): DnsSetting
->success()
->send();

return $this->record;
if ($shouldRedirect) {
$this->redirect($this->getRedirectUrl());
}
if ($shouldSendSavedNotification) {
$this->notify('saved');
}
}
}
19 changes: 11 additions & 8 deletions app/Filament/Admin/Resources/DomainResource/Pages/CreateDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use App\Filament\Admin\Resources\DomainResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
use Filament\Facades\Filament;

use App\Models\Domain;
use App\Services\DockerComposeService;

use App\Services\DockerComposeService;
use Filament\Notifications\Notification;

Expand All @@ -21,7 +20,7 @@ public function __construct(protected DockerComposeService $dockerCompose)
// ...
}

protected function create(array $data): Domain
public function create(bool $another = false): void
{
$user = auth()->user();

Expand All @@ -32,19 +31,23 @@ protected function create(array $data): Domain
->danger()
->send();

return null;
return;
}

$hostingPlan = $user->currentHostingPlan();

$domain = Domain::create([
...$data,
...$this->form->getState(),
'hosting_plan_id' => $hostingPlan->id,
]);

$this->dockerCompose->generateComposeFile($data, $hostingPlan);
$this->dockerCompose->startServices($data['domain_name']);
$this->dockerCompose->generateComposeFile($this->form->getState(), $hostingPlan);
$this->dockerCompose->startServices($this->form->getState()['domain_name']);

return $domain;
if ($another) {
redirect()->route('filament.resources.domains.create');
} else {
redirect()->route('filament.resources.domains.edit', $domain);
}
}
}
19 changes: 8 additions & 11 deletions app/Filament/Admin/Resources/DomainResource/Pages/EditDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
use App\Filament\Admin\Resources\DomainResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

use App\Models\Domain;
use App\Services\DockerComposeService;


use App\Services\DockerComposeService;
use Filament\Notifications\Notification;
use Illuminate\Database\Eloquent\Model;

class EditDomain extends EditRecord
{
Expand All @@ -29,27 +26,27 @@ protected function getHeaderActions(): array
];
}

protected function handleRecordUpdate(Model $record, array $data): Model
protected function handleRecordUpdate(Illuminate\Database\Eloquent\Model $record, array $data): Illuminate\Database\Eloquent\Model
{
$user = auth()->user();

if ($user->hasReachedDockerComposeLimit()) {
Notification::make()
->title('Docker Compose Limit Reached')
->body('You have reached the limit of Docker Compose instances for your hosting plan.')
->danger()
->send();

return $record;
}

$hostingPlan = $user->currentHostingPlan();

$record->update($data);

$this->dockerCompose->generateComposeFile($data, $hostingPlan);
$this->dockerCompose->startServices($data['domain_name']);

return $record;
}
}

0 comments on commit 21c94b2

Please sign in to comment.