Default chapter templates: Updated api docs and tests

Also applied minor tweaks to some wording and logic.

During review of #4750
This commit is contained in:
Dan Brown 2024-02-01 12:22:16 +00:00
parent 4a8f70240f
commit 4137cf9c8f
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
10 changed files with 46 additions and 40 deletions

View file

@ -61,6 +61,8 @@ class ListingResponseBuilder
} }
}); });
dd($data->first());
return response()->json([ return response()->json([
'data' => $data, 'data' => $data,
'total' => $total, 'total' => $total,

View file

@ -136,13 +136,7 @@ class PageRepo
$page->book_id = $parent->id; $page->book_id = $parent->id;
} }
// check for chapter $defaultTemplate = $page->chapter->defaultTemplate ?? $page->book->defaultTemplate;
if ($page->chapter_id) {
$defaultTemplate = $page->chapter->defaultTemplate;
} else {
$defaultTemplate = $page->book->defaultTemplate;
}
if ($defaultTemplate && userCan('view', $defaultTemplate)) { if ($defaultTemplate && userCan('view', $defaultTemplate)) {
$page->forceFill([ $page->forceFill([
'html' => $defaultTemplate->html, 'html' => $defaultTemplate->html,

View file

@ -1,32 +1,32 @@
<?php <?php
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class AddDefaultTemplateToChapters extends Migration class AddDefaultTemplateToChapters extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
* *
* @return void * @return void
*/ */
public function up() public function up()
{ {
Schema::table('chapters', function (Blueprint $table) { Schema::table('chapters', function (Blueprint $table) {
$table->integer('default_template_id')->nullable()->default(null); $table->integer('default_template_id')->nullable()->default(null);
}); });
} }
/** /**
* Reverse the migrations. * Reverse the migrations.
* *
* @return void * @return void
*/ */
public function down() public function down()
{ {
Schema::table('chapters', function (Blueprint $table) { Schema::table('chapters', function (Blueprint $table) {
$table->dropColumn('default_template_id'); $table->dropColumn('default_template_id');
}); });
} }
} }

View file

@ -3,6 +3,7 @@
"name": "My fantastic new chapter", "name": "My fantastic new chapter",
"description_html": "<p>This is a <strong>great new chapter</strong> that I've created via the API</p>", "description_html": "<p>This is a <strong>great new chapter</strong> that I've created via the API</p>",
"priority": 15, "priority": 15,
"default_template_id": 25,
"tags": [ "tags": [
{"name": "Category", "value": "Top Content"}, {"name": "Category", "value": "Top Content"},
{"name": "Rating", "value": "Highest"} {"name": "Rating", "value": "Highest"}

View file

@ -3,6 +3,7 @@
"name": "My fantastic updated chapter", "name": "My fantastic updated chapter",
"description_html": "<p>This is an <strong>updated chapter</strong> that I've altered via the API</p>", "description_html": "<p>This is an <strong>updated chapter</strong> that I've altered via the API</p>",
"priority": 16, "priority": 16,
"default_template_id": 2428,
"tags": [ "tags": [
{"name": "Category", "value": "Kinda Good Content"}, {"name": "Category", "value": "Kinda Good Content"},
{"name": "Rating", "value": "Medium"} {"name": "Rating", "value": "Medium"}

View file

@ -11,6 +11,7 @@
"updated_by": 1, "updated_by": 1,
"owned_by": 1, "owned_by": 1,
"description_html": "<p>This is a <strong>great new chapter<\/strong> that I've created via the API<\/p>", "description_html": "<p>This is a <strong>great new chapter<\/strong> that I've created via the API<\/p>",
"default_template_id": 25,
"tags": [ "tags": [
{ {
"name": "Category", "name": "Category",

View file

@ -5,6 +5,7 @@
"name": "Content Creation", "name": "Content Creation",
"description": "How to create documentation on whatever subject you need to write about.", "description": "How to create documentation on whatever subject you need to write about.",
"description_html": "<p>How to create <strong>documentation</strong> on whatever subject you need to write about.</p>", "description_html": "<p>How to create <strong>documentation</strong> on whatever subject you need to write about.</p>",
"default_template_id": 25,
"priority": 3, "priority": 3,
"created_at": "2019-05-05T21:49:56.000000Z", "created_at": "2019-05-05T21:49:56.000000Z",
"updated_at": "2019-09-28T11:24:23.000000Z", "updated_at": "2019-09-28T11:24:23.000000Z",

View file

@ -11,6 +11,7 @@
"updated_by": 1, "updated_by": 1,
"owned_by": 1, "owned_by": 1,
"description_html": "<p>This is an <strong>updated chapter<\/strong> that I've altered via the API<\/p>", "description_html": "<p>This is an <strong>updated chapter<\/strong> that I've altered via the API<\/p>",
"default_template_id": 2428,
"tags": [ "tags": [
{ {
"name": "Category", "name": "Category",

View file

@ -40,7 +40,7 @@ return [
'export_text' => 'Plain Text File', 'export_text' => 'Plain Text File',
'export_md' => 'Markdown File', 'export_md' => 'Markdown File',
'default_template' => 'Default Page Template', 'default_template' => 'Default Page Template',
'default_template_explain' => 'Assign a page template that will be used as the default content for all new pages in this book/chapter. Keep in mind this will only be used if the page creator has view access to those chosen template page.', 'default_template_explain' => 'Assign a page template that will be used as the default content for all pages created within this item. Keep in mind this will only be used if the page creator has view access to the chosen template page.',
'default_template_select' => 'Select a template page', 'default_template_select' => 'Select a template page',
// Permissions and restrictions // Permissions and restrictions

View file

@ -35,6 +35,7 @@ class ChaptersApiTest extends TestCase
{ {
$this->actingAsApiEditor(); $this->actingAsApiEditor();
$book = $this->entities->book(); $book = $this->entities->book();
$templatePage = $this->entities->templatePage();
$details = [ $details = [
'name' => 'My API chapter', 'name' => 'My API chapter',
'description' => 'A chapter created via the API', 'description' => 'A chapter created via the API',
@ -46,6 +47,7 @@ class ChaptersApiTest extends TestCase
], ],
], ],
'priority' => 15, 'priority' => 15,
'default_template_id' => $templatePage->id,
]; ];
$resp = $this->postJson($this->baseEndpoint, $details); $resp = $this->postJson($this->baseEndpoint, $details);
@ -147,6 +149,7 @@ class ChaptersApiTest extends TestCase
'name' => $page->name, 'name' => $page->name,
], ],
], ],
'default_template_id' => null,
]); ]);
$resp->assertJsonCount($chapter->pages()->count(), 'pages'); $resp->assertJsonCount($chapter->pages()->count(), 'pages');
} }
@ -155,6 +158,7 @@ class ChaptersApiTest extends TestCase
{ {
$this->actingAsApiEditor(); $this->actingAsApiEditor();
$chapter = $this->entities->chapter(); $chapter = $this->entities->chapter();
$templatePage = $this->entities->templatePage();
$details = [ $details = [
'name' => 'My updated API chapter', 'name' => 'My updated API chapter',
'description' => 'A chapter updated via the API', 'description' => 'A chapter updated via the API',
@ -165,6 +169,7 @@ class ChaptersApiTest extends TestCase
], ],
], ],
'priority' => 15, 'priority' => 15,
'default_template_id' => $templatePage->id,
]; ];
$resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details); $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);