Updated alignments and added orderby query while load plant
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -9,16 +9,16 @@ use App\Models\Block;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class BlockResource extends Resource
|
||||
@@ -46,12 +46,11 @@ class BlockResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$nameId = $get('name');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$nameId) {
|
||||
if (! $nameId) {
|
||||
$set('bNameError', 'Scan the valid name.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('bNameError', null);
|
||||
}
|
||||
})
|
||||
@@ -72,21 +71,21 @@ class BlockResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
return optional(Block::latest()->first())->plant_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$nameId = $get('plant_id');
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (!$nameId) {
|
||||
if (! $nameId) {
|
||||
$set('bPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('bPlantError', null);
|
||||
}
|
||||
})
|
||||
@@ -98,7 +97,7 @@ class BlockResource extends Resource
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
])
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
@@ -117,10 +116,11 @@ class BlockResource extends Resource
|
||||
$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('name')
|
||||
//->unique(ignoreRecord: true)
|
||||
// ->unique(ignoreRecord: true)
|
||||
->label('Block')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
@@ -167,14 +167,14 @@ class BlockResource extends Resource
|
||||
->label('Import Blocks')
|
||||
->color('warning')
|
||||
->importer(BlockImporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import block');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Blocks')
|
||||
->color('warning')
|
||||
->exporter(BlockExporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export block');
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user