Skip to content

Commit

Permalink
Merge branch 'main' into refactor-benchmarking-results
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen authored Nov 26, 2024
2 parents ab6af25 + ce3f4b4 commit d3fe6e5
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 56 deletions.
56 changes: 0 additions & 56 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@

namespace App\Filament\Pages;

use App\Actions\GetOoklaSpeedtestServers;
use App\Actions\Ookla\StartSpeedtest;
use App\Filament\Widgets\RecentDownloadChartWidget;
use App\Filament\Widgets\RecentDownloadLatencyChartWidget;
use App\Filament\Widgets\RecentJitterChartWidget;
use App\Filament\Widgets\RecentPingChartWidget;
use App\Filament\Widgets\RecentUploadChartWidget;
use App\Filament\Widgets\RecentUploadLatencyChartWidget;
use App\Filament\Widgets\StatsOverviewWidget;
use App\Helpers\Ookla;
use Carbon\Carbon;
use Cron\CronExpression;
use Filament\Actions\Action;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Pages\Dashboard as BasePage;
use Filament\Support\Enums\IconPosition;

class Dashboard extends BasePage
{
Expand All @@ -41,55 +34,6 @@ public function getSubheading(): ?string
return 'Next speedtest at: '.$nextRunDate;
}

protected function getHeaderActions(): array
{
return [
Action::make('home')
->label('Public Dashboard')
->icon('heroicon-o-chart-bar')
->iconPosition(IconPosition::Before)
->color('gray')
->hidden(fn (): bool => ! config('speedtest.public_dashboard'))
->url(shouldOpenInNewTab: true, url: '/'),

Action::make('speedtest')
->form([
Forms\Components\Select::make('server_id')
->label('Select Server')
->helperText('Leave empty to run the speedtest without specifying a server.')
->options(function (): array {
return array_filter([
'Manual servers' => Ookla::getConfigServers(),
'Closest servers' => GetOoklaSpeedtestServers::run(),
]);
})
->searchable(),
])
->action(function (array $data) {
$serverId = $data['server_id'] ?? null;

StartSpeedtest::run(
scheduled: false,
serverId: $serverId,
);

Notification::make()
->title('Speedtest started')
->success()
->send();
})
->modalHeading('Run Speedtest')
->modalWidth('lg')
->modalSubmitActionLabel('Start')
->button()
->color('primary')
->label('Run Speedtest')
->icon('heroicon-o-rocket-launch')
->iconPosition(IconPosition::Before)
->hidden(! auth()->user()->is_admin),
];
}

protected function getHeaderWidgets(): array
{
return [
Expand Down
82 changes: 82 additions & 0 deletions app/Livewire/Topbar/RunSpeedtestAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Livewire\Topbar;

use App\Actions\GetOoklaSpeedtestServers;
use App\Actions\Ookla\StartSpeedtest;
use App\Helpers\Ookla;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Filament\Support\Enums\IconPosition;
use Livewire\Component;

class RunSpeedtestAction extends Component implements HasActions, HasForms
{
use InteractsWithActions, InteractsWithForms;

public function dashboardAction(): Action
{
return Action::make('home')
->label('Dashboard')
->icon('heroicon-o-chart-bar')
->iconPosition(IconPosition::Before)
->color('gray')
->hidden(fn (): bool => ! config('speedtest.public_dashboard'))
->url(shouldOpenInNewTab: true, url: '/')
->extraAttributes([
'id' => 'dashboardAction',
]);
}

public function speedtestAction(): Action
{
return Action::make('speedtest')
->form([
Select::make('server_id')
->label('Select Server')
->helperText('Leave empty to run the speedtest without specifying a server.')
->options(function (): array {
return array_filter([
'Manual servers' => Ookla::getConfigServers(),
'Closest servers' => GetOoklaSpeedtestServers::run(),
]);
})
->searchable(),
])
->action(function (array $data) {
$serverId = $data['server_id'] ?? null;

StartSpeedtest::run(
scheduled: false,
serverId: $serverId,
);

Notification::make()
->title('Speedtest started')
->success()
->send();
})
->modalHeading('Run Speedtest')
->modalWidth('lg')
->modalSubmitActionLabel('Start')
->button()
->color('primary')
->label('Speedtest')
->icon('heroicon-o-rocket-launch')
->iconPosition(IconPosition::Before)
->hidden(! auth()->user()->is_admin)
->extraAttributes([
'id' => 'speedtestAction',
]);
}

public function render()
{
return view('livewire.topbar.run-speedtest-action');
}
}
36 changes: 36 additions & 0 deletions app/Providers/FilamentServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Providers;

use Filament\Support\Assets\Css;
use Filament\Support\Facades\FilamentAsset;
use Filament\Support\Facades\FilamentView;
use Filament\View\PanelsRenderHook;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class FilamentServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
FilamentAsset::register([
Css::make('panel', __DIR__.'/../../resources/css/panel.css'),
]);

FilamentView::registerRenderHook(
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
fn (): string => Blade::render("@livewire('topbar.run-speedtest-action')"),
);
}
}
1 change: 1 addition & 0 deletions bootstrap/providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

return [
App\Providers\AppServiceProvider::class,
App\Providers\FilamentServiceProvider::class,
App\Providers\Filament\AdminPanelProvider::class,
];
11 changes: 11 additions & 0 deletions public/css/app/panel.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.fi-topbar #dashboardAction .fi-btn-label,
.fi-topbar #speedtestAction .fi-btn-label {
display: none;
}

@media (min-width: 768px) {
.fi-topbar #dashboardAction .fi-btn-label,
.fi-topbar #speedtestAction .fi-btn-label {
display: block;
}
}
11 changes: 11 additions & 0 deletions resources/css/panel.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.fi-topbar #dashboardAction .fi-btn-label,
.fi-topbar #speedtestAction .fi-btn-label {
display: none;
}

@media (min-width: 768px) {
.fi-topbar #dashboardAction .fi-btn-label,
.fi-topbar #speedtestAction .fi-btn-label {
display: block;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div>
<div class="flex flex-wrap items-start justify-start gap-3">
{{ $this->dashboard }}

{{ $this->speedtestAction }}
</div>

<x-filament-actions::modals />
</div>

0 comments on commit d3fe6e5

Please sign in to comment.