Skip to content

Commit

Permalink
Merge pull request #141 from musimana/11.x
Browse files Browse the repository at this point in the history
v11.10.0
  • Loading branch information
musimana authored Jul 16, 2024
2 parents 0e0e66d + bd331b1 commit 7bc5360
Show file tree
Hide file tree
Showing 88 changed files with 1,542 additions and 1,045 deletions.
11 changes: 11 additions & 0 deletions app/Enums/Blocks/BlockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum BlockType: string
/* List of the content blocks available to the application. */
case HEADER_LOGO = 'header-logo';
case PANEL_LINKS = 'panel-links';
case PRIVACY_POLICY = 'privacy-policy';
case SECTION_DIVIDER = 'section-divider';
case STACK = 'stack';
case TABS = 'tabs';
Expand All @@ -25,6 +26,9 @@ enum BlockType: string
public function staticData(): array
{
return match ($this) {
self::PRIVACY_POLICY => [
'html' => view('partials.static-blocks.privacy')->render(),
],
self::STACK => [
'html' => view('partials.static-blocks.stack', [
'laravel_version' => (new LaravelVersionFormatterResource)->getValue(),
Expand All @@ -41,6 +45,7 @@ public function staticData(): array
*
* @return array{
* label: string,
* description: string,
* inputs: array<int, array<string, string>>,
* inputsRepeatable: array<int, array<string, string>>,
* }
Expand All @@ -66,6 +71,11 @@ public function schema(): array
FormInputType::TEXT->schema('Panel URL', 'url'),
],
],
self::PRIVACY_POLICY => [
'label' => 'Privacy Policy',
'description' => 'Privacy policy for the ' . config('app.name')
. ' website, which covers how this app handles your data.',
],
self::SECTION_DIVIDER => [
'label' => 'Section Divider',
],
Expand All @@ -90,6 +100,7 @@ public function schema(): array

return [
'label' => $block_schema['label'] ?? '{unknown}',
'description' => $block_schema['description'] ?? '',
'inputs' => $block_schema['inputs'] ?? [],
'inputsRepeatable' => $block_schema['inputsRepeatable'] ?? [],
];
Expand Down
19 changes: 19 additions & 0 deletions app/Enums/Webpages/WebpageStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Enums\Webpages;

enum WebpageStatus: int
{
/* List of the webpage statuses available to the application. */
case DRAFT = 1;
case PUBLISHED = 2;

/** Get the status's label. */
public function label(): string
{
return match ($this) {
self::DRAFT => 'Draft',
self::PUBLISHED => 'Published',
};
}
}
1 change: 0 additions & 1 deletion app/Enums/Webpages/WebpageTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ enum WebpageTemplate: string
case AUTH_REGISTER = 'Auth/AuthRegister';
case PROFILE_DASHBOARD = 'Profile/ProfileDashboard';
case PROFILE_EDIT = 'Profile/ProfileEdit';
case PUBLIC_INDEX = 'Public/PublicHomepage';
case PUBLIC_CONTENT = 'Public/PublicContent';
case PUBLIC_CONTENT_CONTROLS = 'Public/PublicContentControls';
case PUBLIC_CONTENT_FORMS = 'Public/PublicContentForms';
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Controllers/Admin/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,37 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\PageUpdateRequest;
use App\Http\Resources\Views\Admin\Pages\CreateEditPageResource;
use App\Http\Resources\Views\Public\Content\PageContentResource;
use App\Http\Resources\Views\Public\Metadata\PageMetadataResource;
use App\Models\Page;
use App\Repositories\Views\AdminViewRepository;
use App\Repositories\Views\PublicViewRepository;
use App\Services\Admin\PageAdminService;
use Illuminate\Http\RedirectResponse;
use Inertia\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;

final class PageController extends Controller
{
/**
* Display the given page's preview.
*
* @throws HttpException
*/
public function show(Page $page): RedirectResponse|Response
{
if (!$page->template) {
abort(404);
}

return (new PublicViewRepository)
->getViewDetails(
$page->template,
(new PageContentResource($page))->getItem(),
(new PageMetadataResource)->getItem($page)
);
}

/**
* Display the edit view for the given page.
*
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/Public/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public function show(Page $page): RedirectResponse|Response
return to_route('home');
}

$template = WebpageTemplate::tryFrom($page?->template ?? '');

if (!$template) {
if (
!$page->isPublished()
|| !$template = WebpageTemplate::tryFrom($page?->template ?? '')
) {
abort(404);
}

Expand Down
25 changes: 15 additions & 10 deletions app/Http/Controllers/Public/PrivacyPolicyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@

namespace App\Http\Controllers\Public;

use App\Enums\Webpages\WebpageTemplate;
use App\Http\Controllers\Controller;
use App\Http\Resources\Views\Public\Content\PageContentResource;
use App\Http\Resources\Views\Public\Metadata\PageMetadataResource;
use App\Models\Page;
use App\Http\Resources\Views\Public\Content\PrivacyPolicyContentResource;
use App\Repositories\Views\PublicViewRepository;
use Inertia\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;

final class PrivacyPolicyController extends Controller
{
/** Display the public privacy policy page. */
/**
* Display the public privacy policy page.
*
* @throws HttpException
*/
public function __invoke(): Response
{
$page = Page::where('slug', 'privacy')->first() ?? Page::factory()->privacyPage()->make();
$template = $page?->template ?? WebpageTemplate::PUBLIC_CONTENT->value;
$content_resource = new PrivacyPolicyContentResource;

if (!$template = $content_resource->getTemplate()) {
abort(404);
}

return (new PublicViewRepository)->getViewDetails(
$template,
(new PageContentResource($page))->getItem(),
(new PageMetadataResource)->getItem($page)
$template->value,
$content_resource->getItem(),
$content_resource->getMetaData()
);
}
}
5 changes: 2 additions & 3 deletions app/Http/Requests/Admin/PageUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Requests\Admin;

use App\Enums\Webpages\WebpageStatus;
use App\Interfaces\Requests\RequestInterface;
use Illuminate\Foundation\Http\FormRequest;

Expand All @@ -17,10 +18,8 @@ public function rules(): array
return [
'blocks' => ['nullable', 'max:5120'],
'title' => ['required', 'string', 'max:255'],
'subtitle' => ['nullable', 'string', 'max:255'],
'content' => ['nullable', 'string', 'max:5120'],
'metaTitle' => ['nullable', 'string', 'max:255'],
'metaDescription' => ['nullable', 'string', 'max:255'],
'webpageStatusId' => ['required', 'integer', 'max:' . WebpageStatus::PUBLISHED->value],
'inSitemap' => ['required', 'boolean'],
];
}
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Resources/Views/Admin/Pages/CreateEditPageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Resources\Views\Admin\Pages;

use App\Enums\Webpages\WebpageStatus;
use App\Http\Resources\Views\Admin\Blocks\AdminBlocksResource;
use App\Interfaces\Resources\Items\PageItemInterface;
use App\Models\Page;
Expand All @@ -19,25 +20,24 @@ final class CreateEditPageResource implements PageItemInterface
* data: array<string, array<int, string>|string>,
* schema: array{label:string, inputs:array<int, bool|int|string>}
* }>,
* content: string,
* subtitle: string,
* title: string,
* metaTitle: string,
* metaDescription: string,
* inSitemap: bool,
* slug: string|null,
* webpageStatusId: \Closure,
* }
*/
public function getItem(Page $page): array
{
return [
'id' => $page->id,
'blocks' => (new AdminBlocksResource($page->blocks, $page))->getItems(),
'content' => $page->getContent(),
'subtitle' => $page->getSubtitle(),
'title' => $page->getTitle(),
'metaTitle' => $page->getMetaTitle(),
'metaDescription' => $page->getMetaDescription(),
'inSitemap' => $page->isInSitemap(),
'slug' => $page->slug,
'webpageStatusId' => fn () => WebpageStatus::tryFrom($page->webpage_status_id ?? 1)?->value
?? WebpageStatus::DRAFT->value,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Resources\Views\Public\Content;

use App\Enums\Blocks\BlockType;
use App\Enums\Webpages\WebpageStatus;
use App\Enums\Webpages\WebpageTemplate;
use App\Interfaces\Resources\Items\ConstantItemInterface;
use App\Models\Block;
Expand All @@ -17,6 +18,7 @@ public function __construct(
if (!$this->page->id) {
$this->page = Page::query()
->isHomepage()
->published()
->with('blocks')
->first()
?? new Page;
Expand All @@ -35,9 +37,6 @@ public function __construct(
* type: string,
* data: array<string, array<int, string>|string>,
* }>,
* bodytext: string,
* heading: string,
* subheading: string,
* }
*/
public function getItem(): array
Expand All @@ -55,7 +54,8 @@ public function getTemplate(): ?WebpageTemplate
public function setDefaultModel(): void
{
$this->page = new Page([
'template' => WebpageTemplate::PUBLIC_INDEX->value,
'webpage_status_id' => WebpageStatus::PUBLISHED->value,
'template' => WebpageTemplate::PUBLIC_CONTENT->value,
'slug' => 'home',
'title' => config('app.name'),
'meta_description' => config('metadata.description'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ public function __construct(
* type: string,
* data: array<string, array<int, string>|string>,
* }>,
* bodytext: string,
* heading: string,
* subheading: string,
* }
*/
public function getItem(): array
{
return [
'blocks' => (new BlocksResource)->getItems($this->page->blocks),
'bodytext' => $this->page->getContent(),
'heading' => $this->page->getTitle(),
'subheading' => $this->page->getSubtitle(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace App\Http\Resources\Views\Public\Content;

use App\Enums\Blocks\BlockType;
use App\Enums\Webpages\WebpageStatus;
use App\Enums\Webpages\WebpageTemplate;
use App\Http\Resources\Views\Public\Metadata\PageMetadataResource;
use App\Interfaces\Resources\Items\ConstantItemInterface;
use App\Models\Block;
use App\Models\Page;

final class PrivacyPolicyContentResource implements ConstantItemInterface
{
/** Instantiate the resource. */
public function __construct(
protected Page $page = new Page,
) {
if (!$this->page->id) {
$this->page = Page::query()
->published()
->where('slug', 'privacy')
->with('blocks')
->first()
?? new Page;
}

if (!$this->getTemplate()) {
$this->setDefaultModel();
}
}

/**
* Get the content array for the site's privacy page.
*
* @return array{
* blocks: array<int, array{
* type: string,
* data: array<string, array<int, string>|string>,
* }>,
* }
*/
public function getItem(): array
{
return (new PageContentResource($this->page))->getItem();
}

/**
* Get the meta-data array for the site's privacy page.
*
* @return array{canonical: string, description: string, title: string}
*/
public function getMetaData(): array
{
return (new PageMetadataResource)->getItem($this->page);
}

/** Get the template for the resource. */
public function getTemplate(): ?WebpageTemplate
{
return $this->page->getTemplate();
}

/** Set the resource's page to the default privacy page model. */
public function setDefaultModel(): void
{
$this->page = new Page([
'webpage_status_id' => WebpageStatus::PUBLISHED->value,
'template' => WebpageTemplate::PUBLIC_CONTENT->value,
'slug' => 'privacy',
'title' => 'Privacy Policy',
'meta_title' => 'Privacy Policy',
'meta_description' => 'Privacy policy for the ' . config('app.name') . ' website, which covers how this app handles your data.',
]);

$this->page->blocks = collect([
new Block([
'type' => BlockType::WYSIWYG->value,
'parent_type' => Page::class,
'parent_id' => $this->page->id,
'data' => json_encode([
'html' => '<h2 class="text-page-title">PRIVACY POLICY</h2>
<p class="text-page-subtitle">' . config('app.name') . '</p>',
]),
]),

new Block([
'type' => BlockType::SECTION_DIVIDER->value,
'parent_type' => Page::class,
'parent_id' => $this->page->id,
]),

new Block([
'type' => BlockType::PRIVACY_POLICY->value,
'parent_type' => Page::class,
'parent_id' => $this->page->id,
]),
]);

$page = Page::factory()->privacyPage()->make();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function getItem(Page $page): array
return [
'canonical' => $page->getUrl(),
'description' => $page->getMetaDescription(),
'title' => $page->getMetaTitle(),
'title' => $page->getTitle(),
];
}
}
Loading

0 comments on commit 7bc5360

Please sign in to comment.