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
*
@@ -18,11 +28,7 @@ class TemplateOverview extends Controller
{
return view('admin.templates.list', [
'directory' => $templatePath,
'isWritable' => is_writable(base_path($templatePath->path)),
'templates' => $templatePath->templates()
->get(),
'subdirectories' => $templatePath->subdirectories()
->get()
'isWritable' => is_writable(base_path($templatePath->path))
]);
}
}
@@ -26,6 +26,8 @@ class TemplatePathInstaller
// install registered widgets
$registator->saveTemplates();
$registator->deleteNonExistingPaths();
return $next($request);
}
}
@@ -2,6 +2,9 @@
@section('pageHeading', @trans('admin/fileManager.edit', ['name' => $file->original_filename]))
@section('headerButtons')
<a href="{{route('upload.overview')}}" class="btn btn-secondary rounded btn-sm"><i class="fa fa-list"></i></a>
@can('delete', $file)
<a href="{{route('upload.delete', ['id' => $file->id])}}" class="btn btn-danger btn-sm confirm rounded"
title="@lang('admin/fileManager.delete')">
@@ -15,11 +18,18 @@
<div class="row">
<div class="col-lg-8">
<div class="large-preview">
<div class="card items">
<div class="card-block">
{!! \App\CMS\Helpers\FileManager::getLargePreview($file) !!}
</div>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card items">
<div class="card-block">
<div class="row callout secondary">
<h3>{{$file->original_filename}}</h3>
@@ -30,7 +40,8 @@
<li>@lang('admin/fileManager.hash'): <span
title="{{$file->file_hash}}">{{str_limit($file->file_hash, 10)}}</span></li>
<li>@lang('admin/fileManager.url'): <a
href="{{config('app.upload_url')}}/{{$file->filename}}">{{$file->filename}}</a></li>
href="{{config('app.upload_url')}}/{{$file->filename}}">{{$file->filename}}</a>
</li>
<li>@lang('admin/fileManager.fileSize')
: {{\App\CMS\Helpers\FileManager::getFormattedSize($file)}}</li>
@@ -46,6 +57,8 @@
</div>
</div>
</div>
</div>
</div>
@stop
@section('head_stylesheets')
@@ -15,6 +15,8 @@
</div>
<div class="col-lg-4">
<div class="card items">
<div class="card-block">
<div id="file-manager-controls" role="tablist" aria-multiselectable="true">
@can('upload', \App\Models\FileManager\File::class)
@@ -40,7 +42,8 @@
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="edit-dir-title">
<h5 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#file-manager-controls"
<a class="collapsed" data-toggle="collapse"
data-parent="#file-manager-controls"
href="#edit-dir" aria-expanded="false" aria-controls="edit-dir">
@lang('admin/fileManager.editDirectory')
</a>
@@ -73,4 +76,6 @@
</div>
</div>
</div>
</div>
</div>
@endsection
@@ -14,11 +14,8 @@
{{--@endif--}}
<div>
<h5>@lang('admin/templates.subdirectories')</h5>
<ul>
@forelse($subdirectories as $subdirectory)
@forelse($directory->subdirectories as $subdirectory)
<li><a href="{{route('templates.overview', ['path' => $subdirectory->id])}}">{{trans($subdirectory->name)}}</a></li>
@empty
<li><em>@lang('admin/templates.noSubdirectories')</em></li>
@@ -1,5 +1,5 @@
<div class="tile-overview sameheight-container">
@forelse($templates as $template)
@forelse($directory->templates as $template)
<div class="col-lg-3">
<div class="text-center bold" data-toggle="tooltip" title="{{$template->name}}">
{{str_limit($template->name, 15)}}
@@ -3,5 +3,5 @@
@section('pageHeading', @trans('admin/templates.edit', ['name' => $template->template_name]))
@section('content')
@include('admin.templates.editForm')
@include('admin.templates._partials.editForm')
@stop
@@ -0,0 +1,13 @@
@extends('admin.layoutWithNavigation')
@section('pageHeading', @trans('admin/templates.overview'))
@section('content')
<div class="card items">
<div class="card-block">
@foreach($templatePaths as $directory)
@include('admin.templates._partials.directoriesList')
@endforeach
</div>
</div>
@endsection
+12 -3
View File
@@ -3,14 +3,23 @@
@section('pageHeading', @trans('admin/templates.overview'))
@section('content')
<div class="row">
<div class="col-lg-9">
@include('admin.templates.templatesTiles')
<div class="card items">
<div class="card-block">
@include('admin.templates._partials.templatesTiles')
</div>
</div>
</div>
<div class="col-lg-3">
<div class="callout">
@include('admin.templates.directoriesList')
<div class="card items">
<div class="card-block">
@include('admin.templates._partials.directoriesList')
</div>
</div>
</div>
</div>
+6 -1
View File
@@ -1,7 +1,12 @@
<?php
// these routes are available only for user with role admin
Route::group(['namespace' => 'Templates'], function () {
Route::get('templates/overview/path/{templatePath}', 'TemplateOverview@getPath')
Route::get('templates', 'TemplateOverview@index')
->name('templates.index')
->middleware('can:manage,' . \App\Models\Templates\Template::class);
Route::get('templates/{templatePath}', 'TemplateOverview@getPath')
->name('templates.overview')
->middleware('can:manage,' . \App\Models\Templates\Template::class);