Merge branch 'feature/615'

This commit is contained in:
Dan Brown 2018-05-20 10:13:34 +01:00
commit 019b8196ad
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
15 changed files with 164 additions and 107 deletions

View File

@ -33,22 +33,41 @@ class HomeController extends Controller
$recents = $this->signedIn ? Views::getUserRecentlyViewed(12*$recentFactor, 0) : $this->entityRepo->getRecentlyCreated('book', 12*$recentFactor);
$recentlyUpdatedPages = $this->entityRepo->getRecentlyUpdated('page', 12);
// Custom homepage
$customHomepage = false;
$homepageSetting = setting('app-homepage');
if ($homepageSetting) {
$id = intval(explode(':', $homepageSetting)[0]);
$customHomepage = $this->entityRepo->getById('page', $id, false, true);
$this->entityRepo->renderPage($customHomepage, true);
$books = false;
$booksViewType = false;
// Check book homepage
$bookHomepageSetting = setting('app-book-homepage');
if ($bookHomepageSetting) {
$books = $this->entityRepo->getAllPaginated('book', 18);
$booksViewType = setting()->getUser($this->currentUser, 'books_view_type', config('app.views.books', 'list'));
} else {
// Check custom homepage
$homepageSetting = setting('app-homepage');
if ($homepageSetting) {
$id = intval(explode(':', $homepageSetting)[0]);
$customHomepage = $this->entityRepo->getById('page', $id, false, true);
$this->entityRepo->renderPage($customHomepage, true);
}
}
$view = $customHomepage ? 'home-custom' : 'home';
return view($view, [
$view = 'home';
if ($bookHomepageSetting) {
$view = 'home-book';
} else if ($customHomepage) {
$view = 'home-custom';
}
return view('common/' . $view, [
'activity' => $activity,
'recents' => $recents,
'recentlyUpdatedPages' => $recentlyUpdatedPages,
'draftPages' => $draftPages,
'customHomepage' => $customHomepage
'customHomepage' => $customHomepage,
'books' => $books,
'booksViewType' => $booksViewType
]);
}
@ -131,7 +150,7 @@ class HomeController extends Controller
$allowRobots = $sitePublic;
}
return response()
->view('robots', ['allowRobots' => $allowRobots])
->view('common/robots', ['allowRobots' => $allowRobots])
->header('Content-Type', 'text/plain');
}

View File

@ -9,6 +9,7 @@
color: #666;
width: 250px;
max-width: 100%;
&.neg, &.invalid {
border: 1px solid $negative;
}

View File

@ -34,6 +34,7 @@ return [
'app_homepage' => 'Application Homepage',
'app_homepage_desc' => 'Select a page to show on the homepage instead of the default view. Page permissions are ignored for selected pages.',
'app_homepage_default' => 'Default homepage view chosen',
'app_homepage_books' => 'Or select the books page as your homepage. This will override any page selected as your homepage.',
'app_disable_comments' => 'Disable comments',
'app_disable_comments_desc' => 'Disable comments across all pages in the application. Existing comments are not shown.',

View File

@ -3,16 +3,7 @@
@section('toolbar')
<div class="col-xs-6">
<div class="action-buttons text-left">
<form action="{{ baseUrl("/settings/users/{$currentUser->id}/switch-book-view") }}" method="POST" class="inline">
{!! csrf_field() !!}
{!! method_field('PATCH') !!}
<input type="hidden" value="{{ $booksViewType === 'list'? 'grid' : 'list' }}" name="book_view_type">
@if ($booksViewType === 'list')
<button type="submit" class="text-pos text-button">@icon('grid'){{ trans('common.grid_view') }}</button>
@else
<button type="submit" class="text-pos text-button">@icon('list'){{ trans('common.list_view') }}</button>
@endif
</form>
@include('books/view-toggle', ['booksViewType' => $booksViewType])
</div>
</div>
<div class="col-xs-6 faded">
@ -52,34 +43,5 @@
@stop
@section('body')
@if($booksViewType === 'list')
<div class="container small" ng-non-bindable>
@else
<div class="container" ng-non-bindable>
@endif
<h1>{{ trans('entities.books') }}</h1>
@if(count($books) > 0)
@if($booksViewType === 'list')
@foreach($books as $book)
@include('books/list-item', ['book' => $book])
<hr>
@endforeach
{!! $books->render() !!}
@else
<div class="grid third">
@foreach($books as $key => $book)
@include('books/grid-item', ['book' => $book])
@endforeach
</div>
<div>
{!! $books->render() !!}
</div>
@endif
@else
<p class="text-muted">{{ trans('entities.books_empty') }}</p>
@if(userCan('books-create-all'))
<a href="{{ baseUrl("/create-book") }}" class="text-pos">@icon('edit'){{ trans('entities.create_one_now') }}</a>
@endif
@endif
</div>
@include('books/list', ['books' => $books, 'bookViewType' => $booksViewType])
@stop

View File

@ -0,0 +1,31 @@
@if($booksViewType === 'list')
<div class="container small">
@else
<div class="container">
@endif
<h1>{{ trans('entities.books') }}</h1>
@if(count($books) > 0)
@if($booksViewType === 'list')
@foreach($books as $book)
@include('books/list-item', ['book' => $book])
<hr>
@endforeach
{!! $books->render() !!}
@else
<div class="grid third">
@foreach($books as $key => $book)
@include('books/grid-item', ['book' => $book])
@endforeach
</div>
<div>
{!! $books->render() !!}
</div>
@endif
@else
<p class="text-muted">{{ trans('entities.books_empty') }}</p>
@if(userCan('books-create-all'))
<a href="{{ baseUrl("/create-book") }}" class="text-pos">@icon('edit'){{ trans('entities.create_one_now') }}</a>
@endif
@endif
</div>

View File

@ -0,0 +1,10 @@
<form action="{{ baseUrl("/settings/users/{$currentUser->id}/switch-book-view") }}" method="POST" class="inline">
{!! csrf_field() !!}
{!! method_field('PATCH') !!}
<input type="hidden" value="{{ $booksViewType === 'list'? 'grid' : 'list' }}" name="book_view_type">
@if ($booksViewType === 'list')
<button type="submit" class="text-pos text-button">@icon('grid'){{ trans('common.grid_view') }}</button>
@else
<button type="submit" class="text-pos text-button">@icon('list'){{ trans('common.list_view') }}</button>
@endif
</form>

View File

@ -0,0 +1,18 @@
@extends('sidebar-layout')
@section('toolbar')
<div class="col-sm-6 faded">
<div class="action-buttons text-left">
<a expand-toggle=".entity-list.compact .entity-item-snippet" class="text-primary text-button">@icon('expand-text'){{ trans('common.toggle_details') }}</a>
@include('books/view-toggle', ['booksViewType' => $booksViewType])
</div>
</div>
@stop
@section('sidebar')
@include('common/home-sidebar')
@stop
@section('body')
@include('books/list', ['books' => $books, 'bookViewType' => $booksViewType])
@stop

View File

@ -0,0 +1,19 @@
@extends('sidebar-layout')
@section('toolbar')
<div class="col-sm-6 faded">
<div class="action-buttons text-left">
<a expand-toggle=".entity-list.compact .entity-item-snippet" class="text-primary text-button">@icon('expand-text'){{ trans('common.toggle_details') }}</a>
</div>
</div>
@stop
@section('sidebar')
@include('common/home-sidebar')
@stop
@section('body')
<div class="page-content" page-display="{{ $customHomepage->id }}">
@include('pages/page-display', ['page' => $customHomepage])
</div>
@stop

View File

@ -0,0 +1,31 @@
@if(count($draftPages) > 0)
<div id="recent-drafts" class="card">
<h3>@icon('edit') {{ trans('entities.my_recent_drafts') }}</h3>
@include('partials/entity-list', ['entities' => $draftPages, 'style' => 'compact'])
</div>
@endif
<div class="card">
<h3>@icon($signedIn ? 'view' : 'star-circle') {{ trans('entities.' . ($signedIn ? 'my_recently_viewed' : 'books_recent')) }}</h3>
@include('partials/entity-list', [
'entities' => $recents,
'style' => 'compact',
'emptyText' => $signedIn ? trans('entities.no_pages_viewed') : trans('entities.books_empty')
])
</div>
<div class="card">
<h3>@icon('file') <a class="no-color" href="{{ baseUrl("/pages/recently-updated") }}">{{ trans('entities.recently_updated_pages') }}</a></h3>
<div id="recently-updated-pages">
@include('partials/entity-list', [
'entities' => $recentlyUpdatedPages,
'style' => 'compact',
'emptyText' => trans('entities.no_pages_recently_updated')
])
</div>
</div>
<div id="recent-activity" class="card">
<h3>@icon('time') {{ trans('entities.recent_activity') }}</h3>
@include('partials/activity-list', ['activity' => $activity])
</div>

View File

@ -1,56 +0,0 @@
@extends('sidebar-layout')
@section('toolbar')
<div class="col-sm-6 faded">
<div class="action-buttons text-left">
<a expand-toggle=".entity-list.compact .entity-item-snippet" class="text-primary text-button">@icon('expand-text'){{ trans('common.toggle_details') }}</a>
</div>
</div>
@stop
@section('sidebar')
@if(count($draftPages) > 0)
<div id="recent-drafts" class="card">
<h3>@icon('edit') {{ trans('entities.my_recent_drafts') }}</h3>
@include('partials/entity-list', ['entities' => $draftPages, 'style' => 'compact'])
</div>
@endif
<div class="card">
<h3>@icon($signedIn ? 'view' : 'star-circle') {{ trans('entities.' . ($signedIn ? 'my_recently_viewed' : 'books_recent')) }}</h3>
@include('partials/entity-list', [
'entities' => $recents,
'style' => 'compact',
'emptyText' => $signedIn ? trans('entities.no_pages_viewed') : trans('entities.books_empty')
])
</div>
<div class="card">
<h3>@icon('file') <a class="no-color" href="{{ baseUrl("/pages/recently-updated") }}">{{ trans('entities.recently_updated_pages') }}</a></h3>
<div id="recently-updated-pages">
@include('partials/entity-list', [
'entities' => $recentlyUpdatedPages,
'style' => 'compact',
'emptyText' => trans('entities.no_pages_recently_updated')
])
</div>
</div>
<div id="recent-activity" class="card">
<h3>@icon('time') {{ trans('entities.recent_activity') }}</h3>
@include('partials/activity-list', ['activity' => $activity])
</div>
@stop
@section('body')
<div class="page-content" ng-non-bindable>
@include('pages/page-display', ['page' => $customHomepage])
</div>
@stop
@section('scripts')
<script>
setupPageShow({{$customHomepage->id}});
</script>
@stop

View File

@ -118,7 +118,7 @@
@stop
@section('body')
<div class="page-content" page-display="{{ $page->id }}" ng-non-bindable>
<div class="page-content" page-display="{{ $page->id }}">
<div class="pointer-container" id="pointer">
<div class="pointer anim" >

View File

@ -80,6 +80,8 @@
<label for="setting-app-homepage">{{ trans('settings.app_homepage') }}</label>
<p class="small">{{ trans('settings.app_homepage_desc') }}</p>
@include('components.page-picker', ['name' => 'setting-app-homepage', 'placeholder' => trans('settings.app_homepage_default'), 'value' => setting('app-homepage')])
<p class="small">{{ trans('settings.app_homepage_books') }}</p>
@include('components.toggle-switch', ['name' => 'setting-app-book-homepage', 'value' => setting('app-book-homepage')])
</div>
</div>

View File

@ -49,4 +49,23 @@ class HomepageTest extends TestCase
$homeVisit->assertSee($name);
$homeVisit->assertStatus(200);
}
public function test_set_book_homepage()
{
$editor = $this->getEditor();
setting()->putUser($editor, 'books_view_type', 'grid');
$this->setSettings(['app-book-homepage' => true]);
$this->asEditor();
$homeVisit = $this->get('/');
$homeVisit->assertSee('Books');
$homeVisit->assertSee('book-grid-item grid-card');
$homeVisit->assertSee('grid-card-content');
$homeVisit->assertSee('grid-card-footer');
$homeVisit->assertSee('featured-image-container');
$this->setSettings(['app-book-homepage' => false]);
$this->test_default_homepage_visible();
}
}