mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Expanded chapters interface and improved book/page deletion
This commit is contained in:
@ -78,8 +78,7 @@ class BookController extends Controller
|
||||
public function show($slug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($slug);
|
||||
$pageTree = $this->pageRepo->getTreeByBookId($book->id);
|
||||
return view('books/show', ['book' => $book, 'pageTree' => $pageTree]);
|
||||
return view('books/show', ['book' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,15 +117,26 @@ class BookController extends Controller
|
||||
return redirect($book->getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the page to confirm deletion
|
||||
* @param $bookSlug
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showDelete($bookSlug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
return view('books/delete', ['book' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified book from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param $bookSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy($bookSlug)
|
||||
{
|
||||
$this->bookRepo->destroyById($id);
|
||||
$this->bookRepo->destroyBySlug($bookSlug);
|
||||
return redirect('/books');
|
||||
}
|
||||
}
|
||||
|
@ -25,20 +25,10 @@ class ChapterController extends Controller
|
||||
$this->bookRepo = $bookRepo;
|
||||
$this->chapterRepo = $chapterRepo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* Show the form for creating a new chapter.
|
||||
*
|
||||
* @param $bookSlug
|
||||
* @return Response
|
||||
@ -50,7 +40,7 @@ class ChapterController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* Store a newly created chapter in storage.
|
||||
*
|
||||
* @param $bookSlug
|
||||
* @param Request $request
|
||||
@ -65,52 +55,88 @@ class ChapterController extends Controller
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->newFromInput($request->all());
|
||||
$chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id);
|
||||
$chapter->priority = $this->bookRepo->getNewPriority($book);
|
||||
$book->chapters()->save($chapter);
|
||||
return redirect($book->getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
* Display the specified chapter.
|
||||
*
|
||||
* @param int $id
|
||||
* @param $bookSlug
|
||||
* @param $chapterSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function show($id)
|
||||
public function show($bookSlug, $chapterSlug)
|
||||
{
|
||||
//
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
|
||||
return view('chapters/show', ['book' => $book, 'chapter' => $chapter]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* Show the form for editing the specified chapter.
|
||||
*
|
||||
* @param int $id
|
||||
* @param $bookSlug
|
||||
* @param $chapterSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit($bookSlug, $chapterSlug)
|
||||
{
|
||||
//
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
|
||||
return view('chapters/edit', ['book' => $book, 'chapter' => $chapter]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* Update the specified chapter in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @param Request $request
|
||||
* @param $bookSlug
|
||||
* @param $chapterSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, $bookSlug, $chapterSlug)
|
||||
{
|
||||
//
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
|
||||
$chapter->fill($request->all());
|
||||
$chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id, $chapter->id);
|
||||
$chapter->save();
|
||||
return redirect($chapter->getUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* Shows the page to confirm deletion of this chapter.
|
||||
* @param $bookSlug
|
||||
* @param $chapterSlug
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showDelete($bookSlug, $chapterSlug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
|
||||
return view('chapters/delete', ['book' => $book, 'chapter' => $chapter]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified chapter from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param $bookSlug
|
||||
* @param $chapterSlug
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy($bookSlug, $chapterSlug)
|
||||
{
|
||||
//
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
|
||||
if(count($chapter->pages) > 0) {
|
||||
foreach($chapter->pages as $page) {
|
||||
$page->chapter_id = 0;
|
||||
$page->save();
|
||||
}
|
||||
}
|
||||
$chapter->delete();
|
||||
return redirect($book->getUrl());
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ class PageController extends Controller
|
||||
$this->validate($request, [
|
||||
'name' => 'required|string|max:255',
|
||||
'html' => 'required|string',
|
||||
'priority' => 'integer',
|
||||
'parent' => 'integer|exists:pages,id'
|
||||
]);
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
@ -72,7 +71,8 @@ class PageController extends Controller
|
||||
while($this->pageRepo->countBySlug($slug, $book->id) > 0) {
|
||||
$slug .= '1';
|
||||
}
|
||||
$page->slug =$slug;
|
||||
$page->slug = $slug;
|
||||
$page->priority = $this->bookRepo->getNewPriority($book);
|
||||
|
||||
if($request->has('parent')) {
|
||||
$page->page_id = $request->get('parent');
|
||||
@ -96,9 +96,8 @@ class PageController extends Controller
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
||||
$breadCrumbs = $this->pageRepo->getBreadCrumbs($page);
|
||||
$sidebarBookTree = $this->bookRepo->getTree($book, $page->id);
|
||||
//dd($sidebarBookTree);
|
||||
return view('pages/show', ['page' => $page, 'breadCrumbs' => $breadCrumbs, 'book' => $book, 'sidebarBookTree' => $sidebarBookTree]);
|
||||
return view('pages/show', ['page' => $page, 'breadCrumbs' => $breadCrumbs, 'book' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,14 +186,26 @@ class PageController extends Controller
|
||||
return redirect($book->getUrl());
|
||||
}
|
||||
|
||||
public function showDelete($bookSlug, $pageSlug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
||||
return view('pages/delete', ['book' => $book, 'page' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param $bookSlug
|
||||
* @param $pageSlug
|
||||
* @return Response
|
||||
* @internal param int $id
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy($bookSlug, $pageSlug)
|
||||
{
|
||||
//
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
||||
$page->delete();
|
||||
return redirect($book->getUrl());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user