Edition.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. :extractid="extractid"
  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. this.extractid = null
  189. if (to.params.extract) {
  190. console.log('extract params from route', to.params.extract)
  191. this.extractid = to.params.ocid
  192. // scrolling is not working :(
  193. this.reftoscrollto = '#mark-1'
  194. }
  195. } else if (this.toc) {
  196. // if no textid in new route (e.g. edition front)
  197. // but we have toc
  198. // get the first item
  199. // will be replaced by front page of edition
  200. this.textid = this.toc[0].children[1].uuid
  201. } else {
  202. this.textid = null
  203. }
  204. },
  205. reftoscrollto (newref, oldref) {
  206. console.log('reftoscrollto changed', oldref, newref)
  207. },
  208. textid (newid, oldid) {
  209. console.log('textid watcher', this, oldid, newid)
  210. this.texts = []
  211. this.textsuuids = []
  212. this.pages = []
  213. this.pagesOtpions = []
  214. if (newid) {
  215. this.getTextContent(newid)
  216. this.inifinite_load_id += 1
  217. }
  218. },
  219. textdata (newtxtdata, oldtxtdata) {
  220. console.log('textdata watcher', oldtxtdata, newtxtdata)
  221. this.metainfotitle = `${this.title} ${newtxtdata.meta.title}`
  222. },
  223. page_selected (newp, oldp) {
  224. console.log('page_selected watcher', oldp, newp)
  225. this.scrollToPage(newp)
  226. },
  227. flattoc (n, o) {
  228. console.log('flattoc watcher', o, n)
  229. // this.scrollToPage(newp)
  230. }
  231. },
  232. created () {
  233. // console.log('Edition this.$route.params.id', this.$route.params.id)
  234. this.editionid = this.$route.params.id
  235. // get the text if textid available
  236. if (this.$route.params.textid) {
  237. this.textid = this.$route.params.textid
  238. }
  239. // get the searchkeys from route param (only comming from result item) for text highlighting
  240. if (this.$route.params.ocid) {
  241. this.extractid = this.$route.params.ocid
  242. // scrolling is not working :(
  243. this.reftoscrollto = '#mark-1'
  244. }
  245. // wait for editions list from Corpus Store if not already loaded
  246. if (!this.corpusLoaded) {
  247. // this.getCorpuses()
  248. // subsribe to store to get the editionbyuuid list
  249. // https://dev.to/viniciuskneves/watch-for-vuex-state-changes-2mgj
  250. this.edUuuidsUnsubscribe = this.$store.subscribe((mutation, state) => {
  251. // console.log('Edition store subscribe', mutation.type)
  252. if (mutation.type === 'Corpus/setEditionsByUUID') {
  253. // console.log('Edition state.Coprus.editionsbyuuid', this.editionid, state.Corpus.editionsbyuuid)
  254. this.title = this.metainfotitle = state.Corpus.editionsbyuuid[this.editionid].title
  255. this.biblio = state.Corpus.editionsbyuuid[this.editionid].biblio
  256. this.description = state.Corpus.editionsbyuuid[this.editionid].description
  257. this.date = state.Corpus.editionsbyuuid[this.editionid].date
  258. this.author = state.Corpus.editionsbyuuid[this.editionid].author
  259. }
  260. if (mutation.type === 'Corpus/setTocs') {
  261. console.log('Edition Corpus/setTocs', this.editionid, state.Corpus.editionsbyuuid)
  262. this.toc = state.Corpus.editionsbyuuid[this.editionid].toc
  263. }
  264. if (mutation.type === 'Corpus/buildFlatTocs') {
  265. console.log('Edition Corpus/buildFlatTocs', this.editionid, state.Corpus.editionsbyuuid)
  266. this.flattoc = state.Corpus.editionsbyuuid[this.editionid].flattoc
  267. // launch infinitloading
  268. this.inifinite_load_id += 1
  269. // if no textid in new route (e.g. edition front)
  270. // but we have toc
  271. // get the first item
  272. // will be replaced by front page of edition
  273. if (!this.textid) { this.textid = this.flattoc[1] }
  274. }
  275. if (mutation.type === 'Corpus/setPaginations') {
  276. // console.log('Edition state.Coprus.editionsbyuuid', this.editionid, state.Corpus.editionsbyuuid)
  277. this.pagination = state.Corpus.editionsbyuuid[this.editionid].pagination
  278. }
  279. })
  280. } else {
  281. // console.log('');
  282. this.title = this.metainfotitle = this.editionsbyuuid[this.editionid].title
  283. this.biblio = this.editionsbyuuid[this.editionid].biblio
  284. this.description = this.editionsbyuuid[this.editionid].description
  285. this.date = this.editionsbyuuid[this.editionid].date
  286. this.author = this.editionsbyuuid[this.editionid].author
  287. this.toc = this.editionsbyuuid[this.editionid].toc
  288. this.flattoc = this.editionsbyuuid[this.editionid].flattoc
  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.toc[0].children[0].uuid }
  294. this.pagination = this.editionsbyuuid[this.editionid].pagination
  295. }
  296. },
  297. methods: {
  298. ...mapActions({
  299. getCorpuses: 'Corpus/getCorpuses'
  300. }),
  301. getTextContent (textid, $state = null, direction = 'next') {
  302. console.log('getTextContent', textid)
  303. let params = {
  304. depth: 0
  305. }
  306. let q = qs.stringify(params)
  307. REST.get(`${window.apipath}/items/${textid}?${q}`, {})
  308. .then(({ data }) => {
  309. console.log('text REST: data', data)
  310. if (direction === 'next') {
  311. this.texts.push(data)
  312. this.textsuuids.push(data.content.uuid)
  313. } else {
  314. this.texts.unshift(data)
  315. this.textsuuids.unshift(data.content.uuid)
  316. }
  317. if ($state) {
  318. $state.loaded()
  319. this.next_loaded = true
  320. }
  321. })
  322. .catch((error) => {
  323. console.warn('Issue with getTextContent', error)
  324. Promise.reject(error)
  325. // if some item don't load and if we come from infinite loading
  326. // retry with next step
  327. if ($state) {
  328. switch (direction) {
  329. case 'next':
  330. this.nextText($state, 2)
  331. break
  332. case 'prev':
  333. this.prevText($state, 2)
  334. break
  335. }
  336. }
  337. // this.$router.replace({
  338. // name: 'notfound',
  339. // query: { fullpath: this.$route.path }
  340. // })
  341. })
  342. },
  343. onCenterScrolled (e) {
  344. console.log('Edition centerScrolled(e)', e.target.scrollTop)
  345. if (!this.center_scrolled && e.target.scrollTop > this.inifinite_load_distance * 1.5) {
  346. this.center_scrolled = true
  347. // this.$store.commit('History/setOpened', false)
  348. }
  349. this.indexitem = null
  350. },
  351. nextText ($state, indent = 1) {
  352. console.log('infinite loading nextText()')
  353. let indexofnext = this.flattoc.indexOf(this.textsuuids[this.textsuuids.length - 1]) + indent
  354. if (indexofnext < this.flattoc.length) {
  355. this.getTextContent(this.flattoc[indexofnext], $state, 'next')
  356. } else {
  357. $state.complete()
  358. }
  359. },
  360. prevText ($state, indent = 1) {
  361. console.log('infinite loading prevText()')
  362. let indexofprev = this.flattoc.indexOf(this.textsuuids[0]) - indent
  363. if (indexofprev >= 0) {
  364. this.getTextContent(this.flattoc[indexofprev], $state, 'prev')
  365. } else {
  366. $state.complete()
  367. }
  368. },
  369. onHoverLink (elmt) {
  370. console.log('Edition onHoverLink(elmt)', elmt)
  371. this.tooltip_top = elmt.rect.top
  372. this.getIndexItem(elmt)
  373. },
  374. onLeaveLink () {
  375. console.log('Edition onLeaveLink()')
  376. this.indexitem = null
  377. },
  378. getIndexItem (item) {
  379. this.indexitem = 'loading'
  380. REST.get(`${window.apipath}/index${item.index.charAt(0).toUpperCase()}${item.index.slice(1)}/${item.uuid}`, {})
  381. .then(({ data }) => {
  382. console.log('index tooltip REST: data', data)
  383. if (this.indexitem === 'loading') {
  384. this.indexitem = data.content
  385. this.indexitem.index = item.index
  386. }
  387. })
  388. .catch((error) => {
  389. console.warn('Issue with index tooltip rest', error)
  390. Promise.reject(error)
  391. this.indexitem = null
  392. })
  393. },
  394. onClickTocItem (uuid) {
  395. console.log('Edition onClickTocItem', uuid, this.$refs)
  396. if (this.textsuuids.indexOf(uuid) !== -1) {
  397. // if already loaded, scroll to uuid
  398. this.reftoscrollto = `.tei[data-uuid="${uuid}"]`
  399. } else {
  400. // if not already loaded, change route
  401. this.$router.push({
  402. name: `editiontext`,
  403. params: {
  404. id: this.editionid,
  405. textid: uuid
  406. }
  407. })
  408. }
  409. },
  410. onClickPaginationItem (o) {
  411. console.log('onClickPaginationItem', o)
  412. if (this.textsuuids.indexOf(o.uuid) !== -1) {
  413. // if already loaded, scroll to uuid
  414. // this.scrollToPage(o)
  415. this.reftoscrollto = `span[role="pageBreak"][id="${o.code}"]`
  416. } else {
  417. // if not already loaded, change route
  418. this.$router.push({
  419. name: `editiontext`,
  420. params: {
  421. id: this.editionid,
  422. textid: o.uuid
  423. }
  424. })
  425. }
  426. },
  427. // scrollToPage (p) {
  428. // console.log('scrollToPage', p)
  429. //
  430. // },
  431. onOpenCloseNav (e) {
  432. console.log('onOpenCloseNav', e)
  433. this.navopened = !this.navopened
  434. },
  435. onClickTooltip (e) {
  436. console.log(`onClickTooltip index: ${e.target.dataset.index}, uuid: ${e.target.dataset.uuid}`)
  437. this.$router.push({
  438. name: e.target.dataset.index,
  439. params: { id: e.target.dataset.uuid }
  440. })
  441. },
  442. onClickManifestation (e) {
  443. console.log(`onClickManifestation`)
  444. this.$router.push({
  445. name: 'bibliographieItem',
  446. params: { type: 'manifestations', uuid: this.biblio.uuid }
  447. })
  448. }
  449. }
  450. }
  451. </script>
  452. <style lang="scss" scoped>
  453. </style>