Fix SpiceChart: use class property for spice IDs, build edit URLs via url()
Deploy / deploy (push) Successful in 15s
Deploy / deploy (push) Successful in 15s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
092a78e306
commit
7d45e3027c
1 file changed
+36
-43
@@ -6,32 +6,37 @@ use Leandrocfe\FilamentApexCharts\Widgets\ApexChartWidget;
|
||||
use Filament\Support\RawJs;
|
||||
use App\Models\Spice;
|
||||
|
||||
class SpiceChart extends ApexChartWidget {
|
||||
class SpiceChart extends ApexChartWidget
|
||||
{
|
||||
protected static ?string $chartId = 'spiceChart';
|
||||
protected static ?string $heading = 'Rohstoffmengen im Lager';
|
||||
|
||||
protected function getOptions(): array {
|
||||
$data = Spice::all();
|
||||
private array $spiceIds = [];
|
||||
|
||||
$data_array = [];
|
||||
protected function getOptions(): array
|
||||
{
|
||||
$spices = Spice::all();
|
||||
|
||||
$data = [];
|
||||
$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 [
|
||||
'chart' => [
|
||||
@@ -40,38 +45,28 @@ class SpiceChart extends ApexChartWidget {
|
||||
],
|
||||
'series' => [
|
||||
[
|
||||
'name' => 'BasicBarChart',
|
||||
'data' => $data_array,
|
||||
'name' => 'Bestand',
|
||||
'data' => $data,
|
||||
],
|
||||
],
|
||||
'xaxis' => [
|
||||
'categories' => $labels,
|
||||
'labels' => [
|
||||
'style' => [
|
||||
'fontFamily' => 'inherit',
|
||||
],
|
||||
],
|
||||
'labels' => ['style' => ['fontFamily' => 'inherit']],
|
||||
],
|
||||
'yaxis' => [
|
||||
'labels' => [
|
||||
'style' => [
|
||||
'fontFamily' => 'inherit',
|
||||
],
|
||||
],
|
||||
'labels' => ['style' => ['fontFamily' => 'inherit']],
|
||||
],
|
||||
'colors' => ['#f59e0b'],
|
||||
'plotOptions' => [
|
||||
'bar' => [
|
||||
'borderRadius' => 3,
|
||||
'horizontal' => false,
|
||||
],
|
||||
'bar' => ['borderRadius' => 3, 'horizontal' => false],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function extraJsOptions(): ?RawJs {
|
||||
$urls = \App\Models\Spice::all()
|
||||
->map(fn ($s) => \App\Filament\User\Resources\SpiceResource::getUrl('edit', ['record' => $s->id]))
|
||||
protected function extraJsOptions(): ?RawJs
|
||||
{
|
||||
$urls = collect($this->spiceIds)
|
||||
->map(fn ($id) => url('/dashboard/rohstoffe/' . $id . '/edit'))
|
||||
->values()
|
||||
->toJson();
|
||||
|
||||
@@ -89,18 +84,16 @@ class SpiceChart extends ApexChartWidget {
|
||||
xaxis: {
|
||||
labels: {
|
||||
formatter: function (val) {
|
||||
return val.replace('( ', '(')
|
||||
return val.replace('( ', '(');
|
||||
}
|
||||
}
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: true,
|
||||
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: {
|
||||
enabled: true
|
||||
}
|
||||
dropShadow: { enabled: true }
|
||||
}
|
||||
}
|
||||
JS);
|
||||
|
||||
Reference in new issue
Block a user