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:
@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\CheckPointTimeExporter;
|
||||
use App\Filament\Imports\CheckPointTimeImporter;
|
||||
use App\Filament\Resources\CheckPointTimeResource\Pages;
|
||||
use App\Filament\Resources\CheckPointTimeResource\RelationManagers;
|
||||
use App\Models\CheckPointName;
|
||||
use App\Models\CheckPointTime;
|
||||
use App\Models\Plant;
|
||||
@@ -43,20 +42,20 @@ class CheckPointTimeResource 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(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->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) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
$set('cPtPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('cPtPlantError', null);
|
||||
$set('created_by', Filament::auth()->user()?->name);
|
||||
}
|
||||
@@ -78,17 +77,17 @@ class CheckPointTimeResource extends Resource
|
||||
})
|
||||
->rule(function (callable $get) {
|
||||
return Rule::unique('check_point_times', 'sequence_number')
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->ignore($get('id'));
|
||||
//->where('check_point1_id', $get('check_point1_id'))
|
||||
//->where('check_point2_id', $get('check_point2_id'))
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->ignore($get('id'));
|
||||
// ->where('check_point1_id', $get('check_point1_id'))
|
||||
// ->where('check_point2_id', $get('check_point2_id'))
|
||||
}),
|
||||
Forms\Components\Select::make('check_point1_id')
|
||||
->label('Check Point Name 1')
|
||||
// ->relationship('checkPointNames', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -101,19 +100,19 @@ class CheckPointTimeResource extends Resource
|
||||
->default(function () {
|
||||
return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point1_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$checkPoint1 = $get('check_point1_id');
|
||||
$checkPoint2 = $get('check_point2_id');
|
||||
if (!$checkPoint1) {
|
||||
if (! $checkPoint1) {
|
||||
$set('cPtCheckPoint1Error', 'Please select a check point 1 first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($checkPoint2 && $checkPoint1 == $checkPoint2) {
|
||||
$set('cPtCheckPoint1Error', 'Duplicate check point 2 found.');
|
||||
$set('check_point2_id', null);
|
||||
|
||||
return;
|
||||
}
|
||||
$set('cPtCheckPoint1Error', null);
|
||||
@@ -131,7 +130,7 @@ class CheckPointTimeResource extends Resource
|
||||
// ->relationship('checkPointNames', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -144,19 +143,19 @@ class CheckPointTimeResource extends Resource
|
||||
->default(function () {
|
||||
return optional(CheckPointTime::where('created_by', Filament::auth()->user()?->name)->latest()->first())->check_point2_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$checkPoint1 = $get('check_point1_id');
|
||||
$checkPoint2 = $get('check_point2_id');
|
||||
if (!$checkPoint2) {
|
||||
if (! $checkPoint2) {
|
||||
$set('cPtCheckPoint2Error', 'Please select a check point 2 first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($checkPoint1 && $checkPoint1 == $checkPoint2) {
|
||||
$set('cPtCheckPoint2Error', 'Duplicate check point 2 found.');
|
||||
$set('check_point2_id', null);
|
||||
|
||||
return;
|
||||
}
|
||||
$set('cPtCheckPoint1Error', null);
|
||||
@@ -185,32 +184,30 @@ class CheckPointTimeResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$timeLapse = $state;
|
||||
$timeLapseCushioning = $get('time_lapse_cushioning');
|
||||
if (!$timeLapse) {
|
||||
if (! $timeLapse) {
|
||||
$set('cPtTimeLapseError', 'Please enter a valid time lapse!');
|
||||
$set('time_lapse_cushioning', null);
|
||||
$set('min_cushioning', null);
|
||||
$set('max_cushioning', null);
|
||||
|
||||
return;
|
||||
}
|
||||
elseif(!$timeLapseCushioning)
|
||||
{
|
||||
} elseif (! $timeLapseCushioning) {
|
||||
// $set('cPtTimeLapseError', 'Please enter a valid time lapse cushioning!');
|
||||
$set('time_lapse_cushioning', 1);
|
||||
$set('cPtTimeLapseError', null);
|
||||
$set('min_cushioning', $timeLapse - 1);
|
||||
$set('max_cushioning', $timeLapse + 1);
|
||||
$set('created_by', Filament::auth()->user()?->name);
|
||||
|
||||
return;
|
||||
}
|
||||
elseif ($timeLapseCushioning > $timeLapse) {
|
||||
} elseif ($timeLapseCushioning > $timeLapse) {
|
||||
$set('cPtTimeLapseError', 'Must be greater than or equal to time lapse cushioning!');
|
||||
$set('time_lapse_cushioning', null);
|
||||
$set('min_cushioning', null);
|
||||
$set('max_cushioning', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('cPtTimeLapseError', null);
|
||||
$set('cPtTimeLapseCushError', null);
|
||||
$set('min_cushioning', $timeLapse - $timeLapseCushioning);
|
||||
@@ -233,32 +230,30 @@ class CheckPointTimeResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$timeLapse = $get('time_lapse');
|
||||
$timeLapseCushioning = $state;
|
||||
if (!$timeLapse) {
|
||||
if (! $timeLapse) {
|
||||
$set('cPtTimeLapseCushError', 'Please enter a valid time lapse first.');
|
||||
$set('time_lapse_cushioning', null);
|
||||
$set('min_cushioning', null);
|
||||
$set('max_cushioning', null);
|
||||
|
||||
return;
|
||||
}
|
||||
elseif(!$timeLapseCushioning)
|
||||
{
|
||||
} elseif (! $timeLapseCushioning) {
|
||||
// $set('cPtTimeLapseCushError', 'Please enter a valid time lapse cushioning!');
|
||||
$set('time_lapse_cushioning', 1);
|
||||
$set('cPtTimeLapseCushError', null);
|
||||
$set('min_cushioning', $timeLapse - 1);
|
||||
$set('max_cushioning', $timeLapse + 1);
|
||||
$set('created_by', Filament::auth()->user()?->name);
|
||||
|
||||
return;
|
||||
}
|
||||
elseif ($timeLapseCushioning > $timeLapse) {
|
||||
} elseif ($timeLapseCushioning > $timeLapse) {
|
||||
$set('cPtTimeLapseCushError', 'Must be less than or equal to time lapse!');
|
||||
$set('time_lapse_cushioning', null);
|
||||
$set('min_cushioning', null);
|
||||
$set('max_cushioning', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('cPtTimeLapseError', null);
|
||||
$set('cPtTimeLapseCushError', null);
|
||||
$set('min_cushioning', $timeLapse - $timeLapseCushioning);
|
||||
@@ -308,6 +303,7 @@ class CheckPointTimeResource 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('id')
|
||||
@@ -387,14 +383,14 @@ class CheckPointTimeResource extends Resource
|
||||
->label('Import Check Point Times')
|
||||
->color('warning')
|
||||
->importer(CheckPointTimeImporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import check point time');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Check Point Times')
|
||||
->color('warning')
|
||||
->exporter(CheckPointTimeExporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export check point time');
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user