Edition.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <MainContentLayout
  3. id="edition"
  4. :reftoscrollto="reftoscrollto"
  5. :navopened="navopened"
  6. @onCenterScrolled="onCenterScrolled"
  7. >
  8. <!-- <transition name="fade" mode="out-in"> -->
  9. <template v-if="!corpusLoaded" #header>
  10. <span class="loading">Loading ...</span>
  11. </template>
  12. <template v-else #header>
  13. <h1>
  14. <router-link :to="{ name:'edition', params: { id: editionid }}">{{ title }}</router-link>
  15. </h1>
  16. <div v-if="author">
  17. <p>{{ author }}</p>
  18. </div>
  19. <div v-if="date">
  20. <p>{{ date }}</p>
  21. </div>
  22. <div v-if="description">
  23. <p v-html="description" />
  24. </div>
  25. <div v-if="biblio" class="biblio">
  26. <p v-html="biblio.description" />
  27. <a
  28. :href="edition_manifestation_href"
  29. @click.prevent="onClickManifestation"
  30. @keyup.enter="onClickManifestation"
  31. >
  32. // todo better label
  33. {{ biblio.uuid }}
  34. </a>
  35. </div>
  36. <!-- displayed on hover entity on texte -->
  37. <aside
  38. v-if="indexitem"
  39. class="index-tooltip"
  40. :style="{ top:tooltip_top + 'px' }"
  41. :data-index="indexitem.index"
  42. :data-uuid="indexitem.uuid"
  43. @click.prevent="onClickTooltip"
  44. @keyup.enter="onClickTooltip"
  45. >
  46. <span v-if="indexitem == 'loading'" class="loading">Loading ...</span>
  47. <template v-if="indexitem !== 'loading'">
  48. <h1 v-html="indexitem.title" />
  49. <p v-if="indexitem.birthDate" class="birthdeath">
  50. <time>{{ indexitem.birthDate }}</time>, <span class="place">{{ indexitem.birthPlace }}</span><br>
  51. <time>{{ indexitem.deathDate }}</time>, <span class="place">{{ indexitem.deathPlace }}</span>
  52. </p>
  53. <p v-if="indexitem.occupation" class="occupation">
  54. {{ indexitem.occupation }}
  55. </p>
  56. <p v-if="indexitem.type" class="type">
  57. {{ indexitem.type }}
  58. </p>
  59. </template>
  60. </aside>
  61. </template>
  62. <!-- </transition> -->
  63. <!-- default slot -->
  64. <div id="text">
  65. <template v-if="texts.length">
  66. <infinite-loading
  67. v-if="flattoc && center_scrolled"
  68. :identifier="inifinite_load_id"
  69. direction="top"
  70. :distance="inifinite_load_distance"
  71. @infinite="prevText"
  72. />
  73. <!-- <transition-group name="edition-texts" tag="div"> -->
  74. <EdText
  75. v-for="text in texts"
  76. :ref="text.content.uuid"
  77. :key="text.content.uuid"
  78. :tei="text.content.tei"
  79. :uuid="text.content.uuid"
  80. :url="text.content.url"
  81. :textid="textid"
  82. :extract="extract"
  83. @onHoverLink="onHoverLink"
  84. @onLeaveLink="onLeaveLink"
  85. />
  86. <!-- </transition-group> -->
  87. <infinite-loading
  88. v-if="flattoc"
  89. :identifier="inifinite_load_id"
  90. @infinite="nextText"
  91. />
  92. </template>
  93. </div>
  94. <template #nav>
  95. <span
  96. class="nav-title"
  97. @click.prevent="onOpenCloseNav"
  98. @keyup.enter="onOpenCloseNav"
  99. >
  100. <svg xmlns="http://www.w3.org/2000/svg" width="14" height="10" role="presentation" class="vs__open-indicator"><path d="M9.211364 7.59931l4.48338-4.867229c.407008-.441854.407008-1.158247 0-1.60046l-.73712-.80023c-.407008-.441854-1.066904-.441854-1.474243 0L7 5.198617 2.51662.33139c-.407008-.441853-1.066904-.441853-1.474243 0l-.737121.80023c-.407008.441854-.407008 1.158248 0 1.600461l4.48338 4.867228L7 10l2.211364-2.40069z" /></svg>
  101. Sommaire
  102. </span>
  103. <EdToc
  104. id="toc"
  105. :toc="toc"
  106. :loadedtextsuuids="textsuuids"
  107. @onClickTocItem="onClickTocItem"
  108. />
  109. <EdPagination
  110. v-if="pagination"
  111. id="page-nav"
  112. :pagination="pagination"
  113. @onClickPaginationItem="onClickPaginationItem"
  114. />
  115. </template>
  116. </MainContentLayout>
  117. </template>
  118. <script>
  119. import qs from 'querystring'
  120. import { REST } from 'api/rest-axios'
  121. import { mapState, mapActions } from 'vuex'
  122. import MainContentLayout from '../components/Layouts/MainContentLayout'
  123. import EdText from '../components/Content/EdText'
  124. import EdToc from '../components/Content/EdToc'
  125. import EdPagination from '../components/Content/EdPagination'
  126. export default {
  127. name: 'Edition',
  128. metaInfo () {
  129. // console.log('metainfo', this.meta)
  130. return {
  131. title: this.metainfotitle
  132. }
  133. },
  134. components: {
  135. MainContentLayout,
  136. EdText,
  137. EdToc,
  138. EdPagination
  139. },
  140. data: () => ({
  141. meta: null,
  142. editionid: null,
  143. textid: null,
  144. extract: null,
  145. texts: [],
  146. textsuuids: [],
  147. metainfotitle: undefined,
  148. title: undefined,
  149. biblio: undefined,
  150. author: undefined,
  151. date: undefined,
  152. description: undefined,
  153. texttitle: undefined,
  154. //
  155. indexitem: null,
  156. tooltip_top: null,
  157. //
  158. next_loaded: false,
  159. center_scrolled: false,
  160. inifinite_load_distance: 10,
  161. inifinite_load_id: +new Date(),
  162. reftoscrollto: null,
  163. //
  164. toc: null,
  165. flattoc: null,
  166. //
  167. pagination: null,
  168. //
  169. navopened: false
  170. }),
  171. computed: {
  172. ...mapState({
  173. corpusLoaded: state => state.Corpus.corpusLoaded,
  174. editionslist: state => state.Corpus.editionslist,
  175. editionsbyuuid: state => state.Corpus.editionsbyuuid
  176. }),
  177. edition_manifestation_href () {
  178. return `${this.biblio.path}${this.biblio.uuid}`
  179. }
  180. },
  181. watch: {
  182. $route (to, from) {
  183. console.log('Edition Watcher $route', from, to)
  184. if (to.params.textid) {
  185. // change textid when route change
  186. this.textid = to.params.textid
  187. // change also extract if exists
  188. if (to.params.extract) {
  189. console.log('extract params from route', to.params.extract)
  190. this.extract = to.params.extract
  191. // scrolling is not working :(
  192. this.reftoscrollto = '#mark-1'
  193. }
  194. } else if (this.toc) {
  195. // if no textid in new route (e.g. edition front)
  196. // but we have toc
  197. // get the first item
  198. // will be replaced by front page of edition
  199. this.textid = this.toc[0].children[1].uuid
  200. } else {
  201. this.textid = null
  202. }
  203. },
  204. reftoscrollto (newref, oldref) {
  205. console.log('reftoscrollto changed', oldref, newref)
  206. },
  207. textid (newid, oldid) {
  208. console.log('textid watcher', this, oldid, newid)
  209. this.texts = []
  210. this.textsuuids = []
  211. this.pages = []
  212. this.pagesOtpions = []
  213. if (newid) {
  214. this.getTextContent(newid)
  215. this.inifinite_load_id += 1
  216. }
  217. },
  218. textdata (newtxtdata, oldtxtdata) {
  219. console.log('textdata watcher', oldtxtdata, newtxtdata)
  220. this.metainfotitle = `${this.title} ${newtxtdata.meta.title}`
  221. },
  222. page_selected (newp, oldp) {
  223. console.log('page_selected watcher', oldp, newp)
  224. this.scrollToPage(newp)
  225. },
  226. flattoc (n, o) {
  227. console.log('flattoc watcher', o, n)
  228. // this.scrollToPage(newp)
  229. }
  230. },
  231. created () {
  232. // console.log('Edition this.$route.params.id', this.$route.params.id)
  233. this.editionid = this.$route.params.id
  234. // get the text if textid available
  235. if (this.$route.params.textid) {
  236. this.textid = this.$route.params.textid
  237. }
  238. // get the searchkeys from route param (only comming from result item) for text highlighting
  239. if (this.$route.params.extract) {
  240. this.extract = this.$route.params.extract
  241. // scrolling is not working :(
  242. this.reftoscrollto = '#mark-1'
  243. }
  244. // wait for editions list from Corpus Store if not already loaded
  245. if (!this.corpusLoaded) {
  246. // this.getCorpuses()
  247. // subsribe to store to get the editionbyuuid list
  248. // https://dev.to/viniciuskneves/watch-for-vuex-state-changes-2mgj
  249. this.edUuuidsUnsubscribe = this.$store.subscribe((mutation, state) => {
  250. // console.log('Edition store subscribe', mutation.type)
  251. if (mutation.type === 'Corpus/setEditionsByUUID') {
  252. // console.log('Edition state.Coprus.editionsbyuuid', this.editionid, state.Corpus.editionsbyuuid)
  253. this.title = this.metainfotitle = state.Corpus.editionsbyuuid[this.editionid].title
  254. this.biblio = state.Corpus.editionsbyuuid[this.editionid].biblio
  255. this.description = state.Corpus.editionsbyuuid[this.editionid].description
  256. this.date = state.Corpus.editionsbyuuid[this.editionid].date
  257. this.author = state.Corpus.editionsbyuuid[this.editionid].author
  258. }
  259. if (mutation.type === 'Corpus/setTocs') {
  260. console.log('Edition Corpus/setTocs', this.editionid, state.Corpus.editionsbyuuid)
  261. this.toc = state.Corpus.editionsbyuuid[this.editionid].toc
  262. }
  263. if (mutation.type === 'Corpus/buildFlatTocs') {
  264. console.log('Edition Corpus/buildFlatTocs', this.editionid, state.Corpus.editionsbyuuid)
  265. this.flattoc = state.Corpus.editionsbyuuid[this.editionid].flattoc
  266. // launch infinitloading
  267. this.inifinite_load_id += 1
  268. // if no textid in new route (e.g. edition front)
  269. // but we have toc
  270. // get the first item
  271. // will be replaced by front page of edition
  272. if (!this.textid) { this.textid = this.flattoc[1] }
  273. }
  274. if (mutation.type === 'Corpus/setPaginations') {
  275. // console.log('Edition state.Coprus.editionsbyuuid', this.editionid, state.Corpus.editionsbyuuid)
  276. this.pagination = state.Corpus.editionsbyuuid[this.editionid].pagination
  277. }
  278. })
  279. } else {
  280. // console.log('');
  281. this.title = this.metainfotitle = this.editionsbyuuid[this.editionid].title
  282. this.biblio = this.editionsbyuuid[this.editionid].biblio
  283. this.description = this.editionsbyuuid[this.editionid].description
  284. this.date = this.editionsbyuuid[this.editionid].date
  285. this.author = this.editionsbyuuid[this.editionid].author
  286. this.toc = this.editionsbyuuid[this.editionid].toc
  287. this.flattoc = this.editionsbyuuid[this.editionid].flattoc
  288. // if no textid in new route (e.g. edition front)
  289. // but we have toc
  290. // get the first item
  291. // will be replaced by front page of edition
  292. if (!this.textid) { this.textid = this.toc[0].children[0].uuid }
  293. this.pagination = this.editionsbyuuid[this.editionid].pagination
  294. }
  295. },
  296. methods: {
  297. ...mapActions({
  298. getCorpuses: 'Corpus/getCorpuses'
  299. }),
  300. getTextContent (textid, $state = null, direction = 'next') {
  301. console.log('getTextContent', textid)
  302. let params = {
  303. depth: 0
  304. }
  305. let q = qs.stringify(params)
  306. REST.get(`${window.apipath}/items/${textid}?${q}`, {})
  307. .then(({ data }) => {
  308. console.log('text REST: data', data)
  309. if (direction === 'next') {
  310. this.texts.push(data)
  311. this.textsuuids.push(data.content.uuid)
  312. } else {
  313. this.texts.unshift(data)
  314. this.textsuuids.unshift(data.content.uuid)
  315. }
  316. if ($state) {
  317. $state.loaded()
  318. this.next_loaded = true
  319. }
  320. })
  321. .catch((error) => {
  322. console.warn('Issue with getTextContent', error)
  323. Promise.reject(error)
  324. // if some item don't load and if we come from infinite loading
  325. // retry with next step
  326. if ($state) {
  327. switch (direction) {
  328. case 'next':
  329. this.nextText($state, 2)
  330. break
  331. case 'prev':
  332. this.prevText($state, 2)
  333. break
  334. }
  335. }
  336. // this.$router.replace({
  337. // name: 'notfound',
  338. // query: { fullpath: this.$route.path }
  339. // })
  340. })
  341. },
  342. onCenterScrolled (e) {
  343. console.log('Edition centerScrolled(e)', e.target.scrollTop)
  344. if (!this.center_scrolled && e.target.scrollTop > this.inifinite_load_distance * 1.5) {
  345. this.center_scrolled = true
  346. }
  347. this.indexitem = null
  348. },
  349. nextText ($state, indent = 1) {
  350. console.log('infinite loading nextText()')
  351. let indexofnext = this.flattoc.indexOf(this.textsuuids[this.textsuuids.length - 1]) + indent
  352. if (indexofnext < this.flattoc.length) {
  353. this.getTextContent(this.flattoc[indexofnext], $state, 'next')
  354. } else {
  355. $state.complete()
  356. }
  357. },
  358. prevText ($state, indent = 1) {
  359. console.log('infinite loading prevText()')
  360. let indexofprev = this.flattoc.indexOf(this.textsuuids[0]) - indent
  361. if (indexofprev >= 0) {
  362. this.getTextContent(this.flattoc[indexofprev], $state, 'prev')
  363. } else {
  364. $state.complete()
  365. }
  366. },
  367. onHoverLink (elmt) {
  368. console.log('Edition onHoverLink(elmt)', elmt)
  369. this.tooltip_top = elmt.rect.top
  370. this.getIndexItem(elmt)
  371. },
  372. onLeaveLink () {
  373. console.log('Edition onLeaveLink()')
  374. this.indexitem = null
  375. },
  376. getIndexItem (item) {
  377. this.indexitem = 'loading'
  378. REST.get(`${window.apipath}/index${item.index.charAt(0).toUpperCase()}${item.index.slice(1)}/${item.uuid}`, {})
  379. .then(({ data }) => {
  380. console.log('index tooltip REST: data', data)
  381. if (this.indexitem === 'loading') {
  382. this.indexitem = data.content
  383. this.indexitem.index = item.index
  384. }
  385. })
  386. .catch((error) => {
  387. console.warn('Issue with index tooltip rest', error)
  388. Promise.reject(error)
  389. this.indexitem = null
  390. })
  391. },
  392. onClickTocItem (uuid) {
  393. console.log('Edition onClickTocItem', uuid, this.$refs)
  394. if (this.textsuuids.indexOf(uuid) !== -1) {
  395. // if already loaded, scroll to uuid
  396. this.reftoscrollto = `.tei[data-uuid="${uuid}"]`
  397. } else {
  398. // if not already loaded, change route
  399. this.$router.push({
  400. name: `editiontext`,
  401. params: {
  402. id: this.editionid,
  403. textid: uuid
  404. }
  405. })
  406. }
  407. },
  408. onClickPaginationItem (o) {
  409. console.log('onClickPaginationItem', o)
  410. if (this.textsuuids.indexOf(o.uuid) !== -1) {
  411. // if already loaded, scroll to uuid
  412. // this.scrollToPage(o)
  413. this.reftoscrollto = `span[role="pageBreak"][id="${o.code}"]`
  414. } else {
  415. // if not already loaded, change route
  416. this.$router.push({
  417. name: `editiontext`,
  418. params: {
  419. id: this.editionid,
  420. textid: o.uuid
  421. }
  422. })
  423. }
  424. },
  425. // scrollToPage (p) {
  426. // console.log('scrollToPage', p)
  427. //
  428. // },
  429. onOpenCloseNav (e) {
  430. console.log('onOpenCloseNav', e)
  431. this.navopened = !this.navopened
  432. },
  433. onClickTooltip (e) {
  434. console.log(`onClickTooltip index: ${e.target.dataset.index}, uuid: ${e.target.dataset.uuid}`)
  435. this.$router.push({
  436. name: e.target.dataset.index,
  437. params: { id: e.target.dataset.uuid }
  438. })
  439. },
  440. onClickManifestation (e) {
  441. console.log(`onClickManifestation`)
  442. this.$router.push({
  443. name: 'bibliographieItem',
  444. params: { type: 'manifestations', uuid: this.biblio.uuid }
  445. })
  446. }
  447. }
  448. }
  449. </script>
  450. <style lang="scss" scoped>
  451. </style>