Concernement.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <script>
  2. import { mapActions, mapState } from 'pinia'
  3. import { ConcernementsStore } from '@stores/concernements'
  4. import { CommonStore } from '@/stores/common'
  5. import { print } from 'graphql/language/printer'
  6. import gql from 'graphql-tag'
  7. import GQL from '@api/graphql-axios'
  8. import EntiteFields from '@api/gql/entite.fragment.gql'
  9. import SvgIcon from '@jamescoyle/vue-icon';
  10. import { mdiArrowUp } from '@mdi/js';
  11. import TerrainDeVie from '@components/contents/TerrainDeVie.vue';
  12. import PuissanceAgir from '@components/contents/PuissanceAgir.vue';
  13. import Doleancer from '@components/contents/Doleancer.vue';
  14. export default {
  15. props: ['cid', 'eid'],
  16. data(){
  17. return {
  18. entite: null,
  19. opened_besoin_id: null,
  20. arrowup_path: mdiArrowUp
  21. }
  22. },
  23. computed: {
  24. ...mapState(ConcernementsStore,['map_mode',
  25. 'opened_concernement',
  26. 'concernements_loaded',
  27. 'allSuperpositions_byid']),
  28. // ...mapState(CommonStore,['hover_elmt']),
  29. superposition_id () {
  30. console.log('superposition_id computed');
  31. if(this.$route.query.superposition_id){
  32. return this.$route.query.superposition_id
  33. } else {
  34. return null;
  35. }
  36. },
  37. superposition () {
  38. console.log('superposition computed', this.superposition_id);
  39. if(this.superposition_id){
  40. let sid = this.$route.query.superposition_id;
  41. let ids = sid.match(/(\d+)_(\d+)__(\d+)_(\d+)/i)
  42. let couple_key = `${ids[1]}-${ids[3]}`
  43. console.log('superposition_id', sid, couple_key, ids);
  44. if (this.allSuperpositions_byid[couple_key][sid]) {
  45. let s = this.allSuperpositions_byid[couple_key][sid]
  46. console.log(s);
  47. return s;
  48. }else{
  49. return null;
  50. }
  51. } else {
  52. return null;
  53. }
  54. },
  55. superposed_cid_eid () {
  56. if (this.superposition) {
  57. let r = null;
  58. this.superposition.forEach(s => {
  59. if(s.cid !== this.opened_concernement.id){
  60. r = {
  61. cid: s.cid,
  62. eid: s.eid
  63. }
  64. }
  65. });
  66. console.log('superposed_cid_eid', r);
  67. return r;
  68. } else {
  69. return null
  70. }
  71. }
  72. },
  73. created () {
  74. console.log(`Concernement view created, id: ${this.cid}, eid: ${this.eid}, opened_concernement:${this.opened_concernement}`);
  75. console.log('Concernement view created, allSuperpositions_byid', this.allSuperpositions_byid);
  76. console.log("superposition", this.superposition);
  77. // when we arrived directly to the url, load the entite
  78. // this.eid provided by route params
  79. if (!this.entity && this.eid) {
  80. this.openEntity();
  81. }
  82. },
  83. watch: {
  84. concernements_loaded: {
  85. handler (n, o){
  86. // console.log(`watch concernements_loaded n: ${n}, opened_concernement:${this.opened_concernement}, id:${this.id}`);
  87. // when we arrived directly to the url then all concernement are loaded: do open the concernement
  88. if (!this.opened_concernement) {
  89. this.openCloseConcernements(parseInt(this.cid))
  90. }
  91. },
  92. deep: true
  93. },
  94. eid: {
  95. handler (n, o){
  96. if(n){
  97. this.openEntity()
  98. }else{
  99. this.entite = false;
  100. this.setOpenedEntityId(null);
  101. }
  102. },
  103. deep: true
  104. }
  105. },
  106. methods: {
  107. ...mapActions(ConcernementsStore,['openCloseConcernements',
  108. 'setOpenedEntityId',
  109. 'setMapMode',
  110. 'resetConcernementOpened']),
  111. openEntity(){
  112. this.setOpenedEntityId(parseInt(this.eid))
  113. this.loadEntite()
  114. },
  115. loadEntite(){
  116. const ast = gql`{
  117. entite (id: ${this.eid}) {
  118. ...EntiteFields
  119. }
  120. }
  121. ${EntiteFields}
  122. `
  123. console.log('ast', ast);
  124. GQL.post('', { query: print(ast) })
  125. .then(({data: { data: { entite }}}) => {
  126. console.log('load entite loaded', entite)
  127. this.entite = entite
  128. })
  129. .catch(error => {
  130. console.warn('Issue with load entite', error)
  131. })
  132. },
  133. closeConcernement(){
  134. this.resetConcernementOpened();
  135. }
  136. },
  137. components: {
  138. TerrainDeVie,
  139. PuissanceAgir,
  140. Doleancer,
  141. SvgIcon
  142. }
  143. }
  144. </script>
  145. <template>
  146. <section v-if="opened_concernement" class="concernement">
  147. <TerrainDeVie v-if="map_mode === 'terraindevie' || map_mode === 'action'|| map_mode === 'superposition'" :cid="cid" :eid="eid" :entite="entite"/>
  148. <PuissanceAgir v-if="map_mode === 'puissancedagir'" :id="cid"/>
  149. <Doleancer v-if="map_mode === 'doleancer'" :id="cid"/>
  150. </section>
  151. <section v-if="map_mode === 'superposition' && superposition" class="concernement clone">
  152. <TerrainDeVie :cid="superposed_cid_eid.cid" :eid="superposed_cid_eid.eid" />
  153. </section>
  154. <nav class="close-concernement" @click="closeConcernement">
  155. <svg class="close-btn" viewbox="0 0 24 24" width="24" height="24" style="--sx: 1; --sy: 1; --r: 0deg;">
  156. <mask id="arrowMask">
  157. <rect x="0" y="0" width="24" height="24" fill="white"/>
  158. <path :d="arrowup_path" fill="black"/>
  159. </mask>
  160. <circle cx="12" cy="12" r="12" mask="url(#arrowMask)" fill="white" />
  161. </svg>
  162. </nav>
  163. </template>
  164. <style lang="scss" scoped>
  165. nav.close-concernement{
  166. position: absolute;
  167. top:65px;
  168. left: -30px;
  169. cursor: pointer;
  170. }
  171. </style>