Skip to content

Commit

Permalink
Merge pull request #345 from Boy132/show-git-version
Browse files Browse the repository at this point in the history
Show update info on dashboard & show git commit (when using git)
  • Loading branch information
notAreYouScared authored Jun 8, 2024
2 parents 7be0cd6 + 55badb5 commit dd7a01a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function handle(): void
{
$this->output->title('Version Information');
$this->table([], [
['Panel Version', config('app.version')],
['Panel Version', $this->versionService->versionData()['version']],
['Latest Version', $this->versionService->getPanel()],
['Up-to-Date', $this->versionService->isLatestPanel() ? 'Yes' : $this->formatText('No', 'bg=red')],
], 'compact');
Expand Down
16 changes: 15 additions & 1 deletion app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Node;
use App\Models\Server;
use App\Models\User;
use App\Services\Helpers\SoftwareVersionService;
use Filament\Actions\CreateAction;
use Filament\Pages\Page;

Expand All @@ -29,8 +30,14 @@ public function getTitle(): string

public function getViewData(): array
{
/** @var SoftwareVersionService $softwareVersionService */
$softwareVersionService = app(SoftwareVersionService::class);

return [
'inDevelopment' => config('app.version') === 'canary',
'version' => $softwareVersionService->versionData()['version'],
'latestVersion' => $softwareVersionService->getPanel(),
'isLatest' => $softwareVersionService->isLatestPanel(),
'eggsCount' => Egg::query()->count(),
'nodesList' => ListNodes::getUrl(),
'nodesCount' => Node::query()->count(),
Expand All @@ -43,6 +50,13 @@ public function getViewData(): array
->icon('tabler-brand-github')
->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)
->color('warning'),
],
'nodeActions' => [
CreateAction::make()
->label(trans('dashboard/index.sections.intro-first-node.button_label'))
Expand All @@ -53,7 +67,7 @@ public function getViewData(): array
CreateAction::make()
->label(trans('dashboard/index.sections.intro-support.button_donate'))
->icon('tabler-cash')
->url('https://pelican.dev/donate', true)
->url($softwareVersionService->getDonations(), true)
->color('success'),
],
'helpActions' => [
Expand Down
34 changes: 4 additions & 30 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models;
use App\Models\ApiKey;
use App\Models\Node;
use App\Services\Helpers\SoftwareVersionService;
use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi;
use Dedoc\Scramble\Support\Generator\SecurityScheme;
Expand All @@ -30,8 +31,9 @@ public function boot(): void
{
Schema::defaultStringLength(191);

View::share('appVersion', $this->versionData()['version'] ?? 'undefined');
View::share('appIsGit', $this->versionData()['is_git'] ?? false);
$versionData = app(SoftwareVersionService::class)->versionData();
View::share('appVersion', $versionData['version'] ?? 'undefined');
View::share('appIsGit', $versionData['is_git'] ?? false);

Paginator::useBootstrap();

Expand Down Expand Up @@ -96,34 +98,6 @@ public function register(): void
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
{
Sanctum::usePersonalAccessTokenModel(ApiKey::class);
Expand Down
32 changes: 30 additions & 2 deletions app/Services/Helpers/SoftwareVersionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public function getDiscord(): string
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.
*/
Expand Down Expand Up @@ -93,8 +101,28 @@ protected function cacheVersionData(): array
});
}

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,
];
});
}
}
4 changes: 4 additions & 0 deletions lang/en/dashboard/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
'button_issues' => 'Create Issue',
'button_features' => 'Discuss Features',
],
'intro-update' => [
'heading' => 'Update available',
'content' => ':latestVersion is available! Read our documentation to update your Panel.',
],
'intro-first-node' => [
'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!",
Expand Down
18 changes: 17 additions & 1 deletion resources/views/filament/pages/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:actions="$this->getCachedHeaderActions()"
:breadcrumbs="filament()->hasBreadcrumbs() ? $this->getBreadcrumbs() : []"
:heading=" trans('dashboard/index.heading')"
:subheading="trans('strings.version', ['version' => config('app.version')])"
:subheading="trans('strings.version', ['version' => $version])"
></x-filament-panels::header>

<p>{{ trans('dashboard/index.expand_sections') }}</p>
Expand All @@ -30,6 +30,22 @@
</x-filament::section>
@endif

@if (!$isLatest)
<x-filament::section
icon="tabler-info-circle"
icon-color="warning"
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 --}}
@if ($nodesCount <= 0)
<x-filament::section
Expand Down

0 comments on commit dd7a01a

Please sign in to comment.