mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-23 03:12:32 +01:00
Default Templates: Started review and updates from PR code
This commit is contained in:
parent
968bc8cdf3
commit
d61f42a377
@ -7,7 +7,6 @@ use BookStack\Activity\ActivityType;
|
|||||||
use BookStack\Activity\Models\View;
|
use BookStack\Activity\Models\View;
|
||||||
use BookStack\Activity\Tools\UserEntityWatchOptions;
|
use BookStack\Activity\Tools\UserEntityWatchOptions;
|
||||||
use BookStack\Entities\Models\Bookshelf;
|
use BookStack\Entities\Models\Bookshelf;
|
||||||
use BookStack\Entities\Models\Page;
|
|
||||||
use BookStack\Entities\Repos\BookRepo;
|
use BookStack\Entities\Repos\BookRepo;
|
||||||
use BookStack\Entities\Tools\BookContents;
|
use BookStack\Entities\Tools\BookContents;
|
||||||
use BookStack\Entities\Tools\Cloner;
|
use BookStack\Entities\Tools\Cloner;
|
||||||
@ -25,15 +24,11 @@ use Throwable;
|
|||||||
|
|
||||||
class BookController extends Controller
|
class BookController extends Controller
|
||||||
{
|
{
|
||||||
protected BookRepo $bookRepo;
|
public function __construct(
|
||||||
protected ShelfContext $shelfContext;
|
protected ShelfContext $shelfContext,
|
||||||
protected ReferenceFetcher $referenceFetcher;
|
protected BookRepo $bookRepo,
|
||||||
|
protected ReferenceFetcher $referenceFetcher
|
||||||
public function __construct(ShelfContext $entityContextManager, BookRepo $bookRepo, ReferenceFetcher $referenceFetcher)
|
) {
|
||||||
{
|
|
||||||
$this->bookRepo = $bookRepo;
|
|
||||||
$this->shelfContext = $entityContextManager;
|
|
||||||
$this->referenceFetcher = $referenceFetcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,14 +77,8 @@ class BookController extends Controller
|
|||||||
|
|
||||||
$this->setPageTitle(trans('entities.books_create'));
|
$this->setPageTitle(trans('entities.books_create'));
|
||||||
|
|
||||||
$templates = Page::visible()
|
|
||||||
->where('template', '=', true)
|
|
||||||
->orderBy('name', 'asc')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return view('books.create', [
|
return view('books.create', [
|
||||||
'bookshelf' => $bookshelf,
|
'bookshelf' => $bookshelf,
|
||||||
'templates' => $templates,
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +96,7 @@ class BookController extends Controller
|
|||||||
'description' => ['string', 'max:1000'],
|
'description' => ['string', 'max:1000'],
|
||||||
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
|
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
|
||||||
'tags' => ['array'],
|
'tags' => ['array'],
|
||||||
'default_template' => ['nullable', 'exists:pages,id'],
|
'default_template' => ['nullable', 'integer'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$bookshelf = null;
|
$bookshelf = null;
|
||||||
@ -162,12 +151,7 @@ class BookController extends Controller
|
|||||||
$this->checkOwnablePermission('book-update', $book);
|
$this->checkOwnablePermission('book-update', $book);
|
||||||
$this->setPageTitle(trans('entities.books_edit_named', ['bookName' => $book->getShortName()]));
|
$this->setPageTitle(trans('entities.books_edit_named', ['bookName' => $book->getShortName()]));
|
||||||
|
|
||||||
$templates = Page::visible()
|
return view('books.edit', ['book' => $book, 'current' => $book]);
|
||||||
->where('template', '=', true)
|
|
||||||
->orderBy('name', 'asc')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return view('books.edit', ['book' => $book, 'current' => $book, 'templates' => $templates]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,7 +171,7 @@ class BookController extends Controller
|
|||||||
'description' => ['string', 'max:1000'],
|
'description' => ['string', 'max:1000'],
|
||||||
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
|
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
|
||||||
'tags' => ['array'],
|
'tags' => ['array'],
|
||||||
'default_template' => ['nullable', 'exists:pages,id'],
|
'default_template' => ['nullable', 'integer'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->has('image_reset')) {
|
if ($request->has('image_reset')) {
|
||||||
|
@ -259,13 +259,13 @@ class PageController extends Controller
|
|||||||
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
|
||||||
$this->checkOwnablePermission('page-delete', $page);
|
$this->checkOwnablePermission('page-delete', $page);
|
||||||
$this->setPageTitle(trans('entities.pages_delete_named', ['pageName' => $page->getShortName()]));
|
$this->setPageTitle(trans('entities.pages_delete_named', ['pageName' => $page->getShortName()]));
|
||||||
$times_used_as_template = Book::where('default_template', '=', $page->id)->count();
|
$usedAsTemplate = Book::query()->where('default_template', '=', $page->id)->count() > 0;
|
||||||
|
|
||||||
return view('pages.delete', [
|
return view('pages.delete', [
|
||||||
'book' => $page->book,
|
'book' => $page->book,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'current' => $page,
|
'current' => $page,
|
||||||
'times_used_as_template' => $times_used_as_template,
|
'usedAsTemplate' => $usedAsTemplate,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ use Illuminate\Support\Collection;
|
|||||||
* @property \Illuminate\Database\Eloquent\Collection $pages
|
* @property \Illuminate\Database\Eloquent\Collection $pages
|
||||||
* @property \Illuminate\Database\Eloquent\Collection $directPages
|
* @property \Illuminate\Database\Eloquent\Collection $directPages
|
||||||
* @property \Illuminate\Database\Eloquent\Collection $shelves
|
* @property \Illuminate\Database\Eloquent\Collection $shelves
|
||||||
|
* @property ?Page $defaultTemplate
|
||||||
*/
|
*/
|
||||||
class Book extends Entity implements HasCoverImage
|
class Book extends Entity implements HasCoverImage
|
||||||
{
|
{
|
||||||
@ -27,7 +28,7 @@ class Book extends Entity implements HasCoverImage
|
|||||||
|
|
||||||
public $searchFactor = 1.2;
|
public $searchFactor = 1.2;
|
||||||
|
|
||||||
protected $fillable = ['name', 'description', 'default_template'];
|
protected $fillable = ['name', 'description'];
|
||||||
protected $hidden = ['pivot', 'image_id', 'deleted_at'];
|
protected $hidden = ['pivot', 'image_id', 'deleted_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,9 +136,11 @@ class PageRepo
|
|||||||
$page->book_id = $parent->id;
|
$page->book_id = $parent->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($page->book->defaultTemplate) {
|
$defaultTemplate = $page->book->defaultTemplate;
|
||||||
|
if ($defaultTemplate && userCan('view', $defaultTemplate)) {
|
||||||
$page->forceFill([
|
$page->forceFill([
|
||||||
'html' => $page->book->defaultTemplate->html,
|
'html' => $defaultTemplate->html,
|
||||||
|
'markdown' => $defaultTemplate->markdown,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +132,8 @@ return [
|
|||||||
'books_edit_named' => 'Edit Book :bookName',
|
'books_edit_named' => 'Edit Book :bookName',
|
||||||
'books_form_book_name' => 'Book Name',
|
'books_form_book_name' => 'Book Name',
|
||||||
'books_save' => 'Save Book',
|
'books_save' => 'Save Book',
|
||||||
|
'books_default_template' => 'Default Page Template',
|
||||||
|
'books_default_template_explain' => 'Assign a default template that will be used for all new pages in this book. Keep in mind this will only be used if the page creator has view access to those chosen template.',
|
||||||
'books_permissions' => 'Book Permissions',
|
'books_permissions' => 'Book Permissions',
|
||||||
'books_permissions_updated' => 'Book Permissions Updated',
|
'books_permissions_updated' => 'Book Permissions Updated',
|
||||||
'books_empty_contents' => 'No pages or chapters have been created for this book.',
|
'books_empty_contents' => 'No pages or chapters have been created for this book.',
|
||||||
@ -204,7 +206,7 @@ return [
|
|||||||
'pages_delete_draft' => 'Delete Draft Page',
|
'pages_delete_draft' => 'Delete Draft Page',
|
||||||
'pages_delete_success' => 'Page deleted',
|
'pages_delete_success' => 'Page deleted',
|
||||||
'pages_delete_draft_success' => 'Draft page deleted',
|
'pages_delete_draft_success' => 'Draft page deleted',
|
||||||
'pages_delete_warning_template' => '{0}|{1}Be careful: this page is used as a template for :count book.|[2,*]Be careful: this page is used as a template for :count books.',
|
'pages_delete_warning_template' => 'This page is in active use as a book default page template. These books will no longer have a page default template assigned after this page is deleted.',
|
||||||
'pages_delete_confirm' => 'Are you sure you want to delete this page?',
|
'pages_delete_confirm' => 'Are you sure you want to delete this page?',
|
||||||
'pages_delete_draft_confirm' => 'Are you sure you want to delete this draft page?',
|
'pages_delete_draft_confirm' => 'Are you sure you want to delete this draft page?',
|
||||||
'pages_editing_named' => 'Editing Page :pageName',
|
'pages_editing_named' => 'Editing Page :pageName',
|
||||||
@ -351,8 +353,6 @@ return [
|
|||||||
'templates_replace_content' => 'Replace page content',
|
'templates_replace_content' => 'Replace page content',
|
||||||
'templates_append_content' => 'Append to page content',
|
'templates_append_content' => 'Append to page content',
|
||||||
'templates_prepend_content' => 'Prepend to page content',
|
'templates_prepend_content' => 'Prepend to page content',
|
||||||
'default_template' => 'Default Page Template',
|
|
||||||
'default_template_explain' => "Assign a default template that will be used for all new pages in this book.",
|
|
||||||
|
|
||||||
// Profile View
|
// Profile View
|
||||||
'profile_user_for_x' => 'User for :time',
|
'profile_user_for_x' => 'User for :time',
|
||||||
|
@ -27,10 +27,9 @@
|
|||||||
|
|
||||||
<main class="content-wrap card">
|
<main class="content-wrap card">
|
||||||
<h1 class="list-heading">{{ trans('entities.books_create') }}</h1>
|
<h1 class="list-heading">{{ trans('entities.books_create') }}</h1>
|
||||||
<form action="{{ isset($bookshelf) ? $bookshelf->getUrl('/create-book') : url('/books') }}" method="POST" enctype="multipart/form-data">
|
<form action="{{ $bookshelf?->getUrl('/create-book') ?? url('/books') }}" method="POST" enctype="multipart/form-data">
|
||||||
@include('books.parts.form', [
|
@include('books.parts.form', [
|
||||||
'templates' => $templates,
|
'returnLocation' => $bookshelf?->getUrl() ?? url('/books')
|
||||||
'returnLocation' => isset($bookshelf) ? $bookshelf->getUrl() : url('/books')
|
|
||||||
])
|
])
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
<input type="hidden" name="_method" value="PUT">
|
<input type="hidden" name="_method" value="PUT">
|
||||||
@include('books.parts.form', [
|
@include('books.parts.form', [
|
||||||
'model' => $book,
|
'model' => $book,
|
||||||
'templates' => $templates,
|
|
||||||
'returnLocation' => $book->getUrl()
|
'returnLocation' => $book->getUrl()
|
||||||
])
|
])
|
||||||
</form>
|
</form>
|
||||||
|
@ -37,10 +37,10 @@
|
|||||||
|
|
||||||
<div class="form-group collapsible" component="collapsible" id="template-control">
|
<div class="form-group collapsible" component="collapsible" id="template-control">
|
||||||
<button refs="collapsible@trigger" type="button" class="collapse-title text-primary" aria-expanded="false">
|
<button refs="collapsible@trigger" type="button" class="collapse-title text-primary" aria-expanded="false">
|
||||||
<label for="template-manager">{{ trans('entities.default_template') }}</label>
|
<label for="template-manager">{{ trans('entities.books_default_template') }}</label>
|
||||||
</button>
|
</button>
|
||||||
<div refs="collapsible@content" class="collapse-content">
|
<div refs="collapsible@content" class="collapse-content">
|
||||||
@include('entities.template-manager', ['entity' => $book ?? null, 'templates' => $templates])
|
@include('books.parts.template-selector', ['entity' => $book ?? null, 'templates' => []])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<p class="text-muted small">
|
<p class="text-muted small">
|
||||||
{!! nl2br(e(trans('entities.default_template_explain'))) !!}
|
{{ trans('entities.books_default_template_explain') }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<select name="default_template" id="default_template">
|
<select name="default_template" id="default_template">
|
||||||
@ -8,3 +8,6 @@
|
|||||||
<option @if(isset($entity) && $entity->default_template === $template->id) selected @endif value="{{ $template->id }}">{{ $template->name }}</option>
|
<option @if(isset($entity) && $entity->default_template === $template->id) selected @endif value="{{ $template->id }}">{{ $template->name }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
@include('settings.parts.page-picker', ['name' => 'setting-app-homepage', 'placeholder' => trans('settings.app_homepage_select'), 'value' => setting('app-homepage')])
|
@ -19,8 +19,8 @@
|
|||||||
<div class="card content-wrap auto-height">
|
<div class="card content-wrap auto-height">
|
||||||
<h1 class="list-heading">{{ $page->draft ? trans('entities.pages_delete_draft') : trans('entities.pages_delete') }}</h1>
|
<h1 class="list-heading">{{ $page->draft ? trans('entities.pages_delete_draft') : trans('entities.pages_delete') }}</h1>
|
||||||
|
|
||||||
@if ($times_used_as_template > 0)
|
@if($usedAsTemplate)
|
||||||
<p>{{ trans_choice('entities.pages_delete_warning_template', $times_used_as_template) }}</p>
|
<p>{{ trans('entities.pages_delete_warning_template') }}</p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<div class="grid half v-center">
|
<div class="grid half v-center">
|
||||||
|
Loading…
Reference in New Issue
Block a user