diff --git a/app/Book.php b/app/Book.php index cdd512c97..cdad27879 100644 --- a/app/Book.php +++ b/app/Book.php @@ -24,4 +24,17 @@ class Book extends Model return $this->hasMany('Oxbow\Page'); } + public function chapters() + { + return $this->hasMany('Oxbow\Chapter'); + } + + public function children() + { + $pages = $this->pages()->get(); + $chapters = $this->chapters()->get(); + $children = $pages->merge($chapters); + return $children->sortBy('priority'); + } + } diff --git a/app/Chapter.php b/app/Chapter.php new file mode 100644 index 000000000..f4e9dce66 --- /dev/null +++ b/app/Chapter.php @@ -0,0 +1,25 @@ +belongsTo('Oxbow\Book'); + } + + public function children() + { + return $this->hasMany('Oxbow\Page')->orderBy('priority', 'ASC'); + } + + public function getUrl() + { + return '/books/' . $this->book->slug . '/chapter/' . $this->slug; + } + +} diff --git a/app/Http/Controllers/BookController.php b/app/Http/Controllers/BookController.php index 03954fc51..fcb8c7752 100644 --- a/app/Http/Controllers/BookController.php +++ b/app/Http/Controllers/BookController.php @@ -79,7 +79,6 @@ class BookController extends Controller { $book = $this->bookRepo->getBySlug($slug); $pageTree = $this->pageRepo->getTreeByBookId($book->id); - // dd($pageTree); return view('books/show', ['book' => $book, 'pageTree' => $pageTree]); } diff --git a/app/Http/Controllers/ChapterController.php b/app/Http/Controllers/ChapterController.php new file mode 100644 index 000000000..e7d1f1799 --- /dev/null +++ b/app/Http/Controllers/ChapterController.php @@ -0,0 +1,116 @@ +bookRepo = $bookRepo; + $this->chapterRepo = $chapterRepo; + } + + + /** + * Display a listing of the resource. + * + * @return Response + */ + public function index() + { + // + } + + /** + * Show the form for creating a new resource. + * + * @param $bookSlug + * @return Response + */ + public function create($bookSlug) + { + $book = $this->bookRepo->getBySlug($bookSlug); + return view('chapters/create', ['book' => $book]); + } + + /** + * Store a newly created resource in storage. + * + * @param $bookSlug + * @param Request $request + * @return Response + */ + public function store($bookSlug, Request $request) + { + $this->validate($request, [ + 'name' => 'required|string|max:255' + ]); + + $book = $this->bookRepo->getBySlug($bookSlug); + $chapter = $this->chapterRepo->newFromInput($request->all()); + $chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id); + $book->chapters()->save($chapter); + return redirect($book->getUrl()); + } + + /** + * Display the specified resource. + * + * @param int $id + * @return Response + */ + public function show($id) + { + // + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return Response + */ + public function edit($id) + { + // + } + + /** + * Update the specified resource in storage. + * + * @param Request $request + * @param int $id + * @return Response + */ + public function update(Request $request, $id) + { + // + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return Response + */ + public function destroy($id) + { + // + } +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 0dd0226a2..8204599f5 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -26,10 +26,14 @@ Route::group(['prefix' => 'books'], function() { Route::post('/{bookSlug}/page', 'PageController@store'); Route::get('/{bookSlug}/sort', 'PageController@sortPages'); Route::put('/{bookSlug}/sort', 'PageController@savePageSort'); - Route::get('/{bookSlug}/{pageSlug}', 'PageController@show'); - Route::get('/{bookSlug}/{pageSlug}/create', 'PageController@create'); - Route::get('/{bookSlug}/{pageSlug}/edit', 'PageController@edit'); - Route::put('/{bookSlug}/{pageSlug}', 'PageController@update'); + Route::get('/{bookSlug}/page/{pageSlug}', 'PageController@show'); + Route::get('/{bookSlug}/page/{pageSlug}/create', 'PageController@create'); + Route::get('/{bookSlug}/page/{pageSlug}/edit', 'PageController@edit'); + Route::put('/{bookSlug}/page/{pageSlug}', 'PageController@update'); + + Route::get('/{bookSlug}/chapter/create', 'ChapterController@create'); + Route::post('/{bookSlug}/chapter/create', 'ChapterController@store'); + }); Route::post('/upload/image', 'ImageController@upload'); diff --git a/app/Page.php b/app/Page.php index 819b14024..53cfc9ada 100644 --- a/app/Page.php +++ b/app/Page.php @@ -34,7 +34,7 @@ class Page extends Model public function getUrl() { - return '/books/' . $this->book->slug . '/' . $this->slug; + return '/books/' . $this->book->slug . '/page/' . $this->slug; } } diff --git a/app/Repos/ChapterRepo.php b/app/Repos/ChapterRepo.php new file mode 100644 index 000000000..7cf1db2ce --- /dev/null +++ b/app/Repos/ChapterRepo.php @@ -0,0 +1,65 @@ +chapter = $chapter; + } + + public function getById($id) + { + return $this->chapter->findOrFail($id); + } + + public function getAll() + { + return $this->chapter->all(); + } + + public function getBySlug($slug, $bookId) + { + return $this->chapter->where('slug', '=', $slug)->where('book_id', '=', $bookId)->first(); + } + + public function newFromInput($input) + { + return $this->chapter->fill($input); + } + + public function destroyById($id) + { + $page = $this->getById($id); + $page->delete(); + } + + public function doesSlugExist($slug, $bookId, $currentId = false) + { + $query = $this->chapter->where('slug', '=', $slug)->where('book_id', '=', $bookId); + if($currentId) { + $query = $query->where('id', '!=', $currentId); + } + return $query->count() > 0; + } + + public function findSuitableSlug($name, $bookId) + { + $slug = Str::slug($name); + while($this->doesSlugExist($slug, $bookId)) { + $slug .= '-' . substr(md5(rand(1, 500)), 0, 3); + } + return $slug; + } + +} \ No newline at end of file diff --git a/app/Repos/PageRepo.php b/app/Repos/PageRepo.php index 0e2f136be..897c9ff77 100644 --- a/app/Repos/PageRepo.php +++ b/app/Repos/PageRepo.php @@ -114,7 +114,7 @@ class PageRepo */ private function getTopLevelPages($bookId) { - return $this->page->where('book_id', '=', $bookId)->where('page_id', '=', 0)->orderBy('priority')->get(); + return $this->page->where('book_id', '=', $bookId)->where('chapter_id', '=', 0)->orderBy('priority')->get(); } /** diff --git a/database/migrations/2015_07_12_190027_create_pages_table.php b/database/migrations/2015_07_12_190027_create_pages_table.php index d42166db3..b7b1dc130 100644 --- a/database/migrations/2015_07_12_190027_create_pages_table.php +++ b/database/migrations/2015_07_12_190027_create_pages_table.php @@ -15,7 +15,7 @@ class CreatePagesTable extends Migration Schema::create('pages', function (Blueprint $table) { $table->increments('id'); $table->integer('book_id'); - $table->integer('page_id'); + $table->integer('chapter_id'); $table->string('name'); $table->string('slug')->indexed(); $table->longText('html'); diff --git a/database/migrations/2015_07_27_172342_create_chapters_table.php b/database/migrations/2015_07_27_172342_create_chapters_table.php new file mode 100644 index 000000000..5467e63f2 --- /dev/null +++ b/database/migrations/2015_07_27_172342_create_chapters_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->integer('book_id'); + $table->string('slug')->indexed(); + $table->text('name'); + $table->text('description'); + $table->integer('priority'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('chapters'); + } +} diff --git a/gulpfile.js b/gulpfile.js index 1da6e0497..f5d59ff8e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,5 @@ var elixir = require('laravel-elixir'); -require('laravel-elixir-livereload'); +//require('laravel-elixir-livereload'); /* |-------------------------------------------------------------------------- @@ -13,5 +13,5 @@ require('laravel-elixir-livereload'); */ elixir(function(mix) { - mix.sass('styles.scss').livereload(); + mix.sass('styles.scss');//.livereload(); }); diff --git a/readme.md b/readme.md index f67a6cf7c..7d9210790 100644 --- a/readme.md +++ b/readme.md @@ -1,27 +1,3 @@ -## Laravel PHP Framework +# BookStack -[![Build Status](https://travis-ci.org/laravel/framework.svg)](https://travis-ci.org/laravel/framework) -[![Total Downloads](https://poser.pugx.org/laravel/framework/d/total.svg)](https://packagist.org/packages/laravel/framework) -[![Latest Stable Version](https://poser.pugx.org/laravel/framework/v/stable.svg)](https://packagist.org/packages/laravel/framework) -[![Latest Unstable Version](https://poser.pugx.org/laravel/framework/v/unstable.svg)](https://packagist.org/packages/laravel/framework) -[![License](https://poser.pugx.org/laravel/framework/license.svg)](https://packagist.org/packages/laravel/framework) - -Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, queueing, and caching. - -Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked. - -## Official Documentation - -Documentation for the framework can be found on the [Laravel website](http://laravel.com/docs). - -## Contributing - -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions). - -## Security Vulnerabilities - -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed. - -### License - -The Laravel framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) +A platform to create documentation/wiki content. \ No newline at end of file diff --git a/resources/assets/sass/styles.scss b/resources/assets/sass/styles.scss index b855a8067..1b1318f92 100644 --- a/resources/assets/sass/styles.scss +++ b/resources/assets/sass/styles.scss @@ -379,4 +379,9 @@ body.dragging, body.dragging * { } .sortable-page-list li.placeholder:before { position: absolute; +} + +.material-icons { + font-size: 1em; + line-height: 1.4em; } \ No newline at end of file diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index 47c4a13d3..5fc10ce74 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -4,7 +4,7 @@
{{$book->description}}
- @include('pages/page-tree-list', ['pageTree' => $pageTree]) +