added theme service class
page editing was missing the selector to choose what template the page was using, so a theme class was created to handle retrieving and sorting what classes where avaiable in the themes directory still looking for twig files because themes haven't been converted over yet, but one step at a time
This commit is contained in:
parent
ad57c29e8d
commit
b527884c51
4 changed files with 94 additions and 2 deletions
|
@ -4,18 +4,22 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Interfaces\PageRepositoryInterface;
|
use App\Interfaces\PageRepositoryInterface;
|
||||||
use App\Services\AuthService;
|
use App\Services\AuthService;
|
||||||
|
use App\Services\ThemeService;
|
||||||
|
|
||||||
class DashController extends Controller
|
class DashController extends Controller
|
||||||
{
|
{
|
||||||
protected PageRepositoryInterface $pages;
|
protected PageRepositoryInterface $pages;
|
||||||
protected AuthService $auth;
|
protected AuthService $auth;
|
||||||
|
protected ThemeService $themes;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PageRepositoryInterface $pageRepository,
|
PageRepositoryInterface $pageRepository,
|
||||||
AuthService $authService,
|
AuthService $authService,
|
||||||
|
ThemeService $themeService,
|
||||||
) {
|
) {
|
||||||
$this->pages = $pageRepository;
|
$this->pages = $pageRepository;
|
||||||
$this->auth = $authService;
|
$this->auth = $authService;
|
||||||
|
$this->themes = $themeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start()
|
public function start()
|
||||||
|
@ -52,6 +56,7 @@ class DashController extends Controller
|
||||||
"status" => $this->auth::status(),
|
"status" => $this->auth::status(),
|
||||||
"mode" => $mode,
|
"mode" => $mode,
|
||||||
"page" => $page,
|
"page" => $page,
|
||||||
|
"views" => $this->themes->getCustomViews($page['layout']),
|
||||||
"title" => 'Editing ' . $page['title']
|
"title" => 'Editing ' . $page['title']
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use App\Services\SettingsService;
|
||||||
use App\Services\AuthService;
|
use App\Services\AuthService;
|
||||||
use App\Services\ContentService;
|
use App\Services\ContentService;
|
||||||
use App\Services\PaginateService;
|
use App\Services\PaginateService;
|
||||||
|
use App\Services\ThemeService;
|
||||||
|
|
||||||
class FipamoServiceProvider extends ServiceProvider
|
class FipamoServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
@ -30,6 +31,10 @@ class FipamoServiceProvider extends ServiceProvider
|
||||||
return new ContentService();
|
return new ContentService();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->app->bind(ThemeService::class, function ($app) {
|
||||||
|
return new ThemeService(new SettingsService());
|
||||||
|
});
|
||||||
|
|
||||||
$this->app->bind(PaginateService::class, function ($app) {
|
$this->app->bind(PaginateService::class, function ($app) {
|
||||||
return new PaginateService(new ContentService());
|
return new PaginateService(new ContentService());
|
||||||
});
|
});
|
||||||
|
|
73
app/Services/ThemeService.php
Normal file
73
app/Services/ThemeService.php
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
class ThemeService
|
||||||
|
{
|
||||||
|
protected $themes = [];
|
||||||
|
protected $settings;
|
||||||
|
|
||||||
|
public function __construct(SettingsService $settingsService)
|
||||||
|
{
|
||||||
|
$this->settings = $settingsService;
|
||||||
|
$_themes = glob(env('THEMES_PATH') . '/*', GLOB_ONLYDIR);
|
||||||
|
foreach ($_themes as $theme) {
|
||||||
|
array_push(
|
||||||
|
$this->themes,
|
||||||
|
json_decode(file_get_contents($theme . '/theme.json'), true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getThemes()
|
||||||
|
{
|
||||||
|
return $this->themes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomViews($layout)
|
||||||
|
{
|
||||||
|
$views = [];
|
||||||
|
if (str_contains($layout, 'index')) {
|
||||||
|
$views = $this->findCustomIndex();
|
||||||
|
} else {
|
||||||
|
$views = $this->findCustomViews();
|
||||||
|
}
|
||||||
|
return $views;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findCustomIndex()
|
||||||
|
{
|
||||||
|
$currentTheme = $this->settings->getGlobal()['theme'];
|
||||||
|
$folder = '../content/themes/' . $currentTheme;
|
||||||
|
$files = array_filter(glob("$folder/*twig"), 'is_file');
|
||||||
|
$views = [];
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$path = explode('/', $file);
|
||||||
|
$fileName = $path[4];
|
||||||
|
if (str_contains($fileName, 'index')) {
|
||||||
|
$page = explode('.', $fileName);
|
||||||
|
$views[] = $page[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $views;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findCustomViews()
|
||||||
|
{
|
||||||
|
$currentTheme = $this->settings->getGlobal()['theme'];
|
||||||
|
$folder = '../content/themes/' . $currentTheme;
|
||||||
|
$files = array_filter(glob("$folder/*twig"), 'is_file');
|
||||||
|
$views = [];
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$path = explode('/', $file);
|
||||||
|
$fileName = $path[4];
|
||||||
|
if (str_contains($fileName, 'page')) {
|
||||||
|
$page = explode('.', $fileName);
|
||||||
|
$views[] = $page[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $views;
|
||||||
|
}
|
||||||
|
}
|
|
@ -151,6 +151,15 @@
|
||||||
</div>
|
</div>
|
||||||
<div role="page-layouts">
|
<div role="page-layouts">
|
||||||
<strong>LAYOUTS</strong>
|
<strong>LAYOUTS</strong>
|
||||||
|
<select id="page-templates">
|
||||||
|
@foreach($views as $view)
|
||||||
|
@if($view == $page['layout'])
|
||||||
|
<option value={{ $view }} selected>{{ $view }}</option>
|
||||||
|
@else
|
||||||
|
<option value={{ $view }}>{{ $view }}</option>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div role="page-options">
|
<div role="page-options">
|
||||||
<strong>OPTIONS</strong>
|
<strong>OPTIONS</strong>
|
||||||
|
|
Loading…
Reference in a new issue