Thematique.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="loading" v-if="!thematique || loading">
  3. <span>Loading ...</span>
  4. </div>
  5. <article class="thematique" v-else>
  6. <div class="cols">
  7. <div class="col col-left">
  8. <section class="body" v-html="thematique.body"></section>
  9. <section class="visuel">
  10. <img :src="image_accroche.style_cardmedium.url" alt="">
  11. </section>
  12. </div> <!-- //col-left -->
  13. <div class="col col-right">
  14. <aside class="linked-materials">
  15. <div class="card-list">
  16. <ul class="">
  17. <li v-for="node in thematique.linked_materials" v-bind:key="node.id">
  18. <Card :item="node" />
  19. </li>
  20. </ul>
  21. </div>
  22. </aside>
  23. </div> <!-- // col-right -->
  24. </div> <!-- // cols -->
  25. </article>
  26. </template>
  27. <script>
  28. import router from 'vuejs/route'
  29. import store from 'vuejs/store'
  30. // import { JSONAPI } from 'vuejs/api/json-axios'
  31. import { REST } from 'vuejs/api/rest-axios'
  32. import { MGQ } from 'vuejs/api/graphql-axios'
  33. import { print } from 'graphql/language/printer'
  34. import gql from 'graphql-tag'
  35. // import materiauFields from 'vuejs/api/gql/materiau.fragment.gql'
  36. import thematiqueFields from 'vuejs/api/gql/thematique.fragment.gql'
  37. // import qs from 'querystring-es3'
  38. import Card from 'vuejs/components/Content/Card'
  39. import { mapState, mapActions } from 'vuex'
  40. export default {
  41. name: "Thematique",
  42. router,
  43. store,
  44. data(){
  45. return {
  46. nid:null,
  47. path: null,
  48. thematique:{},
  49. image_accroche: null,
  50. loading:true,
  51. }
  52. },
  53. metaInfo () {
  54. return {
  55. title: this.thematique.title
  56. }
  57. },
  58. // computed: {
  59. // ...mapState({
  60. // items: state => state.Blabla.items
  61. // })
  62. // },
  63. created(){
  64. this.getThematique()
  65. },
  66. methods: {
  67. // ...mapActions({
  68. // getItems: 'Blabla/getItems',
  69. // getItemIndex: 'Blabla/getItemIndex',
  70. // getPrevNextItems: 'Blabla/getPrevNextItems'
  71. // }),
  72. getThematique(){
  73. console.log('getThematique', this.$route);
  74. // get the article uuid
  75. // if(this.$route.query.nid){
  76. // // we come from internal link with vuejs
  77. // // directly record uuid
  78. // this.nid = this.$route.query.nid
  79. //
  80. // }else if(drupalDecoupled.entity_type == 'node' && drupalDecoupled.entity_bundle == 'article'){
  81. // // we landed in an internal page
  82. // // get the uuid from drupalDeclouped, provided by materio_decoupled.module
  83. // this.nid = drupalDecoupled.entity_id
  84. // }
  85. if (this.$route.path) {
  86. // we come from internal link with vuejs
  87. this.path = this.$route.path
  88. } else {
  89. // we landed in an internal page
  90. this.path = window.location.pathname
  91. }
  92. if(this.path){
  93. this.loadThematique()
  94. }else{
  95. // if for any reason we dont have the uuid
  96. // redirect to home
  97. this.$route.replace('home')
  98. }
  99. },
  100. loadThematique(){
  101. console.log('loadThematique')
  102. this.loading = true
  103. let ast = gql`{
  104. route(path: "${this.path}", lang: "${drupalDecoupled.lang_code}") {
  105. ...ThematiqueFields
  106. }
  107. }
  108. ${ thematiqueFields }
  109. `
  110. MGQ.post('', { query: print(ast)
  111. })
  112. .then(({ data:{data:{route}}}) => {
  113. console.log('loaded Thematique', route)
  114. this.parseDataGQL(route)
  115. })
  116. .catch(error => {
  117. console.warn('Issue with loadThematique', error)
  118. Promise.reject(error)
  119. })
  120. },
  121. parseDataGQL(thematique){
  122. console.log('parseDataGQL thematique', thematique)
  123. if (thematique) {
  124. this.thematique = thematique
  125. if (thematique.images) {
  126. this.image_accroche = thematique.images[0]
  127. }
  128. // update main page title
  129. this.$store.commit('Common/setPagetitle', thematique.title)
  130. }else{
  131. console.warn('Thematique not loaded');
  132. }
  133. this.loading = false;
  134. },
  135. },
  136. components: {
  137. Card
  138. },
  139. watch: {
  140. '$route' (to, from) {
  141. console.log('route change')
  142. this.getThematique()
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. </style>