forked from pelican-dev/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pelican-dev:main' into main
- Loading branch information
Showing
109 changed files
with
6,047 additions
and
452 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use Filament\Support\Contracts\HasLabel; | ||
|
||
enum EditorLanguages: string implements HasLabel | ||
{ | ||
case plaintext = 'plaintext'; | ||
case abap = 'abap'; | ||
case apex = 'apex'; | ||
case azcali = 'azcali'; | ||
case bat = 'bat'; | ||
case bicep = 'bicep'; | ||
case cameligo = 'cameligo'; | ||
case coljure = 'coljure'; | ||
case coffeescript = 'coffeescript'; | ||
case c = 'c'; | ||
case cpp = 'cpp'; | ||
case csharp = 'csharp'; | ||
case csp = 'csp'; | ||
case css = 'css'; | ||
case cypher = 'cypher'; | ||
case dart = 'dart'; | ||
case dockerfile = 'dockerfile'; | ||
case ecl = 'ecl'; | ||
case elixir = 'elixir'; | ||
case flow9 = 'flow9'; | ||
case fsharp = 'fsharp'; | ||
case go = 'go'; | ||
case graphql = 'graphql'; | ||
case handlebars = 'handlebars'; | ||
case hcl = 'hcl'; | ||
case html = 'html'; | ||
case ini = 'ini'; | ||
case java = 'java'; | ||
case javascript = 'javascript'; | ||
case julia = 'julia'; | ||
case kotlin = 'kotlin'; | ||
case less = 'less'; | ||
case lexon = 'lexon'; | ||
case lua = 'lua'; | ||
case liquid = 'liquid'; | ||
case m3 = 'm3'; | ||
case markdown = 'markdown'; | ||
case mdx = 'mdx'; | ||
case mips = 'mips'; | ||
case msdax = 'msdax'; | ||
case mysql = 'mysql'; | ||
case objectivec = 'objective-c'; | ||
case pascal = 'pascal'; | ||
case pascaligo = 'pascaligo'; | ||
case perl = 'perl'; | ||
case pgsql = 'pgsql'; | ||
case php = 'php'; | ||
case pla = 'pla'; | ||
case postiats = 'postiats'; | ||
case powerquery = 'powerquery'; | ||
case powershell = 'powershell'; | ||
case proto = 'proto'; | ||
case pug = 'pug'; | ||
case python = 'python'; | ||
case qsharp = 'qsharp'; | ||
case r = 'r'; | ||
case razor = 'razor'; | ||
case redis = 'redis'; | ||
case redshift = 'redshift'; | ||
case restructuredtext = 'restructuredtext'; | ||
case ruby = 'ruby'; | ||
case rust = 'rust'; | ||
case sb = 'sb'; | ||
case scala = 'scala'; | ||
case scheme = 'scheme'; | ||
case scss = 'scss'; | ||
case shell = 'shell'; | ||
case sol = 'sol'; | ||
case aes = 'aes'; | ||
case sparql = 'sparql'; | ||
case sql = 'sql'; | ||
case st = 'st'; | ||
case swift = 'swift'; | ||
case systemverilog = 'systemverilog'; | ||
case verilog = 'verilog'; | ||
case tcl = 'tcl'; | ||
case twig = 'twig'; | ||
case typescript = 'typescript'; | ||
case typespec = 'typespec'; | ||
case vb = 'vb'; | ||
case wgsl = 'wgsl'; | ||
case xml = 'xml'; | ||
case yaml = 'yaml'; | ||
case json = 'json'; | ||
|
||
public function getLabel(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace App\Filament\App\Resources; | ||
|
||
use App\Filament\App\Resources\ServerResource\Pages; | ||
use App\Models\Server; | ||
use Filament\Resources\Resource; | ||
|
||
class ServerResource extends Resource | ||
{ | ||
protected static ?string $model = Server::class; | ||
|
||
protected static ?string $slug = '/'; | ||
|
||
protected static bool $shouldRegisterNavigation = false; | ||
|
||
public static function canAccess(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListServers::route('/'), | ||
]; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
app/Filament/App/Resources/ServerResource/Pages/ListServers.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,101 @@ | ||
<?php | ||
|
||
namespace App\Filament\App\Resources\ServerResource\Pages; | ||
|
||
use App\Filament\App\Resources\ServerResource; | ||
use App\Filament\Server\Pages\Console; | ||
use App\Models\Server; | ||
use App\Tables\Columns\ServerEntryColumn; | ||
use Carbon\CarbonInterface; | ||
use Filament\Resources\Pages\ListRecords; | ||
use Filament\Tables\Columns\Layout\Stack; | ||
use Filament\Tables\Table; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Number; | ||
|
||
class ListServers extends ListRecords | ||
{ | ||
protected static string $resource = ServerResource::class; | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->paginated(false) | ||
->query(fn () => auth()->user()->can('viewList server') ? Server::query() : auth()->user()->accessibleServers()) | ||
->poll('15s') | ||
->columns([ | ||
Stack::make([ | ||
ServerEntryColumn::make('server_entry') | ||
->searchable(['name']), | ||
]), | ||
]) | ||
->contentGrid([ | ||
'default' => 1, | ||
'xl' => 2, | ||
]) | ||
->recordUrl(fn (Server $server) => Console::getUrl(panel: 'server', tenant: $server)) | ||
->emptyStateIcon('tabler-brand-docker') | ||
->emptyStateDescription('') | ||
->emptyStateHeading('You don\'t have access to any servers!'); | ||
} | ||
|
||
// @phpstan-ignore-next-line | ||
private function uptime(Server $server): string | ||
{ | ||
$uptime = Arr::get($server->resources(), 'uptime', 0); | ||
|
||
if ($uptime === 0) { | ||
return 'Offline'; | ||
} | ||
|
||
return now()->subMillis($uptime)->diffForHumans(syntax: CarbonInterface::DIFF_ABSOLUTE, short: true, parts: 2); | ||
} | ||
|
||
// @phpstan-ignore-next-line | ||
private function cpu(Server $server): string | ||
{ | ||
$cpu = Number::format(Arr::get($server->resources(), 'cpu_absolute', 0), maxPrecision: 2, locale: auth()->user()->language) . '%'; | ||
$max = Number::format($server->cpu, locale: auth()->user()->language) . '%'; | ||
|
||
return $cpu . ($server->cpu > 0 ? ' Of ' . $max : ''); | ||
} | ||
|
||
// @phpstan-ignore-next-line | ||
private function memory(Server $server): string | ||
{ | ||
$latestMemoryUsed = Arr::get($server->resources(), 'memory_bytes', 0); | ||
$totalMemory = Arr::get($server->resources(), 'memory_limit_bytes', 0); | ||
|
||
$used = config('panel.use_binary_prefix') | ||
? Number::format($latestMemoryUsed / 1024 / 1024 / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB' | ||
: Number::format($latestMemoryUsed / 1000 / 1000 / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB'; | ||
|
||
if ($totalMemory === 0) { | ||
$total = config('panel.use_binary_prefix') | ||
? Number::format($server->memory / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB' | ||
: Number::format($server->memory / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB'; | ||
} else { | ||
$total = config('panel.use_binary_prefix') | ||
? Number::format($totalMemory / 1024 / 1024 / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB' | ||
: Number::format($totalMemory / 1000 / 1000 / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB'; | ||
} | ||
|
||
return $used . ($server->memory > 0 ? ' Of ' . $total : ''); | ||
} | ||
|
||
// @phpstan-ignore-next-line | ||
private function disk(Server $server): string | ||
{ | ||
$usedDisk = Arr::get($server->resources(), 'disk_bytes', 0); | ||
|
||
$used = config('panel.use_binary_prefix') | ||
? Number::format($usedDisk / 1024 / 1024 / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB' | ||
: Number::format($usedDisk / 1000 / 1000 / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB'; | ||
|
||
$total = config('panel.use_binary_prefix') | ||
? Number::format($server->disk / 1024, maxPrecision: 2, locale: auth()->user()->language) .' GiB' | ||
: Number::format($server->disk / 1000, maxPrecision: 2, locale: auth()->user()->language) . ' GB'; | ||
|
||
return $used . ($server->disk > 0 ? ' Of ' . $total : ''); | ||
} | ||
} |
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
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.