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,127 +5,128 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\MfmParameterExporter;
|
||||
use App\Filament\Imports\MfmParameterImporter;
|
||||
use App\Filament\Resources\MfmParameterResource\Pages;
|
||||
use App\Filament\Resources\MfmParameterResource\RelationManagers;
|
||||
use App\Models\MfmParameter;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Form;
|
||||
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\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
|
||||
class MfmParameterResource extends Resource
|
||||
{
|
||||
protected static ?string $model = MfmParameter::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Power House';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->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();
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('device_master_id', null);
|
||||
$set('mfm_meter_id', null);
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\Select::make('device_master_id')
|
||||
->label('Device Master')
|
||||
//->relationship('deviceName', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('device_master_id', null);
|
||||
$set('mfm_meter_id', null);
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\Select::make('device_master_id')
|
||||
->label('Device Master')
|
||||
// ->relationship('deviceName', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
return \App\Models\DeviceMaster::where('plant_id', $plantId)
|
||||
->pluck('name', 'id');
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('mfm_meter_id', null);
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\Select::make('mfm_meter_id')
|
||||
->label('Mfm Meter')
|
||||
// ->relationship('mfmMeter', 'sequence')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return \App\Models\DeviceMaster::where('plant_id', $plantId)
|
||||
->pluck('name', 'id');
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('mfm_meter_id', null);
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\Select::make('mfm_meter_id')
|
||||
->label('Mfm Meter')
|
||||
// ->relationship('mfmMeter', 'sequence')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
return \App\Models\MfmMeter::where('plant_id', $plantId)
|
||||
->pluck('sequence', 'id');
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Parameter Name')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('register_id')
|
||||
->label('Register ID')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('identifier')
|
||||
->label('Identifier')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('byte_to_convert')
|
||||
->label('Byte To Convert')
|
||||
->reactive()
|
||||
->default(2)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('type_to_convert')
|
||||
->label('Type To Convert')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('decimal_to_display')
|
||||
->label('Decimal To Display')
|
||||
->reactive()
|
||||
->default(1)
|
||||
->required(),
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\MfmMeter::where('plant_id', $plantId)
|
||||
->pluck('sequence', 'id');
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Parameter Name')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('register_id')
|
||||
->label('Register ID')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('identifier')
|
||||
->label('Identifier')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('byte_to_convert')
|
||||
->label('Byte To Convert')
|
||||
->reactive()
|
||||
->default(2)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('type_to_convert')
|
||||
->label('Type To Convert')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('decimal_to_display')
|
||||
->label('Decimal To Display')
|
||||
->reactive()
|
||||
->default(1)
|
||||
->required(),
|
||||
])
|
||||
->columns(3),
|
||||
->columns(3),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -139,6 +140,7 @@ class MfmParameterResource 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('plant.name')
|
||||
@@ -212,14 +214,14 @@ class MfmParameterResource extends Resource
|
||||
->label('Import MFM Parameters')
|
||||
->color('warning')
|
||||
->importer(MfmParameterImporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import mfm parameter');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export MFM Parameters')
|
||||
->color('warning')
|
||||
->exporter(MfmParameterExporter::class)
|
||||
->visible(function() {
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export mfm parameter');
|
||||
}),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user