-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ded5d2
commit a1087ac
Showing
22 changed files
with
4,794 additions
and
1,377 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,70 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\ResultResource\Pages; | ||
use App\Filament\Resources\ResultResource\Widgets\StatsOverview; | ||
use App\Models\Result; | ||
use Filament\Resources\Resource; | ||
use Filament\Resources\Table; | ||
use Filament\Tables; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Columns\ViewColumn; | ||
|
||
class ResultResource extends Resource | ||
{ | ||
protected static ?string $model = Result::class; | ||
|
||
protected static ?string $navigationGroup = 'Data'; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-table'; | ||
|
||
protected static ?string $navigationLabel = 'Speedtest Results'; | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
TextColumn::make('id') | ||
->label('ID'), | ||
ViewColumn::make('download') | ||
->view('tables.columns.bytes-column'), | ||
ViewColumn::make('upload') | ||
->view('tables.columns.bytes-column'), | ||
TextColumn::make('ping'), | ||
TextColumn::make('created_at') | ||
->dateTime(), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
// Tables\Actions\ViewAction::make(), | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListResults::route('/'), | ||
]; | ||
} | ||
|
||
public static function getWidgets(): array | ||
{ | ||
return [ | ||
StatsOverview::class, | ||
]; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/Filament/Resources/ResultResource/Pages/ListResults.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,16 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ResultResource\Pages; | ||
|
||
use App\Filament\Resources\ResultResource; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListResults extends ListRecords | ||
{ | ||
protected static string $resource = ResultResource::class; | ||
|
||
protected function getHeaderWidgets(): array | ||
{ | ||
return ResultResource::getWidgets(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/Filament/Resources/ResultResource/Widgets/StatsOverview.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,21 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ResultResource\Widgets; | ||
|
||
use App\Models\Result; | ||
use Filament\Widgets\StatsOverviewWidget as BaseWidget; | ||
use Filament\Widgets\StatsOverviewWidget\Card; | ||
|
||
class StatsOverview extends BaseWidget | ||
{ | ||
protected static ?string $pollingInterval = null; | ||
|
||
protected function getCards(): array | ||
{ | ||
return [ | ||
Card::make('Latest download', formatBytes(Result::latest()->first()->download)), | ||
Card::make('Latest upload', formatBytes(Result::latest()->first()->upload)), | ||
Card::make('Latest ping', round(Result::latest()->first()->ping, 2)), | ||
]; | ||
} | ||
} |
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
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,94 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\Result; | ||
use App\Models\User; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class ResultPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
/** | ||
* Determine whether the user can view any models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function viewAny(User $user) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Determine whether the user can view the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Result $result | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function view(User $user, Result $result) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Determine whether the user can create models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function create(User $user) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Result $result | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function update(User $user, Result $result) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Result $result | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function delete(User $user, Result $result) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Determine whether the user can restore the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Result $result | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function restore(User $user, Result $result) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Determine whether the user can permanently delete the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Result $result | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function forceDelete(User $user, Result $result) | ||
{ | ||
// | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use Filament\Facades\Filament; | ||
use Filament\Navigation\NavigationItem; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class FilamentServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Bootstrap services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
Filament::serving(function () { | ||
Filament::registerNavigationGroups([ | ||
'Data', | ||
'Links', | ||
]); | ||
|
||
Filament::registerNavigationItems([ | ||
NavigationItem::make('Documenation') | ||
->url('https://docs.speedtest-tracker.dev/', shouldOpenInNewTab: true) | ||
->icon('heroicon-o-external-link') | ||
->group('Links') | ||
->sort(0), | ||
NavigationItem::make('Donate') | ||
->url('https://github.com/sponsors/alexjustesen', shouldOpenInNewTab: true) | ||
->icon('heroicon-o-external-link') | ||
->group('Links') | ||
->sort(1), | ||
NavigationItem::make('Source Code') | ||
->url('https://github.com/alexjustesen/speedtest-tracker', shouldOpenInNewTab: true) | ||
->icon('heroicon-o-external-link') | ||
->group('Links') | ||
->sort(2), | ||
]); | ||
}); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace App\Tables\Columns; | ||
|
||
use Filament\Tables\Columns\Column; | ||
|
||
class BytesColumn extends Column | ||
{ | ||
protected string $view = 'tables.columns.bytes-column'; | ||
} |
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 @@ | ||
<?php | ||
|
||
if (! function_exists('formatBytes')) { | ||
function formatBytes(int $bytes, $precision = 2) | ||
{ | ||
$base = log($bytes, 1024); | ||
$suffixes = array('', 'Kbps', 'Mbps', 'Gbps', 'Tbps'); | ||
|
||
return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)]; | ||
} | ||
} |
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
Oops, something went wrong.