FEATURE: add homepage settings for base of one page pages
This commit is contained in:
@@ -28,13 +28,21 @@ class Settings
|
|||||||
* @param string $key settings key
|
* @param string $key settings key
|
||||||
* @param string|null $default default value, which will be returned when given key does not exist
|
* @param string|null $default default value, which will be returned when given key does not exist
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @param null $exists
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public static function get($key, $default = null)
|
public static function get($key, $default = null, & $exists = null)
|
||||||
{
|
{
|
||||||
self::init();
|
self::init();
|
||||||
|
|
||||||
return isset(self::$settings->$key) ? self::$settings->$key : $default;
|
if (isset(self::$settings->$key)) {
|
||||||
|
$exists = true;
|
||||||
|
return self::$settings->$key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$exists = false;
|
||||||
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
use Illuminate\Support\Facades\App;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ class ModuleManager extends ServiceProvider
|
|||||||
{
|
{
|
||||||
// this service provider needs published config - config is merged right after this service provider
|
// this service provider needs published config - config is merged right after this service provider
|
||||||
try {
|
try {
|
||||||
$modules = Module::where('is_template', false)
|
$modules = Module::where('enabled', true)
|
||||||
->get();
|
->get();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// ignore error
|
// ignore error
|
||||||
@@ -26,6 +25,20 @@ class ModuleManager extends ServiceProvider
|
|||||||
|
|
||||||
// iterate over all modules and enable or disable them
|
// iterate over all modules and enable or disable them
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
|
|
||||||
|
$module->module_settings = json_decode($module->module_settings);
|
||||||
|
|
||||||
|
if ($module->is_template) {
|
||||||
|
|
||||||
|
if (isset($module->module_settings->providers) && !empty($module->module_settings->providers)) {
|
||||||
|
foreach ($module->module_settings->providers as $provider) {
|
||||||
|
$this->app->register($provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$this->createModulesJson($module);
|
$this->createModulesJson($module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,7 +61,7 @@ class ModuleManager extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
private function createModulesJson(Module $module)
|
private function createModulesJson(Module $module)
|
||||||
{
|
{
|
||||||
$config = json_decode($module->module_settings);
|
$config = $module->module_settings;
|
||||||
|
|
||||||
if (is_null($config)) {
|
if (is_null($config)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ use App\Models\User;
|
|||||||
|
|
||||||
abstract class OnePage implements TemplateHandler
|
abstract class OnePage implements TemplateHandler
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Name of settings key for list of pages used on homepage
|
||||||
|
*/
|
||||||
|
const HOMEPAGE_PAGES_SETTINGS_KEY = 'template.onepage.homepagePages';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register admin menu (or multiple ones)
|
* Register admin menu (or multiple ones)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
namespace Templates\Base\OnePage\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Helpers\Settings;
|
||||||
|
use App\Http\Controllers\Admin\Controller;
|
||||||
|
use App\Models\Content;
|
||||||
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||||
|
use Templates\Base\OnePage\Handlers\OnePage;
|
||||||
|
|
||||||
|
class SetHomepage extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Content
|
||||||
|
*/
|
||||||
|
private $content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetHomepage constructor.
|
||||||
|
*
|
||||||
|
* @param Content $content
|
||||||
|
*/
|
||||||
|
public function __construct(Content $content)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->content = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display form for organizing pages on homepage
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function getPages()
|
||||||
|
{
|
||||||
|
// get pages which are assigned as homepage parts
|
||||||
|
$usedPagesIds = (array)json_decode(Settings::get(OnePage::HOMEPAGE_PAGES_SETTINGS_KEY, '{}'));
|
||||||
|
|
||||||
|
// get all pages - they will be separated for used and not used on next lines
|
||||||
|
$allPages = $this->content->getOverview()
|
||||||
|
->get();
|
||||||
|
|
||||||
|
// separate pages to used and not used - with help of $usedPAgesIds array defined above
|
||||||
|
$pages = $used = $notUsed = [];
|
||||||
|
foreach ($allPages as $page) {
|
||||||
|
$pages[$page->id] = $page;
|
||||||
|
|
||||||
|
if (in_array($page->id, $usedPagesIds)) {
|
||||||
|
$used[$page->id] = $page;
|
||||||
|
} else {
|
||||||
|
$notUsed[$page->id] = $page;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('template::admin/homepage.set', [
|
||||||
|
'usedPagesIds' => $usedPagesIds,
|
||||||
|
'allPages' => $pages,
|
||||||
|
'usedPages' => $used,
|
||||||
|
'notUsedPages' => $notUsed
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add page into homepage
|
||||||
|
*
|
||||||
|
* @param $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function addPage($id)
|
||||||
|
{
|
||||||
|
|
||||||
|
// try to get page config
|
||||||
|
$settingsEntry = \App\Models\Settings::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$settingsEntry) {
|
||||||
|
$settingsEntry = new \App\Models\Settings();
|
||||||
|
$settingsEntry->language = LaravelLocalization::getCurrentLocale();
|
||||||
|
$settingsEntry->key = OnePage::HOMEPAGE_PAGES_SETTINGS_KEY;
|
||||||
|
$usedPagesIds = [];
|
||||||
|
} else {
|
||||||
|
$usedPagesIds = (array)json_decode($settingsEntry->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($id, $usedPagesIds)) {
|
||||||
|
$usedPagesIds[] = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$settingsEntry->value = json_encode($usedPagesIds);
|
||||||
|
$settingsEntry->save();
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('success', trans('template::admin/setHomepage.successfullyAdded'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove page from homepage
|
||||||
|
*
|
||||||
|
* @param $id
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function removePage($id)
|
||||||
|
{
|
||||||
|
$pages = (array)json_decode(Settings::get(OnePage::HOMEPAGE_PAGES_SETTINGS_KEY, '{}'));
|
||||||
|
|
||||||
|
if (!in_array($id, $pages)) {
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('error', trans('template::admin/setHomepage.invalidPageId'));
|
||||||
|
} else {
|
||||||
|
$pagePosition = array_search($id, $pages);
|
||||||
|
|
||||||
|
// remove page from config array
|
||||||
|
unset($pages[$pagePosition]);
|
||||||
|
|
||||||
|
$pages = array_values($pages);
|
||||||
|
|
||||||
|
// update in database
|
||||||
|
\App\Models\Settings::where('key', OnePage::HOMEPAGE_PAGES_SETTINGS_KEY)
|
||||||
|
->where('language', LaravelLocalization::getCurrentLocale())
|
||||||
|
->update(['value' => json_encode($pages)]);
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->with('success', trans('template::admin/setHomepage.successfullyRemoved'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
Route::group([
|
||||||
|
'middleware' => [
|
||||||
|
'localeSessionRedirect',
|
||||||
|
'localizationRedirect',
|
||||||
|
'web',
|
||||||
|
'auth',
|
||||||
|
'adminMenu'
|
||||||
|
],
|
||||||
|
'prefix' => \LaravelLocalization::setLocale() . '/admin/template',
|
||||||
|
'namespace' => 'Templates\Base\OnePage\Http\Controllers\Admin'
|
||||||
|
], function () {
|
||||||
|
|
||||||
|
// display form for selecting pages for homepage
|
||||||
|
Route::get('homepage', 'SetHomepage@getPages')
|
||||||
|
->name('template.setHomepage');
|
||||||
|
|
||||||
|
// add page into homepage
|
||||||
|
Route::get('add/{id}', 'SetHomepage@addPage')
|
||||||
|
->name('template.homepage.addPage');
|
||||||
|
|
||||||
|
// delete page from homepage
|
||||||
|
Route::get('remove/{id}', 'SetHomepage@removePage')
|
||||||
|
->name('template.homepage.removePage');
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
namespace Templates\Base\OnePage\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class OnePageTemplate extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register the service provider.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
// register translations
|
||||||
|
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'template');
|
||||||
|
|
||||||
|
// load views
|
||||||
|
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||||
|
return $path;
|
||||||
|
}, \Config::get('view.paths')), [__DIR__ . '/../Resources/views']), 'template');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'setHomepage' => 'Homepage settings',
|
||||||
|
'templateName' => 'Onepager'
|
||||||
|
];
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'title' => 'Homepage setup',
|
||||||
|
'pageDescription' => 'On this page you can setup all pages which should appear on homepage. Use drag\'n\'drop feature and organize your pages into your presentation.',
|
||||||
|
'noPagesSelected' => 'No pages selected for homepage. Yet...',
|
||||||
|
'noPagesAvailable' => 'There are no pages you could set up for homepage.',
|
||||||
|
'successfullyAdded' => 'Page successfully added to homepage.',
|
||||||
|
'successfullyRemoved' => 'Page successfully removed from homepage.',
|
||||||
|
'invalidPageId' => 'Cannot remove page from homepage, because given ID does not exist.',
|
||||||
|
'usedPages' => 'Used pages',
|
||||||
|
'notUsedPages' => 'Not used pages',
|
||||||
|
'reallyRemovePage' => 'Do you really want to remove this page from homepage?',
|
||||||
|
|
||||||
|
];
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
@extends('admin.layoutWithNavigation')
|
||||||
|
|
||||||
|
@section('pageHeading', trans('template::admin/setHomepage.title'))
|
||||||
|
@section('pageDescription', trans('template::admin/setHomepage.pageDescription'))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8">
|
||||||
|
<h3>@lang('template::admin/setHomepage.usedPages')</h3>
|
||||||
|
@forelse($usedPagesIds as $pageId)
|
||||||
|
|
||||||
|
{{--ignore non-existing pages--}}
|
||||||
|
@if(!isset($allPages[$pageId]))
|
||||||
|
@continue
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="card card-default">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="header-block">
|
||||||
|
<p class="title"> {{$allPages[$pageId]->title}} </p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-block">
|
||||||
|
<p>
|
||||||
|
<small>(@lang($allPages[$pageId]->module_name))</small>
|
||||||
|
</p>
|
||||||
|
<p>{{str_limit(strip_tags($allPages[$pageId]->content), 200)}}</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer text-right">
|
||||||
|
<a href="{{route('content.edit', ['id' => $allPages[$pageId]->id])}}"
|
||||||
|
class="btn btn-secondary btn-sm"><i
|
||||||
|
class="fa fa-fw fa-pencil"></i></a>
|
||||||
|
<a href="{{route('template.homepage.removePage', ['id' => $allPages[$pageId]->id])}}"
|
||||||
|
class="btn btn-warning confirm btn-sm" data-message="@lang('template::admin/setHomepage.reallyRemovePage')"><i
|
||||||
|
class="fa fa-fw fa-trash"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<div class="alert alert-info">
|
||||||
|
@lang('template::admin/setHomepage.noPagesSelected')
|
||||||
|
</div>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-4">
|
||||||
|
<h3>@lang('template::admin/setHomepage.notUsedPages')</h3>
|
||||||
|
@forelse($notUsedPages as $page)
|
||||||
|
<div class="card card-default">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="header-block">
|
||||||
|
<p class="title">{{$page->title}}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-block">
|
||||||
|
<p>
|
||||||
|
<small>(@lang($page->module_name))</small>
|
||||||
|
</p>
|
||||||
|
<p>{{str_limit(strip_tags($page->content), 200)}}</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer text-right">
|
||||||
|
<a href="{{route('content.edit', ['id' => $page->id])}}"
|
||||||
|
class="btn btn-secondary btn-sm"><i
|
||||||
|
class="fa fa-fw fa-pencil"></i></a>
|
||||||
|
<a href="{{route('template.homepage.addPage', ['id' => $page->id])}}"
|
||||||
|
class="btn btn-sm btn-primary"><i class="fa green fa-fw fa-plus"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<div class="alert alert-info">
|
||||||
|
@lang('template::admin/setHomepage.noPagesAvailable')
|
||||||
|
</div>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endsection
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
return [
|
return [
|
||||||
'handler' => \Templates\Base\OnePage\Handlers\OnePage::class,
|
'providers' => [\Templates\Base\OnePage\Providers\OnePageTemplate::class],
|
||||||
'name' => 'Sablona',
|
'files' => [__DIR__ . '/Http/routes.php'],
|
||||||
'alias' => 'sablona',
|
'handler' => null,
|
||||||
'description' => 'Sablona jednostrankova',
|
'name' => null,
|
||||||
'files' => [
|
'description' => null,
|
||||||
__DIR__.'/routes.php'
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<?php
|
|
||||||
Route::group(['middleware' => 'web', 'prefix' => 'test'], function()
|
|
||||||
{
|
|
||||||
Route::get('/', function() {
|
|
||||||
echo "ahoj";
|
|
||||||
})->name('template.route');
|
|
||||||
});
|
|
||||||
@@ -3,11 +3,24 @@ namespace Templates\Jednostrankovka;
|
|||||||
|
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Pingpong\Menus\MenuFacade;
|
||||||
use Templates\Base\OnePage\Handlers\OnePage;
|
use Templates\Base\OnePage\Handlers\OnePage;
|
||||||
|
|
||||||
class Handler extends OnePage
|
class Handler extends OnePage
|
||||||
{
|
{
|
||||||
|
public static function registerAdminMenu(User $user)
|
||||||
|
{
|
||||||
|
parent::registerAdminMenu($user);
|
||||||
|
|
||||||
|
$menu = \Menu::instance('mainMenu');
|
||||||
|
|
||||||
|
$menu->dropdown(trans('template::admin/mainMenu.templateName'), function ($sub) {
|
||||||
|
$sub->route('template.setHomepage', trans('template::admin/mainMenu.setHomepage'), [], 1, ['icon' => 'fa fa-fw fa-home']);
|
||||||
|
}, 20, ['icon' => 'fa fa-fw fa-send']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare Content object to be rendered using Blade template
|
* Prepare Content object to be rendered using Blade template
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
$config = include_once __DIR__.'/../Base/OnePage/config.php';
|
$config = include_once __DIR__ . '/../Base/OnePage/config.php';
|
||||||
|
|
||||||
|
// override some values
|
||||||
$config['handler'] = \Templates\Jednostrankovka\Handler::class;
|
$config['handler'] = \Templates\Jednostrankovka\Handler::class;
|
||||||
$config['alias'] = 'jednostrankovka';
|
$config['alias'] = 'jednostrankovka';
|
||||||
|
$config['name'] = "Jednostrankova sablona";
|
||||||
|
//$config['providers'][] = '';
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
Reference in New Issue
Block a user