Concernement.vue 6.0 KB

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