-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #215: add Bank CRUD in administration panel
- Loading branch information
Showing
8 changed files
with
489 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> {% trans %}Banque{% endtrans %} | ||
</a> | ||
</ul> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %}#} |
Oops, something went wrong.