still testing…
This commit is contained in:
parent
99e3a9a9f4
commit
c18a861147
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,6 +9,7 @@
|
|||
/src/CoursEndingBundle/Model/Base/
|
||||
/src/CoursEndingBundle/Model/Map/
|
||||
/app/phpunit.xml
|
||||
/web/components/
|
||||
/build/
|
||||
/vendor/
|
||||
/bin/
|
||||
|
|
|
@ -84,3 +84,4 @@ fos_js_routing:
|
|||
routes_to_expose:
|
||||
- api_get_forms
|
||||
- api_get_questions
|
||||
- api_post_forms
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <simon@deblan.fr>
|
||||
|
@ -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());
|
||||
|
|
|
@ -57,7 +57,7 @@ class DataRestContainer
|
|||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
40
src/CoursEndingBundle/Form/Type/FormType.php
Normal file
40
src/CoursEndingBundle/Form/Type/FormType.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace CoursEndingBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Propel\Bundle\PropelBundle\Form\BaseAbstractType;
|
||||
|
||||
class FormType extends BaseAbstractType
|
||||
{
|
||||
protected $options = array(
|
||||
'name' => '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(
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
34
src/CoursEndingBundle/Form/Type/FormsType.php
Normal file
34
src/CoursEndingBundle/Form/Type/FormsType.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace CoursEndingBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Propel\Bundle\PropelBundle\Form\BaseAbstractType;
|
||||
use CoursEndingBundle\Form\Type\FormsType;
|
||||
use Propel\Bundle\PropelBundle\Form\Type\ModelType;
|
||||
use CoursEndingBundle\Model\Form;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
use CoursEndingBundle\Form\Type\FormType;
|
||||
|
||||
class FormsType extends BaseAbstractType
|
||||
{
|
||||
protected $options = array(
|
||||
'name' => '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,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
<behavior name="timestampable"/>
|
||||
|
||||
<behavior name="CoursEndingBundle\Propel\Behavior\FOSRestBehavior">
|
||||
<behavior name="fos_rest">
|
||||
<parameter name="id" value="" />
|
||||
<parameter name="label" value="" />
|
||||
<parameter name="active" value="" />
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -2,17 +2,29 @@
|
|||
|
||||
{% block body %}
|
||||
|
||||
<div id="forms" class="collection">
|
||||
{{form_row(form.forms)}}
|
||||
|
||||
{{ form_rest(form) }}
|
||||
|
||||
<div id="foo"></div>
|
||||
|
||||
<div id="forms-render" class="collection">
|
||||
<div class="collection-item" v-for="form in forms">
|
||||
{% raw %}
|
||||
<div class="collection-item-title">
|
||||
<input type="text" v-model="form.label" />
|
||||
{{ form.label }}
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class="collection-item-content">
|
||||
{{ form.active ? 'ACTVITÉ' : 'NON ACTIVÉ' }}
|
||||
</div>
|
||||
{% endraw %}
|
||||
</div>
|
||||
|
||||
<input v-on:click="save" type="button" value="Enregistrer" />
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue