Thematique.vue 3.8 KB

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