Skip to content

Commit 4137cf9

Browse files
committed
Default chapter templates: Updated api docs and tests
Also applied minor tweaks to some wording and logic. During review of #4750
1 parent 4a8f702 commit 4137cf9

File tree

10 files changed

+46
-40
lines changed

10 files changed

+46
-40
lines changed

app/Api/ListingResponseBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function toResponse(): JsonResponse
6161
}
6262
});
6363

64+
dd($data->first());
65+
6466
return response()->json([
6567
'data' => $data,
6668
'total' => $total,

app/Entities/Repos/PageRepo.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,7 @@ public function getNewDraftPage(Entity $parent)
136136
$page->book_id = $parent->id;
137137
}
138138

139-
// check for chapter
140-
if ($page->chapter_id) {
141-
$defaultTemplate = $page->chapter->defaultTemplate;
142-
} else {
143-
$defaultTemplate = $page->book->defaultTemplate;
144-
}
145-
139+
$defaultTemplate = $page->chapter->defaultTemplate ?? $page->book->defaultTemplate;
146140
if ($defaultTemplate && userCan('view', $defaultTemplate)) {
147141
$page->forceFill([
148142
'html' => $defaultTemplate->html,
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
<?php
2-
3-
use Illuminate\Database\Migrations\Migration;
4-
use Illuminate\Database\Schema\Blueprint;
5-
use Illuminate\Support\Facades\Schema;
6-
7-
class AddDefaultTemplateToChapters extends Migration
8-
{
9-
/**
10-
* Run the migrations.
11-
*
12-
* @return void
13-
*/
14-
public function up()
15-
{
16-
Schema::table('chapters', function (Blueprint $table) {
17-
$table->integer('default_template_id')->nullable()->default(null);
18-
});
19-
}
20-
21-
/**
22-
* Reverse the migrations.
23-
*
24-
* @return void
25-
*/
26-
public function down()
27-
{
28-
Schema::table('chapters', function (Blueprint $table) {
29-
$table->dropColumn('default_template_id');
30-
});
31-
}
32-
}
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddDefaultTemplateToChapters extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('chapters', function (Blueprint $table) {
17+
$table->integer('default_template_id')->nullable()->default(null);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('chapters', function (Blueprint $table) {
29+
$table->dropColumn('default_template_id');
30+
});
31+
}
32+
}

dev/api/requests/chapters-create.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"name": "My fantastic new chapter",
44
"description_html": "<p>This is a <strong>great new chapter</strong> that I've created via the API</p>",
55
"priority": 15,
6+
"default_template_id": 25,
67
"tags": [
78
{"name": "Category", "value": "Top Content"},
89
{"name": "Rating", "value": "Highest"}

dev/api/requests/chapters-update.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"name": "My fantastic updated chapter",
44
"description_html": "<p>This is an <strong>updated chapter</strong> that I've altered via the API</p>",
55
"priority": 16,
6+
"default_template_id": 2428,
67
"tags": [
78
{"name": "Category", "value": "Kinda Good Content"},
89
{"name": "Rating", "value": "Medium"}

dev/api/responses/chapters-create.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"updated_by": 1,
1212
"owned_by": 1,
1313
"description_html": "<p>This is a <strong>great new chapter<\/strong> that I've created via the API<\/p>",
14+
"default_template_id": 25,
1415
"tags": [
1516
{
1617
"name": "Category",

dev/api/responses/chapters-read.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"name": "Content Creation",
66
"description": "How to create documentation on whatever subject you need to write about.",
77
"description_html": "<p>How to create <strong>documentation</strong> on whatever subject you need to write about.</p>",
8+
"default_template_id": 25,
89
"priority": 3,
910
"created_at": "2019-05-05T21:49:56.000000Z",
1011
"updated_at": "2019-09-28T11:24:23.000000Z",

dev/api/responses/chapters-update.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"updated_by": 1,
1212
"owned_by": 1,
1313
"description_html": "<p>This is an <strong>updated chapter<\/strong> that I've altered via the API<\/p>",
14+
"default_template_id": 2428,
1415
"tags": [
1516
{
1617
"name": "Category",

lang/en/entities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'export_text' => 'Plain Text File',
4141
'export_md' => 'Markdown File',
4242
'default_template' => 'Default Page Template',
43-
'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.',
43+
'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.',
4444
'default_template_select' => 'Select a template page',
4545

4646
// Permissions and restrictions

tests/Api/ChaptersApiTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function test_create_endpoint()
3535
{
3636
$this->actingAsApiEditor();
3737
$book = $this->entities->book();
38+
$templatePage = $this->entities->templatePage();
3839
$details = [
3940
'name' => 'My API chapter',
4041
'description' => 'A chapter created via the API',
@@ -46,6 +47,7 @@ public function test_create_endpoint()
4647
],
4748
],
4849
'priority' => 15,
50+
'default_template_id' => $templatePage->id,
4951
];
5052

5153
$resp = $this->postJson($this->baseEndpoint, $details);
@@ -147,6 +149,7 @@ public function test_read_endpoint()
147149
'name' => $page->name,
148150
],
149151
],
152+
'default_template_id' => null,
150153
]);
151154
$resp->assertJsonCount($chapter->pages()->count(), 'pages');
152155
}
@@ -155,6 +158,7 @@ public function test_update_endpoint()
155158
{
156159
$this->actingAsApiEditor();
157160
$chapter = $this->entities->chapter();
161+
$templatePage = $this->entities->templatePage();
158162
$details = [
159163
'name' => 'My updated API chapter',
160164
'description' => 'A chapter updated via the API',
@@ -165,6 +169,7 @@ public function test_update_endpoint()
165169
],
166170
],
167171
'priority' => 15,
172+
'default_template_id' => $templatePage->id,
168173
];
169174

170175
$resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);

0 commit comments

Comments
 (0)