Skip to content
Merged

Dev #3534

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions app/Nova/TrainingResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,26 @@ public function fields(Request $request): array

Select::make('Roadmap embed format', 'roadmap_embed_kind')
->options([
'pdf' => 'PDF (recommended — keeps clickable links from the file)',
'pdf' => 'PDF (inline viewer, links inside the file)',
'image' => 'Image (PNG/JPG thumbnail linking to URL you set)',
'svg' => 'SVG (static graphic; exports usually do not preserve PDF links)',
'none' => 'None (remove placeholder output)',
])
->default('pdf')
->help('Put [[embed_roadmap_pdf]] or [[embed_roadmap]] in Content where the roadmap should appear. Use PDF when the roadmap must open real URLs from the document.'),
->help('Put [[embed_roadmap_pdf]] or [[embed_roadmap]] in Content where the roadmap should appear.'),

Text::make('Roadmap PDF embed URL', 'roadmap_pdf_embed_url')
->nullable()
->rules('nullable', 'url')
->dependsOn(['roadmap_embed_kind'], function (Text $field, NovaRequest $request, FormData $formData) {
if (($formData->roadmap_embed_kind ?? 'pdf') === 'pdf') {
$kind = $formData->roadmap_embed_kind ?? 'pdf';
if ($kind === 'pdf' || $kind === 'image') {
$field->show();
} else {
$field->hide();
}
})
->help('HTTPS URL to the PDF. Shown in an iframe with the browser’s built-in PDF viewer so links inside the file stay active.'),
->help('HTTPS URL to the roadmap PDF. For PDF format this is embedded in-page. For Image format use it too (or Roadmap image link URL) as the PDF click target.'),

Textarea::make('Roadmap SVG', 'roadmap_svg')
->nullable()
Expand All @@ -188,6 +190,30 @@ public function fields(Request $request): array
})
->help('Optional: paste full <svg>...</svg> only for a non-interactive graphic. For clickable resources, prefer PDF above.'),

Text::make('Roadmap image URL', 'roadmap_image_url')
->nullable()
->rules('nullable', 'url')
->dependsOn(['roadmap_embed_kind'], function (Text $field, NovaRequest $request, FormData $formData) {
if (($formData->roadmap_embed_kind ?? 'pdf') === 'image') {
$field->show();
} else {
$field->hide();
}
})
->help('Full URL of the roadmap graphic (e.g. PNG on S3). The whole image is clickable.'),

Text::make('Roadmap image link URL', 'roadmap_image_link_url')
->nullable()
->rules('nullable', 'url')
->dependsOn(['roadmap_embed_kind'], function (Text $field, NovaRequest $request, FormData $formData) {
if (($formData->roadmap_embed_kind ?? 'pdf') === 'image') {
$field->show();
} else {
$field->hide();
}
})
->help('Where clicks go (e.g. full PDF). If empty, falls back to Roadmap PDF embed URL.'),

Text::make('Button text', 'button_text')->nullable(),

Text::make('Button URL', 'button_url')
Expand Down
2 changes: 2 additions & 0 deletions app/TrainingResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class TrainingResource extends Model
'roadmap_pdf_embed_url',
'roadmap_embed_kind',
'roadmap_svg',
'roadmap_image_url',
'roadmap_image_link_url',
'button_text',
'button_url',
'secondary_button_text',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('training_resources', function (Blueprint $table) {
$table->string('roadmap_image_url', 2048)->nullable()->after('roadmap_svg');
$table->string('roadmap_image_link_url', 2048)->nullable()->after('roadmap_image_url');
});
}

public function down(): void
{
Schema::table('training_resources', function (Blueprint $table) {
$table->dropColumn(['roadmap_image_url', 'roadmap_image_link_url']);
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public function run(): void
'roadmap_pdf_embed_url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/+discover-digital-toolkit/DDP_toolkit_roadmap.pdf',
'roadmap_embed_kind' => 'pdf',
'roadmap_svg' => null,
'roadmap_image_url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/+discover-digital-toolkit/DDP_toolkit_roadmap.png',
'roadmap_image_link_url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/+discover-digital-toolkit/DDP_toolkit_roadmap.pdf',
'third_button_text' => 'Register an activity',
'third_button_url' => 'https://codeweek.eu/add?skip=1',
'meta_title' => 'Discover Digital Programme - Toolkit',
Expand Down
40 changes: 40 additions & 0 deletions resources/views/training/partials/roadmap-image-embed.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@props([
'imageUrl',
'linkUrl',
'altText' => null,
])
@php
$alt = $altText !== null && trim((string) $altText) !== '' ? trim((string) $altText) : __('Roadmap overview');
$external = \Illuminate\Support\Str::startsWith($linkUrl, ['http://', 'https://', '//']);
@endphp
<div class="w-full max-w-full my-6 rounded-xl overflow-hidden border border-slate-200 bg-slate-100 shadow-sm">
<a
href="{{ $linkUrl }}"
@if($external)
target="_blank"
rel="noopener noreferrer"
@endif
class="block focus:outline-none focus-visible:ring-2 focus-visible:ring-dark-blue focus-visible:ring-offset-2 rounded-xl"
>
<img
src="{{ $imageUrl }}"
alt="{{ $alt }}"
class="block w-full h-auto max-w-full"
loading="lazy"
decoding="async"
>
</a>
</div>
<p class="text-sm mt-2 mb-0 text-[#333E48]">
<a
href="{{ $linkUrl }}"
@if($external)
target="_blank"
rel="noopener noreferrer"
@endif
class="text-dark-blue underline font-medium"
>
{{ __('Open linked resource') }}
</a>
— {{ __('same destination as clicking the image above.') }}
</p>
12 changes: 11 additions & 1 deletion resources/views/training/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
$renderedContent = $trainingResource->content ?? '';
$roadmapEmbedUrl = trim((string) ($trainingResource->roadmap_pdf_embed_url ?? ''));
$roadmapEmbedKind = strtolower(trim((string) ($trainingResource->roadmap_embed_kind ?? 'pdf')));
if (! in_array($roadmapEmbedKind, ['pdf', 'svg', 'none'], true)) {
if (! in_array($roadmapEmbedKind, ['pdf', 'svg', 'image', 'none'], true)) {
$roadmapEmbedKind = 'pdf';
}
$roadmapSvg = trim((string) ($trainingResource->roadmap_svg ?? ''));
$roadmapImageUrl = trim((string) ($trainingResource->roadmap_image_url ?? ''));
$roadmapImageLinkUrl = trim((string) ($trainingResource->roadmap_image_link_url ?? ''));

$roadmapPlaceholders = ['[[embed_roadmap_pdf]]', '[[embed_roadmap]]'];
$hasRoadmapPlaceholder = str_contains($renderedContent, '[[embed_roadmap_pdf]]')
Expand All @@ -42,6 +44,14 @@
$roadmapEmbedHtml = view('training.partials.roadmap-pdf-embed', ['url' => $roadmapEmbedUrl])->render();
} elseif ($roadmapEmbedKind === 'svg' && $roadmapSvg !== '') {
$roadmapEmbedHtml = view('training.partials.roadmap-svg-embed', ['svg' => $roadmapSvg])->render();
} elseif ($roadmapEmbedKind === 'image' && $roadmapImageUrl !== '') {
$imageLinkHref = $roadmapImageLinkUrl !== '' ? $roadmapImageLinkUrl : $roadmapEmbedUrl;
if ($imageLinkHref !== '') {
$roadmapEmbedHtml = view('training.partials.roadmap-image-embed', [
'imageUrl' => $roadmapImageUrl,
'linkUrl' => $imageLinkHref,
])->render();
}
}

foreach ($roadmapPlaceholders as $token) {
Expand Down
Loading