Skip to content

Commit

Permalink
Cleanup : améliorer les urls de JobController & ClientController (#813)
Browse files Browse the repository at this point in the history
* Cleanup urls in JobController & ClientController

* Additional changes
  • Loading branch information
raphodn authored Apr 15, 2023
1 parent 0398d02 commit df117b0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/Resources/views/admin/client/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_clients') }}"><i class="material-icons">list</i>&nbsp;Gestion des clients (Oauth)</a><i class="material-icons">chevron_right</i>
<a href="{{ path('client_list') }}"><i class="material-icons">list</i>&nbsp;Gestion des clients (Oauth)</a><i class="material-icons">chevron_right</i>
<i class="material-icons">edit</i>&nbsp;Editer
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/Resources/views/admin/client/new.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_clients') }}"><i class="material-icons">list</i>&nbsp;Gestion des clients (Oauth)</a><i class="material-icons">chevron_right</i>
<a href="{{ path('client_list') }}"><i class="material-icons">list</i>&nbsp;Gestion des clients (Oauth)</a><i class="material-icons">chevron_right</i>
<i class="material-icons">add</i>&nbsp;Ajouter
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion app/Resources/views/admin/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
</a>

<h6>Divers</h6>
<a href="{{ path("admin_clients") }}" class="waves-effect waves-light btn">
<a href="{{ path("client_list") }}" class="waves-effect waves-light btn">
<i class="material-icons left">vpn_key</i>Gérer les clients Oauth
</a>
<a href="{{ path("service_list") }}" class="waves-effect waves-light btn">
Expand Down
55 changes: 31 additions & 24 deletions src/AppBundle/Controller/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,39 @@
/**
* Task controller.
*
* @Route("clients")
* @Route("admin/clients")
*/
class ClientController extends Controller
{

/**
* Lists all clients.
*
* @Route("/", name="admin_clients", methods={"GET"})
* @Route("/", name="client_list", methods={"GET"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function listAction()
{
$clients = $this->getDoctrine()->getManager()->getRepository('AppBundle:Client')->findAll();

return $this->render('admin/client/list.html.twig',array('clients'=>$clients));
}

/**
* Add new Client //todo put this auto in service création
*
* @Route("/client_new", name="client_new", methods={"GET","POST"})
* @Route("/new", name="client_new", methods={"GET","POST"})
* @Security("has_role('ROLE_ADMIN')")
*/
public function newAction(Request $request){

public function newAction(Request $request)
{
$session = new Session();

$form = $this->createForm(ClientType::class);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {

$urls = $form->get('urls')->getData();

$service = $form->get('service')->getData();

$clientManager = $this->container->get('fos_oauth_server.client_manager.default');
Expand All @@ -62,15 +61,15 @@ public function newAction(Request $request){
$clientManager->updateClient($client);

$session->getFlashBag()->add('success', 'Le client a bien été créé !');

return $this->redirectToRoute('admin_clients');
return $this->redirectToRoute('client_list');

// return $this->redirect($this->generateUrl('fos_oauth_server_authorize', array(
// 'client_id' => $client->getPublicId(),
// 'redirect_uri' => $url,
// 'response_type' => 'code'
// )));
}

return $this->render('admin/client/new.html.twig', array(
'form' => $form->createView()
));
Expand All @@ -80,10 +79,11 @@ public function newAction(Request $request){
/**
* edit client.
*
* @Route("/edit/{id}", name="client_edit", methods={"GET","POST"})
* @Route("/{id}/edit", name="client_edit", methods={"GET","POST"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function editAction(Request $request,Client $client){
public function editAction(Request $request, Client $client)
{
$session = new Session();

$em = $this->getDoctrine()->getManager();
Expand All @@ -106,18 +106,15 @@ public function editAction(Request $request,Client $client){
$em->flush();

$session->getFlashBag()->add('success', 'Le client a bien été édité !');
return $this->redirectToRoute('admin_clients');
return $this->redirectToRoute('client_list');

} elseif ($form->isSubmitted()) {
foreach ($form->getErrors(true) as $key => $error) {
$session->getFlashBag()->add('error', 'Erreur ' . ($key + 1) . " : " . $error->getMessage());
}
}

$delete_form = $this->createFormBuilder()
->setAction($this->generateUrl('client_remove', array('id' => $client->getId())))
->setMethod('DELETE')
->getForm();
$delete_form = $this->getDeleteForm($client);

return $this->render('admin/client/edit.html.twig', array(
'form' => $form->createView(),
Expand All @@ -127,28 +124,38 @@ public function editAction(Request $request,Client $client){
}

/**
* remove client.
* delete client.
*
* @Route("/remove/{id}", name="client_remove", methods={"DELETE"})
* @Route("/{id}", name="client_delete", methods={"DELETE"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function removeAction(Request $request,Client $client)
public function deleteAction(Request $request, Client $client)
{
$session = new Session();
$form = $this->createFormBuilder()
->setAction($this->generateUrl('client_remove', array('id' => $client->getId())))
->setMethod('DELETE')
->getForm();

$form = $this->getDeleteForm($client);
$form->handleRequest($request);

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

$session->getFlashBag()->add('success', 'Le client a bien été supprimé !');
}

return $this->redirectToRoute('admin_clients');
return $this->redirectToRoute('client_list');
}

/**
* @param Client $client
* @return \Symfony\Component\Form\FormInterface
*/
protected function getDeleteForm(Client $client)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('client_delete', array('id' => $client->getId())))
->setMethod('DELETE')
->getForm();
}
}
9 changes: 6 additions & 3 deletions src/AppBundle/Controller/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function newAction(Request $request)
/**
* Edit job.
*
* @Route("/edit/{id}", name="job_edit", methods={"GET","POST"})
* @Route("/{id}/edit", name="job_edit", methods={"GET","POST"})
* @Security("has_role('ROLE_ADMIN')")
*/
public function editAction(Request $request, Job $job)
Expand All @@ -134,9 +134,11 @@ public function editAction(Request $request, Job $job)
return $this->redirectToRoute('job_list');
}

$delete_form = $this->getDeleteForm($job);

return $this->render('admin/job/edit.html.twig', array(
'form' => $form->createView(),
'delete_form' => $this->getDeleteForm($job)->createView()
'delete_form' => $delete_form->createView()
));
}

Expand All @@ -146,9 +148,10 @@ public function editAction(Request $request, Job $job)
* @Route("/{id}", name="job_delete", methods={"DELETE"})
* @Security("has_role('ROLE_SUPER_ADMIN')")
*/
public function removeAction(Request $request,Job $job)
public function deleteAction(Request $request,Job $job)
{
$session = new Session();

$form = $this->getDeleteForm($job);
$form->handleRequest($request);

Expand Down

0 comments on commit df117b0

Please sign in to comment.