Edition.vue 3.0 KB

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