Dan Brown

Fixed draft time display, Cleaned up some code

Cleaned up some comment spacing in book controller and refactored some of the view service functions.
1 -<?php 1 +<?php namespace BookStack\Http\Controllers;
2 -
3 -namespace BookStack\Http\Controllers;
4 2
5 use Activity; 3 use Activity;
6 use BookStack\Repos\UserRepo; 4 use BookStack\Repos\UserRepo;
7 use Illuminate\Http\Request; 5 use Illuminate\Http\Request;
8 -
9 use Illuminate\Support\Facades\Auth; 6 use Illuminate\Support\Facades\Auth;
10 -use Illuminate\Support\Str;
11 use BookStack\Http\Requests; 7 use BookStack\Http\Requests;
12 use BookStack\Repos\BookRepo; 8 use BookStack\Repos\BookRepo;
13 use BookStack\Repos\ChapterRepo; 9 use BookStack\Repos\ChapterRepo;
...@@ -40,7 +36,6 @@ class BookController extends Controller ...@@ -40,7 +36,6 @@ class BookController extends Controller
40 36
41 /** 37 /**
42 * Display a listing of the book. 38 * Display a listing of the book.
43 - *
44 * @return Response 39 * @return Response
45 */ 40 */
46 public function index() 41 public function index()
...@@ -54,7 +49,6 @@ class BookController extends Controller ...@@ -54,7 +49,6 @@ class BookController extends Controller
54 49
55 /** 50 /**
56 * Show the form for creating a new book. 51 * Show the form for creating a new book.
57 - *
58 * @return Response 52 * @return Response
59 */ 53 */
60 public function create() 54 public function create()
...@@ -88,7 +82,6 @@ class BookController extends Controller ...@@ -88,7 +82,6 @@ class BookController extends Controller
88 82
89 /** 83 /**
90 * Display the specified book. 84 * Display the specified book.
91 - *
92 * @param $slug 85 * @param $slug
93 * @return Response 86 * @return Response
94 */ 87 */
...@@ -103,7 +96,6 @@ class BookController extends Controller ...@@ -103,7 +96,6 @@ class BookController extends Controller
103 96
104 /** 97 /**
105 * Show the form for editing the specified book. 98 * Show the form for editing the specified book.
106 - *
107 * @param $slug 99 * @param $slug
108 * @return Response 100 * @return Response
109 */ 101 */
...@@ -117,7 +109,6 @@ class BookController extends Controller ...@@ -117,7 +109,6 @@ class BookController extends Controller
117 109
118 /** 110 /**
119 * Update the specified book in storage. 111 * Update the specified book in storage.
120 - *
121 * @param Request $request 112 * @param Request $request
122 * @param $slug 113 * @param $slug
123 * @return Response 114 * @return Response
......
...@@ -84,7 +84,7 @@ class EntityRepo ...@@ -84,7 +84,7 @@ class EntityRepo
84 if ($additionalQuery !== false && is_callable($additionalQuery)) { 84 if ($additionalQuery !== false && is_callable($additionalQuery)) {
85 $additionalQuery($query); 85 $additionalQuery($query);
86 } 86 }
87 - return $query->skip($page * $count)->take($count)->get(); 87 + return $query->with('book')->skip($page * $count)->take($count)->get();
88 } 88 }
89 89
90 /** 90 /**
...@@ -114,7 +114,7 @@ class EntityRepo ...@@ -114,7 +114,7 @@ class EntityRepo
114 { 114 {
115 return $this->restrictionService->enforcePageRestrictions($this->page) 115 return $this->restrictionService->enforcePageRestrictions($this->page)
116 ->where('draft', '=', false) 116 ->where('draft', '=', false)
117 - ->orderBy('updated_at', 'desc')->skip($page * $count)->take($count)->get(); 117 + ->orderBy('updated_at', 'desc')->with('book')->skip($page * $count)->take($count)->get();
118 } 118 }
119 119
120 /** 120 /**
......
1 <?php namespace BookStack\Services; 1 <?php namespace BookStack\Services;
2 2
3 -
4 use BookStack\Entity; 3 use BookStack\Entity;
5 use BookStack\View; 4 use BookStack\View;
6 5
...@@ -47,7 +46,6 @@ class ViewService ...@@ -47,7 +46,6 @@ class ViewService
47 return 1; 46 return 1;
48 } 47 }
49 48
50 -
51 /** 49 /**
52 * Get the entities with the most views. 50 * Get the entities with the most views.
53 * @param int $count 51 * @param int $count
...@@ -58,17 +56,13 @@ class ViewService ...@@ -58,17 +56,13 @@ class ViewService
58 { 56 {
59 $skipCount = $count * $page; 57 $skipCount = $count * $page;
60 $query = $this->restrictionService->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type') 58 $query = $this->restrictionService->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type')
61 - ->select('id', 'viewable_id', 'viewable_type', \DB::raw('SUM(views) as view_count')) 59 + ->select('*', 'viewable_id', 'viewable_type', \DB::raw('SUM(views) as view_count'))
62 ->groupBy('viewable_id', 'viewable_type') 60 ->groupBy('viewable_id', 'viewable_type')
63 ->orderBy('view_count', 'desc'); 61 ->orderBy('view_count', 'desc');
64 62
65 if ($filterModel) $query->where('viewable_type', '=', get_class($filterModel)); 63 if ($filterModel) $query->where('viewable_type', '=', get_class($filterModel));
66 64
67 - $views = $query->with('viewable')->skip($skipCount)->take($count)->get(); 65 + return $query->with('viewable')->skip($skipCount)->take($count)->get()->pluck('viewable');
68 - $viewedEntities = $views->map(function ($item) {
69 - return $item->viewable()->getResults();
70 - });
71 - return $viewedEntities;
72 } 66 }
73 67
74 /** 68 /**
...@@ -81,21 +75,18 @@ class ViewService ...@@ -81,21 +75,18 @@ class ViewService
81 public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false) 75 public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false)
82 { 76 {
83 if ($this->user === null) return collect(); 77 if ($this->user === null) return collect();
84 - $skipCount = $count * $page; 78 +
85 $query = $this->restrictionService 79 $query = $this->restrictionService
86 ->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type'); 80 ->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type');
87 81
88 if ($filterModel) $query = $query->where('viewable_type', '=', get_class($filterModel)); 82 if ($filterModel) $query = $query->where('viewable_type', '=', get_class($filterModel));
89 $query = $query->where('user_id', '=', auth()->user()->id); 83 $query = $query->where('user_id', '=', auth()->user()->id);
90 84
91 - $views = $query->with('viewable')->orderBy('updated_at', 'desc')->skip($skipCount)->take($count)->get(); 85 + $viewables = $query->with('viewable')->orderBy('updated_at', 'desc')
92 - $viewedEntities = $views->map(function ($item) { 86 + ->skip($count * $page)->take($count)->get()->pluck('viewable');
93 - return $item->viewable; 87 + return $viewables;
94 - });
95 - return $viewedEntities;
96 } 88 }
97 89
98 -
99 /** 90 /**
100 * Reset all view counts by deleting all views. 91 * Reset all view counts by deleting all views.
101 */ 92 */
...@@ -104,5 +95,4 @@ class ViewService ...@@ -104,5 +95,4 @@ class ViewService
104 $this->view->truncate(); 95 $this->view->truncate();
105 } 96 }
106 97
107 -
108 } 98 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -370,7 +370,7 @@ module.exports = function (ngApp, events) { ...@@ -370,7 +370,7 @@ module.exports = function (ngApp, events) {
370 370
371 $http.put('/ajax/page/' + pageId + '/save-draft', data).then((responseData) => { 371 $http.put('/ajax/page/' + pageId + '/save-draft', data).then((responseData) => {
372 var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate(); 372 var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate();
373 - $scope.draftText = responseData.data.message + moment(updateTime).format('H:m'); 373 + $scope.draftText = responseData.data.message + moment(updateTime).format('HH:mm');
374 if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true; 374 if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
375 }); 375 });
376 } 376 }
......