mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Played around with a new app structure
This commit is contained in:
58
app/Entities/Controllers/PageTemplateController.php
Normal file
58
app/Entities/Controllers/PageTemplateController.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace BookStack\Entities\Controllers;
|
||||
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
use BookStack\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PageTemplateController extends Controller
|
||||
{
|
||||
protected $pageRepo;
|
||||
|
||||
/**
|
||||
* PageTemplateController constructor.
|
||||
*/
|
||||
public function __construct(PageRepo $pageRepo)
|
||||
{
|
||||
$this->pageRepo = $pageRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a list of templates from the system.
|
||||
*/
|
||||
public function list(Request $request)
|
||||
{
|
||||
$page = $request->get('page', 1);
|
||||
$search = $request->get('search', '');
|
||||
$templates = $this->pageRepo->getTemplates(10, $page, $search);
|
||||
|
||||
if ($search) {
|
||||
$templates->appends(['search' => $search]);
|
||||
}
|
||||
|
||||
return view('pages.parts.template-manager-list', [
|
||||
'templates' => $templates,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of a template.
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function get(int $templateId)
|
||||
{
|
||||
$page = $this->pageRepo->getById($templateId);
|
||||
|
||||
if (!$page->template) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'html' => $page->html,
|
||||
'markdown' => $page->markdown,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user