Skip to content

Commit 465183b

Browse files
committed
Add Issues metric to dashboard and refactor ServerResource display
1 parent 734be8c commit 465183b

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

app/Nova/Dashboards/Main.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Helpers\Helper;
66
use App\Helpers\Inspiring;
77
use App\Helpers\Policy;
8-
use App\Nova\Metrics\DiskSpace;
8+
use App\Nova\Metrics\Issues;
99
use App\Nova\Metrics\ServerResource;
1010
use Illuminate\Support\Facades\Auth;
1111
use Illuminate\Support\Facades\Storage;
@@ -51,8 +51,15 @@ public function cards()
5151
->verified(text: $quotes['author'])
5252
->avatar(url: Storage::disk('images')->url('quotes.svg'))
5353
->width('1/2'),
54-
ServerResource::make()->canSee(fn () => Policy::make()->allowedFor('admin')->get()),
55-
ServerResource::make('inode')->canSee(fn () => Policy::make()->allowedFor('admin')->get()),
54+
ServerResource::make()
55+
->width('1/2')
56+
->canSee(fn () => Policy::make()->allowedFor('admin')->get()),
57+
ServerResource::make('inode')
58+
->width('1/2')
59+
->canSee(fn () => Policy::make()->allowedFor('admin')->get()),
60+
Issues::make('')
61+
->width('1/2')
62+
->canSee(fn () => Policy::make()->allowedFor('admin')->get()),
5663
Welcome::make()
5764
->title('Permulaan') // optional
5865
->description('Selamat datang di Aplikasi Simpede. Berikut adalah fitur-fitur yang tersedia:') // optional

app/Nova/Metrics/Issues.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace App\Nova\Metrics;
4+
5+
use DateTimeInterface;
6+
use Laravel\Nova\Http\Requests\NovaRequest;
7+
use Laravel\Nova\Metrics\Value;
8+
use Laravel\Nova\Metrics\ValueResult;
9+
use Laravel\Nova\Nova;
10+
use Symfony\Component\Process\Process;
11+
12+
class Issues extends Value
13+
{
14+
private $type;
15+
16+
public function __construct($type = 'issues')
17+
{
18+
$this->type = $type;
19+
}
20+
21+
public function name()
22+
{
23+
return $this->type === 'issues' ? 'Issues' : 'Outdated Packages';
24+
}
25+
/**
26+
* Calculate the value of the metric.
27+
*/
28+
public function calculate(NovaRequest $request): ValueResult
29+
{
30+
$composer = config('app.composer');
31+
$home = config('app.composer_home');
32+
$devFlag = '--no-dev';
33+
$process = Process::fromShellCommandline("$composer outdated $devFlag -f json", base_path(), ['COMPOSER_HOME' => $home]);
34+
$process->run();
35+
$value = $process->getOutput();
36+
return $this->result($value);
37+
38+
39+
}
40+
41+
/**
42+
* Get the ranges available for the metric.
43+
*
44+
* @return array<int|string, string>
45+
*/
46+
public function ranges(): array
47+
{
48+
return [];
49+
}
50+
51+
/**
52+
* Determine the amount of time the results of the metric should be cached.
53+
*/
54+
public function cacheFor(): DateTimeInterface|null
55+
{
56+
// return now()->addMinutes(5);
57+
58+
return null;
59+
}
60+
}

0 commit comments

Comments
 (0)