Edition.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <MainContentLayout id="edition">
  3. <template v-if="!content" #header>
  4. <span>Loading ...</span>
  5. </template>
  6. <template #header>
  7. <h1>{{ title }}</h1>
  8. <p v-if="meta">{{ meta.author }}</p>
  9. <aside
  10. v-if="indexitem"
  11. class="index-tooltip"
  12. :style="{ top:tooltip_top + 'px' }"
  13. >
  14. <span v-if="indexitem == 'loading'">Loading ...</span>
  15. <template v-if="indexitem !== 'loading'">
  16. <h1 v-html="indexitem.title" />
  17. <p v-if="indexitem.birthDate" class="birthdeath">
  18. <time>{{ indexitem.birthDate }}</time>, <span class="place">{{ indexitem.birthPlace }}</span><br>
  19. <time>{{ indexitem.deathDate }}</time>, <span class="place">{{ indexitem.deathPlace }}</span>
  20. </p>
  21. <p v-if="indexitem.occupation" class="occupation">
  22. {{ indexitem.occupation }}
  23. </p>
  24. <p v-if="indexitem.type" class="type">
  25. {{ indexitem.type }}
  26. </p>
  27. </template>
  28. </aside>
  29. </template>
  30. <!-- default slot -->
  31. <div id="text">
  32. <EdText
  33. v-if="textdata"
  34. :tei="textdata.content.tei"
  35. @onHoverLink="onHoverLink"
  36. @onLeaveLink="onLeaveLink"
  37. />
  38. </div>
  39. <template #nav>
  40. <EdToc :toc="toc" />
  41. </template>
  42. </MainContentLayout>
  43. </template>
  44. <script>
  45. import { REST } from 'api/rest-axios'
  46. import { mapState, mapActions } from 'vuex'
  47. import MainContentLayout from '../components/Layouts/MainContentLayout'
  48. import EdText from '../components/Content/EdText'
  49. import EdToc from '../components/Content/EdToc'
  50. export default {
  51. name: 'Edition',
  52. metaInfo () {
  53. // console.log('metainfo', this.meta)
  54. return {
  55. title: this.metainfotitle
  56. }
  57. },
  58. components: {
  59. MainContentLayout,
  60. EdText,
  61. EdToc
  62. },
  63. data: () => ({
  64. toc: null,
  65. meta: null,
  66. editionid: null,
  67. textid: null,
  68. textdata: null,
  69. metainfotitle: undefined,
  70. title: undefined,
  71. author: undefined,
  72. texttitle: undefined,
  73. //
  74. indexitem: null,
  75. tooltip_top: null
  76. }),
  77. computed: {
  78. ...mapState({
  79. editionslist: state => state.Corpus.editionslist,
  80. editionsbyuuid: state => state.Corpus.editionsbyuuid
  81. })
  82. },
  83. watch: {
  84. textid: function (newid, oldid) {
  85. console.log('textid watcher', this, oldid, newid)
  86. this.getTextContent()
  87. },
  88. textdata: function (newtxtdata, oldtxtdata) {
  89. console.log('textdata watcher', oldtxtdata, newtxtdata)
  90. this.metainfotitle = `${this.title} ${newtxtdata.meta.title}`
  91. }
  92. },
  93. beforeCreate () {
  94. console.log('texts this.$route', this.$route)
  95. // http://localhost:8984/texts/gdpSauval1724/toc
  96. // get the edition's toc
  97. REST.get(`/texts/` + this.$route.params.id + `/toc`, {})
  98. .then(({ data }) => {
  99. console.log('texts/toc REST: data', data)
  100. this.meta = data.meta
  101. this.author = data.meta.author
  102. if (data.content) {
  103. if (Array.isArray(data.content)) {
  104. this.toc = data.content
  105. } else {
  106. this.toc = [data.content]
  107. }
  108. // if front page get the first item in toc
  109. if (!this.$route.params.textid) {
  110. // console.log('toc', this.toc)
  111. this.textid = this.toc[0].children[1].uuid
  112. }
  113. }
  114. })
  115. .catch((error) => {
  116. console.warn('Issue with locorum', error)
  117. Promise.reject(error)
  118. })
  119. },
  120. created () {
  121. // console.log('Edition this.$route.params.id', this.$route.params.id)
  122. this.editionid = this.$route.params.id
  123. // load editions list from Corpus Store if not exist
  124. if (!this.editionslist.length) {
  125. this.getCorpuses()
  126. // subsribe to store to get the editionbyuuid list
  127. // https://dev.to/viniciuskneves/watch-for-vuex-state-changes-2mgj
  128. this.unsubscribe = this.$store.subscribe((mutation, state) => {
  129. // console.log('Edition store subscribe', mutation.type)
  130. if (mutation.type === 'Corpus/setEditionsByUUID') {
  131. console.log('Edition state.Coprus.editionsbyuuid', this.editionid, state.Corpus.editionsbyuuid)
  132. // this.title = 'HoHoHo'
  133. this.title = this.metainfotitle = state.Corpus.editionsbyuuid[this.editionid].title
  134. }
  135. })
  136. } else {
  137. this.title = this.metainfotitle = this.editionsbyuuid[this.editionid].title
  138. }
  139. // get the text if textid available
  140. if (this.$route.params.textid) {
  141. this.textid = this.$route.params.textid
  142. }
  143. },
  144. beforeRouteUpdate (to, from, next) {
  145. // called when the route that renders this component has changed,
  146. // but this component is reused in the new route.
  147. // For example, for a route with dynamic params `/foo/:id`, when we
  148. // navigate between `/foo/1` and `/foo/2`, the same `Foo` component instance
  149. // will be reused, and this hook will be called when that happens.
  150. // has access to `this` component instance.
  151. // console.log('beforeRouteUpdate to', to)
  152. if (to.params.textid) {
  153. this.textid = to.params.textid
  154. }
  155. next()
  156. },
  157. methods: {
  158. ...mapActions({
  159. getCorpuses: 'Corpus/getCorpuses'
  160. }),
  161. getTextContent () {
  162. console.log('getTextContent', this.textid)
  163. if (this.textid) {
  164. REST.get(`/items/` + this.textid, {})
  165. .then(({ data }) => {
  166. console.log('text REST: data', data)
  167. this.textdata = data
  168. })
  169. .catch((error) => {
  170. console.warn('Issue with getTextContent', error)
  171. Promise.reject(error)
  172. })
  173. }
  174. },
  175. onHoverLink (elmt) {
  176. console.log('Edition onHoverLink(elmt)', elmt)
  177. this.tooltip_top = elmt.rect.top
  178. this.getIndexItem(elmt)
  179. },
  180. onLeaveLink () {
  181. console.log('Edition onLeaveLink()')
  182. this.indexitem = null
  183. },
  184. getIndexItem (item) {
  185. this.indexitem = 'loading'
  186. REST.get(`/index${item.index.charAt(0).toUpperCase()}${item.index.slice(1)}/${item.uuid}`, {})
  187. .then(({ data }) => {
  188. console.log('index tooltip REST: data', data)
  189. this.indexitem = data.content
  190. })
  191. .catch((error) => {
  192. console.warn('Issue with index tooltip rest', error)
  193. Promise.reject(error)
  194. this.indexitem = null
  195. })
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. </style>