diff --git a/app/Filament/Resources/TempLiveReadingResource.php b/app/Filament/Resources/TempLiveReadingResource.php new file mode 100644 index 000000000..129817283 --- /dev/null +++ b/app/Filament/Resources/TempLiveReadingResource.php @@ -0,0 +1,134 @@ +schema([ + Section::make('') + ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant') + ->relationship('plant', 'name') + ->reactive() + ->required(), + Forms\Components\Select::make('mfm_meter_id') + ->label('MFM Meter ID') + ->required() + ->reactive() + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if (!$plantId) { + return []; + } + + return MfmMeter::where('plant_id', $plantId) + ->pluck('sequence', 'id') + ->toArray(); + }), + Forms\Components\TextInput::make('register_data') + ->label('Register Data') + ->required(), + Forms\Components\Hidden::make('created_by') + ->default(Filament::auth()->user()?->name), + ]) + ->columns(3), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('id') + ->label('ID') + ->numeric() + ->sortable(), + Tables\Columns\TextColumn::make('plant.name') + ->numeric() + ->sortable(), + // Tables\Columns\TextColumn::make('mfm_meter_id.sequence') + // ->label('Sequence') + // ->sortable(), + Tables\Columns\TextColumn::make('mfmMeter.name') + ->label('Name') + ->sortable(), + Tables\Columns\TextColumn::make('register_data') + ->label('Register Data') + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('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(), + ]), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListTempLiveReadings::route('/'), + 'create' => Pages\CreateTempLiveReading::route('/create'), + 'view' => Pages\ViewTempLiveReading::route('/{record}'), + 'edit' => Pages\EditTempLiveReading::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/TempLiveReadingResource/Pages/CreateTempLiveReading.php b/app/Filament/Resources/TempLiveReadingResource/Pages/CreateTempLiveReading.php new file mode 100644 index 000000000..68da71367 --- /dev/null +++ b/app/Filament/Resources/TempLiveReadingResource/Pages/CreateTempLiveReading.php @@ -0,0 +1,12 @@ +