FEATURE: make own page for template overview

This commit is contained in:
Michal Kváček
2017-09-15 13:32:09 +02:00
parent 4d68156a73
commit ba55702585
14 changed files with 151 additions and 100 deletions
+1 -9
View File
@@ -111,15 +111,7 @@ abstract class BaseHandler implements BaseModuleHandler
* Templates
*/
if ($user->can('manage', Template::class)) {
$templatePaths = TemplatePathsHumanReadableRootOnly::getWithTranslations();
if (!empty($templatePaths)) {
$sub->dropdown(trans('admin/mainMenu.templates'), function ($sub) use ($templatePaths) {
$i = 1;
foreach ($templatePaths as $id => $name) {
$sub->route('templates.overview', $name, ['id' => $id], $i++);
}
}, 60, ['icon' => 'fa fa-fw fa-file-code-o']);
}
$sub->route('templates.index', trans('admin/mainMenu.templates'), [], 70, ['icon' => 'fa fa-fw fa-file-code-o']);
}
if ($user->can('manage', ActionLog::class)) {
@@ -207,6 +207,7 @@ class TemplateRegistrator
protected function registerTemplates($path, $templatePathId)
{
$templates = File::files($path);
$registeredTemplates = Templates::getWithTranslations();
foreach ($templates as $template) {
@@ -217,7 +218,6 @@ class TemplateRegistrator
// get all templates and template name (path/to/template.blade.php -> path.to.template)
$templateName = $this->getTemplateName($template);
$registeredTemplates = Templates::getWithTranslations();
if (!in_array($templateName, $registeredTemplates)) {
$params = [
@@ -316,4 +316,14 @@ class TemplateRegistrator
return $this->namespace . trim($templateName, '.');
}
public function deleteNonExistingPaths()
{
$paths = TemplatePath::all();
foreach ($paths as $path) {
if (!is_dir(base_path($path->path)))
\File::deleteDirectory($path->path);
}
}
}
+1 -2
View File
@@ -7,7 +7,6 @@ use App\CMS\Enumerations\ContentStatuses;
use App\CMS\Repositories\Repository;
use App\Models\Content\Content as ContentModel;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class Content extends Repository implements IContent
@@ -113,7 +112,7 @@ class Content extends Repository implements IContent
->whereNull('contents.parentId')
->where('contents.language', LaravelLocalization::getCurrentLocale())
->where('modules.enabled', 1)
->with('module', 'subpages', 'templateModel')
->with('module', 'subpages', 'subpages.module', 'subpages.templateModel', 'templateModel')
->orderBy('contents.order')
->orderBy('contents.created_at', 'DESC');
@@ -7,6 +7,16 @@ use App\Models\Templates\TemplatePath;
class TemplateOverview extends Controller
{
public function index()
{
$templatePaths = TemplatePath::with('subdirectories')
->whereNull('parent_id')
->get();
return view('admin.templates.index', compact('templatePaths'));
}
/**
* Display overview of all templates in given path
*
@@ -17,12 +27,8 @@ class TemplateOverview extends Controller
public function getPath(TemplatePath $templatePath)
{
return view('admin.templates.list', [
'directory' => $templatePath,
'isWritable' => is_writable(base_path($templatePath->path)),
'templates' => $templatePath->templates()
->get(),
'subdirectories' => $templatePath->subdirectories()
->get()
'directory' => $templatePath,
'isWritable' => is_writable(base_path($templatePath->path))
]);
}
}
@@ -26,6 +26,8 @@ class TemplatePathInstaller
// install registered widgets
$registator->saveTemplates();
$registator->deleteNonExistingPaths();
return $next($request);
}
}