Skip to content

Commit

Permalink
Layout updates
Browse files Browse the repository at this point in the history
  • Loading branch information
agentphoenix committed Oct 3, 2024
1 parent 82ed9ad commit a602fa1
Show file tree
Hide file tree
Showing 152 changed files with 1,312 additions and 2,570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ public function up()
$table->text('credits')->nullable();
$table->text('preview')->nullable();
$table->string('status')->default(ThemeStatus::active->value);
$table->string('layout_auth')->default('auth-simple');
$table->string('layout_public')->default('app-hero');
$table->string('layout_admin')->default('app-sidebar');
$table->json('settings');
$table->timestamps();

Expand Down
2 changes: 2 additions & 0 deletions nova/foundation/Concerns/SetSEOValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

trait SetSEOValues
{
protected array $seoData = [];

protected function setSEOValues(): void
{
$this->setSEOTitle();
Expand Down
22 changes: 0 additions & 22 deletions nova/foundation/Controllers/SimplePageController.php

This file was deleted.

13 changes: 0 additions & 13 deletions nova/foundation/Controllers/WelcomeController.php

This file was deleted.

42 changes: 21 additions & 21 deletions nova/foundation/Http/Middleware/CheckVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ class CheckVersion
public function handle(Request $request, Closure $next): Response
{
if (Nova::isInstalled()) {
// if (Cache::missing('nova-latest-version')) {
// $upstream = Http::get('https://anodyne-productions.com/api/nova/latest-version')->json();
// $upstream = Http::get(url('api/version'))->json();

// if ($upstream) {
// if ($upstream['severity'] === 'critical') {
// Cache::rememberForever('nova-critical-update-available', function () {
// return true;
// });
// }

// if (version_compare($upstream['version'], nova()->version, '>')) {
// Cache::rememberForever('nova-update-available', function () {
// return true;
// });
// }

// Cache::put('nova-latest-version', $upstream, now()->addDay());
// }

// }
if (Cache::missing('nova-latest-version')) {
$upstream = Http::get('https://anodyne-productions.com/api/nova/latest-version')->json();
$upstream = Http::get(url('api/version'))->json();

if ($upstream) {
if ($upstream['severity'] === 'critical') {
Cache::rememberForever('nova-critical-update-available', function () {
return true;
});
}

if (version_compare($upstream['version'], nova()->version, '>')) {
Cache::rememberForever('nova-update-available', function () {
return true;
});
}

Cache::put('nova-latest-version', $upstream, now()->addDay());
}

}
}

return $next($request);
Expand Down
11 changes: 9 additions & 2 deletions nova/foundation/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@
use Nova\Foundation\NovaManager;
use Nova\Foundation\Responses\FiltersManager;
use Nova\Foundation\View\Compilers\BladeCompiler;
use Nova\Foundation\View\Components\EmailLayout;
use Nova\Foundation\View\Components\Tips;
use Nova\Foundation\View\Layouts\AdminLayout;
use Nova\Foundation\View\Layouts\AuthLayout;
use Nova\Foundation\View\Layouts\EmailLayout;
use Nova\Foundation\View\Layouts\PublicLayout;
use Nova\Navigation\Models\Navigation;
use Nova\Pages\Blocks;
use Nova\Pages\Models\Page;
Expand Down Expand Up @@ -191,8 +194,12 @@ protected function setupBlade(): void
{
Blade::anonymousComponentPath(resource_path('views/public-components'), 'public');

Blade::component('tips', Tips::class);
Blade::component('admin-layout', AdminLayout::class);
Blade::component('auth-layout', AuthLayout::class);
Blade::component('email-layout', EmailLayout::class);
Blade::component('public-layout', PublicLayout::class);

Blade::component('tips', Tips::class);

Blade::directive('icon', [NovaBladeDirectives::class, 'icon']);
Blade::directive('novaAdminScripts', [NovaBladeDirectives::class, 'novaAdminScripts']);
Expand Down
61 changes: 15 additions & 46 deletions nova/foundation/Responses/Responsable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

use BadMethodCallException;
use Illuminate\Contracts\Support\Responsable as LaravelResponsable;
use Illuminate\Contracts\View\View as ViewContract;
use Illuminate\Http\Response;
use Illuminate\Pipeline\Pipeline;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Str;
use Nova\Foundation\Concerns\SetSEOValues;
use Nova\Menus\Models\Menu;
Expand All @@ -29,8 +31,6 @@ abstract class Responsable implements LaravelResponsable

protected array $data = [];

protected array $seoData = [];

protected $output;

protected $page;
Expand Down Expand Up @@ -62,9 +62,6 @@ public function __construct(?Page $page)
$this->theme = app('nova.theme');
}

/**
* Handle preparing the data to be used by the view.
*/
public function prepareData(): array
{
return app(Pipeline::class)
Expand All @@ -73,18 +70,16 @@ public function prepareData(): array
->then(fn ($data) => $data->all());
}

public function layout(): string
public function layout(): ?string
{
if ($this->page->layout === 'public') {
return 'layouts.public';
return 'layouts.theme';
}

$layout = $this->layout ?? $this->theme->getPageLayout($this->page);

return "layouts.{$layout}";
return null;
}

public function subnav(): mixed
public function subnav(): ?string
{
if ($this->subnav) {
return "subnavs.{$this->subnav}";
Expand All @@ -93,19 +88,7 @@ public function subnav(): mixed
return null;
}

public function template(): string
{
$template = $this->template ?? 'simple';

return "templates.{$template}";
}

/**
* Render the response.
*
* @return string
*/
public function render()
public function render(): ViewContract
{
$data = array_merge_recursive(
$this->prepareData(),
Expand All @@ -114,10 +97,8 @@ public function render()

$meta = new ResponseMeta(
layout: $this->layout(),
structure: $this->page->layout === 'public' ? 'public' : 'app',
subnav: $this->subnav(),
subnavSection: $this->subnav,
template: $this->template(),
menu: $this->page->layout === 'public' ? Menu::with('items.page', 'items.items')->public()->first() : null,
pageHeading: $this->page->heading,
pageSubheading: $this->page->subheading,
Expand All @@ -126,15 +107,18 @@ public function render()

app()->instance('nova.meta', $meta);

View::share('meta', $meta);
View::share('settings', settings());

$this->setSEOValues();

return view(
"pages.{$this->view}",
array_merge(['meta' => $meta], $data)
);
return view("pages.{$this->view}", array_merge($data, [
'subnav' => $this->subnav,
'meta' => $meta,
]));
}

public function toResponse($request)
public function toResponse($request): Response
{
if ($request->expectsJson()) {
return response()->json($this->data, Response::HTTP_OK);
Expand All @@ -143,13 +127,6 @@ public function toResponse($request)
return response($this->render(), Response::HTTP_OK);
}

/**
* Any data that should be sent with the response.
*
* @param array $data
* @param mixed $key
* @param null|mixed $value
*/
public function with($key, $value = null): self
{
if (is_array($key)) {
Expand All @@ -161,14 +138,6 @@ public function with($key, $value = null): self
return $this;
}

/**
* Dynamically bind parameters to the response.
*
* @param string $method
* @param array $parameters
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters): self
{
if (! Str::startsWith($method, 'with')) {
Expand Down
2 changes: 0 additions & 2 deletions nova/foundation/Responses/ResponseMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ class ResponseMeta
{
public function __construct(
public ?string $layout,
public ?string $structure,
public ?string $subnav,
public ?string $subnavSection,
public ?string $template,
public ?Menu $menu,
public ?string $pageHeading = null,
public ?string $pageSubheading = null,
Expand Down
15 changes: 0 additions & 15 deletions nova/foundation/Responses/SimplePageResponse.php

This file was deleted.

15 changes: 0 additions & 15 deletions nova/foundation/Responses/WelcomePageResponse.php

This file was deleted.

43 changes: 43 additions & 0 deletions nova/foundation/View/Layouts/AdminLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Nova\Foundation\View\Layouts;

use Illuminate\Support\Facades\Auth;
use Illuminate\View\Component;
use Nova\Applications\Models\Application;
use Nova\Pages\Models\Page;

class AdminLayout extends Component
{
protected ?Page $page;

protected ?string $subnav;

public function __construct()
{
$this->page = request()->route()?->findPageFromRoute();
$this->subnav = app('nova.meta')->subnavSection;
}

public function pendingApplicationsCount(): int
{
return once(fn () => Application::pending()->count());
}

public function unreadAnnouncementsCount(): int
{
return once(fn () => Auth::user()->unread_announcements_count);
}

public function unreadMessagesCount(): int
{
return once(fn () => Auth::user()->unread_messages_count);
}

public function render()
{
return view('layouts.admin');
}
}
19 changes: 19 additions & 0 deletions nova/foundation/View/Layouts/AuthLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Nova\Foundation\View\Layouts;

use Illuminate\View\Component;

class AuthLayout extends Component
{
public function __construct(
public string $pageHeader
) {}

public function render()
{
return view('layouts.auth');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Nova\Foundation\View\Components;
namespace Nova\Foundation\View\Layouts;

use Illuminate\View\Component;

Expand Down
Loading

0 comments on commit a602fa1

Please sign in to comment.