Add all files
This commit is contained in:
11
app/Admin/Resources/ServiceResource/Pages/CreateService.php
Normal file
11
app/Admin/Resources/ServiceResource/Pages/CreateService.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ServiceResource\Pages;
|
||||
|
||||
use App\Admin\Resources\ServiceResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateService extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ServiceResource::class;
|
||||
}
|
||||
85
app/Admin/Resources/ServiceResource/Pages/EditService.php
Normal file
85
app/Admin/Resources/ServiceResource/Pages/EditService.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ServiceResource\Pages;
|
||||
|
||||
use App\Admin\Resources\ServiceResource;
|
||||
use App\Helpers\ExtensionHelper;
|
||||
use App\Helpers\NotificationHelper;
|
||||
use App\Models\Service;
|
||||
use Filament\Actions;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class EditService extends EditRecord
|
||||
{
|
||||
protected static string $resource = ServiceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\Action::make('changeStatus')
|
||||
->label('Trigger Extension Action')
|
||||
->form([
|
||||
Select::make('action')
|
||||
->label('Action')
|
||||
->options([
|
||||
'create' => 'Create server',
|
||||
'suspend' => 'Suspend server',
|
||||
'unsuspend' => 'Unsuspend server',
|
||||
'terminate' => 'Terminate server',
|
||||
'upgrade' => 'Upgrade server',
|
||||
])->required(),
|
||||
Checkbox::make('sendNotification')
|
||||
->label('Send Notification')
|
||||
->default(false),
|
||||
])
|
||||
->action(function (array $data, Service $record, Actions\Action $action): void {
|
||||
try {
|
||||
switch ($data['action']) {
|
||||
case 'create':
|
||||
$sdata = ExtensionHelper::createServer($record);
|
||||
if ($data['sendNotification']) {
|
||||
NotificationHelper::serverCreatedNotification($record->order->user, $record, $sdata);
|
||||
}
|
||||
break;
|
||||
case 'suspend':
|
||||
$sdata = ExtensionHelper::suspendServer($record);
|
||||
break;
|
||||
case 'unsuspend':
|
||||
$sdata = ExtensionHelper::unsuspendServer($record);
|
||||
break;
|
||||
case 'terminate':
|
||||
$sdata = ExtensionHelper::terminateServer($record);
|
||||
break;
|
||||
case 'upgrade':
|
||||
$sdata = ExtensionHelper::upgradeServer($record);
|
||||
break;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if (config('app.debug')) {
|
||||
throw $e;
|
||||
}
|
||||
Log::error($e);
|
||||
Notification::make('Error')
|
||||
->title('Error occured while triggering the action:')
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
$action->halt();
|
||||
}
|
||||
Notification::make('Success')
|
||||
->title('Action triggered successfully')
|
||||
->body('The action has been triggered successfully')
|
||||
->success()
|
||||
->send();
|
||||
})
|
||||
->color('primary')
|
||||
->modalSubmitActionLabel('Trigger'),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Admin/Resources/ServiceResource/Pages/ListService.php
Normal file
19
app/Admin/Resources/ServiceResource/Pages/ListService.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ServiceResource\Pages;
|
||||
|
||||
use App\Admin\Resources\ServiceResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListService extends ListRecords
|
||||
{
|
||||
protected static string $resource = ServiceResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ServiceResource\RelationManagers;
|
||||
|
||||
use App\Models\ServiceConfig;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ConfigOptionsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'configs';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('configValue.id')
|
||||
->label('Config Value')
|
||||
->required()
|
||||
->relationship('configValue', 'id', fn (Builder $query, ServiceConfig $record) => $query->where('parent_id', $record->config_option_id))
|
||||
->searchable()
|
||||
->getOptionLabelFromRecordUsing(fn ($record) => $record->name)
|
||||
->getSearchResultsUsing(fn (string $search, ServiceConfig $record): array => $record->configOption->children()->where('name', 'like', "%$search%")->limit(50)->pluck('name', 'id')->toArray())
|
||||
->live()
|
||||
->preload()
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('configOption.name')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('configOption.name'),
|
||||
Tables\Columns\TextColumn::make('configValue.name'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Resources\ServiceResource\RelationManagers;
|
||||
|
||||
use App\Admin\Resources\InvoiceResource;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceItem;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class InvoicesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'invoices';
|
||||
|
||||
// Edit query
|
||||
protected function getTableQuery(): Builder|Relation|null
|
||||
{
|
||||
return Invoice::query()->whereIn('id', InvoiceItem::query()
|
||||
->where(function ($query) {
|
||||
$query->where('reference_type', 'App\Models\Service')
|
||||
->where('reference_id', $this->ownerRecord->id);
|
||||
})->orWhere(function ($query) {
|
||||
$query->where('reference_type', 'App\Models\ServiceUpgrade')
|
||||
->whereIn('reference_id', $this->ownerRecord->upgrade()->pluck('id')->filter());
|
||||
})->pluck('invoice_id'));
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('id')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('id')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
Tables\Columns\TextColumn::make('formattedTotal')->label('Total'),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->label('Status')
|
||||
// Make first letter uppercase
|
||||
->formatStateUsing(fn (string $state): string => ucfirst($state))
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'paid' => 'success',
|
||||
'pending' => 'warning',
|
||||
default => 'danger',
|
||||
}),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make()->url(fn ($record) => InvoiceResource::getUrl('edit', ['record' => $record])),
|
||||
])
|
||||
->defaultSort('invoices.id', 'desc');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user