mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Added sidebar highlighting and fixed code elements. Fixes #18
This commit is contained in:
14
app/Book.php
14
app/Book.php
@ -2,9 +2,7 @@
|
||||
|
||||
namespace Oxbow;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Book extends Model
|
||||
class Book extends Entity
|
||||
{
|
||||
|
||||
protected $fillable = ['name', 'description'];
|
||||
@ -29,16 +27,6 @@ class Book extends Model
|
||||
return $this->hasMany('Oxbow\Chapter');
|
||||
}
|
||||
|
||||
public function createdBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'created_by');
|
||||
}
|
||||
|
||||
public function updatedBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'updated_by');
|
||||
}
|
||||
|
||||
public function children()
|
||||
{
|
||||
$pages = $this->pages()->where('chapter_id', '=', 0)->get();
|
||||
|
@ -1,8 +1,7 @@
|
||||
<?php namespace Oxbow;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Chapter extends Model
|
||||
class Chapter extends Entity
|
||||
{
|
||||
|
||||
protected $fillable = ['name', 'description', 'priority', 'book_id'];
|
||||
@ -17,16 +16,6 @@ class Chapter extends Model
|
||||
return $this->hasMany('Oxbow\Page')->orderBy('priority', 'ASC');
|
||||
}
|
||||
|
||||
public function createdBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'created_by');
|
||||
}
|
||||
|
||||
public function updatedBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'updated_by');
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
|
||||
|
37
app/Entity.php
Normal file
37
app/Entity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Oxbow;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Entity extends Model
|
||||
{
|
||||
/**
|
||||
* Relation for the user that created this entity.
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function createdBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'created_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Relation for the user that updated this entity.
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function updatedBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'updated_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this entity to another given entity.
|
||||
* Matches by comparing class and id.
|
||||
* @param $entity
|
||||
* @return bool
|
||||
*/
|
||||
public function matches($entity)
|
||||
{
|
||||
return [get_class($this), $this->id] === [get_class($entity), $entity->id];
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ class BookController extends Controller
|
||||
public function show($slug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($slug);
|
||||
return view('books/show', ['book' => $book]);
|
||||
return view('books/show', ['book' => $book, 'current' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,7 +89,7 @@ class BookController extends Controller
|
||||
public function edit($slug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($slug);
|
||||
return view('books/edit', ['book' => $book]);
|
||||
return view('books/edit', ['book' => $book, 'current' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +121,7 @@ class BookController extends Controller
|
||||
public function showDelete($bookSlug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
return view('books/delete', ['book' => $book]);
|
||||
return view('books/delete', ['book' => $book, 'current' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ class ChapterController extends Controller
|
||||
public function create($bookSlug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
return view('chapters/create', ['book' => $book]);
|
||||
return view('chapters/create', ['book' => $book, 'current' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +74,7 @@ class ChapterController extends Controller
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
|
||||
return view('chapters/show', ['book' => $book, 'chapter' => $chapter]);
|
||||
return view('chapters/show', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,7 +88,7 @@ class ChapterController extends Controller
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
|
||||
return view('chapters/edit', ['book' => $book, 'chapter' => $chapter]);
|
||||
return view('chapters/edit', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,7 +120,7 @@ class ChapterController extends Controller
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
|
||||
return view('chapters/delete', ['book' => $book, 'chapter' => $chapter]);
|
||||
return view('chapters/delete', ['book' => $book, 'chapter' => $chapter, 'current' => $chapter]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +90,7 @@ class PageController extends Controller
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
||||
return view('pages/show', ['page' => $page, 'book' => $book]);
|
||||
return view('pages/show', ['page' => $page, 'book' => $book, 'current' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +104,7 @@ class PageController extends Controller
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
||||
return view('pages/edit', ['page' => $page, 'book' => $book]);
|
||||
return view('pages/edit', ['page' => $page, 'book' => $book, 'current' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,7 +157,7 @@ class PageController extends Controller
|
||||
public function sortPages($bookSlug)
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
return view('pages/sort', ['book' => $book]);
|
||||
return view('pages/sort', ['book' => $book, 'current' => $book]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,7 +200,7 @@ class PageController extends Controller
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
||||
return view('pages/delete', ['book' => $book, 'page' => $page]);
|
||||
return view('pages/delete', ['book' => $book, 'page' => $page, 'current' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -229,7 +229,7 @@ class PageController extends Controller
|
||||
{
|
||||
$book = $this->bookRepo->getBySlug($bookSlug);
|
||||
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
|
||||
return view('pages/revisions', ['page' => $page, 'book' => $book]);
|
||||
return view('pages/revisions', ['page' => $page, 'book' => $book, 'current' => $page]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,9 +2,8 @@
|
||||
|
||||
namespace Oxbow;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Image extends Model
|
||||
class Image extends Entity
|
||||
{
|
||||
|
||||
protected $fillable = ['name'];
|
||||
@ -14,13 +13,4 @@ class Image extends Model
|
||||
return storage_path() . $this->url;
|
||||
}
|
||||
|
||||
public function createdBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'created_by');
|
||||
}
|
||||
|
||||
public function updatedBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'updated_by');
|
||||
}
|
||||
}
|
||||
|
11
app/Page.php
11
app/Page.php
@ -4,7 +4,7 @@ namespace Oxbow;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Page extends Model
|
||||
class Page extends Entity
|
||||
{
|
||||
protected $fillable = ['name', 'html', 'priority'];
|
||||
|
||||
@ -32,15 +32,6 @@ class Page extends Model
|
||||
return $this->chapter()->count() > 0;
|
||||
}
|
||||
|
||||
public function createdBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'created_by');
|
||||
}
|
||||
|
||||
public function updatedBy()
|
||||
{
|
||||
return $this->belongsTo('Oxbow\User', 'updated_by');
|
||||
}
|
||||
|
||||
public function revisions()
|
||||
{
|
||||
|
Reference in New Issue
Block a user