From ef4df1ab32f2e8ffd0e700ca45ebc42144ce74d9 Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Thu, 12 Jul 2018 22:52:50 +0100 Subject: [PATCH] #59: Added 2 new settings to customise the albums drop-down navigator. It is now possible to choose to only display top-level albums, and also to restrict the number of items. --- app/Helpers/ConfigHelper.php | 2 ++ .../Controllers/Admin/DefaultController.php | 2 ++ app/Http/Middleware/GlobalConfiguration.php | 18 ++++++++++++++ app/Http/Requests/SaveSettingsRequest.php | 3 ++- resources/lang/en/admin.php | 3 +++ resources/lang/en/gallery.php | 1 + .../themes/base/admin/settings.blade.php | 24 +++++++++++++++++++ .../themes/base/partials/navbar.blade.php | 6 ++++- 8 files changed, 57 insertions(+), 2 deletions(-) diff --git a/app/Helpers/ConfigHelper.php b/app/Helpers/ConfigHelper.php index 78561d2..4272bcb 100644 --- a/app/Helpers/ConfigHelper.php +++ b/app/Helpers/ConfigHelper.php @@ -87,6 +87,8 @@ class ConfigHelper $currentAppName = $this->get('app_name', false); return array( + 'albums_menu_parents_only' => false, + 'albums_menu_number_items' => 10, 'allow_self_registration' => true, 'analytics_code' => '', 'app_name' => trans('global.app_name'), diff --git a/app/Http/Controllers/Admin/DefaultController.php b/app/Http/Controllers/Admin/DefaultController.php index dbe658b..9f43ac7 100644 --- a/app/Http/Controllers/Admin/DefaultController.php +++ b/app/Http/Controllers/Admin/DefaultController.php @@ -214,6 +214,7 @@ class DefaultController extends Controller 'smtp_password' ]; $checkboxKeys = [ + 'albums_menu_parents_only', 'allow_self_registration', 'enable_visitor_hits', 'hotlink_protection', @@ -224,6 +225,7 @@ class DefaultController extends Controller 'smtp_encryption', ]; $updateKeys = [ + 'albums_menu_number_items', 'app_name', 'date_format', 'sender_address', diff --git a/app/Http/Middleware/GlobalConfiguration.php b/app/Http/Middleware/GlobalConfiguration.php index 49e8709..1ef4600 100644 --- a/app/Http/Middleware/GlobalConfiguration.php +++ b/app/Http/Middleware/GlobalConfiguration.php @@ -65,6 +65,24 @@ class GlobalConfiguration $albums = DbHelper::getAlbumsForCurrentUser_NonPaged()->get(); View::share('g_albums', $albums); + if (UserConfig::get('albums_menu_parents_only')) + { + // Only show top-level albums in the nav bar + $navbarAlbums = $albums->filter(function($value, $key) + { + return is_null($value->parent_album_id); + }); + } + else + { + // If not just showing top-level albums, we can show all + $navbarAlbums = $albums; + } + + $navbarAlbumsToDisplay = UserConfig::get('albums_menu_number_items'); + View::share('g_albums_menu', $navbarAlbums->take($navbarAlbumsToDisplay)); + View::share('g_more_albums', $navbarAlbums->count() - $navbarAlbumsToDisplay); + $albumsToUpload = DbHelper::getAlbumsForCurrentUser_NonPaged('upload-photos')->get(); View::share('g_albums_upload', $albumsToUpload); } diff --git a/app/Http/Requests/SaveSettingsRequest.php b/app/Http/Requests/SaveSettingsRequest.php index fb59558..8cd1b0f 100644 --- a/app/Http/Requests/SaveSettingsRequest.php +++ b/app/Http/Requests/SaveSettingsRequest.php @@ -24,10 +24,11 @@ class SaveSettingsRequest extends FormRequest public function rules() { return [ + 'albums_menu_number_items' => 'required|integer|min:1', 'app_name' => 'required|max:255', 'date_format' => 'required', 'smtp_server' => 'required', - 'smtp_port' => 'required:integer' + 'smtp_port' => 'required|integer' ]; } } diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index 5d974d6..d6e239c 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -198,6 +198,9 @@ return [ 'security_text' => 'You can assign permissions on this album to either groups (recommended) or directly to users.', 'security_users_heading' => 'User Permissions', 'settings' => [ + 'albums_menu_heading' => 'Albums Navigation Menu', + 'albums_menu_number_items' => 'Number of albums to display:', + 'albums_menu_parents_only' => 'Only show top-level albums', 'analytics_cookie_link_1' => 'Information about the EU Cookie Law directive', 'analytics_cookie_link_2' => 'Cookie Consent by Insites', 'analytics_cookie_warning_1' => 'If you are based in Europe and you enable visitor tracking, you will need to comply with the EU Cookie Law. The easiest way to do so is using a script like Cookie Consent by Insites.', diff --git a/resources/lang/en/gallery.php b/resources/lang/en/gallery.php index 4373799..4681e4b 100644 --- a/resources/lang/en/gallery.php +++ b/resources/lang/en/gallery.php @@ -34,6 +34,7 @@ return [ 'other_albums_heading' => 'More Albums in :album_name', 'photos' => 'photo|photos', 'previous_button' => '« Previous Photo', + 'show_more_albums' => '... and :count other|... and :count others', 'show_more_labels' => '... and :count other|... and :count others', 'show_raw_exif_data' => 'Show all EXIF data', 'shutter_speed' => 'Shutter speed:', diff --git a/resources/views/themes/base/admin/settings.blade.php b/resources/views/themes/base/admin/settings.blade.php index 8ec5c18..37628a7 100644 --- a/resources/views/themes/base/admin/settings.blade.php +++ b/resources/views/themes/base/admin/settings.blade.php @@ -77,6 +77,30 @@ +
+ +
+ @lang('admin.settings.albums_menu_heading') + +
+ +
+ +
+ + + + @if ($errors->has('albums_menu_number_items')) +
+ {{ $errors->first('albums_menu_number_items') }} +
+ @endif +
+

diff --git a/resources/views/themes/base/partials/navbar.blade.php b/resources/views/themes/base/partials/navbar.blade.php index 7030bf1..abc6e66 100644 --- a/resources/views/themes/base/partials/navbar.blade.php +++ b/resources/views/themes/base/partials/navbar.blade.php @@ -20,9 +20,13 @@ @lang('navigation.navbar.albums') @endif