added production line count chart
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Filament\Widgets\CumulativeChart;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
@@ -8,49 +9,51 @@ use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Plant;
|
||||
|
||||
use Filament\Widgets\Widget;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class Dashboard extends \Filament\Pages\Dashboard
|
||||
{
|
||||
use HasFiltersForm;
|
||||
|
||||
public function filtersForm(Form $form): Form
|
||||
{
|
||||
$selectedPlant = session('selected_plant', request()->input('filters.Plant'));
|
||||
return $form->schema([
|
||||
// Plant Filter
|
||||
Select::make('Plant')
|
||||
->options(Plant::pluck('name', 'id')) // Fetch plant names with their IDs
|
||||
->label('Select Plant')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set) use ($selectedPlant) {
|
||||
session(['selected_plant' => $state]);
|
||||
session()->forget('selected_line');
|
||||
$set('Plant', $state);
|
||||
$set('Line', null);
|
||||
$this->triggerChartUpdate();
|
||||
}),
|
||||
protected static ?string $navigationGroup = 'Production DashBoard';
|
||||
|
||||
// Line Filter
|
||||
Select::make('Line')
|
||||
->options(function ($get) {
|
||||
$plantId = $get('Plant');
|
||||
return $plantId ? Plant::find($plantId)->getLineNames()->pluck('name', 'id') : [];
|
||||
})
|
||||
->label('Select Line')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['selected_line' => $state]); // Store in session
|
||||
$this->triggerChartUpdate(); // Notify chart to refresh
|
||||
}),
|
||||
]);
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->filtersForm->fill([
|
||||
'plant' => Plant::first()?->id // Default to first plant
|
||||
]);
|
||||
}
|
||||
|
||||
// Helper to check if both filters are set
|
||||
public function triggerChartUpdate(): void
|
||||
public function filtersForm(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters') // Store form state in 'filters'
|
||||
->schema([
|
||||
Select::make('plant')
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Select Plant')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['selected_plant' => $state]); // fixed typo
|
||||
$this->dispatch('cumulativeChart'); // custom Livewire event
|
||||
}),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
if (session()->has('selected_plant') && session()->has('selected_line')) {
|
||||
$this->dispatch('filtersUpdated');
|
||||
}
|
||||
return 'Production Line Count';
|
||||
}
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Production Line Count';
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user