Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('metrics', function (Blueprint $table) {
$table->boolean('show_when_empty')->after('display_chart')->default(false);
});
}
};
1 change: 1 addition & 0 deletions resources/lang/en/metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

'visible_label' => 'Visible',
'display_chart_label' => 'Display Chart',
'show_when_empty_label' => 'Show when empty',
],
'overview' => [
'metric_points_label' => 'Metric Points',
Expand Down
4 changes: 4 additions & 0 deletions src/Filament/Resources/Metrics/MetricResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public static function form(Schema $schema): Schema
->label(__('cachet::metric.form.display_chart_label'))
->default(true)
->required(),
Toggle::make('show_when_empty')
->label(__('cachet::metric.form.show_when_empty_label'))
->default(true)
->required(),

])->columnSpan(1),
])->columns(4);
Expand Down
2 changes: 2 additions & 0 deletions src/Models/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Metric extends Model
protected $casts = [
'calc_type' => MetricTypeEnum::class,
'display_chart' => 'bool',
'show_when_empty' => 'bool',
'places' => 'int',
'default_view' => MetricViewEnum::class,
'visible' => ResourceVisibilityEnum::class,
Expand All @@ -68,6 +69,7 @@ class Metric extends Model
'description',
'calc_type',
'display_chart',
'show_when_empty',
'places',
'default_value',
'default_view',
Expand Down
2 changes: 1 addition & 1 deletion src/View/Components/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function metrics(Carbon $startDate): Collection
'metricPoints' => fn ($query) => $query->orderBy('created_at'),
])
->where('display_chart', true)
->whereHas('metricPoints', fn (Builder $query) => $query->where('created_at', '>=', $startDate))
->where(fn (Builder $query) => $query->where('show_when_empty', true)->orWhereHas('metricPoints', fn (Builder $query) => $query->where('created_at', '>=', $startDate)))
->orderBy('places')
->get();
}
Expand Down