Skip to content
Merged
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
52 changes: 45 additions & 7 deletions app/GrassrootsGrantsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@

class GrassrootsGrantsPage extends Model
{
public const SLUG_ROUND_1 = 'round-1';

public const SLUG_ROUND_2 = 'round-2';

protected $table = 'grassroots_grants_page';

protected $fillable = [
'slug',
'is_preview_mode',
'hero_title',
'hero_subtitle',
Expand Down Expand Up @@ -58,29 +63,62 @@ public function withoutExcludedEvidence(): self
return $this;
}

public static function config(): self
public static function forSlug(string $slug): self
{
$page = self::first();
$page = self::query()->where('slug', $slug)->first();
if ($page) {
return $page;
}

if ($slug === self::SLUG_ROUND_1) {
return self::create([
'slug' => self::SLUG_ROUND_1,
'is_preview_mode' => true,
'hero_title' => 'EU Code Week Grants for Grassroots',
'hero_subtitle' => 'Round 1 project highlights from grassroots coding initiatives across Europe.',
'hero_image' => '/images/contact-us.png',
'meta_title' => 'Grassroots Grants – Round 1 – EU Code Week',
'meta_description' => 'Discover EU Code Week Round 1 grassroots grant projects, impact, and funded initiatives across Europe.',
'round_title' => 'Round 1 of Grants',
]);
}

return self::create([
'slug' => $slug,
'is_preview_mode' => true,
'hero_title' => 'EU Code Week Grants for Grassroots',
'hero_subtitle' => 'Round 1 project highlights from grassroots coding initiatives across Europe.',
'hero_subtitle' => 'Round 2 project highlights from grassroots coding initiatives across Europe.',
'hero_image' => '/images/contact-us.png',
'meta_title' => 'Grassroots Grants – EU Code Week',
'meta_description' => 'Discover EU Code Week Round 1 grassroots grant projects, impact, and funded initiatives across Europe.',
'round_title' => 'Round 1 of Grants',
'meta_title' => 'Grassroots Grants – Round 2 – EU Code Week',
'meta_description' => 'Discover EU Code Week Round 2 grassroots grant projects, impact, and funded initiatives across Europe.',
'round_title' => 'Round 2 of Grants',
]);
}

/**
* @deprecated Use forSlug() — kept for callers that expect the Round 1 page.
*/
public static function config(): self
{
return self::forSlug(self::SLUG_ROUND_1);
}

public function previewSignedUrl(int $days = 14): string
{
$route = $this->slug === self::SLUG_ROUND_2
? 'grassroots-grants.round-2.preview'
: 'grassroots-grants.preview';

return URL::temporarySignedRoute(
'grassroots-grants.preview',
$route,
now()->addDays($days),
);
}

public function publicRouteName(): string
{
return $this->slug === self::SLUG_ROUND_2
? 'grassroots-grants.round-2'
: 'grassroots-grants';
}
}
38 changes: 22 additions & 16 deletions app/Http/Controllers/GrassrootsGrantsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,41 @@
namespace App\Http\Controllers;

use App\GrassrootsGrantsPage;
use Illuminate\Support\Facades\Schema;
use Illuminate\View\View;

class GrassrootsGrantsController extends Controller
{
public function show(): View
{
$page = $this->loadPage();
return $this->render(GrassrootsGrantsPage::SLUG_ROUND_1, previewMode: false);
}

if ($page->is_preview_mode) {
abort(404);
}
public function preview(): View
{
return $this->render(GrassrootsGrantsPage::SLUG_ROUND_1, previewMode: true);
}

return view('static.grassroots-grants', [
'page' => $page,
'previewMode' => false,
]);
public function showRound2(): View
{
return $this->render(GrassrootsGrantsPage::SLUG_ROUND_2, previewMode: false);
}

public function preview(): View
public function previewRound2(): View
{
return view('static.grassroots-grants', [
'page' => $this->loadPage(),
'previewMode' => true,
]);
return $this->render(GrassrootsGrantsPage::SLUG_ROUND_2, previewMode: true);
}

private function loadPage(): GrassrootsGrantsPage
private function render(string $slug, bool $previewMode): View
{
return GrassrootsGrantsPage::config()->withoutExcludedEvidence();
$page = GrassrootsGrantsPage::forSlug($slug)->withoutExcludedEvidence();

if (! $previewMode && $page->is_preview_mode) {
abort(404);
}

return view('static.grassroots-grants', [
'page' => $page,
'previewMode' => $previewMode,
]);
}
}
6 changes: 5 additions & 1 deletion app/Http/View/Composers/GrassrootsGrantsComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ class GrassrootsGrantsComposer
{
public function compose(View $view): void
{
if ($view->offsetExists('page') && $view->offsetGet('page') !== null) {
return;
}

if (! Schema::hasTable('grassroots_grants_page')) {
$view->with('page', null);

return;
}

$view->with('page', GrassrootsGrantsPage::config()->withoutExcludedEvidence());
$view->with('page', GrassrootsGrantsPage::forSlug(GrassrootsGrantsPage::SLUG_ROUND_1)->withoutExcludedEvidence());
}
}
12 changes: 8 additions & 4 deletions app/Nova/GrassrootsGrantsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GrassrootsGrantsPage extends Resource

public static $model = \App\GrassrootsGrantsPage::class;

public static $title = 'hero_title';
public static $title = 'round_title';

public static $priority = 5;

Expand All @@ -43,17 +43,21 @@ public static function authorizedToCreate(Request $request): bool

public static function indexQuery(NovaRequest $request, $query)
{
return $query->where('id', 1);
return $query->orderBy('slug');
}

public function fields(Request $request): array
{
return [
ID::make()->onlyOnForms(),

Text::make('Slug', 'slug')
->readonly()
->help('round-1 or round-2. Seeded pages only — creation is disabled.'),

Panel::make('Publishing', [
Boolean::make('Preview mode', 'is_preview_mode')
->help('When enabled, /grassroots-grants returns 404 and only the signed preview URL below works. The footer link stays hidden until preview mode is off.'),
->help('When enabled, the public URL returns 404 and only the signed preview URL below works. Menu/footer links stay hidden until preview mode is off.'),
Text::make('Preview URL', function () {
if (! $this->resource?->exists) {
return 'Save first to generate preview URL.';
Expand Down Expand Up @@ -81,7 +85,7 @@ public function fields(Request $request): array
Text::make('Meta description', 'meta_description')->nullable(),
])->collapsable()->collapsedByDefault(),

Panel::make('Round 1 overview', [
Panel::make('Round overview', [
Text::make('Round title', 'round_title')->nullable(),
Trix::make('Overview intro', 'overview_intro')->nullable(),
Trix::make('Common activity types', 'overview_activity_types')->nullable(),
Expand Down
4 changes: 2 additions & 2 deletions app/Services/Support/Content/ContentActionRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function all(): array
'girls_in_digital_faq_item' => ['model' => \App\GirlsInDigitalFaqItem::class, 'label' => 'Girls in Digital FAQ item', 'singleton' => false, 'lookup_fields' => []],
'dream_jobs_page' => ['model' => \App\DreamJobsPage::class, 'label' => 'Dream Jobs page', 'singleton' => true, 'lookup_fields' => []],
'csr_campaign_page' => ['model' => \App\CsrCampaignPage::class, 'label' => 'CSR Campaign page', 'singleton' => true, 'lookup_fields' => []],
'grassroots_grants_page' => ['model' => \App\GrassrootsGrantsPage::class, 'label' => 'Grassroots Grants page', 'singleton' => true, 'lookup_fields' => []],
'grassroots_grants_hub' => ['model' => \App\GrassrootsGrantsHub::class, 'label' => 'Grassroots Grants hub', 'singleton' => true, 'lookup_fields' => []],
'grassroots_grants_page' => ['model' => \App\GrassrootsGrantsPage::class, 'label' => 'Grassroots Grants page', 'singleton' => false, 'lookup_fields' => ['slug']],
'grassroots_grants_hub' => ['model' => \App\GrassrootsGrantsHub::class, 'label' => 'Grassroots Grants hub', 'singleton' => false, 'lookup_fields' => ['title']],
'menu_section' => ['model' => \App\Models\MenuSection::class, 'label' => 'Menu section', 'singleton' => false, 'lookup_fields' => []],
'menu_item' => ['model' => \App\Models\MenuItem::class, 'label' => 'Menu item', 'singleton' => false, 'lookup_fields' => []],
'event' => ['model' => \App\Event::class, 'label' => 'Event', 'singleton' => false, 'lookup_fields' => []],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function up(): void
if (! Schema::hasTable('grassroots_grants_page')) {
Schema::create('grassroots_grants_page', function (Blueprint $table) {
$table->id();
$table->string('slug')->unique()->nullable();
$table->boolean('is_preview_mode')->default(true);
$table->string('hero_title')->nullable();
$table->text('hero_subtitle')->nullable();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

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

return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('grassroots_grants_page')) {
return;
}

if (! Schema::hasColumn('grassroots_grants_page', 'slug')) {
Schema::table('grassroots_grants_page', function (Blueprint $table) {
$table->string('slug')->nullable()->after('id');
});
}

$pages = DB::table('grassroots_grants_page')->orderBy('id')->get();
foreach ($pages as $index => $page) {
if ($page->slug) {
continue;
}

DB::table('grassroots_grants_page')
->where('id', $page->id)
->update(['slug' => $index === 0 ? 'round-1' : 'round-'.($index + 1)]);
}

// Ensure uniqueness without relying on Doctrine.
$duplicates = DB::table('grassroots_grants_page')
->select('slug', DB::raw('count(*) as aggregate'))
->groupBy('slug')
->having('aggregate', '>', 1)
->exists();

if (! $duplicates) {
try {
Schema::table('grassroots_grants_page', function (Blueprint $table) {
$table->unique('slug');
});
} catch (\Throwable) {
// Index may already exist from a partial prior run.
}
}
}

public function down(): void
{
if (! Schema::hasTable('grassroots_grants_page')) {
return;
}

if (! Schema::hasColumn('grassroots_grants_page', 'slug')) {
return;
}

try {
Schema::table('grassroots_grants_page', function (Blueprint $table) {
$table->dropUnique(['slug']);
});
} catch (\Throwable) {
// Ignore if the unique index was never created.
}

Schema::table('grassroots_grants_page', function (Blueprint $table) {
$table->dropColumn('slug');
});
}
};
36 changes: 25 additions & 11 deletions database/seeders/GrassrootsGrantsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,33 @@ public function run(): void
return;
}

$data = require database_path('seeders/data/grassroots_grants_round1.php');

$page = GrassrootsGrantsPage::query()->first();
if ($page) {
GrassrootsGrantsProjectImage::query()->delete();
GrassrootsGrantsProjectLink::query()->delete();
GrassrootsGrantsProject::query()->delete();
GrassrootsGrantsHub::query()->delete();
$page->delete();
}
$this->clearExisting();

$this->seedRound(require database_path('seeders/data/grassroots_grants_round1.php'));
$this->seedRound(require database_path('seeders/data/grassroots_grants_round2.php'));
}

private function clearExisting(): void
{
GrassrootsGrantsProjectImage::query()->delete();
GrassrootsGrantsProjectLink::query()->delete();
GrassrootsGrantsProject::query()->delete();
GrassrootsGrantsHub::query()->delete();
GrassrootsGrantsPage::query()->delete();
}

/**
* @param array{page: array<string, mixed>, hubs: list<array<string, mixed>>} $data
*/
private function seedRound(array $data): void
{
$page = GrassrootsGrantsPage::create($data['page']);

foreach ($data['hubs'] as $position => $hubData) {
$projects = $hubData['projects'] ?? [];
unset($hubData['projects']);

$hub = GrassrootsGrantsPage::find($page->id)->hubs()->create(array_merge($hubData, [
$hub = $page->hubs()->create(array_merge($hubData, [
'position' => $position,
'active' => true,
]));
Expand Down Expand Up @@ -111,6 +120,11 @@ private function seedProjectImages(
$extension = strtolower($file->getExtension());
$fileType = $extension === 'pdf' ? 'pdf' : 'image';

// Skip non-image/non-pdf assets (docx etc.) from gallery.
if (! in_array($extension, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'pdf'], true)) {
continue;
}

$project->images()->create([
'url' => $url,
'alt' => $project->title,
Expand Down
23 changes: 22 additions & 1 deletion database/seeders/StaticPagesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function run(): void
'path' => '/grassroots-grants',
],
[
'name' => 'Grassroots Grants',
'name' => 'Grassroots Grants – Round 1',
'description' => 'EU Code Week Round 1 grassroots grant projects, impact statistics, and funded initiatives across Europe.',
'unique_identifier' => 'grassroots-grants',
'path' => '/grassroots-grants',
Expand All @@ -154,6 +154,27 @@ public function run(): void
]
);

StaticPage::updateOrCreate(
[
'language' => 'en',
'path' => '/grassroots-grants/round-2',
],
[
'name' => 'Grassroots Grants – Round 2',
'description' => 'EU Code Week Round 2 grassroots grant projects, impact statistics, and funded initiatives across Europe.',
'unique_identifier' => 'grassroots-grants-round-2',
'path' => '/grassroots-grants/round-2',
'keywords' => ['Grassroots Grants', 'Round 2', 'EU Code Week', 'Funding', 'Projects'],
'thumbnail' => '/images/contact-us.png',
'meta_title' => 'EU Code Week Grants for Grassroots – Round 2',
'meta_description' => 'Discover EU Code Week Round 2 grassroots grant projects, impact, and funded initiatives across Europe.',
'meta_keywords' => 'EU Code Week, grassroots grants, round 2, funding, coding projects',
'category' => 'General',
'link_type' => 'internal_link',
'is_searchable' => false,
]
);

// Sub Pages
$subPages = [
// Online Cources
Expand Down
Loading
Loading