diff --git a/.gitignore b/.gitignore index 4b8c570..5d1aaa4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /src/CoursEndingBundle/Model/Base/ /src/CoursEndingBundle/Model/Map/ /app/phpunit.xml +/web/components/ /build/ /vendor/ /bin/ diff --git a/app/config/config.yml b/app/config/config.yml index 57b7dfa..fd693fe 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -84,3 +84,4 @@ fos_js_routing: routes_to_expose: - api_get_forms - api_get_questions + - api_post_forms diff --git a/composer.json b/composer.json index c001e28..2941897 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "nelmio/api-doc-bundle": "^2.11", "propel/propel": "dev-master", "propel/propel-bundle": "2.0.x-dev", - "friendsofsymfony/jsrouting-bundle": "^1.6" + "friendsofsymfony/jsrouting-bundle": "^1.6", + "deblan/fos-rest-behavior": "dev-master" }, "require-dev": { "sensio/generator-bundle": "~3.0", diff --git a/src/CoursEndingBundle/Controller/MainController.php b/src/CoursEndingBundle/Controller/MainController.php index efe330b..355680a 100644 --- a/src/CoursEndingBundle/Controller/MainController.php +++ b/src/CoursEndingBundle/Controller/MainController.php @@ -6,6 +6,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Request; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; +use CoursEndingBundle\Form\Type\FormsType; +use CoursEndingBundle\Model\FormQuery; +use CoursEndingBundle\Model\FCollection; class MainController extends Controller { @@ -16,6 +19,16 @@ class MainController extends Controller */ public function indexAction(Request $request) { - return []; + $forms = ['forms' => FormQuery::create()->find()]; + + $form = $this->createForm(FormsType::class, $forms); + + if ($form->isValid()) { + die("ok"); + } + + return [ + 'form' => $form->createView(), + ]; } } diff --git a/src/CoursEndingBundle/Controller/RestController.php b/src/CoursEndingBundle/Controller/RestController.php index 153a9ef..d2a5399 100644 --- a/src/CoursEndingBundle/Controller/RestController.php +++ b/src/CoursEndingBundle/Controller/RestController.php @@ -10,6 +10,8 @@ use Symfony\Component\HttpFoundation\Request; use CoursEndingBundle\Model\FormQuery; use CoursEndingBundle\Model\QuestionQuery; use CoursEndingBundle\DataRestContainer; +use CoursEndingBundle\Form\Type\FormsType; +use FOS\RestBundle\View\View; /** * @author Simon Vieille @@ -50,10 +52,20 @@ class RestController extends FOSRestController * @Rest\View * @ApiDoc( * description="Je suis une description", - * input="RestBundle\Form\Type\FooType", - * output="RestBundle\Api\DataContainer" + * input="CoursEndingBundle\Form\Type\FormsType", * ) */ + public function postFormsAction(Request $request) + { + $forms = ['forms' => FormQuery::create()->find()]; + + $form = $this->createForm(FormsType::class, $forms); + + $form->handleRequest($request); + + return View::create($form, 400); + } + // public function postQuestionsAction(Request $request) // { // // $form = $this->createForm(new FooType()); diff --git a/src/CoursEndingBundle/DataRestContainer.php b/src/CoursEndingBundle/DataRestContainer.php index c0a86e4..632e600 100644 --- a/src/CoursEndingBundle/DataRestContainer.php +++ b/src/CoursEndingBundle/DataRestContainer.php @@ -57,7 +57,7 @@ class DataRestContainer } } - return -1; + return 1; } /** diff --git a/src/CoursEndingBundle/Form/Type/FormType.php b/src/CoursEndingBundle/Form/Type/FormType.php new file mode 100644 index 0000000..a8c4d5d --- /dev/null +++ b/src/CoursEndingBundle/Form/Type/FormType.php @@ -0,0 +1,40 @@ + 'form', + 'allow_extra_fields' => true, + 'data_class' => 'CoursEndingBundle\Model\Form', + ); + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add( + 'id', + TextType::class, + array( + ) + ); + + $builder->add( + 'label', + TextType::class, + array( + ) + ); + + $builder->add( + 'active', + TextType::class, + array( + ) + ); + } +} diff --git a/src/CoursEndingBundle/Form/Type/FormsType.php b/src/CoursEndingBundle/Form/Type/FormsType.php new file mode 100644 index 0000000..31b0c3f --- /dev/null +++ b/src/CoursEndingBundle/Form/Type/FormsType.php @@ -0,0 +1,34 @@ + 'forms', + 'allow_extra_fields' => true, + 'csrf_protection' => false, + ); + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add( + 'forms', + CollectionType::class, + [ + 'entry_type' => FormType::class, + 'allow_add' => true, + 'by_reference' => false, + ] + ); + } +} diff --git a/src/CoursEndingBundle/Model/Form.php b/src/CoursEndingBundle/Model/Form.php index 74dff1f..232af05 100644 --- a/src/CoursEndingBundle/Model/Form.php +++ b/src/CoursEndingBundle/Model/Form.php @@ -19,14 +19,4 @@ class Form extends BaseForm { return new DataRestContainer(parent::getQuestions()->getData()); } - - /** - * {@inheritdoc} - * @JMS\Serializer\Annotation\SerializedName("created_at") - * @JMS\Serializer\Annotation\VirtualProperty - */ - public function getCreatedAtRest() - { - return new DataRestContainer($this->getCreatedAt()); - } } diff --git a/src/CoursEndingBundle/Resources/config/propel/schema.xml b/src/CoursEndingBundle/Resources/config/propel/schema.xml index 8f35ab1..b329e91 100644 --- a/src/CoursEndingBundle/Resources/config/propel/schema.xml +++ b/src/CoursEndingBundle/Resources/config/propel/schema.xml @@ -7,7 +7,7 @@ - + diff --git a/src/CoursEndingBundle/Resources/public/js/app.js b/src/CoursEndingBundle/Resources/public/js/app.js index e7f7bfa..1caf588 100644 --- a/src/CoursEndingBundle/Resources/public/js/app.js +++ b/src/CoursEndingBundle/Resources/public/js/app.js @@ -1,5 +1,5 @@ new Vue({ - el: '#forms', + el: '#forms-render', data: { forms: [] @@ -14,6 +14,19 @@ new Vue({ this.$http.get(Routing.generate('api_get_forms'), function(forms) { this.$set('forms', forms.data); }); + }, + + save: function() { + var data = { + forms: { + forms: this.forms + } + }; + + this.$http.post( + Routing.generate('api_post_forms'), + data + ); } } }) diff --git a/src/CoursEndingBundle/Resources/views/Main/index.html.twig b/src/CoursEndingBundle/Resources/views/Main/index.html.twig index 5016046..e36b825 100644 --- a/src/CoursEndingBundle/Resources/views/Main/index.html.twig +++ b/src/CoursEndingBundle/Resources/views/Main/index.html.twig @@ -2,17 +2,29 @@ {% block body %} -
+{{form_row(form.forms)}} + +{{ form_rest(form) }} + +
+ +
{% raw %}
+ {{ form.label }}
+ +
+
{{ form.active ? 'ACTVITÉ' : 'NON ACTIVÉ' }}
{% endraw %}
+ +
{% endblock %}