Files
hoshpoint-backend/app/Filament/Resources/Templates/RelationManagers/KeysRelationManager.php

107 lines
4.3 KiB
PHP

<?php
namespace App\Filament\Resources\Templates\RelationManagers;
use App\Enums\TemplateKeyType;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class KeysRelationManager extends RelationManager
{
protected static string $relationship = 'keys';
protected static ?string $title = 'کلیدها';
protected static ?string $modelLabel = 'کلید';
protected static ?string $pluralModelLabel = 'کلیدها';
public function form(Schema $schema): Schema
{
return $schema
->components([
TextInput::make('key')
->label('کلید')
->helperText('فقط نام کلید را وارد کنید، بدون آکولاد. مثلاً اگر داخل پاورپوینت نوشته‌اید {Main Title}، اینجا فقط Main Title را وارد کنید؛ آکولاد را خود سیستم موقع جایگزینی اضافه می‌کند. برای عکس/چارت به‌جای این، نام شکل (shape name) را در فیلد پایین وارد کنید.')
->required()
->maxLength(255),
TextInput::make('label')
->label('برچسب')
->required()
->maxLength(255),
Select::make('type')
->label('نوع')
->options([
TemplateKeyType::Text->value => TemplateKeyType::Text->label(),
TemplateKeyType::Image->value => TemplateKeyType::Image->label(),
TemplateKeyType::Chart->value => TemplateKeyType::Chart->label(),
])
->required()
->live(),
TextInput::make('shape_name')
->label('نام شکل (Shape Name)')
->helperText('نام شکل تعیین‌شده در Selection Pane نرم‌افزار PowerPoint')
->visible(fn (Get $get): bool => $get('type') !== TemplateKeyType::Text->value)
->maxLength(255),
TextInput::make('description')
->label('راهنما')
->helperText('توضیحی که برای مصرف‌کننده API نمایش داده می‌شود')
->maxLength(255),
Toggle::make('is_required')
->label('اجباری')
->default(true),
TextInput::make('sort_order')
->label('ترتیب نمایش')
->numeric()
->integer()
->default(0),
]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('key')
->columns([
TextColumn::make('key')
->label('کلید')
->searchable()
->sortable(),
TextColumn::make('label')
->label('برچسب')
->searchable(),
TextColumn::make('type')
->label('نوع')
->badge()
->formatStateUsing(fn (TemplateKeyType $state): string => $state->label()),
TextColumn::make('shape_name')
->label('نام شکل')
->placeholder('—'),
IconColumn::make('is_required')
->label('اجباری')
->boolean(),
TextColumn::make('sort_order')
->label('ترتیب')
->sortable(),
])
->defaultSort('sort_order')
->headerActions([
CreateAction::make(),
])
->recordActions([
EditAction::make(),
DeleteAction::make(),
]);
}
}