Edition.vue 3.0 KB

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