EditionToc.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <MainContentLayout id="edition-toc">
  3. <template v-if="!content" v-slot:header>
  4. <span>Loading ...</span>
  5. </template>
  6. <template v-if="meta" v-slot:header>
  7. <h1>{{ meta.title }}</h1>
  8. <section>
  9. <ul>
  10. <li
  11. v-for="item in content"
  12. :key="item.uuid"
  13. >
  14. <TocItem :item="item" :level="1" :editionid="$route.params.id" />
  15. </li>
  16. </ul>
  17. </section>
  18. </template>
  19. <EdText v-if="textdata" :textdata="textdata" />
  20. <template v-slot:nav />
  21. </MainContentLayout>
  22. </template>
  23. <script>
  24. import { REST } from 'api/rest-axios'
  25. import MainContentLayout from '../components/Layouts/MainContentLayout'
  26. import TocItem from '../components/Content/TocItem'
  27. import EdText from '../components/Content/EdText'
  28. export default {
  29. name: 'EditionToc',
  30. components: {
  31. MainContentLayout,
  32. TocItem,
  33. EdText
  34. },
  35. data: () => ({
  36. content: null,
  37. meta: null,
  38. editionid: null,
  39. textid: null,
  40. textdata: null
  41. }),
  42. watch: {
  43. textid: function (newid, oldid) {
  44. // console.log('textid watcher', this, newid, oldid)
  45. this.getTextContent()
  46. }
  47. },
  48. beforeCreate () {
  49. console.log('texts this.$route', this.$route)
  50. // http://localhost:8984/texts/gdpSauval1724/toc
  51. this.editionid = this.$route.params.id
  52. // get the edition's toc
  53. REST.get(`/texts/` + this.$route.params.id + `/toc`, {})
  54. .then(({ data }) => {
  55. console.log('texts/toc REST: data', data)
  56. this.meta = data.meta
  57. if (data.content) {
  58. if (Array.isArray(data.content)) {
  59. this.content = data.content
  60. } else {
  61. this.content = [data.content]
  62. }
  63. }
  64. })
  65. .catch((error) => {
  66. console.warn('Issue with locorum', error)
  67. Promise.reject(error)
  68. })
  69. },
  70. created () {
  71. // get the text if textid available
  72. if (this.$route.params.textid) {
  73. this.textid = this.$route.params.textid
  74. // this.getTextContent()
  75. }
  76. },
  77. beforeRouteUpdate (to, from, next) {
  78. // called when the route that renders this component has changed,
  79. // but this component is reused in the new route.
  80. // For example, for a route with dynamic params `/foo/:id`, when we
  81. // navigate between `/foo/1` and `/foo/2`, the same `Foo` component instance
  82. // will be reused, and this hook will be called when that happens.
  83. // has access to `this` component instance.
  84. // console.log('beforeRouteUpdate to', to)
  85. if (to.params.textid) {
  86. this.textid = to.params.textid
  87. }
  88. next()
  89. },
  90. methods: {
  91. getTextContent () {
  92. console.log('getTextContent', this.textid)
  93. if (this.textid) {
  94. REST.get(`/items/` + this.textid, {})
  95. .then(({ data }) => {
  96. console.log('text REST: data', data)
  97. this.textdata = data
  98. })
  99. .catch((error) => {
  100. console.warn('Issue with getTextContent', error)
  101. Promise.reject(error)
  102. })
  103. }
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. </style>