Skip to content

Commit d6bad01

Browse files
committed
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 parent a33deed commit d6bad01

File tree

4 files changed

+10
-29
lines changed

4 files changed

+10
-29
lines changed

app/Http/Controllers/BookController.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
<?php
2-
3-
namespace BookStack\Http\Controllers;
1+
<?php namespace BookStack\Http\Controllers;
42

53
use Activity;
64
use BookStack\Repos\UserRepo;
75
use Illuminate\Http\Request;
8-
96
use Illuminate\Support\Facades\Auth;
10-
use Illuminate\Support\Str;
117
use BookStack\Http\Requests;
128
use BookStack\Repos\BookRepo;
139
use BookStack\Repos\ChapterRepo;
@@ -40,7 +36,6 @@ public function __construct(BookRepo $bookRepo, PageRepo $pageRepo, ChapterRepo
4036

4137
/**
4238
* Display a listing of the book.
43-
*
4439
* @return Response
4540
*/
4641
public function index()
@@ -54,7 +49,6 @@ public function index()
5449

5550
/**
5651
* Show the form for creating a new book.
57-
*
5852
* @return Response
5953
*/
6054
public function create()
@@ -88,7 +82,6 @@ public function store(Request $request)
8882

8983
/**
9084
* Display the specified book.
91-
*
9285
* @param $slug
9386
* @return Response
9487
*/
@@ -103,7 +96,6 @@ public function show($slug)
10396

10497
/**
10598
* Show the form for editing the specified book.
106-
*
10799
* @param $slug
108100
* @return Response
109101
*/
@@ -117,7 +109,6 @@ public function edit($slug)
117109

118110
/**
119111
* Update the specified book in storage.
120-
*
121112
* @param Request $request
122113
* @param $slug
123114
* @return Response

app/Repos/EntityRepo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getRecentlyCreatedPages($count = 20, $page = 0, $additionalQuery
8484
if ($additionalQuery !== false && is_callable($additionalQuery)) {
8585
$additionalQuery($query);
8686
}
87-
return $query->skip($page * $count)->take($count)->get();
87+
return $query->with('book')->skip($page * $count)->take($count)->get();
8888
}
8989

9090
/**
@@ -114,7 +114,7 @@ public function getRecentlyUpdatedPages($count = 20, $page = 0)
114114
{
115115
return $this->restrictionService->enforcePageRestrictions($this->page)
116116
->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();
118118
}
119119

120120
/**

app/Services/ViewService.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php namespace BookStack\Services;
22

3-
43
use BookStack\Entity;
54
use BookStack\View;
65

@@ -47,7 +46,6 @@ public function add(Entity $entity)
4746
return 1;
4847
}
4948

50-
5149
/**
5250
* Get the entities with the most views.
5351
* @param int $count
@@ -58,17 +56,13 @@ public function getPopular($count = 10, $page = 0, $filterModel = false)
5856
{
5957
$skipCount = $count * $page;
6058
$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'))
6260
->groupBy('viewable_id', 'viewable_type')
6361
->orderBy('view_count', 'desc');
6462

6563
if ($filterModel) $query->where('viewable_type', '=', get_class($filterModel));
6664

67-
$views = $query->with('viewable')->skip($skipCount)->take($count)->get();
68-
$viewedEntities = $views->map(function ($item) {
69-
return $item->viewable()->getResults();
70-
});
71-
return $viewedEntities;
65+
return $query->with('viewable')->skip($skipCount)->take($count)->get()->pluck('viewable');
7266
}
7367

7468
/**
@@ -81,21 +75,18 @@ public function getPopular($count = 10, $page = 0, $filterModel = false)
8175
public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false)
8276
{
8377
if ($this->user === null) return collect();
84-
$skipCount = $count * $page;
78+
8579
$query = $this->restrictionService
8680
->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type');
8781

8882
if ($filterModel) $query = $query->where('viewable_type', '=', get_class($filterModel));
8983
$query = $query->where('user_id', '=', auth()->user()->id);
9084

91-
$views = $query->with('viewable')->orderBy('updated_at', 'desc')->skip($skipCount)->take($count)->get();
92-
$viewedEntities = $views->map(function ($item) {
93-
return $item->viewable;
94-
});
95-
return $viewedEntities;
85+
$viewables = $query->with('viewable')->orderBy('updated_at', 'desc')
86+
->skip($count * $page)->take($count)->get()->pluck('viewable');
87+
return $viewables;
9688
}
9789

98-
9990
/**
10091
* Reset all view counts by deleting all views.
10192
*/
@@ -104,5 +95,4 @@ public function resetAll()
10495
$this->view->truncate();
10596
}
10697

107-
10898
}

resources/assets/js/controllers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ module.exports = function (ngApp, events) {
370370

371371
$http.put('/ajax/page/' + pageId + '/save-draft', data).then((responseData) => {
372372
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');
374374
if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
375375
});
376376
}

0 commit comments

Comments
 (0)