init
This commit is contained in:
11
app/Filament/Resources/Websites/Pages/CreateWebsite.php
Normal file
11
app/Filament/Resources/Websites/Pages/CreateWebsite.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Pages;
|
||||
|
||||
use App\Filament\Resources\Websites\WebsiteResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateWebsite extends CreateRecord
|
||||
{
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Websites/Pages/EditWebsite.php
Normal file
19
app/Filament/Resources/Websites/Pages/EditWebsite.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Pages;
|
||||
|
||||
use App\Filament\Resources\Websites\WebsiteResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditWebsite extends EditRecord
|
||||
{
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Websites/Pages/ListWebsites.php
Normal file
19
app/Filament/Resources/Websites/Pages/ListWebsites.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Pages;
|
||||
|
||||
use App\Filament\Resources\Websites\WebsiteResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListWebsites extends ListRecords
|
||||
{
|
||||
protected static string $resource = WebsiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\RelationManagers;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class TokensRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'tokens';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable()
|
||||
->label('Token Name'),
|
||||
TextColumn::make('last_used_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->placeholder('Never used'),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->label('Created'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->label('Create Token')
|
||||
->modalHeading('Create New API Token')
|
||||
->modalDescription('The token will only be shown once. Make sure to copy it to a secure location.')
|
||||
->using(function (array $data, RelationManager $livewire): void {
|
||||
$token = $livewire->getOwnerRecord()->createToken($data['name']);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Token Created Successfully')
|
||||
->body(Str::markdown("**Your API Token:**\n\n`{$token->plainTextToken}`\n\n⚠️ **Important:** Copy this token now and store it securely. You won't be able to see it again!"))
|
||||
->persistent()
|
||||
->send();
|
||||
})
|
||||
->successNotification(null),
|
||||
])
|
||||
->recordActions([
|
||||
DeleteAction::make()
|
||||
->label('Revoke')
|
||||
->modalHeading('Revoke API Token')
|
||||
->modalDescription('This will permanently revoke this token. Any applications using this token will no longer be able to authenticate.')
|
||||
->successNotificationTitle('Token revoked successfully'),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make()
|
||||
->label('Revoke Selected')
|
||||
->modalHeading('Revoke Selected Tokens')
|
||||
->successNotificationTitle('Tokens revoked successfully'),
|
||||
]),
|
||||
])
|
||||
->emptyStateHeading('No API Tokens')
|
||||
->emptyStateDescription('Create a token to allow this website to authenticate with the API.')
|
||||
->emptyStateActions([
|
||||
CreateAction::make()
|
||||
->label('Create First Token')
|
||||
->modalHeading('Create New API Token')
|
||||
->modalDescription('The token will only be shown once. Make sure to copy it to a secure location.')
|
||||
->using(function (array $data, RelationManager $livewire): void {
|
||||
$token = $livewire->getOwnerRecord()->createToken($data['name']);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Token Created Successfully')
|
||||
->body(Str::markdown("**Your API Token:**\n\n`{$token->plainTextToken}`\n\n⚠️ **Important:** Copy this token now and store it securely. You won't be able to see it again!"))
|
||||
->persistent()
|
||||
->send();
|
||||
})
|
||||
->successNotification(null),
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/Filament/Resources/Websites/Schemas/WebsiteForm.php
Normal file
41
app/Filament/Resources/Websites/Schemas/WebsiteForm.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Schemas;
|
||||
|
||||
use App\Models\Tier;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class WebsiteForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required(),
|
||||
TextInput::make('domain')
|
||||
->required(),
|
||||
Select::make('tier_id')
|
||||
->label('Tier')
|
||||
->relationship('tier', 'name')
|
||||
->required()
|
||||
->searchable()
|
||||
->preload(),
|
||||
TextInput::make('cache_hit_rate_limit')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(100),
|
||||
TextInput::make('external_api_rate_limit')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(10),
|
||||
Toggle::make('is_active')
|
||||
->required(),
|
||||
Toggle::make('bypass_rate_limit')
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
56
app/Filament/Resources/Websites/Tables/WebsitesTable.php
Normal file
56
app/Filament/Resources/Websites/Tables/WebsitesTable.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class WebsitesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable(),
|
||||
TextColumn::make('domain')
|
||||
->searchable(),
|
||||
TextColumn::make('tier.name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('cache_hit_rate_limit')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('external_api_rate_limit')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
IconColumn::make('is_active')
|
||||
->boolean(),
|
||||
IconColumn::make('bypass_rate_limit')
|
||||
->boolean(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
48
app/Filament/Resources/Websites/WebsiteResource.php
Normal file
48
app/Filament/Resources/Websites/WebsiteResource.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Websites;
|
||||
|
||||
use App\Filament\Resources\Websites\Pages\CreateWebsite;
|
||||
use App\Filament\Resources\Websites\Pages\EditWebsite;
|
||||
use App\Filament\Resources\Websites\Pages\ListWebsites;
|
||||
use App\Filament\Resources\Websites\Schemas\WebsiteForm;
|
||||
use App\Filament\Resources\Websites\Tables\WebsitesTable;
|
||||
use App\Models\Website;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class WebsiteResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Website::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return WebsiteForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return WebsitesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\TokensRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListWebsites::route('/'),
|
||||
'create' => CreateWebsite::route('/create'),
|
||||
'edit' => EditWebsite::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user