show update info on dashboard, show git commit (when using git)

This commit is contained in:
Boy132 2024-06-08 00:38:46 +02:00
parent b9d1ce4438
commit 93f059025c
6 changed files with 70 additions and 35 deletions

View File

@ -26,7 +26,7 @@ class InfoCommand extends Command
{ {
$this->output->title('Version Information'); $this->output->title('Version Information');
$this->table([], [ $this->table([], [
['Panel Version', config('app.version')], ['Panel Version', $this->versionService->versionData()['version']],
['Latest Version', $this->versionService->getPanel()], ['Latest Version', $this->versionService->getPanel()],
['Up-to-Date', $this->versionService->isLatestPanel() ? 'Yes' : $this->formatText('No', 'bg=red')], ['Up-to-Date', $this->versionService->isLatestPanel() ? 'Yes' : $this->formatText('No', 'bg=red')],
], 'compact'); ], 'compact');

View File

@ -7,6 +7,7 @@ use App\Models\Egg;
use App\Models\Node; use App\Models\Node;
use App\Models\Server; use App\Models\Server;
use App\Models\User; use App\Models\User;
use App\Services\Helpers\SoftwareVersionService;
use Filament\Actions\CreateAction; use Filament\Actions\CreateAction;
use Filament\Pages\Page; use Filament\Pages\Page;
@ -29,8 +30,14 @@ class Dashboard extends Page
public function getViewData(): array public function getViewData(): array
{ {
/** @var SoftwareVersionService $softwareVersionService */
$softwareVersionService = app(SoftwareVersionService::class);
return [ return [
'inDevelopment' => config('app.version') === 'canary', 'inDevelopment' => config('app.version') === 'canary',
'version' => $softwareVersionService->versionData()['version'],
'latestVersion' => $softwareVersionService->getPanel(),
'isLatest' => $softwareVersionService->isLatestPanel(),
'eggsCount' => Egg::query()->count(), 'eggsCount' => Egg::query()->count(),
'nodesList' => ListNodes::getUrl(), 'nodesList' => ListNodes::getUrl(),
'nodesCount' => Node::query()->count(), 'nodesCount' => Node::query()->count(),
@ -43,6 +50,12 @@ class Dashboard extends Page
->icon('tabler-brand-github') ->icon('tabler-brand-github')
->url('https://github.com/pelican-dev/panel/discussions', true), ->url('https://github.com/pelican-dev/panel/discussions', true),
], ],
'updateActions' => [
CreateAction::make()
->label('Read Documentation')
->icon('tabler-clipboard-text')
->url('https://pelican.dev/docs/panel/update', true),
],
'nodeActions' => [ 'nodeActions' => [
CreateAction::make() CreateAction::make()
->label(trans('dashboard/index.sections.intro-first-node.button_label')) ->label(trans('dashboard/index.sections.intro-first-node.button_label'))
@ -53,7 +66,7 @@ class Dashboard extends Page
CreateAction::make() CreateAction::make()
->label(trans('dashboard/index.sections.intro-support.button_donate')) ->label(trans('dashboard/index.sections.intro-support.button_donate'))
->icon('tabler-cash') ->icon('tabler-cash')
->url('https://pelican.dev/donate', true) ->url($softwareVersionService->getDonations(), true)
->color('success'), ->color('success'),
], ],
'helpActions' => [ 'helpActions' => [

View File

@ -6,6 +6,7 @@ use App\Extensions\Themes\Theme;
use App\Models; use App\Models;
use App\Models\ApiKey; use App\Models\ApiKey;
use App\Models\Node; use App\Models\Node;
use App\Services\Helpers\SoftwareVersionService;
use Dedoc\Scramble\Scramble; use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi; use Dedoc\Scramble\Support\Generator\OpenApi;
use Dedoc\Scramble\Support\Generator\SecurityScheme; use Dedoc\Scramble\Support\Generator\SecurityScheme;
@ -30,8 +31,9 @@ class AppServiceProvider extends ServiceProvider
{ {
Schema::defaultStringLength(191); Schema::defaultStringLength(191);
View::share('appVersion', $this->versionData()['version'] ?? 'undefined'); $versionData = app(SoftwareVersionService::class)->versionData();
View::share('appIsGit', $this->versionData()['is_git'] ?? false); View::share('appVersion', $versionData['version'] ?? 'undefined');
View::share('appIsGit', $versionData['is_git'] ?? false);
Paginator::useBootstrap(); Paginator::useBootstrap();
@ -96,34 +98,6 @@ class AppServiceProvider extends ServiceProvider
Scramble::ignoreDefaultRoutes(); Scramble::ignoreDefaultRoutes();
} }
/**
* Return version information for the footer.
*/
protected function versionData(): array
{
return cache()->remember('git-version', 5, function () {
if (file_exists(base_path('.git/HEAD'))) {
$head = explode(' ', file_get_contents(base_path('.git/HEAD')));
if (array_key_exists(1, $head)) {
$path = base_path('.git/' . trim($head[1]));
}
}
if (isset($path) && file_exists($path)) {
return [
'version' => substr(file_get_contents($path), 0, 8),
'is_git' => true,
];
}
return [
'version' => config('app.version'),
'is_git' => false,
];
});
}
public function bootAuth(): void public function bootAuth(): void
{ {
Sanctum::usePersonalAccessTokenModel(ApiKey::class); Sanctum::usePersonalAccessTokenModel(ApiKey::class);

View File

@ -49,6 +49,14 @@ class SoftwareVersionService
return Arr::get(self::$result, 'discord') ?? 'https://pelican.dev/discord'; return Arr::get(self::$result, 'discord') ?? 'https://pelican.dev/discord';
} }
/**
* Get the donation URL.
*/
public function getDonations(): string
{
return Arr::get(self::$result, 'donate') ?? 'https://pelican.dev/donate';
}
/** /**
* Determine if the current version of the panel is the latest. * Determine if the current version of the panel is the latest.
*/ */
@ -93,8 +101,28 @@ class SoftwareVersionService
}); });
} }
public function getDonations(): string public function versionData(): array
{ {
return 'https://github.com'; return cache()->remember('git-version', 5, function () {
if (file_exists(base_path('.git/HEAD'))) {
$head = explode(' ', file_get_contents(base_path('.git/HEAD')));
if (array_key_exists(1, $head)) {
$path = base_path('.git/' . trim($head[1]));
}
}
if (isset($path) && file_exists($path)) {
return [
'version' => 'canary (' . substr(file_get_contents($path), 0, 8) . ')',
'is_git' => true,
];
}
return [
'version' => config('app.version'),
'is_git' => false,
];
});
} }
} }

View File

@ -19,6 +19,10 @@ return [
'button_issues' => 'Create Issue', 'button_issues' => 'Create Issue',
'button_features' => 'Discuss Features', 'button_features' => 'Discuss Features',
], ],
'intro-update' => [
'heading' => 'Update available',
'content' => ':latestVersion is available! Read our documentation to update your Panel.',
],
'intro-first-node' => [ 'intro-first-node' => [
'heading' => 'No Nodes Detected', 'heading' => 'No Nodes Detected',
'content' => "It looks like you don't have any Nodes set up yet, but don't worry because you click the action button to create your first one!", 'content' => "It looks like you don't have any Nodes set up yet, but don't worry because you click the action button to create your first one!",

View File

@ -4,7 +4,7 @@
:actions="$this->getCachedHeaderActions()" :actions="$this->getCachedHeaderActions()"
:breadcrumbs="filament()->hasBreadcrumbs() ? $this->getBreadcrumbs() : []" :breadcrumbs="filament()->hasBreadcrumbs() ? $this->getBreadcrumbs() : []"
:heading=" trans('dashboard/index.heading')" :heading=" trans('dashboard/index.heading')"
:subheading="trans('strings.version', ['version' => config('app.version')])" :subheading="trans('strings.version', ['version' => $version])"
></x-filament-panels::header> ></x-filament-panels::header>
<p>{{ trans('dashboard/index.expand_sections') }}</p> <p>{{ trans('dashboard/index.expand_sections') }}</p>
@ -30,6 +30,22 @@
</x-filament::section> </x-filament::section>
@endif @endif
@if (!$isLatest)
<x-filament::section
icon="tabler-info-circle"
icon-color="primary"
id="intro-update"
collapsible
persist-collapsed
:header-actions="$updateActions"
>
<x-slot name="heading">{{ trans('dashboard/index.sections.intro-update.heading') }}</x-slot>
<p>{{ trans('dashboard/index.sections.intro-update.content', ['latestVersion' => $latestVersion]) }}</p>
</x-filament::section>
@endif
{{-- No Nodes Created --}} {{-- No Nodes Created --}}
@if ($nodesCount <= 0) @if ($nodesCount <= 0)
<x-filament::section <x-filament::section