Add sidebar
This commit is contained in:
parent
9c23282b59
commit
bdaa255e98
10 changed files with 177 additions and 11 deletions
|
@ -1 +1,16 @@
|
||||||
@import '~mdb-ui-kit/src/scss/mdb.free';
|
@import '~mdb-ui-kit/src/scss/mdb.free';
|
||||||
|
|
||||||
|
#body {
|
||||||
|
width: 80vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
overflow: auto;
|
||||||
|
transition: all .3s ease-in;
|
||||||
|
width: 20vw;
|
||||||
|
height: 100%;
|
||||||
|
z-index: 7;
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,6 @@ framework:
|
||||||
cookie_samesite: lax
|
cookie_samesite: lax
|
||||||
|
|
||||||
#esi: true
|
#esi: true
|
||||||
#fragments: true
|
fragments: { path: /_fragment }
|
||||||
php_errors:
|
php_errors:
|
||||||
log: true
|
log: true
|
||||||
|
|
44
src/Controller/AdminController.php
Normal file
44
src/Controller/AdminController.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
class AdminController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Route("/admin", name="admin")
|
||||||
|
*/
|
||||||
|
public function index(): Response
|
||||||
|
{
|
||||||
|
return $this->render('admin/index.html.twig', [
|
||||||
|
'controller_name' => 'AdminController',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/admin/posts", name="posts")
|
||||||
|
*/
|
||||||
|
public function posts(): Response
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/admin/categories", name="categories")
|
||||||
|
*/
|
||||||
|
public function categories(): Response
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/admin/comments", name="comments")
|
||||||
|
*/
|
||||||
|
public function comments(): Response
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Category;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
@ -17,4 +18,12 @@ class CategoryController extends AbstractController
|
||||||
'controller_name' => 'CategoryController',
|
'controller_name' => 'CategoryController',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function categorySummary(): Response
|
||||||
|
{
|
||||||
|
return $this->render('category_summary.html.twig', [
|
||||||
|
'controller_name' => 'CategoryController',
|
||||||
|
'Categories' => array_filter($this->getDoctrine()->getRepository(Category::class)->findAll(), static function ($c) {return count($c->getPosts())>=1;})
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Comment;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
@ -17,4 +18,12 @@ class CommentController extends AbstractController
|
||||||
'controller_name' => 'CommentController',
|
'controller_name' => 'CommentController',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function recentComment(): Response
|
||||||
|
{
|
||||||
|
return $this->render('recent_comment.html.twig', [
|
||||||
|
'controller_name' => 'CommentController',
|
||||||
|
'comments' => $this->getDoctrine()->getRepository(Comment::class)->findBy(array('valid' => true), array('createdAt' => 'DESC'), 5, 0)
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
47
templates/admin/base-admin.html.twig
Normal file
47
templates/admin/base-admin.html.twig
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{% block title %}Welcome!{% endblock %}</title>
|
||||||
|
{% block stylesheets %}
|
||||||
|
{{ encore_entry_link_tags('app') }}
|
||||||
|
{% endblock %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="{{ path('home') }}">Blog</a>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="navbar-toggler"
|
||||||
|
type="button"
|
||||||
|
data-mdb-toggle="collapse"
|
||||||
|
data-mdb-target="#navbarSupportedContent"
|
||||||
|
aria-controls="navbarSupportedContent"
|
||||||
|
aria-expanded="false"
|
||||||
|
aria-label="Toggle navigation"
|
||||||
|
>
|
||||||
|
<i class="fas fa-bars"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" aria-current="page" href="{{ path('posts') }}">Posts</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" aria-current="page" href="{{ path('categories') }}">Categories</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" aria-current="page" href="{{ path('comments') }}">Comments</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
{% block body %}{% endblock %}
|
||||||
|
{% block javascripts %}
|
||||||
|
{{ encore_entry_script_tags('app') }}
|
||||||
|
{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
20
templates/admin/index.html.twig
Normal file
20
templates/admin/index.html.twig
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{% extends 'admin/base-admin.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Hello AdminController!{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<style>
|
||||||
|
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
||||||
|
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="example-wrapper">
|
||||||
|
<h1>Hello {{ controller_name }}! ✅</h1>
|
||||||
|
|
||||||
|
This friendly message is coming from:
|
||||||
|
<ul>
|
||||||
|
<li>Your controller at <code><a href="{{ '/home/flifloo/Nextcloud/IUT/PHP Avancée/blog/src/Controller/AdminController.php'|file_link(0) }}">src/Controller/AdminController.php</a></code></li>
|
||||||
|
<li>Your template at <code><a href="{{ '/home/flifloo/Nextcloud/IUT/PHP Avancée/blog/templates/admin/index.html.twig'|file_link(0) }}">templates/admin/index.html.twig</a></code></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -6,7 +6,6 @@
|
||||||
{% block stylesheets %}
|
{% block stylesheets %}
|
||||||
{{ encore_entry_link_tags('app') }}
|
{{ encore_entry_link_tags('app') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% set admin = false %} <!-- ToDo: Change this with dynamic -->
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
@ -27,19 +26,20 @@
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
{% if admin %}
|
<li class="nav-item">
|
||||||
<li class="nav-item">
|
<a class="nav-link active" aria-current="page" href="{{ path('admin') }}">Admin</a>
|
||||||
<a class="nav-link active" aria-current="page" href="{{ path('post') }}">Posts</a>
|
</li>
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link active" aria-current="page" href="{{ path('category') }}">Categories</a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
{% block body %}{% endblock %}
|
<div class="sidebar">
|
||||||
|
{{ render(controller('App\\Controller\\CommentController::recentComment')) }}
|
||||||
|
{{ render(controller('App\\Controller\\CategoryController::categorySummary')) }}
|
||||||
|
</div>
|
||||||
|
<div id="body">
|
||||||
|
{% block body %}{% endblock %}
|
||||||
|
</div>
|
||||||
{% block javascripts %}
|
{% block javascripts %}
|
||||||
{{ encore_entry_script_tags('app') }}
|
{{ encore_entry_script_tags('app') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
6
templates/category_summary.html.twig
Normal file
6
templates/category_summary.html.twig
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<h4>Categories summary</h4>
|
||||||
|
<ul class="list-group">
|
||||||
|
{% for category in Categories %}
|
||||||
|
<li class="list-group-item">{{ category.getName() }}: {{ category.getPosts()|length }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
16
templates/recent_comment.html.twig
Normal file
16
templates/recent_comment.html.twig
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<h4>Recent comments</h4>
|
||||||
|
<div class="accordion" id="accordionComment">
|
||||||
|
{% for comment in comments %}
|
||||||
|
<div class="accordion-item">
|
||||||
|
|
||||||
|
<h2 class="accordion-header" id="heading{{ comment.id }}">
|
||||||
|
<button class="accordion-button" type="button" data-mdb-toggle="collapse" data-mdb-target="#collapse{{ comment.id }}" aria-controls="collapse{{ comment.id }}">
|
||||||
|
{{ comment.post.title }}: {{ comment.username }} <code class="text-muted">{{ comment.createdAt.format('Y-m-d H:i:s') }}</code>
|
||||||
|
</button>
|
||||||
|
</h2>
|
||||||
|
<div id="collapse{{ comment.id }}" class="accordion-collapse collapse" aria-labelledby="heading{{ comment.id }}" data-mdb-parent="#accordionComment">
|
||||||
|
<div class="accordion-body">{{ comment.content }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
Reference in a new issue