From 40a9f14c5307bea1e2bb53ca4b802083e8867385 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 23 Jun 2025 18:07:02 +0530 Subject: [PATCH] Added check_point_name resource files --- .../Resources/CheckPointNameResource.php | 186 ++++++++++++++++++ .../Pages/CreateCheckPointName.php | 12 ++ .../Pages/EditCheckPointName.php | 22 +++ .../Pages/ListCheckPointNames.php | 19 ++ .../Pages/ViewCheckPointName.php | 19 ++ 5 files changed, 258 insertions(+) create mode 100644 app/Filament/Resources/CheckPointNameResource.php create mode 100644 app/Filament/Resources/CheckPointNameResource/Pages/CreateCheckPointName.php create mode 100644 app/Filament/Resources/CheckPointNameResource/Pages/EditCheckPointName.php create mode 100644 app/Filament/Resources/CheckPointNameResource/Pages/ListCheckPointNames.php create mode 100644 app/Filament/Resources/CheckPointNameResource/Pages/ViewCheckPointName.php diff --git a/app/Filament/Resources/CheckPointNameResource.php b/app/Filament/Resources/CheckPointNameResource.php new file mode 100644 index 000000000..727f8ef7f --- /dev/null +++ b/app/Filament/Resources/CheckPointNameResource.php @@ -0,0 +1,186 @@ +schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant') + ->relationship('plant', 'name') + ->required() + ->reactive() + ->default(function () { + return optional(CheckPointName::where('created_by', Filament::auth()->user()?->name)->latest()->first())->plant_id; + }) + ->disabled(fn (Get $get) => !empty($get('id'))) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $plantId = $get('plant_id'); + if (!$plantId) { + $set('cPnPlantError', 'Please select a plant first.'); + return; + } + else + { + $set('cPnPlantError', null); + $set('created_by', Filament::auth()->user()?->name); + } + }) + ->extraAttributes(fn ($get) => [ + 'class' => $get('cPnPlantError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('cPnPlantError') ? $get('cPnPlantError') : null) + ->hintColor('danger'), + Forms\Components\TextInput::make('name') + ->label('Name') + ->required() + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('created_by', Filament::auth()->user()?->name); + }) + ->rule(function (callable $get) { + return Rule::unique('check_point_names', 'name') + ->where('plant_id', $get('plant_id')) + ->ignore($get('id')); + }), + Forms\Components\Hidden::make('created_by') + ->default(fn () => Filament::auth()->user()?->name) + ->required(), + Forms\Components\TextInput::make('id') + ->hidden() + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('created_by', Filament::auth()->user()?->name); + }) + ->readOnly(), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('No.') + ->label('No.') + ->getStateUsing(function ($record, $livewire, $column, $rowLoop) { + $paginator = $livewire->getTableRecords(); + $perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10; + $currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1; + return ($currentPage - 1) * $perPage + $rowLoop->iteration; + }), + // Tables\Columns\TextColumn::make('id') + // ->label('ID') + // ->numeric() + // ->sortable(), + Tables\Columns\TextColumn::make('plant.name') + ->label('Plant') + ->alignCenter() + ->searchable() + ->sortable(), + Tables\Columns\TextColumn::make('name') + ->label('Check Point Name') + ->alignCenter() + ->searchable() + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->label('Created At') + ->dateTime() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('created_by') + ->label('Created By') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('updated_at') + ->label('Updated At') + ->dateTime() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('deleted_at') + ->label('Deleted At') + ->dateTime() + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + Tables\Filters\TrashedFilter::make(), + ]) + ->actions([ + Tables\Actions\ViewAction::make(), + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\ForceDeleteBulkAction::make(), + Tables\Actions\RestoreBulkAction::make(), + ]), + ]) + ->headerActions([ + ImportAction::make() + ->importer(CheckPointNameExporter::class) + ->visible(function() { + return Filament::auth()->user()->can('view import check point name'); + }), + ExportAction::make() + ->exporter(CheckPointNameExporter::class) + ->visible(function() { + return Filament::auth()->user()->can('view export check point name'); + }), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListCheckPointNames::route('/'), + 'create' => Pages\CreateCheckPointName::route('/create'), + 'view' => Pages\ViewCheckPointName::route('/{record}'), + 'edit' => Pages\EditCheckPointName::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/CheckPointNameResource/Pages/CreateCheckPointName.php b/app/Filament/Resources/CheckPointNameResource/Pages/CreateCheckPointName.php new file mode 100644 index 000000000..93aa00569 --- /dev/null +++ b/app/Filament/Resources/CheckPointNameResource/Pages/CreateCheckPointName.php @@ -0,0 +1,12 @@ +