mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Merge pull request #1527 from BookStackApp/129-page-templates
Page Templates Implementation
This commit is contained in:
@ -110,11 +110,14 @@ class PageController extends Controller
|
||||
$this->setPageTitle(trans('entities.pages_edit_draft'));
|
||||
|
||||
$draftsEnabled = $this->signedIn;
|
||||
$templates = $this->pageRepo->getPageTemplates(10);
|
||||
|
||||
return view('pages.edit', [
|
||||
'page' => $draft,
|
||||
'book' => $draft->book,
|
||||
'isDraft' => true,
|
||||
'draftsEnabled' => $draftsEnabled
|
||||
'draftsEnabled' => $draftsEnabled,
|
||||
'templates' => $templates,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -239,11 +242,14 @@ class PageController extends Controller
|
||||
}
|
||||
|
||||
$draftsEnabled = $this->signedIn;
|
||||
$templates = $this->pageRepo->getPageTemplates(10);
|
||||
|
||||
return view('pages.edit', [
|
||||
'page' => $page,
|
||||
'book' => $page->book,
|
||||
'current' => $page,
|
||||
'draftsEnabled' => $draftsEnabled
|
||||
'draftsEnabled' => $draftsEnabled,
|
||||
'templates' => $templates,
|
||||
]);
|
||||
}
|
||||
|
||||
|
63
app/Http/Controllers/PageTemplateController.php
Normal file
63
app/Http/Controllers/PageTemplateController.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace BookStack\Http\Controllers;
|
||||
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PageTemplateController extends Controller
|
||||
{
|
||||
protected $pageRepo;
|
||||
|
||||
/**
|
||||
* PageTemplateController constructor.
|
||||
* @param $pageRepo
|
||||
*/
|
||||
public function __construct(PageRepo $pageRepo)
|
||||
{
|
||||
$this->pageRepo = $pageRepo;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a list of templates from the system.
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function list(Request $request)
|
||||
{
|
||||
$page = $request->get('page', 1);
|
||||
$search = $request->get('search', '');
|
||||
$templates = $this->pageRepo->getPageTemplates(10, $page, $search);
|
||||
|
||||
if ($search) {
|
||||
$templates->appends(['search' => $search]);
|
||||
}
|
||||
|
||||
return view('pages.template-manager-list', [
|
||||
'templates' => $templates
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of a template.
|
||||
* @param $templateId
|
||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function get($templateId)
|
||||
{
|
||||
$page = $this->pageRepo->getById('page', $templateId);
|
||||
|
||||
if (!$page->template) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'html' => $page->html,
|
||||
'markdown' => $page->markdown,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user