Thematique.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div class="loading" v-if="!thematique || loading">
  3. <span>{{ $t('default.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_cardfull_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 MGQ from 'vuejs/api/graphql-axios'
  31. import { print } from 'graphql/language/printer'
  32. import gql from 'graphql-tag'
  33. // import materiauFields from 'vuejs/api/gql/materiau.fragment.gql'
  34. import thematiqueFields from 'vuejs/api/gql/thematique.fragment.gql'
  35. // import qs from 'querystring-es3'
  36. import Card from 'vuejs/components/Content/Card'
  37. // import { mapState, mapActions } from 'vuex'
  38. export default {
  39. name: "Thematique",
  40. // router,
  41. store,
  42. data(){
  43. return {
  44. nid:null,
  45. path: null,
  46. thematique:{},
  47. image_accroche: null,
  48. loading:true,
  49. }
  50. },
  51. metaInfo () {
  52. return {
  53. title: this.thematique.title
  54. }
  55. },
  56. // computed: {
  57. // ...mapState({
  58. // items: state => state.Blabla.items
  59. // })
  60. // },
  61. created(){
  62. this.getThematique()
  63. },
  64. methods: {
  65. // ...mapActions({
  66. // getItems: 'Blabla/getItems',
  67. // getItemIndex: 'Blabla/getItemIndex',
  68. // getPrevNextItems: 'Blabla/getPrevNextItems'
  69. // }),
  70. getThematique(){
  71. console.log('getThematique', this.$route)
  72. if (this.$route.params.id) {
  73. // we come from internal link with vuejs
  74. // using path to load from route is hasardous
  75. // this.path = this.$route.path
  76. this.id = this.$route.params.id
  77. } else if (drupalDecoupled.entity_type == 'node' && drupalDecoupled.entity_bundle == 'thematique') {
  78. // we landed in an internal page
  79. // get the id from drupalDeclouped, provided by materio_decoupled.module
  80. this.id = drupalDecoupled.entity_id
  81. }
  82. if (this.id) {
  83. this.loadThematique()
  84. } else {
  85. // if for any reason we dont have the id redirect to home
  86. this.$router.replace({name:'home'})
  87. }
  88. },
  89. loadThematique(){
  90. console.log('loadThematique')
  91. this.loading = true
  92. //
  93. const ast = gql`{
  94. thematique(id: ${this.id}, lang: "${drupalDecoupled.lang_code}") {
  95. ...ThematiqueFields
  96. }
  97. }
  98. ${thematiqueFields}
  99. `
  100. MGQ.post('', { query: print(ast)
  101. })
  102. .then(({ data:{data:{thematique}}}) => {
  103. console.log('loaded Thematique', thematique)
  104. this.parseDataGQL(thematique)
  105. })
  106. .catch(error => {
  107. console.warn('Issue with loadThematique', error)
  108. Promise.reject(error)
  109. })
  110. },
  111. parseDataGQL(thematique){
  112. console.log('parseDataGQL thematique', thematique)
  113. if (thematique) {
  114. this.thematique = thematique
  115. if (thematique.images) {
  116. this.image_accroche = thematique.images[0]
  117. }
  118. // update main page title
  119. this.$store.commit('Common/setPagetitle', thematique.title)
  120. } else {
  121. console.warn('Thematique not loaded');
  122. }
  123. this.loading = false;
  124. },
  125. },
  126. components: {
  127. Card
  128. },
  129. watch: {
  130. '$route' (to, from) {
  131. console.log('route change')
  132. this.getThematique()
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. </style>