Add trend chart analysis page and blade file
This commit is contained in:
128
app/Filament/Pages/TrendChartAnalys.php
Normal file
128
app/Filament/Pages/TrendChartAnalys.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Filament\Widgets\TrendChartAnalysis;
|
||||
use App\Models\MfmMeter;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||
use App\Models\Plant;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class TrendChartAnalys extends Page
|
||||
{
|
||||
use HasFiltersForm;
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.trend-chart-analys';
|
||||
|
||||
protected static ?string $navigationGroup = 'EMS DashBoard';
|
||||
|
||||
// use HasFiltersForm;
|
||||
public function mount(): void
|
||||
{
|
||||
session()->forget(['selected_plant', 'selected_meter', 'from_datetime', 'to_datetime', 'parameter']);
|
||||
$this->filtersForm->fill([
|
||||
'selected_plant' => null,
|
||||
'selected_meter' => null,
|
||||
'from_datetime' => null,
|
||||
'to_datetime' => null,
|
||||
'parameter' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function filtersForm(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters')
|
||||
->schema([
|
||||
|
||||
DateTimePicker::make('from_datetime')
|
||||
->label('From DateTime')
|
||||
->required()
|
||||
->before('to_datetime')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
$formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s');
|
||||
session(['from_datetime' => $formatted]);
|
||||
}),
|
||||
DateTimePicker::make('to_datetime')
|
||||
->label('To DateTime')
|
||||
->required()
|
||||
->after('from_datetime')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
$formatted = \Carbon\Carbon::parse($state)->format('Y-m-d H:i:s');
|
||||
session(['to_datetime' => $formatted]);
|
||||
}),
|
||||
Select::make('plant')
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Select Plant')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
session(['selected_plant' => $state]);
|
||||
// When plant changes, also reset meter_name
|
||||
$set('meter_name', null);
|
||||
session(['selected_meter' => null]);
|
||||
// dd($state);
|
||||
}),
|
||||
|
||||
Select::make('meter_name')
|
||||
->options(function ($get) {
|
||||
$plantId = $get('plant');
|
||||
// Return meter name/id pairs from mfm_meters where plant_id matches selected plant
|
||||
return $plantId ? MfmMeter::where('plant_id', $plantId)->pluck('name', 'id') : [];
|
||||
})
|
||||
->label('Select Meter')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['selected_meter' => $state]);
|
||||
}),
|
||||
Select::make('parameter')
|
||||
->options([
|
||||
'Phase Voltage' => 'Phase Voltage',
|
||||
'Line Voltage' => 'Line Voltage',
|
||||
'Current' => 'Current',
|
||||
'Active Power' => 'Active Power',
|
||||
'Power Factor' => 'Power Factor',
|
||||
'Units' => 'Units',
|
||||
])
|
||||
->label('Select Parameter')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state) {
|
||||
session(['parameter' => $state]);
|
||||
}),
|
||||
|
||||
])
|
||||
->columns(5);
|
||||
}
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return 'Trend Chart Analysis';
|
||||
}
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Trend Chart Analysis';
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
$widgets = [];
|
||||
|
||||
if (TrendChartAnalysis::canView()) {
|
||||
$widgets[] = TrendChartAnalysis::class;
|
||||
}
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view ems trend chart analysis dashboard');
|
||||
}
|
||||
}
|
||||
11
resources/views/filament/pages/trend-chart-analys.blade.php
Normal file
11
resources/views/filament/pages/trend-chart-analys.blade.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<x-filament-panels::page>
|
||||
<div class="space-y-4">
|
||||
{{-- Filters form --}}
|
||||
{{ $this->filtersForm($this->form) }}
|
||||
|
||||
{{-- Chart widget --}}
|
||||
<x-filament-widgets::widgets :widgets="$this->getWidgets()" />
|
||||
|
||||
</div>
|
||||
|
||||
</x-filament-panels::page>
|
||||
Reference in New Issue
Block a user