Files
autocrm/app/Filament/Central/Resources/SuperAdminResource.php
T
Vasyka 78ff8d4b43 feat: i18n on Filament admin sidebar — 54 resources/pages translated
User screenshots showed the tenant admin panel (Filament) had sidebar
labels stuck in Romanian even when switching to Russian: 'Cereri',
'Calendar vizual', 'Atelierul meu', 'KPI mecanici', 'Fișe lucru',
'Norme-ore', 'Tehnicieni', 'Șabloane servicii', 'Depozite', 'Scaner',
'Depozit', 'VIN-căutare', 'Furnizori', 'Achiziții', 'Procentaj',
'Coeficienți preț', plus all group headers.

Root cause: every Filament Resource and Page had static properties
'protected static ?string $navigationLabel = "Fișe lucru"' — string
literals baked into class definitions. Static properties don't run
through the translation layer.

Fix in two parts:

1. New translation files with 52 label keys + 12 group keys:
   - lang/ro/nav.php — Romanian (identity)
   - lang/ru/nav.php — full Russian translations (Заказ-наряды,
     Автомобили, Клиенты, Календарь, Моя мастерская, Механики KPI,
     Настройки, etc.)
   - lang/en/nav.php — English translations (Work orders, Vehicles,
     Clients, Calendar, My workshop, Mechanic KPI, Settings, etc.)

   Keyed by the Romanian original so lookups map 1:1 —
   'nav.label.Fișe lucru' returns 'Заказ-наряды' in RU, 'Work orders'
   in EN, 'Fișe lucru' in RO.

2. Python transformer converted 54 files:
   - 33 Filament Tenant Resources
   - 15 Filament Tenant Pages
   - 4 Filament Central Resources
   - 1 Filament Central Page
   - 1 Widget

   Each 'protected static ?string $navigationLabel = "X";' became
   'public static function getNavigationLabel(): string { return
   __("nav.label.X"); }'. Same treatment for $navigationGroup.

Cleanup: 6 resources already had manually-added getNavigationLabel
methods from an earlier partial effort — those used flat JSON keys
(__("Cereri")) that never resolved. Deduped so only the nav.label.*
version remains.

Untouched (intentional):
- $modelLabel / $pluralModelLabel (used in breadcrumbs and headings —
  still hardcoded, next tier of work)
- Section titles, column headers, form field labels (medium priority)
- $navigationSort (numeric, no translation needed)
- $navigationIcon (icon reference)

Suite: 306 passed (853 assertions). Unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-07-13 20:41:55 +00:00

161 lines
7.2 KiB
PHP

<?php
namespace App\Filament\Central\Resources;
use App\Filament\Central\Resources\SuperAdminResource\Pages;
use App\Models\Central\SuperAdmin;
use Filament\Actions;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Schemas;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Hash;
class SuperAdminResource extends Resource
{
protected static ?string $model = SuperAdmin::class;
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-users';
public static function getNavigationLabel(): string
{
return __('nav.label.Utilizatori');
}
protected static ?string $modelLabel = 'utilizator';
protected static ?string $pluralModelLabel = 'utilizatori';
protected static string|\UnitEnum|null $navigationGroup = null;
protected static ?int $navigationSort = 50;
public static function form(Schema $schema): Schema
{
return $schema->components([
Schemas\Components\Section::make('Identificare')
->columns(2)
->schema([
Forms\Components\TextInput::make('name')->required()->maxLength(120),
Forms\Components\TextInput::make('email')->email()->required()->unique(ignoreRecord: true)->maxLength(120),
Forms\Components\TextInput::make('phone')->tel()->maxLength(40),
Forms\Components\Toggle::make('is_active')->label('Activ')->default(true),
]),
Schemas\Components\Section::make('Permisiuni')
->columns(1)
->schema([
Forms\Components\Select::make('role')
->options(SuperAdmin::ROLES)
->default('support')
->required()
->helperText('Owner = drepturi totale. Admin = aproape la fel. Sales = doar tenanți + planuri. Finance = facturi. Support = read-only.'),
]),
Schemas\Components\Section::make('Parolă')
->columns(1)
->schema([
Forms\Components\TextInput::make('password')
->password()
->revealable()
->dehydrated(fn ($state) => filled($state))
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->required(fn (string $operation) => $operation === 'create')
->minLength(8)
->helperText(fn (string $operation) => $operation === 'edit' ? 'Lasă gol ca să o păstrezi.' : 'Min 8 caractere.'),
]),
Forms\Components\Textarea::make('notes')->label('Note interne')->rows(2)->columnSpanFull(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')->searchable()->sortable()->weight('bold'),
Tables\Columns\TextColumn::make('email')->searchable()->copyable(),
Tables\Columns\TextColumn::make('role')
->badge()
->formatStateUsing(fn ($s) => match ($s) {
'owner' => 'Proprietar',
'admin' => 'Administrator',
'support' => 'Suport',
'sales' => 'Vânzări',
'finance' => 'Financiar',
default => $s,
})
->color(fn ($s) => match ($s) {
'owner' => 'danger',
'admin' => 'warning',
'finance' => 'success',
'sales' => 'info',
default => 'gray',
}),
Tables\Columns\IconColumn::make('is_active')->boolean()->label('Activ'),
Tables\Columns\IconColumn::make('app_authentication_secret')
->label('2FA')
->boolean()
->getStateUsing(fn ($record) => $record?->app_authentication_secret !== null)
->trueIcon('heroicon-o-lock-closed')
->falseIcon('heroicon-o-lock-open')
->trueColor('success')
->falseColor('warning'),
Tables\Columns\TextColumn::make('last_login_at')->label('Ultim login')->dateTime()->placeholder('—'),
Tables\Columns\TextColumn::make('created_at')->date(),
])
->filters([
Tables\Filters\SelectFilter::make('role')->options(SuperAdmin::ROLES),
Tables\Filters\TernaryFilter::make('is_active')->label('Activ'),
])
->actions([
Actions\Action::make('reset_password')
->label('Reset parolă')
->icon('heroicon-m-key')
->color('warning')
->schema([
Forms\Components\TextInput::make('new_password')
->password()->required()->minLength(8)->revealable(),
])
->action(function (SuperAdmin $record, array $data) {
$record->update(['password' => Hash::make($data['new_password'])]);
Notification::make()->title('Parolă resetată.')->success()->send();
}),
Actions\Action::make('toggle_2fa')
->label(fn (SuperAdmin $record) => $record->app_authentication_secret ? 'Dezactivează 2FA' : 'Forțează re-setare 2FA')
->icon('heroicon-m-lock-open')
->color('danger')
->visible(fn (SuperAdmin $record) => $record->app_authentication_secret !== null)
->requiresConfirmation()
->action(function (SuperAdmin $record) {
$record->forceFill([
'app_authentication_secret' => null,
'app_authentication_recovery_codes' => null,
'email_authentication_at' => null,
])->saveQuietly();
Notification::make()->title('2FA dezactivat.')->success()->send();
}),
Actions\EditAction::make(),
Actions\DeleteAction::make()
->before(function (SuperAdmin $record) {
if (auth('central')->id() === $record->id) {
Notification::make()->title('Nu te poți șterge pe tine!')->danger()->send();
return false;
}
}),
])
->emptyStateHeading('Doar tu ești aici')
->emptyStateDescription('Adaugă echipa ta — colegi de la suport, sales, finance — fiecare cu rolul lui.')
->defaultSort('created_at', 'desc');
}
public static function getPages(): array
{
return [
'index' => Pages\ListSuperAdmins::route('/'),
'create' => Pages\CreateSuperAdmin::route('/create'),
'edit' => Pages\EditSuperAdmin::route('/{record}/edit'),
];
}
}