Edition.vue 17 KB

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