Added a settings page allowing the date format and application name to be configured
This commit is contained in:
parent
ef95fd31ba
commit
00ab249476
18
app/Facade/UserConfig.php
Normal file
18
app/Facade/UserConfig.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Facade;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
class UserConfig extends Facade
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the registered name of the component.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function getFacadeAccessor()
|
||||||
|
{
|
||||||
|
return 'user_config';
|
||||||
|
}
|
||||||
|
}
|
59
app/Helpers/ConfigHelper.php
Normal file
59
app/Helpers/ConfigHelper.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Configuration;
|
||||||
|
|
||||||
|
class ConfigHelper
|
||||||
|
{
|
||||||
|
public function allowedDateFormats()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Y-m-d - H:i',
|
||||||
|
'd/m/Y - H:i',
|
||||||
|
'm/d/Y - H:i',
|
||||||
|
'jS F Y - H:i',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defaults()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'app_name' => trans('global.app_name'),
|
||||||
|
'date_format' => $this->allowedDateFormats()[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($key, $defaultIfUnset = true)
|
||||||
|
{
|
||||||
|
$config = Configuration::where('key', $key)->first();
|
||||||
|
|
||||||
|
return (is_null($config) ? $this->defaults()[$key] : $config->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAll()
|
||||||
|
{
|
||||||
|
$results = array();
|
||||||
|
|
||||||
|
foreach (Configuration::all() as $config)
|
||||||
|
{
|
||||||
|
$results[$config->key] = $config->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrCreateModel($key)
|
||||||
|
{
|
||||||
|
$config = Configuration::where('key', $key)->first();
|
||||||
|
if (is_null($config) || $config === false)
|
||||||
|
{
|
||||||
|
$config = new Configuration();
|
||||||
|
$config->key = $key;
|
||||||
|
$config->value = '';
|
||||||
|
$config->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
|
}
|
@ -3,8 +3,13 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Album;
|
use App\Album;
|
||||||
|
use App\Configuration;
|
||||||
use App\Facade\Theme;
|
use App\Facade\Theme;
|
||||||
|
use App\Facade\UserConfig;
|
||||||
|
use App\Helpers\ConfigHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\SaveSettingsRequest;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class DefaultController extends Controller
|
class DefaultController extends Controller
|
||||||
@ -19,4 +24,44 @@ class DefaultController extends Controller
|
|||||||
'album_count' => $albumCount
|
'album_count' => $albumCount
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function saveSettings(SaveSettingsRequest $request)
|
||||||
|
{
|
||||||
|
$updateKeys = [
|
||||||
|
'app_name',
|
||||||
|
'date_format'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($updateKeys as $key)
|
||||||
|
{
|
||||||
|
$config = UserConfig::getOrCreateModel($key);
|
||||||
|
$config->value = $request->request->get($key);
|
||||||
|
$config->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$request->session()->flash('success', trans('admin.settings_saved_message'));
|
||||||
|
return redirect(route('admin.settings'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settings(Request $request)
|
||||||
|
{
|
||||||
|
$this->authorize('admin-access');
|
||||||
|
|
||||||
|
// Load the current configuration
|
||||||
|
$config = array_merge(UserConfig::defaults(), UserConfig::getAll());
|
||||||
|
|
||||||
|
$dateFormats = UserConfig::allowedDateFormats();
|
||||||
|
$dateFormatsLookup = [];
|
||||||
|
|
||||||
|
foreach ($dateFormats as $dateFormat)
|
||||||
|
{
|
||||||
|
$dateFormatsLookup[$dateFormat] = date($dateFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Theme::render('admin.settings', [
|
||||||
|
'config' => $config,
|
||||||
|
'date_formats' => $dateFormatsLookup,
|
||||||
|
'success' => $request->session()->get('success')
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
31
app/Http/Requests/SaveSettingsRequest.php
Normal file
31
app/Http/Requests/SaveSettingsRequest.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class SaveSettingsRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'app_name' => 'required|max:255',
|
||||||
|
'date_format' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,8 @@ namespace App\Providers;
|
|||||||
|
|
||||||
use App\Album;
|
use App\Album;
|
||||||
use App\Facade\Theme;
|
use App\Facade\Theme;
|
||||||
|
use App\Facade\UserConfig;
|
||||||
|
use App\Helpers\ConfigHelper;
|
||||||
use App\Helpers\ImageHelper;
|
use App\Helpers\ImageHelper;
|
||||||
use App\Helpers\ThemeHelper;
|
use App\Helpers\ThemeHelper;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
@ -27,6 +29,10 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
return new ThemeHelper();
|
return new ThemeHelper();
|
||||||
});
|
});
|
||||||
|
$this->app->singleton('user_config', function($app)
|
||||||
|
{
|
||||||
|
return new ConfigHelper();
|
||||||
|
});
|
||||||
|
|
||||||
// When running migrations or CLI tasks, don't need to add things to the view
|
// When running migrations or CLI tasks, don't need to add things to the view
|
||||||
if (php_sapi_name() != 'cli')
|
if (php_sapi_name() != 'cli')
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
// Version number of Photo Perfect
|
// Version number of Blue Twilight
|
||||||
'version' => '1.0.0-ALPHA',
|
'version' => '1.0.0-ALPHA',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -230,6 +230,7 @@ return [
|
|||||||
'Form' => Collective\Html\FormFacade::class,
|
'Form' => Collective\Html\FormFacade::class,
|
||||||
'Html' => Collective\Html\HtmlFacade::class,
|
'Html' => Collective\Html\HtmlFacade::class,
|
||||||
'Theme' => App\Facade\Theme::class,
|
'Theme' => App\Facade\Theme::class,
|
||||||
|
'UserConfig' => App\Facade\UserConfig::class
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
2
public/themes/bootstrap3/theme.css
vendored
2
public/themes/bootstrap3/theme.css
vendored
@ -31,5 +31,5 @@
|
|||||||
.tab-content {
|
.tab-content {
|
||||||
border: solid 1px #ddd;
|
border: solid 1px #ddd;
|
||||||
border-top: 0;
|
border-top: 0;
|
||||||
padding: 10px;
|
padding: 20px;
|
||||||
}
|
}
|
@ -11,6 +11,10 @@ return [
|
|||||||
'list_albums_name_column' => 'Album name',
|
'list_albums_name_column' => 'Album name',
|
||||||
'no_albums_text' => 'You have no photo albums yet. Click the button below to create one.',
|
'no_albums_text' => 'You have no photo albums yet. Click the button below to create one.',
|
||||||
'no_albums_title' => 'No Photo Albums',
|
'no_albums_title' => 'No Photo Albums',
|
||||||
|
'settings_link' => 'Settings',
|
||||||
|
'settings_save_action' => 'Update Settings',
|
||||||
|
'settings_saved_message' => 'The settings were updated successfully.',
|
||||||
|
'settings_title' => 'Settings',
|
||||||
'stats_albums' => 'album|albums',
|
'stats_albums' => 'album|albums',
|
||||||
'stats_panel' => 'Statistics'
|
'stats_panel' => 'Statistics'
|
||||||
];
|
];
|
@ -22,6 +22,7 @@
|
|||||||
<div class="panel-heading">@lang('admin.actions_panel')</div>
|
<div class="panel-heading">@lang('admin.actions_panel')</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<a href="{{ route('albums.create') }}" class="btn btn-default"><i class="fa fa-fw fa-plus"></i> @lang('admin.create_album_link')</a>
|
<a href="{{ route('albums.create') }}" class="btn btn-default"><i class="fa fa-fw fa-plus"></i> @lang('admin.create_album_link')</a>
|
||||||
|
<a href="{{ route('admin.settings') }}" class="btn btn-default"><i class="fa fa-fw fa-cog"></i> @lang('admin.settings_link')</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
48
resources/views/themes/base/admin/settings.blade.php
Normal file
48
resources/views/themes/base/admin/settings.blade.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
@extends('themes.base.layout')
|
||||||
|
@section('title', trans('admin.settings_title'))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<h1>@yield('title')</h1>
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
{!! Form::model($config, ['route' => 'admin.saveSettings', 'method' => 'POST']) !!}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{{-- Nav tabs --}}
|
||||||
|
<ul class="nav nav-tabs" role="tablist">
|
||||||
|
<li role="presentation" class="active"><a href="#upload-tab" aria-controls="upload-tab" role="tab" data-toggle="tab"><i class="fa fa-fw fa-info-circle"></i> General</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{{-- Tab panes --}}
|
||||||
|
<div class="tab-content">
|
||||||
|
<div role="tabpanel" class="tab-pane active" id="upload-tab">
|
||||||
|
<div class="form-group">
|
||||||
|
{!! Form::label('app_name', 'Gallery name:', ['class' => 'control-label']) !!}
|
||||||
|
{!! Form::text('app_name', old('app_name'), ['class' => 'form-control']) !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-sm-4">
|
||||||
|
<div class="form-group">
|
||||||
|
{!! Form::label('date_format', 'Date format:', ['class' => 'control-label']) !!}
|
||||||
|
{!! Form::select('date_format', $date_formats, old('date_format'), ['class' => 'form-control']) !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-right" style="margin-top: 15px;">
|
||||||
|
<a href="{{ route('admin') }}" class="btn btn-default">@lang('forms.cancel_action')</a>
|
||||||
|
{!! Form::submit(trans('admin.settings_save_action'), ['class' => 'btn btn-success']) !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!! Form::close() !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
@ -33,7 +33,7 @@
|
|||||||
@if (strlen($photo->taken_at) > 0)
|
@if (strlen($photo->taken_at) > 0)
|
||||||
<tr>
|
<tr>
|
||||||
<td class="metadata_name">Date taken:</td>
|
<td class="metadata_name">Date taken:</td>
|
||||||
<td class="metadata_value">{{ $photo->taken_at }}</td>
|
<td class="metadata_value">{{ date(UserConfig::get('date_format'), strtotime($photo->taken_at)) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="generator" content="{{ config('app.name') }} v{{ config('app.version') }} (framework v{{ App::VERSION() }})">
|
<meta name="generator" content="{{ config('app.name') }} v{{ config('app.version') }} (framework v{{ App::VERSION() }})">
|
||||||
|
|
||||||
<title>@yield('title') | @lang('global.app_name')</title>
|
<title>@yield('title') | {{ UserConfig::get('app_name') }}</title>
|
||||||
<base href="{{ url('/') }}">
|
<base href="{{ url('/') }}">
|
||||||
|
|
||||||
{{-- Cannot use $theme_url here: if a theme uses the base layout, it would also have to provide all these dependencies! --}}
|
{{-- Cannot use $theme_url here: if a theme uses the base layout, it would also have to provide all these dependencies! --}}
|
||||||
@ -33,6 +33,14 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if (isset($success))
|
||||||
|
<div class="container">
|
||||||
|
<div class="alert alert-success">
|
||||||
|
<strong><i class="fa fa-info-circle fa-fw"></i></strong> {{ $success }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
@yield('content')
|
@yield('content')
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</button>
|
</button>
|
||||||
<a class="navbar-brand" href="{{ route('home') }}">@lang('global.app_name')</a>
|
<a class="navbar-brand" href="{{ route('home') }}">{{ UserConfig::get('app_name') }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Collect the nav links, forms, and other content for toggling -->
|
<!-- Collect the nav links, forms, and other content for toggling -->
|
||||||
|
@ -16,6 +16,8 @@ Auth::routes();
|
|||||||
// Administration
|
// Administration
|
||||||
Route::group(['prefix' => 'admin'], function () {
|
Route::group(['prefix' => 'admin'], function () {
|
||||||
Route::get('/', 'Admin\DefaultController@index')->name('admin');
|
Route::get('/', 'Admin\DefaultController@index')->name('admin');
|
||||||
|
Route::post('settings/save', 'Admin\DefaultController@saveSettings')->name('admin.saveSettings');
|
||||||
|
Route::get('settings', 'Admin\DefaultController@settings')->name('admin.settings');
|
||||||
|
|
||||||
// Album management
|
// Album management
|
||||||
Route::get('albums/{id}/delete', 'Admin\AlbumController@delete')->name('albums.delete');
|
Route::get('albums/{id}/delete', 'Admin\AlbumController@delete')->name('albums.delete');
|
||||||
@ -30,6 +32,6 @@ Route::group(['prefix' => 'admin'], function () {
|
|||||||
|
|
||||||
// Gallery
|
// Gallery
|
||||||
Route::get('/', 'Gallery\DefaultController@index')->name('home');
|
Route::get('/', 'Gallery\DefaultController@index')->name('home');
|
||||||
Route::get('/{albumUrlAlias}', 'Gallery\AlbumController@index')->name('viewAlbum');
|
Route::get('{albumUrlAlias}', 'Gallery\AlbumController@index')->name('viewAlbum');
|
||||||
Route::get('/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')->name('viewPhoto');
|
Route::get('{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@show')->name('viewPhoto');
|
||||||
Route::get('/photo/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@download')->name('downloadPhoto');
|
Route::get('photo/{albumUrlAlias}/{photoFilename}', 'Gallery\PhotoController@download')->name('downloadPhoto');
|
Loading…
Reference in New Issue
Block a user