This commit is contained in:
Bozhidar 2024-04-26 19:29:28 +03:00
parent 3fc7ea370a
commit aad913e5bb
6 changed files with 156 additions and 0 deletions

View file

@ -138,6 +138,10 @@ class DatabaseResource extends Resource
->label('Database Server')
->sortable(),
Tables\Columns\TextColumn::make('hostingSubscription.domain')
->searchable()
->sortable(),
])
->filters([
//

View file

@ -0,0 +1,86 @@
<?php
namespace Modules\Customer\App\Filament\Resources;
use App\Models\HostingSubscriptionBackup;
use Modules\Customer\App\Filament\Resources\HostingSubscriptionBackupResource\Pages;
use Modules\Customer\App\Filament\Resources\HostingSubscriptionBackupResource\RelationManagers;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class HostingSubscriptionBackupResource extends Resource
{
protected static ?string $model = HostingSubscriptionBackup::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $label = 'Backups';
public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('backup_type')
->state(function (HostingSubscriptionBackup $backup) {
return ucfirst($backup->backup_type);
}),
Tables\Columns\BadgeColumn::make('status')
->badge(),
Tables\Columns\TextColumn::make('completed_at')
->state(function (HostingSubscriptionBackup $backup) {
return $backup->completed_at ? $backup->completed_at : 'N/A';
}),
Tables\Columns\TextColumn::make('size')
->state(function (HostingSubscriptionBackup $backup) {
return $backup->size ? $backup->size : 'N/A';
}),
Tables\Columns\TextColumn::make('hostingSubscription.domain')
->searchable()
->sortable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListHostingSubscriptionBackups::route('/'),
'create' => Pages\CreateHostingSubscriptionBackup::route('/create'),
'edit' => Pages\EditHostingSubscriptionBackup::route('/{record}/edit'),
];
}
}

View file

@ -0,0 +1,12 @@
<?php
namespace Modules\Customer\App\Filament\Resources\HostingSubscriptionBackupResource\Pages;
use Modules\Customer\App\Filament\Resources\HostingSubscriptionBackupResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateHostingSubscriptionBackup extends CreateRecord
{
protected static string $resource = HostingSubscriptionBackupResource::class;
}

View file

@ -0,0 +1,19 @@
<?php
namespace Modules\Customer\App\Filament\Resources\HostingSubscriptionBackupResource\Pages;
use Modules\Customer\App\Filament\Resources\HostingSubscriptionBackupResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditHostingSubscriptionBackup extends EditRecord
{
protected static string $resource = HostingSubscriptionBackupResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace Modules\Customer\App\Filament\Resources\HostingSubscriptionBackupResource\Pages;
use Modules\Customer\App\Filament\Resources\HostingSubscriptionBackupResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListHostingSubscriptionBackups extends ListRecords
{
protected static string $resource = HostingSubscriptionBackupResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View file

@ -4,6 +4,7 @@ namespace App\Models;
use App\Filament\Enums\BackupStatus;
use App\Helpers;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -32,6 +33,16 @@ class HostingSubscriptionBackup extends Model
'status' => BackupStatus::class,
];
protected static function booted(): void
{
static::addGlobalScope('customer', function (Builder $query) {
if (auth()->check() && auth()->guard()->name == 'web_customer') {
$query->whereHas('hostingSubscription', function ($query) {
$query->where('customer_id', auth()->user()->id);
});
}
});
}
public static function boot()
{
parent::boot();
@ -239,4 +250,9 @@ class HostingSubscriptionBackup extends Model
}
}
public function hostingSubscription()
{
return $this->belongsTo(HostingSubscription::class);
}
}