Bozhidar Slaveykov 1 年之前
父節點
當前提交
927b059688

+ 16 - 13
web/app/Filament/Widgets/CustomersCount.php

@@ -10,11 +10,14 @@ use Filament\Widgets\StatsOverviewWidget\Stat;
 class CustomersCount extends BaseWidget
 {
     protected static bool $isLazy = false;
+
+    protected static ?int $sort = 4;
+
     protected function getStats(): array
     {
 
-        $serverStatistic = new \App\Statistics\ServerStatistic();
-        $serverStats = $serverStatistic->getCurrentStats();
+//        $serverStatistic = new \App\Statistics\ServerStatistic();
+//        $serverStats = $serverStatistic->getCurrentStats();
 
 
 //
@@ -27,17 +30,17 @@ class CustomersCount extends BaseWidget
         $websiteCount = Website::count();
 
         return [
-            Stat::make('Total Memory', $serverStats['memory']['total']),
-            Stat::make('Used Memory', $serverStats['memory']['used']),
-            Stat::make('Free Memory', $serverStats['memory']['free']),
-            Stat::make('Shared Memory', $serverStats['memory']['shared']),
-            Stat::make('Buffer Cache', $serverStats['memory']['buffCache']),
-            Stat::make('Available Memory', $serverStats['memory']['available']),
-
-            Stat::make('Total Disk', $serverStats['disk']['total']),
-            Stat::make('Used Disk', $serverStats['disk']['used']),
-            Stat::make('Free Disk', $serverStats['disk']['free']),
-            Stat::make('Used Disk Percentage', $serverStats['disk']['usedPercentage']),
+//            Stat::make('Total Memory', $serverStats['memory']['total']),
+//            Stat::make('Used Memory', $serverStats['memory']['used']),
+//            Stat::make('Free Memory', $serverStats['memory']['free']),
+//            Stat::make('Shared Memory', $serverStats['memory']['shared']),
+//            Stat::make('Buffer Cache', $serverStats['memory']['buffCache']),
+//            Stat::make('Available Memory', $serverStats['memory']['available']),
+//
+//            Stat::make('Total Disk', $serverStats['disk']['total']),
+//            Stat::make('Used Disk', $serverStats['disk']['used']),
+//            Stat::make('Free Disk', $serverStats['disk']['free']),
+//            Stat::make('Used Disk Percentage', $serverStats['disk']['usedPercentage']),
 
 
             Stat::make('Websites', $websiteCount)->icon('heroicon-o-globe-alt'),

+ 117 - 0
web/app/Filament/Widgets/ServerStatistic.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace App\Filament\Widgets;
+
+use Leandrocfe\FilamentApexCharts\Widgets\ApexChartWidget;
+
+class ServerStatistic extends ApexChartWidget
+{
+    /**
+     * Chart Id
+     *
+     * @var string
+     */
+    protected static ?string $chartId = 'serverStatisticChart';
+
+    /**
+     * Widget Title
+     *
+     * @var string|null
+     */
+    protected static ?string $heading = 'Disk Usage';
+
+    protected static ?int $sort = 1;
+
+
+    /**
+     * Widget content height
+     */
+    protected static ?int $contentHeight = 100;
+
+
+    /**
+     * Widget Footer
+     */
+    protected function getFooter(): \Illuminate\View\View
+    {
+        $serverStatistic = new \App\Statistics\ServerStatistic();
+        $serverStats = $serverStatistic->getCurrentStats();
+
+        return view('charts.order-status.footer', ['data' => $serverStats]);
+    }
+
+
+    /**
+     * Chart options (series, labels, types, size, animations...)
+     * https://apexcharts.com/docs/options
+     */
+    protected function getOptions(): array
+    {
+        $serverStatistic = new \App\Statistics\ServerStatistic();
+        $serverStats = $serverStatistic->getCurrentStats();
+
+        $userPercentage = $serverStats['disk']['usedPercentage'];
+        $userPercentage = str_replace('%', '', $userPercentage);
+        $userPercentage = floatval($userPercentage);
+
+        return [
+            'chart' => [
+                'type' => 'radialBar',
+                'height' => 200,
+                'toolbar' => [
+                    'show' => false,
+                ],
+            ],
+            'series' => [$userPercentage],
+            'plotOptions' => [
+                'radialBar' => [
+                    'startAngle' => 0,
+                    'endAngle' => 360,
+                    'hollow' => [
+                        'size' => '60%',
+                        'background' => 'transparent',
+                    ],
+                    'track' => [
+                        'background' => 'transparent',
+                        'strokeWidth' => '100%',
+                    ],
+                    'dataLabels' => [
+                        'show' => true,
+                        'name' => [
+                            'show' => true,
+                            'offsetY' => -10,
+                            'fontWeight' => 600,
+                            'fontFamily' => 'inherit',
+                        ],
+                        'value' => [
+                            'show' => true,
+                            'fontWeight' => 600,
+                            'fontSize' => '24px',
+                            'fontFamily' => 'inherit',
+                        ],
+                    ],
+
+                ],
+            ],
+            'fill' => [
+                'type' => 'gradient',
+                'gradient' => [
+                    'shade' => 'dark',
+                    'type' => 'horizontal',
+                    'shadeIntensity' => 0.5,
+                    'gradientToColors' => ['#f59e0b'],
+                    'inverseColors' => true,
+                    'opacityFrom' => 1,
+                    'opacityTo' => 0.6,
+                    'stops' => [30, 70, 100],
+                ],
+            ],
+            'stroke' => [
+                'dashArray' => 10,
+            ],
+            'labels' => ['Free Space'],
+            'colors' => ['#16a34a'],
+
+        ];
+    }
+}

+ 2 - 0
web/app/Filament/Widgets/Websites.php

@@ -16,6 +16,8 @@ class Websites extends BaseWidget
 
     protected int | string | array $columnSpan = 2;
 
+    protected static ?int $sort =5;
+
     public function table(Table $table): Table
     {
         return $table

+ 3 - 1
web/app/Providers/Filament/AdminPanelProvider.php

@@ -4,6 +4,7 @@ namespace App\Providers\Filament;
 
 use App\Filament\Pages\Settings\Settings;
 use App\Filament\Widgets\CustomersCount;
+use App\Filament\Widgets\ServerStatistic;
 use App\Filament\Widgets\Websites;
 use Filament\Http\Middleware\Authenticate;
 use Filament\Http\Middleware\DisableBladeIconComponents;
@@ -78,9 +79,10 @@ class AdminPanelProvider extends PanelProvider
             ])
             ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
             ->widgets([
+                ServerStatistic::class,
                 CustomersCount::class,
                 Websites::class,
-//                Widgets\AccountWidget::class,
+               // Widgets\AccountWidget::class,
 //                Widgets\FilamentInfoWidget::class,
             ])
             ->middleware([

+ 16 - 0
web/resources/views/charts/order-status/footer.blade.php

@@ -0,0 +1,16 @@
+<div class="flex items-center justify-between mt-6 text-center">
+    <div>
+        <h1>
+            Total Disk
+        </h1>
+        <div class="text-3xl">{{ $data['disk']['total'] }}</div>
+    </div>
+    <div>
+        <h1>Used Disk</h1>
+        <div class="text-3xl">{{ $data['disk']['used'] }}</div>
+    </div>
+    <div>
+        <h1>Free Disk</h1>
+        <div class="text-3xl">{{ $data['disk']['free'] }}</div>
+    </div>
+</div>