From 31bc4a7fd0171e01d750bc521c39e5277a721c67 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 22 Dec 2025 17:01:57 +0530 Subject: [PATCH] Added sticker structure detail resource pages --- .../StickerStructureDetailResource.php | 201 ++++++++++++++++++ .../Pages/CreateStickerStructureDetail.php | 12 ++ .../Pages/EditStickerStructureDetail.php | 22 ++ .../Pages/ListStickerStructureDetails.php | 19 ++ .../Pages/ViewStickerStructureDetail.php | 19 ++ 5 files changed, 273 insertions(+) create mode 100644 app/Filament/Resources/StickerStructureDetailResource.php create mode 100644 app/Filament/Resources/StickerStructureDetailResource/Pages/CreateStickerStructureDetail.php create mode 100644 app/Filament/Resources/StickerStructureDetailResource/Pages/EditStickerStructureDetail.php create mode 100644 app/Filament/Resources/StickerStructureDetailResource/Pages/ListStickerStructureDetails.php create mode 100644 app/Filament/Resources/StickerStructureDetailResource/Pages/ViewStickerStructureDetail.php diff --git a/app/Filament/Resources/StickerStructureDetailResource.php b/app/Filament/Resources/StickerStructureDetailResource.php new file mode 100644 index 0000000..95618a7 --- /dev/null +++ b/app/Filament/Resources/StickerStructureDetailResource.php @@ -0,0 +1,201 @@ +schema([ + Forms\Components\TextInput::make('sticker_id') + ->label('Sticker ID') + ->reactive() + ->required() + ->afterStateUpdated(function ($state, callable $set) { + //\Log::info('Sticker ID typed:', ['sticker_id' => $state]); + $set('sticker_id_live', $state); + }), + Forms\Components\TextInput::make('sticker_width') + ->label('Sticker Width') + ->required(), + Forms\Components\TextInput::make('sticker_height') + ->label('Sticker Height') + ->required(), + Forms\Components\TextInput::make('sticker_lmargin') + ->label('Sticker Left Margin') + ->required(), + Forms\Components\TextInput::make('sticker_rmargin') + ->label('Sticker Right Margin') + ->required(), + Forms\Components\TextInput::make('sticker_tmargin') + ->label('Sticker Top Margin') + ->required(), + Forms\Components\TextInput::make('sticker_bmargin') + ->label('Sticker Bottom Margin') + ->required(), + Forms\Components\Hidden::make('created_by') + ->label('Created By') + ->default(Filament::auth()->user()?->name), + Forms\Components\Hidden::make('updated_by') + ->label('Updated By') + ->default(Filament::auth()->user()?->name), + Forms\Components\TextInput::make('sticker_id_live') + ->default(fn ($get) => $get('sticker_id')) + ->reactive() + ->afterStateUpdated(function ($state, callable $set) { + \Log::info('Sticker ID Live:', ['sticker_id_live' => $state]); + $set('sticker_id_live', $state); + }), + Forms\Components\ViewField::make('generate_template') + ->view('fields.generate-template') + ->reactive() + ->key(fn ($get) => 'generate-template' . ($get('sticker_id_live') ?? 'empty')) + ->viewData(fn (Get $get) => [ + 'sticker_id' => $get('sticker_id_live') ?? 'empty', + ]) + // ->extraAttributes([ + // // Pass the current sticker_id typed by the user + // //'sticker_id' => fn ($get) => $get('sticker_id'), + + // 'sticker_id' => fn ($get) => $get('sticker_id') ?? 'empty', + + + // // 'sticker_id' => function ($get) { + // // \Log::info('ViewField closure executed'); + + // // $stickerId = $get('sticker_id'); + + // // // Use Laravel log to see value in real time + // // \Log::info('Sticker ID in ViewField:', $stickerId); + + // // // You can also temporarily dd(), but it will stop form render + // // // dd($stickerId); + + // // return $stickerId; + // // }, + // ]), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('id') + ->label('ID') + ->numeric() + ->sortable(), + Tables\Columns\TextColumn::make('sticker_id') + ->label('Sticker ID'), + Tables\Columns\TextColumn::make('sticker_width') + ->label('Sticker Width'), + Tables\Columns\TextColumn::make('sticker_height') + ->label('Sticker Height'), + Tables\Columns\TextColumn::make('sticker_lmargin') + ->label('Sticker Left Margin'), + Tables\Columns\TextColumn::make('sticker_rmargin') + ->label('Sticker Right Margin'), + Tables\Columns\TextColumn::make('sticker_tmargin') + ->label('Sticker Top Margin'), + Tables\Columns\TextColumn::make('sticker_bmargin') + ->label('Sticker Bottom Margin'), + Tables\Columns\TextColumn::make('created_at') + ->label('Created At') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->label('Updated At') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('deleted_at') + ->label('Deleted At') + ->dateTime() + ->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() + ->label('Import Sticker Structure Details') + ->color('warning') + ->importer(StickerStructureDetailImporter::class) + ->visible(function() { + return Filament::auth()->user()->can('view import sticker structure details'); + }), + ExportAction::make() + ->label('Export Sticker Structure Details') + ->color('warning') + ->exporter(StickerStructureDetailExporter::class) + ->visible(function() { + return Filament::auth()->user()->can('view export sticker structure details'); + }), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListStickerStructureDetails::route('/'), + 'create' => Pages\CreateStickerStructureDetail::route('/create'), + 'view' => Pages\ViewStickerStructureDetail::route('/{record}'), + 'edit' => Pages\EditStickerStructureDetail::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/StickerStructureDetailResource/Pages/CreateStickerStructureDetail.php b/app/Filament/Resources/StickerStructureDetailResource/Pages/CreateStickerStructureDetail.php new file mode 100644 index 0000000..2adf130 --- /dev/null +++ b/app/Filament/Resources/StickerStructureDetailResource/Pages/CreateStickerStructureDetail.php @@ -0,0 +1,12 @@ +