Added CRUD for domain pages

This commit is contained in:
Skylar Sadlier 2023-10-14 14:48:17 -06:00
parent 21178d9a1f
commit d76c0d31f9
13 changed files with 12277 additions and 1 deletions

5
config/config.yml Normal file
View File

@ -0,0 +1,5 @@
stof_doctrine_extensions:
orm:
default:
sluggable: true
timestampable: true

12006
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
<?php
namespace App\Controller;
use App\Entity\DomainPage;
use App\Form\DomainPageType;
use App\Repository\DomainPageRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/page')]
class PageController extends AbstractController
{
#[Route('/', name: 'app_page_index', methods: ['GET'])]
public function index(DomainPageRepository $domainPageRepository): Response
{
return $this->render('page/index.html.twig', [
'domain_pages' => $domainPageRepository->findAll(),
]);
}
#[Route('/new', name: 'app_page_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$domainPage = new DomainPage();
$form = $this->createForm(DomainPageType::class, $domainPage);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($domainPage);
$entityManager->flush();
return $this->redirectToRoute('app_page_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('page/new.html.twig', [
'domain_page' => $domainPage,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_page_show', methods: ['GET'])]
public function show(DomainPage $domainPage): Response
{
return $this->render('page/show.html.twig', [
'domain_page' => $domainPage,
]);
}
#[Route('/{id}/edit', name: 'app_page_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, DomainPage $domainPage, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(DomainPageType::class, $domainPage);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_page_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('page/edit.html.twig', [
'domain_page' => $domainPage,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_page_delete', methods: ['POST'])]
public function delete(Request $request, DomainPage $domainPage, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$domainPage->getId(), $request->request->get('_token'))) {
$entityManager->remove($domainPage);
$entityManager->flush();
}
return $this->redirectToRoute('app_page_index', [], Response::HTTP_SEE_OTHER);
}
}

View File

@ -56,6 +56,11 @@ class Domain
$this->domainPages = new ArrayCollection();
}
public function __toString()
{
return $this->getName() ?? $this->getId();
}
public function getId(): ?int
{
return $this->id;

View File

@ -9,6 +9,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: DomainPageRepository::class)]
class DomainPage
@ -35,9 +36,11 @@ class DomainPage
private ?string $title = null;
#[ORM\Column]
#[Gedmo\Timestampable(on: "create")]
private ?DateTimeImmutable $createdAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Gedmo\Timestampable(on: "update")]
private ?DateTimeInterface $updatedAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
@ -49,6 +52,7 @@ class DomainPage
public function __construct()
{
$this->comments = new ArrayCollection();
$this->commentCount = 0;
}
public function getId(): ?int

View File

@ -0,0 +1,42 @@
<?php
namespace App\Form;
use App\Entity\Domain;
use App\Entity\DomainPage;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class DomainPageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('locked')
->add('domain', EntityType::class, [
'class' => Domain::class,
])
->add('path', TextType::class, [
'attr' => [
'placeholder' => '/example/path'
]
])
->add('title', TextType::class, [
'attr' => [
'placeholder' => 'Example Article Name'
]
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => DomainPage::class,
]);
}
}

View File

@ -32,10 +32,14 @@
<i class="fas fa-comments fa-fw me-3"></i>
<span>Comments</span>
</a>
<a href="{{ path('app_domain_index') }}" class="list-group-item list-group-item-action py-2 ripple">
<a href="{{ path('app_domain_index') }}" class="list-group-item list-group-item-action py-2 ripple{{ app.request.pathInfo starts with path('app_domain_index') ? ' active' : ''}}">
<i class="fas fa-globe fa-fw me-3"></i>
<span>Domains</span>
</a>
<a href="{{ path('app_page_index') }}" class="list-group-item list-group-item-action py-2 ripple{{ app.request.pathInfo starts with path('app_page_index') ? ' active' : ''}}">
<i class="fas fa-file fa-fw me-3"></i>
<span>Pages</span>
</a>
<a href="#" class="list-group-item list-group-item-action py-2 ripple">
<i class="fas fa-users fa-fw me-3"></i>
<span>Users</span>

View File

@ -0,0 +1,4 @@
<form method="post" action="{{ path('app_page_delete', {'id': domain_page.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ domain_page.id) }}">
<button class="btn">Delete</button>
</form>

View File

@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn btn-primary float-start m-1">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}

View File

@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}
{% block title %}Edit DomainPage{% endblock %}
{% block body %}
<h1>Edit DomainPage</h1>
{{ include('page/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('app_page_index') }}">back to list</a>
{{ include('page/_delete_form.html.twig') }}
{% endblock %}

View File

@ -0,0 +1,47 @@
{% extends 'base.html.twig' %}
{% block title %}Pages List{% endblock %}
{% block body %}
<h1>Pages List</h1>
<table class="table">
<thead>
<tr>
<th>Domain</th>
<th>Path</th>
<th>Locked</th>
<th>CommentCount</th>
<th>Title</th>
<th>CreatedAt</th>
<th>UpdatedAt</th>
<th>DeletedAt</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for domain_page in domain_pages %}
<tr>
<td><a href="{{ path('app_domain_show', {'id': domain_page.domain.id}) }}">{{ domain_page.domain.domain }}</a></td>
<td>{{ domain_page.path }}</td>
<td>{{ domain_page.locked ? 'Yes' : 'No' }}</td>
<td>{{ domain_page.commentCount }}</td>
<td>{{ domain_page.title }}</td>
<td>{{ domain_page.createdAt ? domain_page.createdAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ domain_page.updatedAt ? domain_page.updatedAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ domain_page.deletedAt ? domain_page.deletedAt|date('Y-m-d H:i:s') : '' }}</td>
<td>
<a href="{{ path('app_page_show', {'id': domain_page.id}) }}">show</a>
<a href="{{ path('app_page_edit', {'id': domain_page.id}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="9">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('app_page_new') }}">Create new</a>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}New DomainPage{% endblock %}
{% block body %}
<h1>Create new DomainPage</h1>
{{ include('page/_form.html.twig') }}
<a href="{{ path('app_page_index') }}" class="btn btn-secondary float-end m-1">Cancel</a>
{% endblock %}

View File

@ -0,0 +1,50 @@
{% extends 'base.html.twig' %}
{% block title %}DomainPage{% endblock %}
{% block body %}
<h1>DomainPage</h1>
<table class="table">
<tbody>
<tr>
<th>Id</th>
<td>{{ domain_page.id }}</td>
</tr>
<tr>
<th>Path</th>
<td>{{ domain_page.path }}</td>
</tr>
<tr>
<th>Locked</th>
<td>{{ domain_page.locked ? 'Yes' : 'No' }}</td>
</tr>
<tr>
<th>CommentCount</th>
<td>{{ domain_page.commentCount }}</td>
</tr>
<tr>
<th>Title</th>
<td>{{ domain_page.title }}</td>
</tr>
<tr>
<th>CreatedAt</th>
<td>{{ domain_page.createdAt ? domain_page.createdAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
<tr>
<th>UpdatedAt</th>
<td>{{ domain_page.updatedAt ? domain_page.updatedAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
<tr>
<th>DeletedAt</th>
<td>{{ domain_page.deletedAt ? domain_page.deletedAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
</tbody>
</table>
<a href="{{ path('app_page_index') }}">back to list</a>
<a href="{{ path('app_page_edit', {'id': domain_page.id}) }}">edit</a>
{{ include('page/_delete_form.html.twig') }}
{% endblock %}