nicer cruds

This commit is contained in:
Kayn Ty 2018-04-05 17:24:43 +02:00
parent d5ef71f734
commit c66aa69037
19 changed files with 475 additions and 141 deletions

View File

@ -11,11 +11,14 @@
{% block navigation %} {% block navigation %}
{% include 'default/login-choices.html.twig' %} {% include 'default/login-choices.html.twig' %}
{% endblock %} {% endblock %}
{% block body %} <div class="container">
<div class="well">
Votre caisse mobile en ligne {% block body %}
</div> <div class="well">
{% endblock %} Votre caisse mobile en ligne
</div>
{% endblock %}
</div>
{% block javascripts %} {% block javascripts %}
<script src="{{ asset('build/app.js') }}"></script> <script src="{{ asset('build/app.js') }}"></script>
{% endblock %} {% endblock %}

View File

@ -4,10 +4,27 @@
<div class="well"> <div class="well">
<div class="login-choices"> <div class="login-choices">
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %} {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
{{ 'layout.logged_in_as'|trans({'%username%': app.user.username}, 'FOSUserBundle') }} | <div class="row">
<a class="btn btn-default" href="{{ path('fos_user_security_logout') }}"> <div class="col-xs-6">
{{ 'layout.logout'|trans({}, 'FOSUserBundle') }} <a class="btn btn-default" href="{{ path('homepage') }}">
</a>
<i class="fa fa-home"></i>
Caisse
</a>
<a class="btn btn-default" href="{{ path('dashboard') }}">
<i class="fa fa-list"></i>
Dashboard
</a>
</div>
<div class="col-xs-6 text-right">
{{ 'layout.logged_in_as'|trans({'%username%': app.user.username}, 'FOSUserBundle') }} |
<a class="btn btn-default" href="{{ path('fos_user_security_logout') }}">
{{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
</a>
</div>
</div>
{% else %} {% else %}
<a class="btn btn-default btn-block btn-twitter" href="{{ hwi_oauth_login_url('google') }}"> <a class="btn btn-default btn-block btn-twitter" href="{{ hwi_oauth_login_url('google') }}">
<i class="fa fa-google"></i> <i class="fa fa-google"></i>

View File

@ -0,0 +1,21 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Festival edit</h1>
{{ form_start(edit_form) }}
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
{{ form_end(edit_form) }}
<ul>
<li>
<a href="{{ path('festival_index') }}">Back to the list</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,41 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Festivals list</h1>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Datecreation</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for festival in festivals %}
<tr>
<td><a href="{{ path('festival_show', { 'id': festival.id }) }}">{{ festival.id }}</a></td>
<td>{{ festival.name }}</td>
<td>{% if festival.dateCreation %}{{ festival.dateCreation|date('Y-m-d H:i:s') }}{% endif %}</td>
<td>
<ul>
<li>
<a href="{{ path('festival_show', { 'id': festival.id }) }}">show</a>
</li>
<li>
<a href="{{ path('festival_edit', { 'id': festival.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('festival_new') }}">Create a new festival</a>
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Festival creation</h1>
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
{{ form_end(form) }}
<ul>
<li>
<a href="{{ path('festival_index') }}">Back to the list</a>
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,36 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Festival</h1>
<table>
<tbody>
<tr>
<th>Id</th>
<td>{{ festival.id }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ festival.name }}</td>
</tr>
<tr>
<th>Datecreation</th>
<td>{% if festival.dateCreation %}{{ festival.dateCreation|date('Y-m-d H:i:s') }}{% endif %}</td>
</tr>
</tbody>
</table>
<ul>
<li>
<a href="{{ path('festival_index') }}">Back to the list</a>
</li>
<li>
<a href="{{ path('festival_edit', { 'id': festival.id }) }}">Edit</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}

View File

@ -62,7 +62,13 @@
<div class="text-right"> <div class="text-right">
<h3 >Total: <strong>{{CurrentSellingTotal()}}€</strong></h3> <h3 >Total: <strong>{{CurrentSellingTotal()}}€</strong></h3>
<input type="number" id="paid_amount" ng-model="paidAmount"> <input type="number" id="paid_amount" ng-model="paidAmount">
<div class="alert alert-success" ng-if="CurrentSellingTotal() - paidAmount <=0">
<h3>Rendu: {{ CurrentSellingTotal() - paidAmount }}€</h3> <h3>Rendu: {{ CurrentSellingTotal() - paidAmount }}€</h3>
</div>
<div class="alert alert-warning" ng-if="CurrentSellingTotal() - paidAmount >0">
<h3>il manque: {{ CurrentSellingTotal() - paidAmount }}€</h3>
</div>
</div> </div>
{% endverbatim %} {% endverbatim %}

View File

@ -9,10 +9,10 @@
<a href="#caisse-now" data-toggle="tab">Caisse</a> <a href="#caisse-now" data-toggle="tab">Caisse</a>
</li> </li>
<li> <li>
<a href="#categories" data-toggle="tab">Catégories</a> <a href="{{ path('productcategory_index') }}">Catégories</a>
</li> </li>
<li> <li>
<a href="#products" data-toggle="tab">Produits</a> <a href="{{ path('product_index') }}" data-toggle="tab">Produits</a>
</li> </li>
<li> <li>
<a href="#history" data-toggle="tab">Historique</a> <a href="#history" data-toggle="tab">Historique</a>

View File

@ -0,0 +1,21 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Product edit</h1>
{{ form_start(edit_form) }}
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
{{ form_end(edit_form) }}
<ul>
<li>
<a href="{{ path('product_index') }}">Back to the list</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Product creation</h1>
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
{{ form_end(form) }}
<ul>
<li>
<a href="{{ path('product_index') }}">Back to the list</a>
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,44 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Product</h1>
<table>
<tbody>
<tr>
<th>Id</th>
<td>{{ product.id }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ product.name }}</td>
</tr>
<tr>
<th>Image</th>
<td>{{ product.image }}</td>
</tr>
<tr>
<th>Price</th>
<td>{{ product.price }}</td>
</tr>
<tr>
<th>Comment</th>
<td>{{ product.comment }}</td>
</tr>
</tbody>
</table>
<ul>
<li>
<a href="{{ path('product_index') }}">Back to the list</a>
</li>
<li>
<a href="{{ path('product_edit', { 'id': product.id }) }}">Edit</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,21 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Productcategory edit</h1>
{{ form_start(edit_form) }}
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
{{ form_end(edit_form) }}
<ul>
<li>
<a href="{{ path('productcategory_index') }}">Back to the list</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,39 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Productcategories list</h1>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for productCategory in productCategories %}
<tr>
<td><a href="{{ path('productcategory_show', { 'id': productCategory.id }) }}">{{ productCategory.id }}</a></td>
<td>{{ productCategory.name }}</td>
<td>
<ul>
<li>
<a href="{{ path('productcategory_show', { 'id': productCategory.id }) }}">show</a>
</li>
<li>
<a href="{{ path('productcategory_edit', { 'id': productCategory.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('productcategory_new') }}">Create a new productCategory</a>
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Productcategory creation</h1>
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" value="Create" />
{{ form_end(form) }}
<ul>
<li>
<a href="{{ path('productcategory_index') }}">Back to the list</a>
</li>
</ul>
{% endblock %}

View File

@ -0,0 +1,32 @@
{% extends 'base.html.twig' %}
{% block body %}
<h1>Productcategory</h1>
<table>
<tbody>
<tr>
<th>Id</th>
<td>{{ productCategory.id }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ productCategory.name }}</td>
</tr>
</tbody>
</table>
<ul>
<li>
<a href="{{ path('productcategory_index') }}">Back to the list</a>
</li>
<li>
<a href="{{ path('productcategory_edit', { 'id': productCategory.id }) }}">Edit</a>
</li>
<li>
{{ form_start(delete_form) }}
<input type="submit" value="Delete">
{{ form_end(delete_form) }}
</li>
</ul>
{% endblock %}

View File

@ -3,3 +3,7 @@
list-style-type: none; list-style-type: none;
} }
} }
table {
width: 100%;
}

View File

@ -5,132 +5,129 @@ namespace AppBundle\Controller;
use AppBundle\Entity\ProductCategory; use AppBundle\Entity\ProductCategory;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
/** /**
* Productcategory controller. * Productcategory controller.
* *
* @Route("productcategory") * @Route("productcategory")
*/ */
class ProductCategoryController extends Controller class ProductCategoryController extends Controller {
{ /**
/** * Lists all productCategory entities.
* Lists all productCategory entities. *
* * @Route("/", name="productcategory_index")
* @Route("/", name="productcategory_index") * @Method("GET")
* @Method("GET") */
*/ public function indexAction() {
public function indexAction() $em = $this->getDoctrine()->getManager();
{
$em = $this->getDoctrine()->getManager();
$productCategories = $em->getRepository('AppBundle:ProductCategory')->findAll(); $productCategories = $em->getRepository( 'AppBundle:ProductCategory' )->findAll();
return $this->render('productcategory/index.html.twig', array( return $this->render( 'productcategory/index.html.twig',
'productCategories' => $productCategories, [
)); 'productCategories' => $productCategories,
} ] );
}
/** /**
* Creates a new productCategory entity. * Creates a new productCategory entity.
* *
* @Route("/new", name="productcategory_new") * @Route("/new", name="productcategory_new")
* @Method({"GET", "POST"}) * @Method({"GET", "POST"})
*/ */
public function newAction(Request $request) public function newAction( Request $request ) {
{ $productCategory = new Productcategory();
$productCategory = new Productcategory(); $form = $this->createForm( 'AppBundle\Form\ProductCategoryType', $productCategory );
$form = $this->createForm('AppBundle\Form\ProductCategoryType', $productCategory); $form->handleRequest( $request );
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ( $form->isSubmitted() && $form->isValid() ) {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$em->persist($productCategory); $em->persist( $productCategory );
$em->flush(); $em->flush();
return $this->redirectToRoute('productcategory_show', array('id' => $productCategory->getId())); return $this->redirectToRoute( 'productcategory_show', [ 'id' => $productCategory->getId() ] );
} }
return $this->render('productcategory/new.html.twig', array( return $this->render( 'productcategory/new.html.twig',
'productCategory' => $productCategory, [
'form' => $form->createView(), 'productCategory' => $productCategory,
)); 'form' => $form->createView(),
} ] );
}
/** /**
* Finds and displays a productCategory entity. * Finds and displays a productCategory entity.
* *
* @Route("/{id}", name="productcategory_show") * @Route("/{id}", name="productcategory_show")
* @Method("GET") * @Method("GET")
*/ */
public function showAction(ProductCategory $productCategory) public function showAction( ProductCategory $productCategory ) {
{ $deleteForm = $this->createDeleteForm( $productCategory );
$deleteForm = $this->createDeleteForm($productCategory);
return $this->render('productcategory/show.html.twig', array( return $this->render( 'productcategory/show.html.twig',
'productCategory' => $productCategory, [
'delete_form' => $deleteForm->createView(), 'productCategory' => $productCategory,
)); 'delete_form' => $deleteForm->createView(),
} ] );
}
/** /**
* Displays a form to edit an existing productCategory entity. * Displays a form to edit an existing productCategory entity.
* *
* @Route("/{id}/edit", name="productcategory_edit") * @Route("/{id}/edit", name="productcategory_edit")
* @Method({"GET", "POST"}) * @Method({"GET", "POST"})
*/ */
public function editAction(Request $request, ProductCategory $productCategory) public function editAction( Request $request, ProductCategory $productCategory ) {
{ $deleteForm = $this->createDeleteForm( $productCategory );
$deleteForm = $this->createDeleteForm($productCategory); $editForm = $this->createForm( 'AppBundle\Form\ProductCategoryType', $productCategory );
$editForm = $this->createForm('AppBundle\Form\ProductCategoryType', $productCategory); $editForm->handleRequest( $request );
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) { if ( $editForm->isSubmitted() && $editForm->isValid() ) {
$this->getDoctrine()->getManager()->flush(); $this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('productcategory_edit', array('id' => $productCategory->getId())); return $this->redirectToRoute( 'productcategory_edit', [ 'id' => $productCategory->getId() ] );
} }
return $this->render('productcategory/edit.html.twig', array( return $this->render( 'productcategory/edit.html.twig',
'productCategory' => $productCategory, [
'edit_form' => $editForm->createView(), 'productCategory' => $productCategory,
'delete_form' => $deleteForm->createView(), 'edit_form' => $editForm->createView(),
)); 'delete_form' => $deleteForm->createView(),
} ] );
}
/** /**
* Deletes a productCategory entity. * Deletes a productCategory entity.
* *
* @Route("/{id}", name="productcategory_delete") * @Route("/{id}", name="productcategory_delete")
* @Method("DELETE") * @Method("DELETE")
*/ */
public function deleteAction(Request $request, ProductCategory $productCategory) public function deleteAction( Request $request, ProductCategory $productCategory ) {
{ $form = $this->createDeleteForm( $productCategory );
$form = $this->createDeleteForm($productCategory); $form->handleRequest( $request );
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ( $form->isSubmitted() && $form->isValid() ) {
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$em->remove($productCategory); $em->remove( $productCategory );
$em->flush(); $em->flush();
} }
return $this->redirectToRoute('productcategory_index'); return $this->redirectToRoute( 'productcategory_index' );
} }
/** /**
* Creates a form to delete a productCategory entity. * Creates a form to delete a productCategory entity.
* *
* @param ProductCategory $productCategory The productCategory entity * @param ProductCategory $productCategory The productCategory entity
* *
* @return \Symfony\Component\Form\Form The form * @return \Symfony\Component\Form\Form The form
*/ */
private function createDeleteForm(ProductCategory $productCategory) private function createDeleteForm( ProductCategory $productCategory ) {
{ return $this->createFormBuilder()
return $this->createFormBuilder() ->setAction( $this->generateUrl( 'productcategory_delete', [ 'id' => $productCategory->getId() ] ) )
->setAction($this->generateUrl('productcategory_delete', array('id' => $productCategory->getId()))) ->setMethod( 'DELETE' )
->setMethod('DELETE') ->getForm();
->getForm() }
;
}
} }

View File

@ -30,6 +30,10 @@ class ProductCategory {
*/ */
private $users; private $users;
public function __toString() {
return $this->getName() . ' (' . count( $this->getProducts() ) . ' produits)';
}
/** /**
* @return mixed * @return mixed
*/ */

View File

@ -6,31 +6,31 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
class ProductType extends AbstractType class ProductType extends AbstractType {
{ /**
/** * {@inheritdoc}
* {@inheritdoc} */
*/ public function buildForm( FormBuilderInterface $builder, array $options ) {
public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'name' )->add( 'image',
{ null,
$builder->add('name')->add('image')->add('price')->add('comment')->add('category')->add('user'); [ 'label' => 'URL pour image' ] )->add( 'price' )->add( 'comment' )->add( 'category' )->add( 'user' );
}/** }
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Product'
));
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getBlockPrefix() public function configureOptions( OptionsResolver $resolver ) {
{ $resolver->setDefaults( [
return 'appbundle_product'; 'data_class' => 'AppBundle\Entity\Product',
} ] );
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix() {
return 'appbundle_product';
}
} }