From 99e3a9a9f426e2a7f0346e8332a6c41a9b191de9 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sat, 19 Mar 2016 17:33:18 +0100 Subject: [PATCH] test of vuejs --- app/AppKernel.php | 1 + app/Resources/views/base.html.twig | 13 ++-- app/Resources/views/default/index.html.twig | 76 ------------------- app/config/config.yml | 5 ++ app/config/routing.yml | 3 + bower.json | 3 +- composer.json | 3 +- .../Controller/RestController.php | 9 ++- src/CoursEndingBundle/DataRestContainer.php | 23 ++++++ src/CoursEndingBundle/Model/Form.php | 13 +++- .../Resources/public/js/app.js | 24 ++++-- .../Resources/views/Main/index.html.twig | 50 +++--------- 12 files changed, 92 insertions(+), 131 deletions(-) delete mode 100644 app/Resources/views/default/index.html.twig diff --git a/app/AppKernel.php b/app/AppKernel.php index 0eda410..69294e4 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -19,6 +19,7 @@ class AppKernel extends Kernel // dependencies new FOS\RestBundle\FOSRestBundle(), + new FOS\JsRoutingBundle\FOSJsRoutingBundle(), new JMS\SerializerBundle\JMSSerializerBundle(), new Nelmio\ApiDocBundle\NelmioApiDocBundle(), new Propel\Bundle\PropelBundle\PropelBundle(), diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index dffb999..2085b45 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -9,10 +9,13 @@ {% block body %}{% endblock %} {% block javascripts %} - - - - - {% endblock %} + + + + + + + + {% endblock %} diff --git a/app/Resources/views/default/index.html.twig b/app/Resources/views/default/index.html.twig deleted file mode 100644 index 7319df7..0000000 --- a/app/Resources/views/default/index.html.twig +++ /dev/null @@ -1,76 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block body %} -
-
-
-

Welcome to Symfony {{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}

-
- -
-

- - - Your application is now ready. You can start working on it at: - {{ base_dir }}/ -

-
- - - -
-
-{% endblock %} - -{% block stylesheets %} - -{% endblock %} diff --git a/app/config/config.yml b/app/config/config.yml index 13734e1..57b7dfa 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -79,3 +79,8 @@ propel: dsn: %database_driver%:host=%database_host%;dbname=%database_name%;charset=UTF8 options: {} attributes: {} + +fos_js_routing: + routes_to_expose: + - api_get_forms + - api_get_questions diff --git a/app/config/routing.yml b/app/config/routing.yml index 7973488..e47f203 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -10,3 +10,6 @@ CoursEndingBundle: NelmioApiDocBundle: resource: "@NelmioApiDocBundle/Resources/config/routing.yml" prefix: /api/doc + +FOSJsRouting: + resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml" diff --git a/bower.json b/bower.json index 3aa538c..6079124 100644 --- a/bower.json +++ b/bower.json @@ -15,6 +15,7 @@ "dependencies": { "vue": "~1.0.18", "vue-validator": "~1.4.4", - "marked": "~0.3.5" + "marked": "~0.3.5", + "vue-resource": "~0.7.0" } } diff --git a/composer.json b/composer.json index 28e6123..c001e28 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "jms/serializer-bundle": "dev-master", "nelmio/api-doc-bundle": "^2.11", "propel/propel": "dev-master", - "propel/propel-bundle": "2.0.x-dev" + "propel/propel-bundle": "2.0.x-dev", + "friendsofsymfony/jsrouting-bundle": "^1.6" }, "require-dev": { "sensio/generator-bundle": "~3.0", diff --git a/src/CoursEndingBundle/Controller/RestController.php b/src/CoursEndingBundle/Controller/RestController.php index ca73bcb..153a9ef 100644 --- a/src/CoursEndingBundle/Controller/RestController.php +++ b/src/CoursEndingBundle/Controller/RestController.php @@ -11,6 +11,9 @@ use CoursEndingBundle\Model\FormQuery; use CoursEndingBundle\Model\QuestionQuery; use CoursEndingBundle\DataRestContainer; +/** + * @author Simon Vieille + */ class RestController extends FOSRestController { /** @@ -27,7 +30,7 @@ class RestController extends FOSRestController return $container; } - + /** * @Rest\View * @ApiDoc( @@ -38,7 +41,9 @@ class RestController extends FOSRestController { $data = QuestionQuery::create()->find()->getData(); - return $data; + $container = new DataRestContainer($data); + + return $container; } /** diff --git a/src/CoursEndingBundle/DataRestContainer.php b/src/CoursEndingBundle/DataRestContainer.php index cdef62c..c0a86e4 100644 --- a/src/CoursEndingBundle/DataRestContainer.php +++ b/src/CoursEndingBundle/DataRestContainer.php @@ -13,6 +13,16 @@ class DataRestContainer */ protected $count; + /** + * @var string + */ + protected $type; + + /** + * @var string + */ + protected $class; + /** * @var mixed */ @@ -50,6 +60,18 @@ class DataRestContainer return -1; } + /** + * + */ + public function type() + { + $this->type = gettype($this->data); + + if ($this->type === 'object') { + $this->class = get_class($this->data); + } + } + /** * @param mixed $data * @return DataRestContainer @@ -59,6 +81,7 @@ class DataRestContainer $this->data = $data; $this->count(); + $this->type(); return $this; } diff --git a/src/CoursEndingBundle/Model/Form.php b/src/CoursEndingBundle/Model/Form.php index 9988249..74dff1f 100644 --- a/src/CoursEndingBundle/Model/Form.php +++ b/src/CoursEndingBundle/Model/Form.php @@ -6,6 +6,7 @@ use CoursEndingBundle\Model\Base\Form as BaseForm; use JMS\Serializer\Annotation\VirtualProperty; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Connection\ConnectionInterface; +use CoursEndingBundle\DataRestContainer; class Form extends BaseForm { @@ -16,6 +17,16 @@ class Form extends BaseForm */ public function getQuestionsRest() { - return parent::getQuestions()->getData(); + 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/public/js/app.js b/src/CoursEndingBundle/Resources/public/js/app.js index cb6d711..e7f7bfa 100644 --- a/src/CoursEndingBundle/Resources/public/js/app.js +++ b/src/CoursEndingBundle/Resources/public/js/app.js @@ -1,9 +1,19 @@ new Vue({ - el: '#editor', - data: { - input: '# hello' - }, - filters: { - marked: marked - } + el: '#forms', + + data: { + forms: [] + }, + + ready: function() { + this.fetchForms(); + }, + + methods: { + fetchForms: function() { + this.$http.get(Routing.generate('api_get_forms'), function(forms) { + this.$set('forms', forms.data); + }); + } + } }) diff --git a/src/CoursEndingBundle/Resources/views/Main/index.html.twig b/src/CoursEndingBundle/Resources/views/Main/index.html.twig index df0b0ea..5016046 100644 --- a/src/CoursEndingBundle/Resources/views/Main/index.html.twig +++ b/src/CoursEndingBundle/Resources/views/Main/index.html.twig @@ -1,44 +1,18 @@ {% extends '::base.html.twig' %} {% block body %} - - - -
- -
+
+
+ {% raw %} +
+ {{ form.label }} +
+
+ {{ form.active ? 'ACTVITÉ' : 'NON ACTIVÉ' }} +
+ {% endraw %} +
+ {% endblock %}