Skip to content

Commit

Permalink
Ref #215: add Bank CRUD in administration panel
Browse files Browse the repository at this point in the history
  • Loading branch information
LucileDT committed Dec 14, 2020
1 parent 00a407c commit c4b1a6c
Show file tree
Hide file tree
Showing 8 changed files with 489 additions and 5 deletions.
84 changes: 84 additions & 0 deletions src/Controller/BankController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Controller;

use App\Entity\Bank;
use App\Form\BankType;
use App\Repository\BankRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/{_locale}/bank")
*/
class BankController extends AbstractController
{
/**
* @Route("/", name="bank_list", methods={"GET"})
* @Security("is_granted('ROLE_ADMIN')")
*/
public function list(BankRepository $bankRepository): Response
{
return $this->render('Bank/list.html.twig', [
'banks' => $bankRepository->findAll(),
]);
}

/**
* @Route("/new", name="bank_new", methods={"GET","POST"})
* @Security("is_granted('ROLE_ADMIN')")
*/
public function new(Request $request): Response
{
$bank = new Bank();
$form = $this->createForm(BankType::class, $bank);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($bank);
$entityManager->flush();

return $this->redirectToRoute('bank_list');
}

return $this->render('Bank/new.html.twig', [
'bank' => $bank,
'form' => $form->createView(),
]);
}

/**
* @Route("/{id}", name="bank_show", methods={"GET"})
* @Security("is_granted('ROLE_ADMIN')")
*/
public function show(Bank $bank): Response
{
return $this->render('Bank/show.html.twig', [
'bank' => $bank,
]);
}

/**
* @Route("/{id}/edit", name="bank_edit", methods={"GET","POST"})
* @Security("is_granted('ROLE_ADMIN')")
*/
public function edit(Request $request, Bank $bank): Response
{
$form = $this->createForm(BankType::class, $bank);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();

return $this->redirectToRoute('bank_list');
}

return $this->render('Bank/edit.html.twig', [
'bank' => $bank,
'form' => $form->createView(),
]);
}
}
10 changes: 5 additions & 5 deletions src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UserController extends AbstractController
public function __construct(TranslatorInterface $translator) {
$this->translator = $translator;
}

/**
* Lists all user entities.
* @return views
Expand Down Expand Up @@ -94,7 +94,7 @@ public function createFromListAction(Request $request, UserService $userService,
$couldntBeCreatedTranslation
)
);

return $this->renderNewUserView($from, $form, $createdUser);
}
catch (FormIsInvalid $ex)
Expand All @@ -109,7 +109,7 @@ public function createFromListAction(Request $request, UserService $userService,
$couldntBeCreatedTranslation
)
);

return $this->renderNewUserView($from, $form, $createdUser);
}
catch (\Exception $e)
Expand All @@ -120,7 +120,7 @@ public function createFromListAction(Request $request, UserService $userService,
);
return $this->renderNewUserView($from, $form, $createdUser);
}

$userTranslation = $this->translator->trans('L\'utilisateurice');
$hasBeenCreatedTranslation = $this->translator->trans('a été créé.e');

Expand Down Expand Up @@ -324,7 +324,7 @@ public function deleteAction(Request $request, User $currentUser)
$em = $this->getDoctrine()->getManager();
$em->remove($currentUser);
$em->flush();

$userTranslation = $this->translator->trans('L\'utilisateurice');
$hasBeenDeletedTranslation = $this->translator->trans('ont bien été supprimées');

Expand Down
30 changes: 30 additions & 0 deletions templates/Administration/dashboard.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@
</div>
</div>
</div>
<div class="col-4">
<div class="flip-card" data-toggle="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<div class="flip-card-icon">
<ion-icon name="business-outline"></ion-icon>
<i class="icon ion-md-business"></i>
</div>
<h4>
{% trans %}Gestion des<br>banques{% endtrans %}
</h4>
<p class="">
{% trans %}Tout ce qui concerne les banques dont les paiements proviennent.{% endtrans %}
</p>
</div>
<div class="flip-card-back">
<div class="flip-card-item">
<a class="" href="{{ path('bank_list') }}">
{% trans %}Liste des banques{% endtrans %}
</a>
</div>
<div>
<a class="btn btn-primary btn-block" href="{{ path('bank_new', {from: 'dashboard'}) }}">
{% trans %}Enregistrer une nouvelle banque{% endtrans %}
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
20 changes: 20 additions & 0 deletions templates/Bank/_menu-bank.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% block body %}
{% set show_bank = show_bank is defined ? show_bank : null %}
{% set edit_bank = edit_bank is defined ? edit_bank : null %}

<ul class="list-group">
<a href="{{ path('bank_show', { 'id': bank.id }) }}"
class="list-group-item list-group-item-action {{ show_bank }}"
>
{% trans %}Banque{% endtrans %}
</a>
</ul>
<h4 class="mt-4">{% trans %}Édition{% endtrans %}</h4>
<ul class="list-group">
<a href="{{ path('bank_edit', { 'id': bank.id }) }}"
class="list-group-item list-group-item-action {{ edit_bank }}"
>
<i class="icon ion-md-create"></i>&nbsp;{% trans %}Banque{% endtrans %}
</a>
</ul>
{% endblock %}
80 changes: 80 additions & 0 deletions templates/Bank/edit.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{% extends 'Home/base.html.twig' %}

{% block title %}
{% trans %}Éditer la banque{% endtrans %} {{ bank.name }}
{% endblock %}

{% block javascript %}
{% endblock %}

{% block stylesheets %}
{% endblock %}

{% block breadcrumb %}
<li class="breadcrumb-item">
<a href="/">{% trans %}Accueil{% endtrans %}</a>
</li>
{% if is_granted("ROLE_ADMIN") %}
<li class="breadcrumb-item">
<a href="{{ path('administration_dashboard') }}">{% trans %}Administration{% endtrans %}</a>
</li>
{% endif %}
{% if is_granted("ROLE_GESTION") %}
<li class="breadcrumb-item">
<a href="{{ path('bank_list') }}">{% trans %}Liste des banques{% endtrans %}</a>
</li>
{% endif %}
<li class="breadcrumb-item">
<a href="{{ path('bank_show', { 'id': bank.id }) }}">
{{ bank.name }}
</a>
</li>
<li class="breadcrumb-item active" aria-current="page">
{% trans %}Éditer la banque{% endtrans %} {{ bank.name }}
</li>
{% endblock %}

{% block body %}
<br>
<div class="container">
<div class="row">
<div class="col-8 col-md-2">
{{ include('Bank/_menu-bank.html.twig', { edit_bank: 'active' }) }}
</div>
<br>
<div class="col-12 col-md-10">
<div class="row">
<div class="col text-left">
<h1>{% trans %}Éditer la banque{% endtrans %} {{ bank.name }}</h1>
</div>
</div>
<br>

<div class="row">
<div class="col">
<p> {% trans %}Les champs notés avec * sont requis.{% endtrans %} </p>
<div>
{{ form_start(form, {'attr': {'id': 'form-edit-bank'}}) }}
<div class="form-group">
{{ form_label(form.name) }} *
{{ form_widget(form.name) }}
</div>
{{ form_widget(form._token) }}
{{ form_end(form, {'render_rest': false}) }}
</div>
<div class="col text-right">
<button
id="edit-bank-submit-button"
type="submit"
form="form-edit-bank"
class="btn btn-primary"
>
{% trans %}Enregistrer les modifications{% endtrans %}
</button>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
113 changes: 113 additions & 0 deletions templates/Bank/list.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{% extends 'Home/base.html.twig' %}

{% block title %}{% trans %}Liste des banques{% endtrans %}{% endblock %}

{% block breadcrumb %}
<li class="breadcrumb-item">
<a href="/">{% trans %}Accueil{% endtrans %}</a>
</li>
{% if is_granted("ROLE_ADMIN") %}
<li class="breadcrumb-item">
<a href="{{ path('administration_dashboard') }}">{% trans %}Administration{% endtrans %}</a>
</li>
{% endif %}
<li class="breadcrumb-item active" aria-current="page">
{% trans %}Liste des banques{% endtrans %}
</li>
{% endblock %}

{% block body %}
<br>
<div class="container">
<div class="row">
<div class="col">
<h1>{% trans %}Liste des banques{% endtrans %}</h1>
</div>
</div>
</div>
<br>

<div class="container">
<table
class="table table-striped"
data-toggle="datatable"
data-filter-bar="toggle"
data-create-label="Enregistrer une nouvelle banque"
data-create-path="{{ path('bank_new', {from: 'list'}) }}"
data-fixed-columns-right="2"
>
<thead>
<tr>
<th data-sortable="true" data-exportable="true">{% trans %}Identifiant{% endtrans %}</th>
<th data-sortable="true" data-exportable="true">{% trans %}Nom{% endtrans %}</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{% set delete_user_form = "" %}
{% for bank in banks %}
<tr>
<td class="align-middle"><a href="{{ path('bank_show', { 'id': bank.id }) }}">{{ bank.id }}</a></td>
<td class="align-middle">{{ bank.name }}</td>
<td class="align-middle column-action">
<a
href="{{ path('bank_show', { 'id': bank.id }) }}"
class="btn btn-secondary"
data-toggle="tooltip"
title="{% trans %}Voir la banque{% endtrans %}"
>
<i class="icon ion-md-eye"></i>
</a>
</td>
<td class="align-middle column-action">
<a
href="{{ path('bank_edit', { 'id': bank.id }) }}"
class="btn btn-secondary"
data-toggle="tooltip"
title="{% trans %}Éditer la banque{% endtrans %}"
>
<i class="icon ion-md-create"></i>
</a>
</td>
</tr>
{% endfor %}

</tbody>
</table>
</div>
{% endblock %}

{#<title>Bank index</title>
{% block body %}
<h1>Bank index</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for bank in banks %}
<tr>
<td>{{ bank.id }}</td>
<td>{{ bank.name }}</td>
<td>
<a href="{{ path('bank_show', {'id': bank.id}) }}">show</a>
<a href="{{ path('bank_edit', {'id': bank.id}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="3">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('bank_new') }}">Create new</a>
{% endblock %}#}
Loading

0 comments on commit c4b1a6c

Please sign in to comment.