-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refactor-benchmarking-results
- Loading branch information
Showing
7 changed files
with
150 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')"), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
resources/views/livewire/topbar/run-speedtest-action.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |