Added locators resource file
This commit is contained in:
147
app/Filament/Resources/LocatorResource.php
Normal file
147
app/Filament/Resources/LocatorResource.php
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Exports\LocatorExporter;
|
||||||
|
use App\Filament\Imports\LocatorImporter;
|
||||||
|
use App\Filament\Resources\LocatorResource\Pages;
|
||||||
|
use App\Filament\Resources\LocatorResource\RelationManagers;
|
||||||
|
use App\Models\Locator;
|
||||||
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
|
||||||
|
class LocatorResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Locator::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
|
||||||
|
protected static ?string $navigationGroup = 'Master Entries';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 9;
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
Forms\Components\Select::make('plant_id')
|
||||||
|
->relationship('plant', 'name')
|
||||||
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('locator_number')
|
||||||
|
->label('Locator Number')
|
||||||
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('locator_quantity')
|
||||||
|
->required()
|
||||||
|
->numeric()
|
||||||
|
->label('Locator Quantity')
|
||||||
|
->default(0),
|
||||||
|
Forms\Components\Hidden::make('operator_id')
|
||||||
|
->default(Filament::auth()->user()?->name)
|
||||||
|
->required(),
|
||||||
|
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
// Tables\Columns\TextColumn::make('id')
|
||||||
|
// ->label('ID')
|
||||||
|
// ->numeric()
|
||||||
|
// ->sortable(),
|
||||||
|
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('plant.name')
|
||||||
|
->numeric()
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('locator_number')
|
||||||
|
->label('Locator Number')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('locator_quantity')
|
||||||
|
->label('Locator Quantity')
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('operator_id')
|
||||||
|
->label('Operator ID')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('updated_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable(),
|
||||||
|
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(),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->headerActions([
|
||||||
|
ImportAction::make()
|
||||||
|
->importer(LocatorImporter::class)
|
||||||
|
->visible(function() {
|
||||||
|
return Filament::auth()->user()->can('view import locator');
|
||||||
|
}),
|
||||||
|
ExportAction::make()
|
||||||
|
->exporter(LocatorExporter::class)
|
||||||
|
->visible(function() {
|
||||||
|
return Filament::auth()->user()->can('view export locator');
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListLocators::route('/'),
|
||||||
|
'create' => Pages\CreateLocator::route('/create'),
|
||||||
|
'view' => Pages\ViewLocator::route('/{record}'),
|
||||||
|
'edit' => Pages\EditLocator::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()
|
||||||
|
->withoutGlobalScopes([
|
||||||
|
SoftDeletingScope::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\LocatorResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\LocatorResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateLocator extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = LocatorResource::class;
|
||||||
|
}
|
||||||
22
app/Filament/Resources/LocatorResource/Pages/EditLocator.php
Normal file
22
app/Filament/Resources/LocatorResource/Pages/EditLocator.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\LocatorResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\LocatorResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditLocator extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = LocatorResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\ViewAction::make(),
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
Actions\ForceDeleteAction::make(),
|
||||||
|
Actions\RestoreAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\LocatorResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\LocatorResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListLocators extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = LocatorResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/LocatorResource/Pages/ViewLocator.php
Normal file
19
app/Filament/Resources/LocatorResource/Pages/ViewLocator.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\LocatorResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\LocatorResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewLocator extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = LocatorResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user