Fix SpiceChart: use class property for spice IDs, build edit URLs via url()
Deploy / deploy (push) Successful in 15s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-13 00:14:30 +02:00
1 parent 092a78e306
commit 7d45e3027c
1 file changed
+36 -43
@@ -6,32 +6,37 @@ use Leandrocfe\FilamentApexCharts\Widgets\ApexChartWidget;
use Filament\Support\RawJs; use Filament\Support\RawJs;
use App\Models\Spice; use App\Models\Spice;
class SpiceChart extends ApexChartWidget { class SpiceChart extends ApexChartWidget
{
protected static ?string $chartId = 'spiceChart'; protected static ?string $chartId = 'spiceChart';
protected static ?string $heading = 'Rohstoffmengen im Lager'; protected static ?string $heading = 'Rohstoffmengen im Lager';
protected function getOptions(): array { private array $spiceIds = [];
$data = Spice::all();
$data_array = []; protected function getOptions(): array
{
$spices = Spice::all();
$data = [];
$labels = []; $labels = [];
foreach ($data as $label) {
if ($label->unit == 'grams') {
$data_array[] = round($label->quantity / 1000, 2);
$labels[] = $label->name . ' (kg)';
} else {
$data_array[] = $label->quantity;
if ($label->unit == 'pieces') {
$labels[] = $label->name . ' (Stück)';
} elseif ($label->unit == 'liter') {
$labels[] = $label->name . ' (Liter)';
} else {
$labels[] = $label->name . ' (' . ucfirst($label->unit) . ')';
}
}
}
foreach ($spices as $spice) {
$this->spiceIds[] = $spice->id;
if ($spice->unit === 'grams') {
$data[] = round($spice->quantity / 1000, 2);
$labels[] = $spice->name . ' (kg)';
} elseif ($spice->unit === 'pieces') {
$data[] = $spice->quantity;
$labels[] = $spice->name . ' (Stück)';
} elseif ($spice->unit === 'liter') {
$data[] = $spice->quantity;
$labels[] = $spice->name . ' (Liter)';
} else {
$data[] = $spice->quantity;
$labels[] = $spice->name . ' (' . ucfirst($spice->unit) . ')';
}
}
return [ return [
'chart' => [ 'chart' => [
@@ -40,38 +45,28 @@ class SpiceChart extends ApexChartWidget {
], ],
'series' => [ 'series' => [
[ [
'name' => 'BasicBarChart', 'name' => 'Bestand',
'data' => $data_array, 'data' => $data,
], ],
], ],
'xaxis' => [ 'xaxis' => [
'categories' => $labels, 'categories' => $labels,
'labels' => [ 'labels' => ['style' => ['fontFamily' => 'inherit']],
'style' => [
'fontFamily' => 'inherit',
],
],
], ],
'yaxis' => [ 'yaxis' => [
'labels' => [ 'labels' => ['style' => ['fontFamily' => 'inherit']],
'style' => [
'fontFamily' => 'inherit',
],
],
], ],
'colors' => ['#f59e0b'], 'colors' => ['#f59e0b'],
'plotOptions' => [ 'plotOptions' => [
'bar' => [ 'bar' => ['borderRadius' => 3, 'horizontal' => false],
'borderRadius' => 3,
'horizontal' => false,
],
], ],
]; ];
} }
protected function extraJsOptions(): ?RawJs { protected function extraJsOptions(): ?RawJs
$urls = \App\Models\Spice::all() {
->map(fn ($s) => \App\Filament\User\Resources\SpiceResource::getUrl('edit', ['record' => $s->id])) $urls = collect($this->spiceIds)
->map(fn ($id) => url('/dashboard/rohstoffe/' . $id . '/edit'))
->values() ->values()
->toJson(); ->toJson();
@@ -89,18 +84,16 @@ class SpiceChart extends ApexChartWidget {
xaxis: { xaxis: {
labels: { labels: {
formatter: function (val) { formatter: function (val) {
return val.replace('( ', '(') return val.replace('( ', '(');
} }
} }
}, },
dataLabels: { dataLabels: {
enabled: true, enabled: true,
formatter: function (val, opt) { formatter: function (val, opt) {
return val+''+opt.w.globals.labels[opt.dataPointIndex].match(/\((.*?)\)/)[1] return val + '' + opt.w.globals.labels[opt.dataPointIndex].match(/\((.*?)\)/)[1];
}, },
dropShadow: { dropShadow: { enabled: true }
enabled: true
}
} }
} }
JS); JS);