Entite.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <script>
  2. import REST from '@api/rest-axios'
  3. import JSONAPI from '@api/json-axios'
  4. import { mapActions, mapState } from 'pinia'
  5. import { ConcernementsStore } from '@stores/concernements'
  6. import { UserStore } from '@stores/user'
  7. import Source from '@components/contents/Source.vue';
  8. import ContentEditable from '@components/editable/ContentEditable.vue';
  9. import CheckboxEditable from '@components/editable/CheckboxEditable.vue';
  10. import ImageEditable from '@components/editable/ImageEditable.vue';
  11. import SvgIcon from '@jamescoyle/vue-icon';
  12. import { mdiTextBoxPlusOutline } from '@mdi/js';
  13. export default {
  14. props: ['concernement', 'entite', 'eid'],
  15. emits: ['reloadEntite'],
  16. data() {
  17. return {
  18. mdiTextBoxPlusOutline_path: mdiTextBoxPlusOutline,
  19. }
  20. },
  21. computed: {
  22. ...mapState(ConcernementsStore,['opened_concernement',
  23. 'ct_concernement',
  24. 'ct_entite']),
  25. ...mapState(UserStore,['csrf_token']),
  26. field_menace_maintien_label (){
  27. let str;
  28. if (this.concernement.entites_byid[this.eid].menacemaintien < 0) {
  29. str = this.ct_entite.field_menace_maintien.description.replace('/maintient', '')
  30. } else {
  31. str = this.ct_entite.field_menace_maintien.description.replace('menace/', '')
  32. }
  33. return str;
  34. },
  35. },
  36. methods: {
  37. reloadEntite(){
  38. this.$emit('reloadEntite');
  39. },
  40. addSource(){
  41. console.log('add source');
  42. const params_parag = {
  43. type: [{target_id: 'source'}],
  44. parent_type:{value: 'node'},
  45. parent_id:{value: this.entite.id},
  46. parent_field_name:{value: 'field_sources'}
  47. };
  48. const configs = {
  49. headers: {'X-CSRF-Token': this.csrf_token}
  50. };
  51. // call the api
  52. // https://www.drupal.org/project/paragraphs/issues/3012600
  53. REST.post(`/entity/paragraph?_format=json`, params_parag, configs)
  54. .then(({ data }) => {
  55. console.log('REST post new source parag', data);
  56. const params_node = {
  57. type: 'entite',
  58. nid: [{value: this.entite.id}],
  59. 'field_sources': [{
  60. target_id: data.id[0].value,
  61. target_revision_id: data.revision_id[0].value
  62. }]
  63. };
  64. // call the api
  65. REST.patch(`/node/${this.entite.id}?_format=json`, params_node, configs)
  66. .then(({ data }) => {
  67. console.log('REST patch entite new field_sources', data)
  68. this.reloadEntite();
  69. })
  70. .catch(error => {
  71. console.warn(`Issue with patch node entite field_sources`, error)
  72. Promise.reject(error)
  73. })
  74. })
  75. .catch(error => {
  76. console.warn(`Issue with post new paragraph source`, error)
  77. Promise.reject(error)
  78. })
  79. }
  80. },
  81. components: {
  82. Source,
  83. ContentEditable,
  84. CheckboxEditable,
  85. ImageEditable,
  86. SvgIcon
  87. }
  88. }
  89. </script>
  90. <template>
  91. <section class="entite">
  92. <section v-if="entite.image.length || entite.can_update" class="image">
  93. <ImageEditable
  94. :can_update="entite.can_update"
  95. :image="entite.image[0]"
  96. :data="{
  97. entitytype: 'node',
  98. bundle: 'entite',
  99. id: this.entite.id,
  100. uuid: this.entite.uuid,
  101. field: 'field_image'
  102. }"
  103. v-on:updated="reloadEntite" />
  104. </section>
  105. <section v-if="entite.action || entite.can_update" class="action">
  106. <label v-if="ct_entite">{{ ct_entite.field_action.description }}</label>
  107. <!-- <p>{{ entite.action }}</p> -->
  108. <ContentEditable
  109. tag="p"
  110. :value="entite.action"
  111. :contenteditable="entite.can_update"
  112. :data="{
  113. entitytype: 'node',
  114. bundle: 'entite',
  115. id: this.entite.id,
  116. field: {field_name: 'field_action', value:'value'}
  117. }"
  118. v-on:updated="reloadEntite" />
  119. </section>
  120. <section v-if="entite.menacemaintien || entite.can_update" class="menace-maintien">
  121. <label v-if="ct_entite">{{ field_menace_maintien_label }}</label>
  122. <!-- <p>{{ entite.menacemaintien }}</p> -->
  123. <ContentEditable
  124. tag="p"
  125. :value="entite.menacemaintien"
  126. :contenteditable="entite.can_update"
  127. :data="{
  128. entitytype: 'node',
  129. bundle: 'entite',
  130. id: this.entite.id,
  131. field: {field_name: 'field_menace_maintien', value:'value'}
  132. }"
  133. v-on:updated="reloadEntite" />
  134. </section>
  135. <!-- SOURCES (experiences vecues) -->
  136. <section
  137. v-if="entite.sources.length"
  138. class="sources multiple">
  139. <!-- <h5>Experience(s) Vécue(s)</h5> -->
  140. <Source
  141. v-for="(source, index) in entite.sources"
  142. :key="index"
  143. :concernement="concernement"
  144. :entite="entite"
  145. :eid="eid"
  146. :source="source"
  147. v-on:reloadEntite="reloadEntite" />
  148. </section>
  149. <section
  150. v-else-if="entite.can_update"
  151. class="sources add">
  152. <div @click="addSource" class="add-source-btn">
  153. <span>Ajouter une experience vécue</span>
  154. <svg-icon type="mdi" :path="mdiTextBoxPlusOutline_path"/>
  155. </div>
  156. </section>
  157. </section>
  158. </template>
  159. <style lang="css">
  160. section.action p,
  161. section.menace-maintien p {
  162. white-space: pre-wrap;
  163. }
  164. </style>