Update CPU list view to be a bit more managable

This commit is contained in:
Timothy Warren 2022-11-03 10:46:44 -04:00
parent fd6217eddc
commit 5e7658c7b9
3 changed files with 71 additions and 57 deletions

View File

@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\BrandCategory; use App\Entity\BrandCategory;
use App\Form\BrandCategoryType; use App\Form\BrandCategoryType;
use App\Traits\FormControllerTrait;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -13,72 +14,44 @@ use Symfony\Component\Routing\Annotation\Route;
#[Route('/brand/category')] #[Route('/brand/category')]
class BrandCategoryController extends AbstractController class BrandCategoryController extends AbstractController
{ {
#[Route('/', name: 'brand-category_index', methods: ['GET'])] use FormControllerTrait;
public function index(EntityManagerInterface $entityManager): Response
{
$brandCategories = $entityManager
->getRepository(BrandCategory::class)
->findAll();
return $this->render('brand_category/index.html.twig', [ protected const ENTITY = BrandCategory::class;
'brand_categories' => $brandCategories, protected const TEMPLATE_PATH = 'brand_category/';
]); protected const ROUTE_PREFIX = 'brand-category_';
protected const FORM = BrandCategoryType::class;
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}
#[Route('/', name: 'brand-category_index', methods: ['GET'])]
public function index(): Response
{
return $this->indexView('brand_categories');
} }
#[Route('/new', name: 'brand-category_new', methods: ['GET', 'POST'])] #[Route('/new', name: 'brand-category_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response public function new(Request $request, EntityManagerInterface $entityManager): Response
{ {
$brandCategory = new BrandCategory(); return $this->itemCreate($request, 'brand_category');
$form = $this->createForm(BrandCategoryType::class, $brandCategory);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($brandCategory);
$entityManager->flush();
return $this->redirectToRoute('brand-category_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('brand_category/new.html.twig', [
'brand_category' => $brandCategory,
'form' => $form,
]);
} }
#[Route('/{name}', name: 'brand-category_show', methods: ['GET'])] #[Route('/{name}', name: 'brand-category_show', methods: ['GET'])]
public function show(BrandCategory $brandCategory): Response public function show(BrandCategory $brandCategory): Response
{ {
return $this->render('brand_category/show.html.twig', [ return $this->itemView($brandCategory, 'brand_category');
'brand_category' => $brandCategory,
]);
} }
#[Route('/{name}/edit', name: 'brand-category_edit', methods: ['GET', 'POST'])] #[Route('/{name}/edit', name: 'brand-category_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, BrandCategory $brandCategory, EntityManagerInterface $entityManager): Response public function edit(Request $request, BrandCategory $brandCategory): Response
{ {
$form = $this->createForm(BrandCategoryType::class, $brandCategory); return $this->itemUpdate($request, $brandCategory, 'brand_category');
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('brand-category_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('brand_category/edit.html.twig', [
'brand_category' => $brandCategory,
'form' => $form,
]);
} }
#[Route('/{name}', name: 'brand-category_delete', methods: ['POST'])] #[Route('/{name}', name: 'brand-category_delete', methods: ['POST'])]
public function delete(Request $request, BrandCategory $brandCategory, EntityManagerInterface $entityManager): Response public function delete(Request $request, BrandCategory $brandCategory): Response
{ {
if ($this->isCsrfTokenValid('delete'.$brandCategory->getName(), $request->request->get('_token'))) { return $this->deleteCSRF($request, $brandCategory);
$entityManager->remove($brandCategory);
$entityManager->flush();
}
return $this->redirectToRoute('brand_category_index', [], Response::HTTP_SEE_OTHER);
} }
} }

View File

@ -27,7 +27,26 @@ class CpuController extends AbstractController {
#[Route('/', name: 'cpu_index', methods: ['GET'])] #[Route('/', name: 'cpu_index', methods: ['GET'])]
public function index(): Response public function index(): Response
{ {
return $this->itemListView('cpus', []); $template = self::TEMPLATE_PATH . 'index.html.twig';
$items = $this->entityManager->getRepository(self::ENTITY)->findBy([], [
'productLine' => 'ASC',
'model' => 'ASC',
]);
$amd = array_filter($items, static fn (Cpu $cpu) => $cpu->getBrand()->getName() === 'AMD' && $cpu->isReceived());
$intel = array_filter($items, static fn (Cpu $cpu) => $cpu->getBrand()->getName() === 'Intel' && $cpu->isReceived());
$others = array_filter($items, static fn (Cpu $cpu) => ( ! in_array($cpu->getBrand()->getName(), ['AMD','Intel'])) && $cpu->isReceived());
$notReceived = array_filter($items, static fn(CPU $cpu) => $cpu->isReceived() === FALSE);
return $this->render($template, [
'all' => [
'not_acquired' => $notReceived,
'amd' => $amd,
'intel' => $intel,
'others' => $others,
],
]);
} }
#[Route('/new', name: 'cpu_new', methods: ['GET', 'POST'])] #[Route('/new', name: 'cpu_new', methods: ['GET', 'POST'])]

View File

@ -13,6 +13,33 @@
</ul> </ul>
</div> </div>
<ul
class="tabs"
data-deep-link="true"
data-update-history="true"
data-deep-link-smudge="true"
data-deep-link-smudge-delay="500"
data-tabs
id="classifications"
>
<li class="tabs-title is-active">
<a href="#not_acquired">On the Way</a>
</li>
<li class="tabs-title" aria-selected="true">
<a href="#amd">AMD</a>
</li>
<li class="tabs-title">
<a href="#intel">Intel</a>
</li>
<li class="tabs-title">
<a href="#others">Others</a>
</li>
</ul>
<div class="tabs-content" data-tabs-content="classifications">
{% for label, cpus in all %}
<div class="tabs-panel {% if label == 'not_acquired' %}is-active{% endif %}" id="{{ label }}">
<table class="hover scroll sortable stack"> <table class="hover scroll sortable stack">
<thead> <thead>
<tr> <tr>
@ -31,13 +58,9 @@
<th>L2 Cache</th> <th>L2 Cache</th>
<th>L3 Cache</th> <th>L3 Cache</th>
<th>Igp</th> <th>Igp</th>
<th>Voltage</th>
<th>Tdp</th>
<th>ProcessNode</th>
<th>Count</th> <th>Count</th>
<th>Usable</th> <th>Usable</th>
<th>Received</th> <th>Received</th>
<th>Link</th>
<th>Notes</th> <th>Notes</th>
</tr> </tr>
</thead> </thead>
@ -99,13 +122,9 @@
{% endif %} {% endif %}
</td> </td>
<td>{{ cpu.igp }}</td> <td>{{ cpu.igp }}</td>
<td>{{ cpu.voltage }}</td>
<td>{{ cpu.tdp }}</td>
<td>{{ cpu.processNode }}</td>
<td>{{ cpu.count }}</td> <td>{{ cpu.count }}</td>
<td>{{ cpu.usable ? 'Yes' : 'No' }}</td> <td>{{ cpu.usable ? 'Yes' : 'No' }}</td>
<td>{{ cpu.received ? 'Yes' : 'No' }}</td> <td>{{ cpu.received ? 'Yes' : 'No' }}</td>
<td>{{ cpu.link }}</td>
<td>{{ cpu.notes }}</td> <td>{{ cpu.notes }}</td>
</tr> </tr>
{% else %} {% else %}
@ -115,4 +134,7 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</div>
{% endfor %}
</div>
{% endblock %} {% endblock %}