#4: Child album count is now included when using the Album::children() method. Child albums are now displayed in the gallery

This commit is contained in:
Andy Heathershaw 2017-04-17 21:53:47 +01:00
parent a26f9c1c1f
commit 94b2a9d1b6
4 changed files with 76 additions and 17 deletions

View File

@ -58,7 +58,7 @@ class Album extends Model
public function children() public function children()
{ {
return $this->hasMany(Album::class, 'parent_album_id'); return $this->hasMany(Album::class, 'parent_album_id')->withCount('photos');
} }
public function doesGroupHavePermission(Group $group, Permission $permission) public function doesGroupHavePermission(Group $group, Permission $permission)

View File

@ -1,6 +1,8 @@
@extends('themes.base.layout') @extends('themes.base.layout')
@section('title', $album->name) @section('title', $album->name)
@php ($hasChildren = $album->children()->count() > 0)
@section('content') @section('content')
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
@ -22,13 +24,16 @@
<h1 class="page-title">{{ $album->name }}</h1> <h1 class="page-title">{{ $album->name }}</h1>
<p>{{ $album->description }}</p> <p>{{ $album->description }}</p>
<div class="clearfix"><!-- --></div>
<hr/> <hr/>
</div> </div>
</div> </div>
<div class="row">
<div class="{{ $hasChildren ? 'col-md-8' : 'col-md-10 offset-md-1' }}">
<div class="row"> <div class="row">
@foreach ($photos as $photo) @foreach ($photos as $photo)
<div class="col-sm-6 col-md-4 col-lg-3 photo"> <div class="{{ $hasChildren ? 'col-sm-6 col-md-6 col-lg-4' : 'col-sm-6 col-md-4 col-lg-3' }} photo mb-3">
<div class="card"> <div class="card">
<img src="{{ $photo->thumbnailUrl('preview') }}" alt="" class="card-img-top"/> <img src="{{ $photo->thumbnailUrl('preview') }}" alt="" class="card-img-top"/>
<div class="card-block"> <div class="card-block">
@ -41,6 +46,23 @@
</div> </div>
@endforeach @endforeach
</div> </div>
</div>
@if ($hasChildren)
<div class="col-md-2 offset-md-1">
@foreach ($album->children as $childAlbum)
<div class="card mb-3">
<img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="height: 150px;"/>
<div class="card-block">
<h4 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h4>
</div>
<div class="card-footer">
<small class="text-muted"><i class="fa fa-fw fa-photo"></i> {{ $childAlbum->photos_count }} photos</small>
</div>
</div>
@endforeach
</div>
@endif
</div>
<div class="row" style="margin-top: 15px;"> <div class="row" style="margin-top: 15px;">
<div class="col text-center"> <div class="col text-center">

View File

@ -1,6 +1,8 @@
@extends('themes.base.layout') @extends('themes.base.layout')
@section('title', $album->name) @section('title', $album->name)
@php ($hasChildren = $album->children()->count() > 0)
@section('content') @section('content')
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
@ -13,15 +15,31 @@
</div> </div>
</div> </div>
<div class="container album-container"> <div class="container-fluid album-container">
<div class="row"> <div class="row">
<div class="col-md-8 offset-md-2 text-center"> <div class="{{ $hasChildren ? 'col-md-8' : 'col-md-10 offset-md-1' }} text-center">
<h1>@lang('gallery.album_no_results_heading')</h1> <h1>@lang('gallery.album_no_results_heading')</h1>
<p style="line-height: 1.6em;">@lang('gallery.album_no_results_text', ['admin_link' => sprintf('<a href="%s">%s</a>', route('admin'), trans('admin.title'))])</p> <p style="line-height: 1.6em;">@lang('gallery.album_no_results_text', ['admin_link' => sprintf('<a href="%s">%s</a>', route('admin'), trans('admin.title'))])</p>
<p style="margin-bottom: 30px; line-height: 1.6em;">@lang('gallery.album_no_results_text_2')</p> <p style="margin-bottom: 30px; line-height: 1.6em;">@lang('gallery.album_no_results_text_2')</p>
<img src="{{ asset('themes/base/images/smartphone-photo.jpg') }}" class="img-fluid rounded" style="display: inline;" /> <img src="{{ asset('themes/base/images/smartphone-photo.jpg') }}" class="img-fluid rounded" style="display: inline;" />
</div> </div>
@if ($hasChildren)
<div class="col-md-2 offset-md-1">
@foreach ($album->children as $childAlbum)
<div class="card mb-3">
<img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="height: 150px;"/>
<div class="card-block">
<h4 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h4>
</div>
<div class="card-footer">
<small class="text-muted"><i class="fa fa-fw fa-photo"></i> {{ $childAlbum->photos_count }} photos</small>
</div>
</div>
@endforeach
</div>
@endif
</div> </div>
</div> </div>
@endsection @endsection

View File

@ -9,19 +9,20 @@
@section('content') @section('content')
<div class="container album-container album-slideshow-container"> <div class="container album-container album-slideshow-container">
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col">
<div class="pull-right"> <div class="pull-right">
@include(\App\Facade\Theme::viewName('partials.album_view_selector')) @include(\App\Facade\Theme::viewName('partials.album_view_selector'))
</div> </div>
<h1 class="page-title">{{ $album->name }}</h1> <h1 class="page-title">{{ $album->name }}</h1>
<p>{{ $album->description }}</p> <p>{{ $album->description }}</p>
<div class="clearfix"><!-- --></div>
<hr/> <hr/>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-xs-12 text-center"> <div class="col text-center">
<div class="pull-right"> <div class="pull-right">
<div class="btn btn-group"> <div class="btn btn-group">
<button class="btn btn-default" data-bind="click: pauseSlideshow, disable: isPaused, visible: isRunning"><i class="fa fa-fw fa-pause"></i></button> <button class="btn btn-default" data-bind="click: pauseSlideshow, disable: isPaused, visible: isRunning"><i class="fa fa-fw fa-pause"></i></button>
@ -38,7 +39,7 @@
</div> </div>
<div class="row" style="margin-top: 15px;"> <div class="row" style="margin-top: 15px;">
<div class="col-xs-12"> <div class="col">
<div class="thumbnails"> <div class="thumbnails">
@foreach ($photos as $photo) @foreach ($photos as $photo)
<a href="{{ $photo->url() }}" data-bind="click: function() { viewModel.changeCurrentImage({{ $photo->id }}); }"> <a href="{{ $photo->url() }}" data-bind="click: function() { viewModel.changeCurrentImage({{ $photo->id }}); }">
@ -48,6 +49,24 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row" style="margin-top: 30px;">
@if ($album->children()->count() > 0)
<div class="col-6 col-md-3">
@foreach ($album->children as $childAlbum)
<div class="card mb-3">
<img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="height: 150px;"/>
<div class="card-block">
<h4 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h4>
</div>
<div class="card-footer">
<small class="text-muted"><i class="fa fa-fw fa-photo"></i> {{ $childAlbum->photos_count }} photos</small>
</div>
</div>
@endforeach
</div>
@endif
</div>
</div> </div>
@endsection @endsection