1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-06 12:02:45 +03:00

Added recent pages to home view and made the home content more compact

This commit is contained in:
Dan Brown
2016-02-20 12:37:06 +00:00
parent 86fbc9a936
commit bab6fd1f2f
8 changed files with 173 additions and 79 deletions

View File

@@ -3,25 +3,21 @@
namespace BookStack\Http\Controllers;
use Activity;
use Illuminate\Http\Request;
use BookStack\Repos\EntityRepo;
use BookStack\Http\Requests;
use BookStack\Repos\BookRepo;
use Views;
class HomeController extends Controller
{
protected $activityService;
protected $bookRepo;
protected $entityRepo;
/**
* HomeController constructor.
* @param BookRepo $bookRepo
* @param EntityRepo $entityRepo
*/
public function __construct(BookRepo $bookRepo)
public function __construct(EntityRepo $entityRepo)
{
$this->bookRepo = $bookRepo;
$this->entityRepo = $entityRepo;
parent::__construct();
}
@@ -33,9 +29,16 @@ class HomeController extends Controller
*/
public function index()
{
$activity = Activity::latest();
$recents = $this->signedIn ? Views::getUserRecentlyViewed(10, 0) : $this->bookRepo->getLatest(10);
return view('home', ['activity' => $activity, 'recents' => $recents]);
$activity = Activity::latest(10);
$recents = $this->signedIn ? Views::getUserRecentlyViewed(12, 0) : $this->entityRepo->getRecentlyCreatedBooks(10);
$recentlyCreatedPages = $this->entityRepo->getRecentlyCreatedPages(5);
$recentlyUpdatedPages = $this->entityRepo->getRecentlyUpdatedPages(5);
return view('home', [
'activity' => $activity,
'recents' => $recents,
'recentlyCreatedPages' => $recentlyCreatedPages,
'recentlyUpdatedPages' => $recentlyUpdatedPages
]);
}
}

71
app/Repos/EntityRepo.php Normal file
View File

@@ -0,0 +1,71 @@
<?php namespace BookStack\Repos;
use BookStack\Book;
use BookStack\Chapter;
use BookStack\Page;
class EntityRepo
{
public $book;
public $chapter;
public $page;
/**
* EntityService constructor.
* @param $book
* @param $chapter
* @param $page
*/
public function __construct(Book $book, Chapter $chapter, Page $page)
{
$this->book = $book;
$this->chapter = $chapter;
$this->page = $page;
}
/**
* Get the latest books added to the system.
* @param $count
* @param $page
*/
public function getRecentlyCreatedBooks($count = 20, $page = 0)
{
return $this->book->orderBy('created_at', 'desc')->skip($page*$count)->take($count)->get();
}
/**
* Get the most recently updated books.
* @param $count
* @param int $page
* @return mixed
*/
public function getRecentlyUpdatedBooks($count = 20, $page = 0)
{
return $this->book->orderBy('updated_at', 'desc')->skip($page*$count)->take($count)->get();
}
/**
* Get the latest pages added to the system.
* @param $count
* @param $page
*/
public function getRecentlyCreatedPages($count = 20, $page = 0)
{
return $this->page->orderBy('created_at', 'desc')->skip($page*$count)->take($count)->get();
}
/**
* Get the most recently updated pages.
* @param $count
* @param int $page
* @return mixed
*/
public function getRecentlyUpdatedPages($count = 20, $page = 0)
{
return $this->page->orderBy('updated_at', 'desc')->skip($page*$count)->take($count)->get();
}
}

View File

@@ -1,11 +1,7 @@
<?php namespace BookStack\Repos;
use BookStack\Page;
use BookStack\Role;
use BookStack\Services\EntityService;
use BookStack\User;
use Carbon\Carbon;
use Setting;
class UserRepo
@@ -13,19 +9,19 @@ class UserRepo
protected $user;
protected $role;
protected $entityService;
protected $entityRepo;
/**
* UserRepo constructor.
* @param User $user
* @param Role $role
* @param EntityService $entityService
* @param EntityRepo $entityRepo
*/
public function __construct(User $user, Role $role, EntityService $entityService)
public function __construct(User $user, Role $role, EntityRepo $entityRepo)
{
$this->user = $user;
$this->role = $role;
$this->entityService = $entityService;
$this->entityRepo = $entityRepo;
}
/**
@@ -141,11 +137,11 @@ class UserRepo
public function getRecentlyCreated(User $user, $count = 20)
{
return [
'pages' => $this->entityService->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
->take($count)->get(),
'chapters' => $this->entityService->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
->take($count)->get(),
'books' => $this->entityService->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->orderBy('created_at', 'desc')
->take($count)->get()
];
}
@@ -158,9 +154,9 @@ class UserRepo
public function getAssetCounts(User $user)
{
return [
'pages' => $this->entityService->page->where('created_by', '=', $user->id)->count(),
'chapters' => $this->entityService->chapter->where('created_by', '=', $user->id)->count(),
'books' => $this->entityService->book->where('created_by', '=', $user->id)->count(),
'pages' => $this->entityRepo->page->where('created_by', '=', $user->id)->count(),
'chapters' => $this->entityRepo->chapter->where('created_by', '=', $user->id)->count(),
'books' => $this->entityRepo->book->where('created_by', '=', $user->id)->count(),
];
}

View File

@@ -1,29 +0,0 @@
<?php namespace BookStack\Services;
use BookStack\Book;
use BookStack\Chapter;
use BookStack\Page;
class EntityService
{
public $book;
public $chapter;
public $page;
/**
* EntityService constructor.
* @param $book
* @param $chapter
* @param $page
*/
public function __construct(Book $book, Chapter $chapter, Page $page)
{
$this->book = $book;
$this->chapter = $chapter;
$this->page = $page;
}
}