From b1d7e543fc5a556c9d9b4ef8ea2bedd874654052 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 27 May 2021 17:36:33 +0200 Subject: [PATCH] controller return json to vue via twig; init vue App --- .../Controller/ActivityController.php | 17 +---- .../Resources/public/vuejs/Activity/App.vue | 18 +++++ .../Resources/public/vuejs/Activity/i18n.js | 8 ++ .../Resources/public/vuejs/Activity/index.js | 16 ++++ .../Resources/public/vuejs/Activity/store.js | 31 ++++++++ .../Resources/views/Activity/edit.html.twig | 73 ++++++++++++------- .../Activity/editAccompanyingCourse.html.twig | 5 ++ .../views/Activity/editPerson.html.twig | 4 + .../Resources/views/Activity/new.html.twig | 4 +- .../Activity/newAccompanyingCourse.html.twig | 11 +-- .../views/Activity/newPerson.html.twig | 3 +- 11 files changed, 138 insertions(+), 52 deletions(-) create mode 100644 src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/App.vue create mode 100644 src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/i18n.js create mode 100644 src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 09f6e0c80..c116c5d35 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -209,19 +209,8 @@ class ActivityController extends AbstractController throw $this->createNotFoundException('Template not found'); } - //$activity_json = $this->serializer->serialize($entity, 'json', []); - // "A circular reference has been detected when serializing the object of class "Chill\PersonBundle\Entity\AccompanyingPeriod" (configured limit: 1)." + $activity_json = $this->serializer->serialize($entity, 'json', ['groups' => 'read']); - $activity_json = null; - // activity_json doit retourner qqch comme : - // { - // "type": "activity", - // "persons": [ - // { type: person, id: xxx, ...} - // { ...} - // ], "" - // } - return $this->render($view, [ 'person' => $person, 'accompanyingCourse' => $accompanyingPeriod, @@ -334,13 +323,15 @@ class ActivityController extends AbstractController throw $this->createNotFoundException('Template not found'); } + $activity_json = $this->serializer->serialize($entity, 'json', ['groups' => ['read']]); + return $this->render($view, array( 'entity' => $entity, 'edit_form' => $form->createView(), 'delete_form' => $deleteForm->createView(), 'person' => $person, 'accompanyingCourse' => $accompanyingPeriod, - 'activity_json' => null + 'activity_json' => $activity_json )); } diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/App.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/App.vue new file mode 100644 index 000000000..74466733a --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/App.vue @@ -0,0 +1,18 @@ + + + + + diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/i18n.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/i18n.js new file mode 100644 index 000000000..b38767780 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/i18n.js @@ -0,0 +1,8 @@ +const appMessages = { + fr: { + + } +} +export { + appMessages +}; diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/index.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/index.js index e69de29bb..bd850419e 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/index.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/index.js @@ -0,0 +1,16 @@ +import { createApp } from 'vue'; +import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n' +import { appMessages } from './i18n' +import store from './store' + +import App from './App.vue'; + +const i18n = _createI18n(appMessages); + +const app = createApp({ + template: ``, +}) +.use(store) +.use(i18n) +.component('app', App) +.mount('#activity'); diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js new file mode 100644 index 000000000..769e87245 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js @@ -0,0 +1,31 @@ +import 'es6-promise/auto'; +import { createStore } from 'vuex'; + +const debug = process.env.NODE_ENV !== 'production'; +//console.log('window.activity', window.activity); + +const store = createStore({ + strict: debug, + state: { + activity: window.activity + }, + getters: { + + }, + mutations: { + addPerson(state, payload) { + + } + }, + actions: { + addPerson() { + //let el = document.getElementById('form['activity']['xxx']['xxxx']'); + //let option = document.createElement('option'); + //option.value = person.id; + //el.appendChild(option); + commit('addPerson', payload) + } + } +}); + +export default store; diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig index 0625174ac..902278874 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig @@ -1,6 +1,15 @@

{{ "Update activity"|trans }}

{{ form_start(edit_form) }} +{{ form_errors(edit_form) }} + +{%- if edit_form.emergency is defined -%} + {{ form_row(edit_form.emergency) }} +{% endif %} + +{%- if edit_form.sentReceived is defined -%} + {{ form_row(edit_form.sentReceived) }} +{% endif %} {%- if edit_form.user is defined -%} {{ form_row(edit_form.user) }} @@ -10,45 +19,55 @@ {{ form_row(edit_form.scope) }} {% endif %} -

{{ 'Activity data'|trans }}

+.. type -{%- if form.date is defined -%} - {{ form_row(form.date) }} +{%- if edit_form.reasons is defined -%} + {{ form_row(edit_form.reasons) }} {% endif %} -{%- if form.durationTime is defined -%} - {{ form_row(form.durationTime) }} + +

Parties concernées

+ +{%- if edit_form.persons is defined -%} + {{ form_row(edit_form.persons) }} {% endif %} -{%- if form.travelTime is defined -%} - {{ form_row(form.travelTime) }} +{%- if edit_form.thirdParties is defined -%} + {{ form_row(edit_form.thirdParties) }} {% endif %} -{%- if form.attendee is defined -%} - {{ form_row(form.attendee) }} +{%- if edit_form.users is defined -%} + {{ form_row(edit_form.users) }} {% endif %} -{%- if form.comment is defined -%} - {{ form_row(form.comment) }} + +

{{ 'Activity data'|trans }}

+ +{%- if edit_form.date is defined -%} + {{ form_row(edit_form.date) }} {% endif %} -{%- if form.reasons is defined -%} - {{ form_row(form.reasons) }} + +.. location + +{%- if edit_form.durationTime is defined -%} + {{ form_row(edit_form.durationTime) }} {% endif %} -{%- if form.persons is defined -%} - {{ form_row(form.persons) }} + +{%- if edit_form.travelTime is defined -%} + {{ form_row(edit_form.travelTime) }} {% endif %} -{%- if form.thirdParties is defined -%} - {{ form_row(form.thirdParties) }} + +{%- if edit_form.comment is defined -%} + .. public and private + {{ form_row(edit_form.comment) }} {% endif %} -{%- if form.users is defined -%} - {{ form_row(form.users) }} + +{%- if edit_form.documents is defined -%} + {{ form_row(edit_form.documents) }} {% endif %} -{%- if form.emergency is defined -%} - {{ form_row(form.emergency) }} -{% endif %} -{%- if form.sentReceived is defined -%} - {{ form_row(form.sentReceived) }} -{% endif %} -{%- if form.documents is defined -%} - {{ form_row(form.documents) }} + +{%- if edit_form.attendee is defined -%} + {{ form_row(edit_form.attendee) }} {% endif %} +.. status + {% set person_id = null %} {% if entity.person %} {% set person_id = entity.person.id %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig index b9a812b09..db4034fa7 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig @@ -5,16 +5,21 @@ {% block title 'Update activity'|trans %} {% block content %} +
{# <=== vue component #} {% include 'ChillActivityBundle:Activity:edit.html.twig' %} + {{ dump() }} {% endblock %} {% block js %} + {{ encore_entry_script_tags('vue_activity') }} {% endblock %} {% block css %} + {{ encore_entry_link_tags('vue_activity') }} {% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editPerson.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editPerson.html.twig index fc32dab49..b0cfa13c2 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editPerson.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editPerson.html.twig @@ -22,15 +22,19 @@ {% block personcontent %} {% include 'ChillActivityBundle:Activity:edit.html.twig' %} +
{# <=== vue component #} {% endblock %} {% block js %} + {{ encore_entry_script_tags('vue_activity') }} {% endblock %} {% block css %} + {{ encore_entry_link_tags('vue_activity') }} {% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig index 067192ad5..83d8a6c58 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig @@ -1,4 +1,4 @@ -

{{ "Activity creation"|trans }}

+

{{ "Activity creation"|trans }}

{{ form_start(form) }} {{ form_errors(form) }} @@ -20,7 +20,7 @@ {{ form_row(form.scope) }} {% endif %} -type.. +.. type {%- if form.reasons is defined -%} {{ form_row(form.reasons) }} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig index aa532b323..163732e97 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig @@ -5,6 +5,7 @@ {% block title 'Activity creation' |trans %} {% block content %} +
{# <=== vue component #} {% include 'ChillActivityBundle:Activity:new.html.twig' %} {{ dump() }} {% endblock %} @@ -13,15 +14,7 @@ {{ encore_entry_script_tags('vue_activity') }} {% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newPerson.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newPerson.html.twig index 5155e9242..335b986c7 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newPerson.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newPerson.html.twig @@ -6,13 +6,14 @@ {% block personcontent %} {% include 'ChillActivityBundle:Activity:new.html.twig' %} +
{# <=== vue component #} {% endblock %} {% block js %} {{ encore_entry_script_tags('vue_activity') }} {% endblock %}