Dan Brown

Added pagination to books page

...@@ -40,7 +40,7 @@ class BookController extends Controller ...@@ -40,7 +40,7 @@ class BookController extends Controller
40 */ 40 */
41 public function index() 41 public function index()
42 { 42 {
43 - $books = $this->bookRepo->getAll(); 43 + $books = $this->bookRepo->getAllPaginated(10);
44 return view('books/index', ['books' => $books]); 44 return view('books/index', ['books' => $books]);
45 } 45 }
46 46
......
...@@ -11,7 +11,7 @@ class BookRepo ...@@ -11,7 +11,7 @@ class BookRepo
11 11
12 /** 12 /**
13 * BookRepo constructor. 13 * BookRepo constructor.
14 - * @param Book $book 14 + * @param Book $book
15 * @param PageRepo $pageRepo 15 * @param PageRepo $pageRepo
16 */ 16 */
17 public function __construct(Book $book, PageRepo $pageRepo) 17 public function __construct(Book $book, PageRepo $pageRepo)
...@@ -30,6 +30,16 @@ class BookRepo ...@@ -30,6 +30,16 @@ class BookRepo
30 return $this->book->all(); 30 return $this->book->all();
31 } 31 }
32 32
33 + /**
34 + * Getas
35 + * @param int $count
36 + * @return mixed
37 + */
38 + public function getAllPaginated($count = 10)
39 + {
40 + return $this->book->orderBy('name', 'asc')->paginate($count);
41 + }
42 +
33 public function getBySlug($slug) 43 public function getBySlug($slug)
34 { 44 {
35 return $this->book->where('slug', '=', $slug)->first(); 45 return $this->book->where('slug', '=', $slug)->first();
...@@ -63,11 +73,11 @@ class BookRepo ...@@ -63,11 +73,11 @@ class BookRepo
63 public function destroyBySlug($bookSlug) 73 public function destroyBySlug($bookSlug)
64 { 74 {
65 $book = $this->getBySlug($bookSlug); 75 $book = $this->getBySlug($bookSlug);
66 - foreach($book->pages as $page) { 76 + foreach ($book->pages as $page) {
67 \Activity::removeEntity($page); 77 \Activity::removeEntity($page);
68 $page->delete(); 78 $page->delete();
69 } 79 }
70 - foreach($book->chapters as $chapter) { 80 + foreach ($book->chapters as $chapter) {
71 \Activity::removeEntity($chapter); 81 \Activity::removeEntity($chapter);
72 $chapter->delete(); 82 $chapter->delete();
73 } 83 }
...@@ -83,7 +93,7 @@ class BookRepo ...@@ -83,7 +93,7 @@ class BookRepo
83 public function doesSlugExist($slug, $currentId = false) 93 public function doesSlugExist($slug, $currentId = false)
84 { 94 {
85 $query = $this->book->where('slug', '=', $slug); 95 $query = $this->book->where('slug', '=', $slug);
86 - if($currentId) { 96 + if ($currentId) {
87 $query = $query->where('id', '!=', $currentId); 97 $query = $query->where('id', '!=', $currentId);
88 } 98 }
89 return $query->count() > 0; 99 return $query->count() > 0;
...@@ -94,7 +104,7 @@ class BookRepo ...@@ -94,7 +104,7 @@ class BookRepo
94 $originalSlug = Str::slug($name); 104 $originalSlug = Str::slug($name);
95 $slug = $originalSlug; 105 $slug = $originalSlug;
96 $count = 2; 106 $count = 2;
97 - while($this->doesSlugExist($slug, $currentId)) { 107 + while ($this->doesSlugExist($slug, $currentId)) {
98 $slug = $originalSlug . '-' . $count; 108 $slug = $originalSlug . '-' . $count;
99 $count++; 109 $count++;
100 } 110 }
......
...@@ -214,4 +214,42 @@ ...@@ -214,4 +214,42 @@
214 .left + .right { 214 .left + .right {
215 margin-left: 30px + $-s; 215 margin-left: 30px + $-s;
216 } 216 }
217 +}
218 +
219 +ul.pagination {
220 + display: inline-block;
221 + list-style: none;
222 + margin: $-m 0;
223 + li {
224 + float: left;
225 + }
226 + li:first-child {
227 + a, span {
228 + border-radius: 3px 0 0 3px;
229 + }
230 + }
231 + li:last-child {
232 + a, span {
233 + border-radius: 0 3px 3px 0;
234 + }
235 + }
236 + a, span {
237 + display: block;
238 + padding: $-xxs $-s;
239 + border: 1px solid #CCC;
240 + margin-left: -1px;
241 + color: #888;
242 + user-select: none;
243 + &.disabled {
244 + cursor: not-allowed;
245 + }
246 + }
247 + li.active span {
248 + background-color: rgba($primary, 0.8);
249 + color: #EEE;
250 + border-color: rgba($primary, 0.8);
251 + }
252 + a {
253 + color: $primary;
254 + }
217 } 255 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
27 @include('books/list-item', ['book' => $book]) 27 @include('books/list-item', ['book' => $book])
28 <hr> 28 <hr>
29 @endforeach 29 @endforeach
30 + {!! $books->render() !!}
30 @else 31 @else
31 <p class="text-muted">No books have been created.</p> 32 <p class="text-muted">No books have been created.</p>
32 <a href="/books/create" class="text-pos"><i class="zmdi zmdi-edit"></i>Create one now</a> 33 <a href="/books/create" class="text-pos"><i class="zmdi zmdi-edit"></i>Create one now</a>
......