diff --git a/app/Facade/UserConfig.php b/app/Facade/UserConfig.php new file mode 100644 index 0000000..341d06d --- /dev/null +++ b/app/Facade/UserConfig.php @@ -0,0 +1,18 @@ + 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; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Admin/DefaultController.php b/app/Http/Controllers/Admin/DefaultController.php index 0e5e3f3..56966ed 100644 --- a/app/Http/Controllers/Admin/DefaultController.php +++ b/app/Http/Controllers/Admin/DefaultController.php @@ -3,8 +3,13 @@ namespace App\Http\Controllers\Admin; use App\Album; +use App\Configuration; use App\Facade\Theme; +use App\Facade\UserConfig; +use App\Helpers\ConfigHelper; use App\Http\Controllers\Controller; +use App\Http\Requests\SaveSettingsRequest; +use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class DefaultController extends Controller @@ -19,4 +24,44 @@ class DefaultController extends Controller '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') + ]); + } } \ No newline at end of file diff --git a/app/Http/Requests/SaveSettingsRequest.php b/app/Http/Requests/SaveSettingsRequest.php new file mode 100644 index 0000000..dd0035a --- /dev/null +++ b/app/Http/Requests/SaveSettingsRequest.php @@ -0,0 +1,31 @@ + 'required|max:255', + 'date_format' => 'required', + ]; + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 46893d0..65d9f7d 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,8 @@ namespace App\Providers; use App\Album; use App\Facade\Theme; +use App\Facade\UserConfig; +use App\Helpers\ConfigHelper; use App\Helpers\ImageHelper; use App\Helpers\ThemeHelper; use Illuminate\Database\QueryException; @@ -27,6 +29,10 @@ class AppServiceProvider extends ServiceProvider { 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 if (php_sapi_name() != 'cli') diff --git a/config/app.php b/config/app.php index 21af61e..a9707ad 100644 --- a/config/app.php +++ b/config/app.php @@ -1,7 +1,7 @@ '1.0.0-ALPHA', /* @@ -230,6 +230,7 @@ return [ 'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class, 'Theme' => App\Facade\Theme::class, + 'UserConfig' => App\Facade\UserConfig::class ], ]; diff --git a/public/themes/bootstrap3/theme.css b/public/themes/bootstrap3/theme.css index 52004ce..de72677 100644 --- a/public/themes/bootstrap3/theme.css +++ b/public/themes/bootstrap3/theme.css @@ -31,5 +31,5 @@ .tab-content { border: solid 1px #ddd; border-top: 0; - padding: 10px; + padding: 20px; } \ No newline at end of file diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index d59c792..3bb6e9c 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -11,6 +11,10 @@ return [ 'list_albums_name_column' => 'Album name', 'no_albums_text' => 'You have no photo albums yet. Click the button below to create one.', '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_panel' => 'Statistics' ]; \ No newline at end of file diff --git a/resources/views/themes/base/admin/index.blade.php b/resources/views/themes/base/admin/index.blade.php index 84d8472..3a62e73 100644 --- a/resources/views/themes/base/admin/index.blade.php +++ b/resources/views/themes/base/admin/index.blade.php @@ -22,6 +22,7 @@