#29: Added a new /labels endpoint to display labels and a preview of their photos
This commit is contained in:
parent
0d0584086b
commit
3254ca1500
@ -13,7 +13,13 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class LabelController extends Controller
|
||||
{
|
||||
public function index(Request $request, $labelAlias)
|
||||
public function index(Request $request)
|
||||
{
|
||||
$labels = Label::withCount('photos')->orderBy('name')->get();
|
||||
return Theme::render('gallery.labels', ['labels' => $labels]);
|
||||
}
|
||||
|
||||
public function show(Request $request, $labelAlias)
|
||||
{
|
||||
$label = Label::where('url_alias', $labelAlias)->first();
|
||||
if (is_null($label))
|
||||
|
@ -6,6 +6,7 @@ use App\Album;
|
||||
use App\Facade\Theme;
|
||||
use App\Facade\UserConfig;
|
||||
use App\Helpers\DbHelper;
|
||||
use App\Label;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Foundation\Application;
|
||||
@ -49,6 +50,7 @@ class GlobalConfiguration
|
||||
{
|
||||
$this->addThemeInfoToView();
|
||||
$this->addAlbumsToView();
|
||||
$this->addLabelsToView();
|
||||
}
|
||||
|
||||
// Set the default mail configuration as per user's requirements
|
||||
@ -63,6 +65,16 @@ class GlobalConfiguration
|
||||
View::share('albums', $albums);
|
||||
}
|
||||
|
||||
private function addLabelsToView()
|
||||
{
|
||||
$NUMBER_TO_SHOW_IN_NAVBAR = 5;
|
||||
$labelCount = Label::count();
|
||||
$labels = Label::withCount('photos')->orderBy('photos_count', 'desc')->limit($NUMBER_TO_SHOW_IN_NAVBAR)->get();
|
||||
|
||||
View::share('g_labels', $labels);
|
||||
View::share('g_more_labels', $labelCount - $NUMBER_TO_SHOW_IN_NAVBAR);
|
||||
}
|
||||
|
||||
private function addThemeInfoToView()
|
||||
{
|
||||
$themeInfo = Theme::info();
|
||||
|
@ -26,6 +26,26 @@ class Label extends Model
|
||||
return $this->belongsToMany(Photo::class, 'photo_labels');
|
||||
}
|
||||
|
||||
public function thumbnailUrl($thumbnailName)
|
||||
{
|
||||
$photo = $this->photos()
|
||||
->inRandomOrder()
|
||||
->first();
|
||||
|
||||
if (!is_null($photo))
|
||||
{
|
||||
return $photo->album->getAlbumSource()->getUrlToPhoto($photo, $thumbnailName);
|
||||
}
|
||||
|
||||
// Rotate standard images
|
||||
$images = [
|
||||
asset('themes/base/images/empty-album-1.jpg'),
|
||||
asset('themes/base/images/empty-album-2.jpg'),
|
||||
asset('themes/base/images/empty-album-3.jpg')
|
||||
];
|
||||
return $images[rand(0, count($images) - 1)];
|
||||
}
|
||||
|
||||
public function url()
|
||||
{
|
||||
return route('viewLabel', $this->url_alias);
|
||||
|
@ -14,11 +14,14 @@ return [
|
||||
'label_no_results_text' => 'No photos are tagged with the label ":name".',
|
||||
'label_no_results_text_2' => 'If you are an admin of this gallery, you can upload and tag photos in the :admin_link.',
|
||||
'labels' => 'Labels:',
|
||||
'labels_title' => 'Labels',
|
||||
'manage_album_link' => 'Manage',
|
||||
'manage_album_link_2' => 'Manage Album',
|
||||
'open_album_link' => 'Open Album',
|
||||
'other_albums_description' => 'You may also be interested in the following albums.',
|
||||
'other_albums_heading' => 'More Albums in :album_name',
|
||||
'photos' => 'photo|photos',
|
||||
'show_more_labels' => '... and :count other|... and :count others',
|
||||
'statistics' => [
|
||||
'album_by_photos' => 'Top 10 largest albums - number of photos',
|
||||
'album_by_size' => 'Top 10 largest albums - photo size (MB)',
|
||||
|
@ -27,6 +27,7 @@ return [
|
||||
'admin' => 'Manage',
|
||||
'albums' => 'Albums',
|
||||
'change_password' => 'Change password',
|
||||
'labels' => 'Labels',
|
||||
'login' => 'Login',
|
||||
'logout' => 'Logout',
|
||||
'register' => 'Register',
|
||||
|
37
resources/views/themes/base/gallery/labels.blade.php
Normal file
37
resources/views/themes/base/gallery/labels.blade.php
Normal file
@ -0,0 +1,37 @@
|
||||
@extends('themes.base.layout')
|
||||
@section('title', trans('gallery.labels_title'))
|
||||
|
||||
@section('breadcrumb')
|
||||
<li class="breadcrumb-item"><a href="{{ route('home') }}"><i class="fa fa-fw fa-home"></i></a></li>
|
||||
<li class="breadcrumb-item">@lang('navigation.breadcrumb.labels')</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="container album-container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class="page-title">@lang('gallery.labels_title')</h1>
|
||||
<div class="clearfix"><!-- --></div>
|
||||
<hr/>
|
||||
|
||||
<table class="table table-hover table-striped">
|
||||
<tbody>
|
||||
@foreach ($labels as $label)
|
||||
<tr>
|
||||
<td style="width: 150px">
|
||||
<img src="{{ $label->thumbnailUrl('admin-preview') }}" style="width: 150px;"/>
|
||||
</td>
|
||||
<td>
|
||||
<span style="font-size: 1.3em;">
|
||||
<a href="{{ $label->url() }}">{{ $label->name }}</a>
|
||||
</span><br/>
|
||||
<p style="margin-bottom: 0;"><b>{{ $label->photos_count }}</b> {{ trans_choice('gallery.photos', $label->photos_count) }}</p>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
@ -39,7 +39,7 @@
|
||||
<ul class="nav nav-pills mb-4">
|
||||
@foreach ($photo->labels()->orderBy('name')->get() as $label)
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ route('viewLabel', ['labelAlias' => $label->url_alias]) }}">
|
||||
<a class="nav-link" href="{{ $label->url() }}">
|
||||
<i class="fa fa-tag"></i> {{ $label->name }}
|
||||
</a>
|
||||
</li>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<nav class="navbar navbar-expand-md navbar-dark">
|
||||
<nav class="navbar navbar-expand-lg navbar-dark">
|
||||
<a class="navbar-brand" href="{{ route('home') }}"><i class="fa fa-fw fa-photo"></i> {{ UserConfig::get('app_name') }}</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<i class="fa fa-fw fa-bars"></i>
|
||||
@ -7,7 +7,7 @@
|
||||
<div class="collapse navbar-collapse" id="navbar-content">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
@if (count($albums) > 0)
|
||||
<li class="nav-item dropdown">
|
||||
<li class="nav-item dropdown ml-2">
|
||||
<a class="nav-link dropdown-toggle" href="{{ url('/') }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-book"></i> @lang('navigation.navbar.albums')
|
||||
</a>
|
||||
@ -17,13 +17,33 @@
|
||||
@endforeach
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
@endif
|
||||
|
||||
@if ($g_labels->count() > 0)
|
||||
<li class="nav-item dropdown ml-2">
|
||||
<a class="nav-link dropdown-toggle" href="{{ url('/') }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-tags"></i> @lang('navigation.navbar.labels')
|
||||
</a>
|
||||
<div class="dropdown-menu">
|
||||
@foreach ($g_labels as $label)
|
||||
<a class="dropdown-item" href="{{ $label->url() }}">{{ $label->name }} ({{ number_format($label->photos_count, 0) }})</a>
|
||||
@endforeach
|
||||
|
||||
@if ($g_more_labels > 0)
|
||||
<a class="dropdown-item" href="{{ route('labels') }}">{{ trans_choice('gallery.show_more_labels', $g_more_labels) }}</a>
|
||||
@endif
|
||||
</div>
|
||||
</li>
|
||||
@endif
|
||||
|
||||
@if (count($albums) > 0)
|
||||
<li class="nav-item ml-2">
|
||||
<a class="nav-link" href="{{ route('statistics.index') }}"><i class="fa fa-bar-chart"></i> @lang('navigation.navbar.statistics')</a>
|
||||
</li>
|
||||
@endif
|
||||
|
||||
@if (!Auth::guest() && (Auth::user()->can('admin:access')))
|
||||
<li class="nav-item">
|
||||
<li class="nav-item ml-2">
|
||||
<a class="nav-link" href="{{ route('admin') }}"><i class="fa fa-fw fa-cog"></i> @lang('navigation.navbar.admin')</a>
|
||||
</li>
|
||||
@endif
|
||||
|
@ -70,6 +70,7 @@ Route::group(['prefix' => 'install'], function () {
|
||||
// Gallery
|
||||
Route::get('/', 'Gallery\DefaultController@index')->name('home');
|
||||
Route::get('/activate/{token}', 'Auth\ActivateController@activate')->name('auth.activate');
|
||||
Route::get('/labels', 'Gallery\LabelController@index')->name('labels');
|
||||
Route::get('/password/change', 'Auth\ChangePasswordController@showChangePasswordForm')->name('auth.changePassword');
|
||||
Route::post('/password/change', 'Auth\ChangePasswordController@processChangePassword')->name('auth.processChangePassword');
|
||||
Route::get('/sitemap.xml', 'Gallery\DefaultController@sitemapXml');
|
||||
@ -89,6 +90,6 @@ Route::get('p/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')
|
||||
Route::get('i/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@download')
|
||||
->name('downloadPhoto')
|
||||
->where('albumUrlAlias', '.*');
|
||||
Route::get('label/{labelAlias}', 'Gallery\LabelController@index')
|
||||
Route::get('label/{labelAlias}', 'Gallery\LabelController@show')
|
||||
->name('viewLabel')
|
||||
->where('labelAlias', '.*');
|
Loading…
Reference in New Issue
Block a user