1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-10-30 07:32:39 +01:00

Fixed draft time display, Cleaned up some code

Cleaned up some comment spacing in book controller and refactored some of the view service functions.
This commit is contained in:
Dan Brown 2016-04-09 14:26:42 +01:00
parent a33deed26b
commit d6bad01130
4 changed files with 10 additions and 29 deletions

View File

@ -1,13 +1,9 @@
<?php <?php namespace BookStack\Http\Controllers;
namespace BookStack\Http\Controllers;
use Activity; use Activity;
use BookStack\Repos\UserRepo; use BookStack\Repos\UserRepo;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use BookStack\Http\Requests; use BookStack\Http\Requests;
use BookStack\Repos\BookRepo; use BookStack\Repos\BookRepo;
use BookStack\Repos\ChapterRepo; use BookStack\Repos\ChapterRepo;
@ -40,7 +36,6 @@ class BookController extends Controller
/** /**
* Display a listing of the book. * Display a listing of the book.
*
* @return Response * @return Response
*/ */
public function index() public function index()
@ -54,7 +49,6 @@ class BookController extends Controller
/** /**
* Show the form for creating a new book. * Show the form for creating a new book.
*
* @return Response * @return Response
*/ */
public function create() public function create()
@ -88,7 +82,6 @@ class BookController extends Controller
/** /**
* Display the specified book. * Display the specified book.
*
* @param $slug * @param $slug
* @return Response * @return Response
*/ */
@ -103,7 +96,6 @@ class BookController extends Controller
/** /**
* Show the form for editing the specified book. * Show the form for editing the specified book.
*
* @param $slug * @param $slug
* @return Response * @return Response
*/ */
@ -117,7 +109,6 @@ class BookController extends Controller
/** /**
* Update the specified book in storage. * Update the specified book in storage.
*
* @param Request $request * @param Request $request
* @param $slug * @param $slug
* @return Response * @return Response

View File

@ -84,7 +84,7 @@ class EntityRepo
if ($additionalQuery !== false && is_callable($additionalQuery)) { if ($additionalQuery !== false && is_callable($additionalQuery)) {
$additionalQuery($query); $additionalQuery($query);
} }
return $query->skip($page * $count)->take($count)->get(); return $query->with('book')->skip($page * $count)->take($count)->get();
} }
/** /**
@ -114,7 +114,7 @@ class EntityRepo
{ {
return $this->restrictionService->enforcePageRestrictions($this->page) return $this->restrictionService->enforcePageRestrictions($this->page)
->where('draft', '=', false) ->where('draft', '=', false)
->orderBy('updated_at', 'desc')->skip($page * $count)->take($count)->get(); ->orderBy('updated_at', 'desc')->with('book')->skip($page * $count)->take($count)->get();
} }
/** /**

View File

@ -1,6 +1,5 @@
<?php namespace BookStack\Services; <?php namespace BookStack\Services;
use BookStack\Entity; use BookStack\Entity;
use BookStack\View; use BookStack\View;
@ -47,7 +46,6 @@ class ViewService
return 1; return 1;
} }
/** /**
* Get the entities with the most views. * Get the entities with the most views.
* @param int $count * @param int $count
@ -58,17 +56,13 @@ class ViewService
{ {
$skipCount = $count * $page; $skipCount = $count * $page;
$query = $this->restrictionService->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type') $query = $this->restrictionService->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type')
->select('id', 'viewable_id', 'viewable_type', \DB::raw('SUM(views) as view_count')) ->select('*', 'viewable_id', 'viewable_type', \DB::raw('SUM(views) as view_count'))
->groupBy('viewable_id', 'viewable_type') ->groupBy('viewable_id', 'viewable_type')
->orderBy('view_count', 'desc'); ->orderBy('view_count', 'desc');
if ($filterModel) $query->where('viewable_type', '=', get_class($filterModel)); if ($filterModel) $query->where('viewable_type', '=', get_class($filterModel));
$views = $query->with('viewable')->skip($skipCount)->take($count)->get(); return $query->with('viewable')->skip($skipCount)->take($count)->get()->pluck('viewable');
$viewedEntities = $views->map(function ($item) {
return $item->viewable()->getResults();
});
return $viewedEntities;
} }
/** /**
@ -81,21 +75,18 @@ class ViewService
public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false) public function getUserRecentlyViewed($count = 10, $page = 0, $filterModel = false)
{ {
if ($this->user === null) return collect(); if ($this->user === null) return collect();
$skipCount = $count * $page;
$query = $this->restrictionService $query = $this->restrictionService
->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type'); ->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type');
if ($filterModel) $query = $query->where('viewable_type', '=', get_class($filterModel)); if ($filterModel) $query = $query->where('viewable_type', '=', get_class($filterModel));
$query = $query->where('user_id', '=', auth()->user()->id); $query = $query->where('user_id', '=', auth()->user()->id);
$views = $query->with('viewable')->orderBy('updated_at', 'desc')->skip($skipCount)->take($count)->get(); $viewables = $query->with('viewable')->orderBy('updated_at', 'desc')
$viewedEntities = $views->map(function ($item) { ->skip($count * $page)->take($count)->get()->pluck('viewable');
return $item->viewable; return $viewables;
});
return $viewedEntities;
} }
/** /**
* Reset all view counts by deleting all views. * Reset all view counts by deleting all views.
*/ */
@ -104,5 +95,4 @@ class ViewService
$this->view->truncate(); $this->view->truncate();
} }
} }

View File

@ -370,7 +370,7 @@ module.exports = function (ngApp, events) {
$http.put('/ajax/page/' + pageId + '/save-draft', data).then((responseData) => { $http.put('/ajax/page/' + pageId + '/save-draft', data).then((responseData) => {
var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate(); var updateTime = moment.utc(moment.unix(responseData.data.timestamp)).toDate();
$scope.draftText = responseData.data.message + moment(updateTime).format('H:m'); $scope.draftText = responseData.data.message + moment(updateTime).format('HH:mm');
if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true; if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
}); });
} }