FEATURE: add saving settings
This commit is contained in:
@@ -127,7 +127,7 @@ abstract class Handler implements AppHandler
|
|||||||
$sub->route('customfields.overview', trans('admin/mainMenu.customFieldsOverview'), [], 50, ['icon' => 'fa fa-code-fork']);
|
$sub->route('customfields.overview', trans('admin/mainMenu.customFieldsOverview'), [], 50, ['icon' => 'fa fa-code-fork']);
|
||||||
}, 30, ['icon' => 'fa fa-code']);
|
}, 30, ['icon' => 'fa fa-code']);
|
||||||
$menu->route('log.overview', trans('admin/mainMenu.actionLog'), [], 40, ['icon' => 'fa fa-history']);
|
$menu->route('log.overview', trans('admin/mainMenu.actionLog'), [], 40, ['icon' => 'fa fa-history']);
|
||||||
$menu->url('#', trans('admin/mainMenu.settings'), 50, ['icon' => 'fa fa-gear']);
|
$menu->route('settings.overview', trans('admin/mainMenu.settings'), [], 50, ['icon' => 'fa fa-gear']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// order
|
// order
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
|
class Settings extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \App\Models\Settings
|
||||||
|
*/
|
||||||
|
protected $settings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings constructor.
|
||||||
|
*
|
||||||
|
* @param \App\Models\Settings $settings
|
||||||
|
*/
|
||||||
|
public function __construct(\App\Models\Settings $settings)
|
||||||
|
{
|
||||||
|
$this->settings = $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOverview()
|
||||||
|
{
|
||||||
|
$sections = App::make('registerSettingsExtension')
|
||||||
|
->get();
|
||||||
|
$settings = $this->settings->getAll();
|
||||||
|
|
||||||
|
return view('admin.settings.overview', [
|
||||||
|
'formSections' => $sections,
|
||||||
|
'settings' => $settings
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveSettings(Requests\SaveSettingsRequest $request)
|
||||||
|
{
|
||||||
|
$data = $request->all();
|
||||||
|
// remove CSRF token field
|
||||||
|
unset($data['_token']);
|
||||||
|
|
||||||
|
$settings = $this->settings->getAll();
|
||||||
|
$updated = 0;
|
||||||
|
foreach($data as $key => $value) {
|
||||||
|
if ($settings->$key != $value) {
|
||||||
|
$updated ++;
|
||||||
|
\App\Models\Settings::where('key', $key)->update(['value' => $value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($updated > 0) {
|
||||||
|
return redirect()->route('settings.overview')->with('success', trans('admin/settings.successfullySaved'));
|
||||||
|
} else {
|
||||||
|
return redirect()->route('settings.overview')->with('error', trans('admin/settings.nothingToSave'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class SaveSettingsRequest extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'pageName' => 'required',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-2
@@ -58,8 +58,8 @@ Route::group([
|
|||||||
Route::post('templates/copy', 'CopyTemplate@createCopy')
|
Route::post('templates/copy', 'CopyTemplate@createCopy')
|
||||||
->name('templates.postCopy');
|
->name('templates.postCopy');
|
||||||
|
|
||||||
// Route::get('templates/new/{pathId}', 'TemplateOverview@getPath')
|
// Route::get('templates/new/{pathId}', 'TemplateOverview@getPath')
|
||||||
// ->name('templates.new');
|
// ->name('templates.new');
|
||||||
|
|
||||||
Route::get('templates/edit/{id}', 'EditTemplate@getEdit')
|
Route::get('templates/edit/{id}', 'EditTemplate@getEdit')
|
||||||
->name('templates.edit');
|
->name('templates.edit');
|
||||||
@@ -209,6 +209,13 @@ Route::group([
|
|||||||
Route::post('upload/image', 'UploadFile@postImage')
|
Route::post('upload/image', 'UploadFile@postImage')
|
||||||
->name('upload.postImage');
|
->name('upload.postImage');
|
||||||
|
|
||||||
|
// form with settings
|
||||||
|
Route::get('settings', 'Settings@getOverview')
|
||||||
|
->name('settings.overview');
|
||||||
|
|
||||||
|
Route::post('settings', 'Settings@saveSettings')
|
||||||
|
->name('settings.save');
|
||||||
|
|
||||||
// custom fields
|
// custom fields
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Settings extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'settings';
|
||||||
|
public $timestamps = false;
|
||||||
|
protected $fillable = ['key', 'value'];
|
||||||
|
|
||||||
|
public function getAll()
|
||||||
|
{
|
||||||
|
$settings = Settings::select(['key', 'value'])
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$data = new \stdClass();
|
||||||
|
foreach ($settings as $conf) {
|
||||||
|
$data->{$conf->key} = $conf->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Handlers\Registrators\SettingsExtensionRegistrator;
|
||||||
use App\Handlers\Registrators\TemplateRegistrator;
|
use App\Handlers\Registrators\TemplateRegistrator;
|
||||||
use App\Handlers\Registrators\WidgetRegistrator;
|
use App\Handlers\Registrators\WidgetRegistrator;
|
||||||
use App\Widgets\HtmlCode\HtmlCode;
|
use App\Widgets\HtmlCode\HtmlCode;
|
||||||
@@ -18,6 +19,7 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$this->registerWidgets();
|
$this->registerWidgets();
|
||||||
$this->registerTemplates();
|
$this->registerTemplates();
|
||||||
|
$this->registerSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,6 +47,10 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$this->app->singleton('registerTemplateDir', function ($app) {
|
$this->app->singleton('registerTemplateDir', function ($app) {
|
||||||
return new TemplateRegistrator($app);
|
return new TemplateRegistrator($app);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->app->singleton('registerSettingsExtension', function ($app) {
|
||||||
|
return new SettingsExtensionRegistrator($app);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,4 +80,15 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
$registrator->register(config('app.theme'), 'admin/templates.core');
|
$registrator->register(config('app.theme'), 'admin/templates.core');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register setting sections
|
||||||
|
*/
|
||||||
|
private function registerSettings()
|
||||||
|
{
|
||||||
|
$registrator = $this->app->make('registerSettingsExtension');
|
||||||
|
|
||||||
|
$registrator->register('basic', 'admin/settings.basic', 'admin.settings.parts.basic');
|
||||||
|
$registrator->register('meta', 'admin/settings.meta', 'admin.settings.parts.meta');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'overview' => 'All available settings',
|
||||||
|
'basic' => 'Basic information',
|
||||||
|
'save' => 'Save',
|
||||||
|
'pageName' => 'Page name',
|
||||||
|
'metaKeywords' => 'Web keywords',
|
||||||
|
'metaDescription' => 'Web description',
|
||||||
|
'googleAnalyticsCode' => 'Google Analytics code',
|
||||||
|
'author' => 'Page owner',
|
||||||
|
'successfullySaved' => 'Settings successfully saved',
|
||||||
|
'nothingToSave' => 'You have submitted unchanged form. Try to change some attribute first.',
|
||||||
|
'meta' => 'Meta information'
|
||||||
|
];
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
@extends('admin.layout')
|
||||||
|
|
||||||
|
@section('pageName', @trans('admin/settings.overview'))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<h2>@lang('admin/settings.overview')</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (session('success'))
|
||||||
|
<div data-alert class="callout success">
|
||||||
|
<strong>{{ session('success') }}</strong>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if (session('error'))
|
||||||
|
<div data-alert class="callout alert">
|
||||||
|
<strong>{{ session('error') }}</strong>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<ul class="tabs" data-tabs id="static-page-controls">
|
||||||
|
@foreach($formSections as $id => $section)
|
||||||
|
<li class="tabs-title @if($section->getId() == reset($formSections)->getId()) is-active @endif">
|
||||||
|
<a href="#{{$id}}" @if($section->getId() == reset($formSections)->getId()) aria-selected="true" @endif>
|
||||||
|
{{trans($section->getName())}}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<form action="{{route('settings.save')}}" method="POST">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
<div class="tabs-content" data-tabs-content="static-page-controls">
|
||||||
|
@foreach($formSections as $id => $section)
|
||||||
|
<div class="tabs-panel @if($id == reset($formSections)->getId()) is-active @endif" id="{{$section->getId()}}">
|
||||||
|
@include($section->getView())
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="columns large-12">
|
||||||
|
<button type="submit" class="button success">@lang('admin/settings.save')</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
@stop
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<label>
|
||||||
|
@lang('admin/settings.pageName')
|
||||||
|
|
||||||
|
<input type="text" name="pageName" value="{{old('pageName', $settings->pageName)}}" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('admin/settings.author')
|
||||||
|
|
||||||
|
<input type="text" name="author" value="{{old('author', $settings->author)}}" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('admin/settings.googleAnalyticsCode')
|
||||||
|
|
||||||
|
<input type="text" name="googleAnalyticsCode" value="{{old('googleAnalyticsCode', $settings->googleAnalyticsCode)}}" />
|
||||||
|
</label>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<label>
|
||||||
|
@lang('admin/settings.metaKeywords')
|
||||||
|
|
||||||
|
<input type="text" name="metaKeywords" value="{{old('metaKeywords', $settings->metaKeywords)}}" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('admin/settings.metaDescription')
|
||||||
|
|
||||||
|
<textarea name="metaDescription" rows="3">{{old('metaDescription', $settings->metaDescription)}}</textarea>
|
||||||
|
</label>
|
||||||
Reference in New Issue
Block a user