Edition.vue 17 KB

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