From 453bcb0d6fc95fb2b74b59478f15aa9410a20f59 Mon Sep 17 00:00:00 2001 From: Ugo Finnendahl Date: Sun, 3 Nov 2024 15:28:43 +0100 Subject: [PATCH] add default game to tnm --- site/blueprints/pages/templates.yml | 10 ++++++++++ site/blueprints/pages/tournament.yml | 16 +++++++++++++++- site/blueprints/pages/xoi.yml | 2 +- site/controllers/home.php | 26 ++++++++++++++++++++------ 4 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 site/blueprints/pages/templates.yml diff --git a/site/blueprints/pages/templates.yml b/site/blueprints/pages/templates.yml new file mode 100644 index 0000000..f601357 --- /dev/null +++ b/site/blueprints/pages/templates.yml @@ -0,0 +1,10 @@ +title: Templates + +create: + status: listed + +sections: + pages: + type: pages + label: Games + template: xoi diff --git a/site/blueprints/pages/tournament.yml b/site/blueprints/pages/tournament.yml index 7d7abe6..765c239 100644 --- a/site/blueprints/pages/tournament.yml +++ b/site/blueprints/pages/tournament.yml @@ -17,6 +17,12 @@ sections: width: 1/2 label: Date type: date + default: + width: 1/1 + label: Template + type: pages + max: 1 + query: site.find("Templates").drafts # layout: # type: layout # layouts: @@ -24,10 +30,18 @@ sections: # fieldsets: # - heading # - simple_game - pages: type: pages label: Games template: xoi text: "[{{ page.startdate.toDate('d.m.') }}] {{ page.players.toPages.first.forename }} {{ page.players.toPages.first.surname }} vs. {{ page.players.toPages.nth(1).forename }} {{ page.players.toPages.nth(1).surname }}" sortBy: startdate desc + status: unlisted + # pages2: + # type: pages + # label: Default + # template: xoi + # sortBy: startdate desc + # status: draft + # max: 1 + # limit: 1 diff --git a/site/blueprints/pages/xoi.yml b/site/blueprints/pages/xoi.yml index 5714aaa..354a924 100644 --- a/site/blueprints/pages/xoi.yml +++ b/site/blueprints/pages/xoi.yml @@ -1,7 +1,7 @@ title: Game create: - status: listed + status: draft sections: fields: diff --git a/site/controllers/home.php b/site/controllers/home.php index 362da11..a4e9683 100644 --- a/site/controllers/home.php +++ b/site/controllers/home.php @@ -18,12 +18,25 @@ return function ($page, $site, $kirby) { try { $kirby->impersonate('kirby'); - $id = $site->find($tournament)->createChild([ - 'content' => $content, - 'slug' => Str::slug($name), - 'template' => 'xoi', - 'isDraft' => false - ]); + if ($site->find($tournament)->default()->toPage()){ + $json["error"] = $site->find($tournament)->default()->toPage()->out(); + $id = $site->find($tournament)->default()->toPage()->copy( + [ + 'slug' => Str::slug($name), + 'parent' => $site->find($tournament), + 'children' => false, // copy children + 'files' => false, // don't copy files + 'isDraft' => false, + ] + ); + } else { + $id = $site->find($tournament)->createChild([ + 'content' => $content, + 'slug' => Str::slug($name), + 'template' => 'xoi', + 'isDraft' => false + ]); + } $json["status"] = "ok"; $json["url"] = $id->url(); } catch (\Exception $e) { @@ -38,3 +51,4 @@ return function ($page, $site, $kirby) { 'error' => $error ]; }; +