Skip to content

Commit c0dff6d

Browse files
committed
ZIP Imports: Added book content ordering to import preview
1 parent 59cfc08 commit c0dff6d

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

app/Exports/ZipExports/Models/ZipExportBook.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ public function metadataOnly(): void
3636
}
3737
}
3838

39+
public function children(): array
40+
{
41+
$children = [
42+
...$this->pages,
43+
...$this->chapters,
44+
];
45+
46+
usort($children, function ($a, $b) {
47+
return ($a->priority ?? 0) - ($b->priority ?? 0);
48+
});
49+
50+
return $children;
51+
}
52+
3953
public static function fromModel(Book $model, ZipExportFiles $files): self
4054
{
4155
$instance = new self();

app/Exports/ZipExports/Models/ZipExportChapter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ZipExportChapter extends ZipExportModel
2020

2121
public function metadataOnly(): void
2222
{
23-
$this->description_html = $this->priority = null;
23+
$this->description_html = null;
2424

2525
foreach ($this->pages as $page) {
2626
$page->metadataOnly();
@@ -30,6 +30,11 @@ public function metadataOnly(): void
3030
}
3131
}
3232

33+
public function children(): array
34+
{
35+
return $this->pages;
36+
}
37+
3338
public static function fromModel(Chapter $model, ZipExportFiles $files): self
3439
{
3540
$instance = new self();

app/Exports/ZipExports/Models/ZipExportPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ZipExportPage extends ZipExportModel
2323

2424
public function metadataOnly(): void
2525
{
26-
$this->html = $this->markdown = $this->priority = null;
26+
$this->html = $this->markdown = null;
2727

2828
foreach ($this->attachments as $attachment) {
2929
$attachment->metadataOnly();

app/Exports/ZipExports/ZipExportReader.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use BookStack\Exceptions\ZipExportException;
66
use BookStack\Exports\ZipExports\Models\ZipExportBook;
77
use BookStack\Exports\ZipExports\Models\ZipExportChapter;
8-
use BookStack\Exports\ZipExports\Models\ZipExportModel;
98
use BookStack\Exports\ZipExports\Models\ZipExportPage;
109
use BookStack\Util\WebSafeMimeSniffer;
1110
use ZipArchive;

resources/views/exports/parts/import-item.blade.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
<span>@icon('tag'){{ count($model->tags) }}</span>
1717
@endif
1818
</div>
19-
@foreach($model->chapters ?? [] as $chapter)
20-
@include('exports.parts.import-item', ['type' => 'chapter', 'model' => $chapter])
21-
@endforeach
22-
@foreach($model->pages ?? [] as $page)
23-
@include('exports.parts.import-item', ['type' => 'page', 'model' => $page])
24-
@endforeach
19+
@if(method_exists($model, 'children'))
20+
@foreach($model->children() as $child)
21+
@include('exports.parts.import-item', [
22+
'type' => ($child instanceof \BookStack\Exports\ZipExports\Models\ZipExportPage) ? 'page' : 'chapter',
23+
'model' => $child
24+
])
25+
@endforeach
26+
@endif
2527
</div>
2628
</div>

0 commit comments

Comments
 (0)