Edition.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. <EdIndexes
  110. v-if="indexes"
  111. id="indexes-filters"
  112. :indexes="indexes"
  113. />
  114. <EdPagination
  115. v-if="pagination"
  116. id="page-nav"
  117. :pagination="pagination"
  118. @onClickPaginationItem="onClickPaginationItem"
  119. />
  120. </template>
  121. </MainContentLayout>
  122. </template>
  123. <script>
  124. import qs from 'querystring'
  125. import { REST } from 'api/rest-axios'
  126. import { mapState, mapActions } from 'vuex'
  127. import MainContentLayout from '../components/Layouts/MainContentLayout'
  128. import EdText from '../components/Content/EdText'
  129. import EdToc from '../components/Content/EdToc'
  130. import EdIndexes from '../components/Content/EdIndexes'
  131. import EdPagination from '../components/Content/EdPagination'
  132. export default {
  133. name: 'Edition',
  134. metaInfo () {
  135. // console.log('metainfo', this.meta)
  136. return {
  137. title: this.metainfotitle
  138. }
  139. },
  140. components: {
  141. MainContentLayout,
  142. EdText,
  143. EdToc,
  144. EdIndexes,
  145. EdPagination
  146. },
  147. data: () => ({
  148. meta: null,
  149. editionid: null,
  150. textid: null,
  151. extract: null,
  152. extractid: null,
  153. texts: [],
  154. textsuuids: [],
  155. metainfotitle: undefined,
  156. title: undefined,
  157. biblio: undefined,
  158. author: undefined,
  159. date: undefined,
  160. description: undefined,
  161. texttitle: undefined,
  162. //
  163. indexitem: null,
  164. tooltip_top: null,
  165. //
  166. next_loaded: false,
  167. center_scrolled: false,
  168. inifinite_load_distance: 10,
  169. inifinite_load_id: +new Date(),
  170. reftoscrollto: null,
  171. //
  172. toc: null,
  173. flattoc: null,
  174. //
  175. indexes: null,
  176. //
  177. pagination: null,
  178. //
  179. navopened: false
  180. }),
  181. computed: {
  182. ...mapState({
  183. corpusLoaded: state => state.Corpus.corpusLoaded,
  184. editionslist: state => state.Corpus.editionslist,
  185. editionsbyuuid: state => state.Corpus.editionsbyuuid
  186. }),
  187. edition_manifestation_href () {
  188. return `${this.biblio.path}${this.biblio.uuid}`
  189. }
  190. },
  191. watch: {
  192. $route (to, from) {
  193. console.log('Edition Watcher $route', from, to)
  194. if (to.params.textid) {
  195. // change textid when route change
  196. this.textid = to.params.textid
  197. // change also extract if exists
  198. this.extractid = null
  199. if (to.params.extract) {
  200. console.log('extract params from route', to.params.extract)
  201. this.extractid = to.params.ocid
  202. // scrolling is not working :(
  203. this.reftoscrollto = '#mark-1'
  204. }
  205. } else if (this.toc) {
  206. // if no textid in new route (e.g. edition front)
  207. // but we have toc
  208. // get the first item
  209. // will be replaced by front page of edition
  210. this.textid = this.toc[0].children[1].uuid
  211. } else {
  212. this.textid = null
  213. }
  214. },
  215. reftoscrollto (newref, oldref) {
  216. console.log('reftoscrollto changed', oldref, newref)
  217. },
  218. textid (newid, oldid) {
  219. console.log('textid watcher', this, oldid, newid)
  220. this.texts = []
  221. this.textsuuids = []
  222. this.pages = []
  223. this.pagesOtpions = []
  224. if (newid) {
  225. this.getTextContent(newid)
  226. this.inifinite_load_id += 1
  227. }
  228. },
  229. textdata (newtxtdata, oldtxtdata) {
  230. console.log('textdata watcher', oldtxtdata, newtxtdata)
  231. this.metainfotitle = `${this.title} ${newtxtdata.meta.title}`
  232. },
  233. page_selected (newp, oldp) {
  234. console.log('page_selected watcher', oldp, newp)
  235. this.scrollToPage(newp)
  236. },
  237. flattoc (n, o) {
  238. console.log('flattoc watcher', o, n)
  239. // this.scrollToPage(newp)
  240. }
  241. },
  242. created () {
  243. // console.log('Edition this.$route.params.id', this.$route.params.id)
  244. this.editionid = this.$route.params.id
  245. // get the text if textid available
  246. if (this.$route.params.textid) {
  247. this.textid = this.$route.params.textid
  248. }
  249. // get the searchkeys from route param (only comming from result item) for text highlighting
  250. if (this.$route.params.ocid) {
  251. this.extractid = this.$route.params.ocid
  252. // scrolling is not working :(
  253. this.reftoscrollto = '#mark-1'
  254. }
  255. // wait for editions list from Corpus Store if not already loaded
  256. if (!this.corpusLoaded) {
  257. // this.getCorpuses()
  258. // subsribe to store to get the editionbyuuid list
  259. // https://dev.to/viniciuskneves/watch-for-vuex-state-changes-2mgj
  260. this.edUuuidsUnsubscribe = this.$store.subscribe((mutation, state) => {
  261. // console.log('Edition store subscribe', mutation.type)
  262. if (mutation.type === 'Corpus/setEditionsByUUID') {
  263. // console.log('Edition state.Coprus.editionsbyuuid', this.editionid, state.Corpus.editionsbyuuid)
  264. this.title = this.metainfotitle = state.Corpus.editionsbyuuid[this.editionid].title
  265. this.biblio = state.Corpus.editionsbyuuid[this.editionid].biblio
  266. this.description = state.Corpus.editionsbyuuid[this.editionid].description
  267. this.date = state.Corpus.editionsbyuuid[this.editionid].date
  268. this.author = state.Corpus.editionsbyuuid[this.editionid].author
  269. }
  270. if (mutation.type === 'Corpus/setTocs') {
  271. console.log('Edition Corpus/setTocs', this.editionid, state.Corpus.editionsbyuuid)
  272. this.toc = state.Corpus.editionsbyuuid[this.editionid].toc
  273. }
  274. if (mutation.type === 'Corpus/buildFlatTocsAndFilters') {
  275. console.log('Edition Corpus/buildFlatTocsAndFilters', this.editionid, state.Corpus.editionsbyuuid)
  276. this.flattoc = state.Corpus.editionsbyuuid[this.editionid].flattoc
  277. // launch infinitloading
  278. this.inifinite_load_id += 1
  279. // if no textid in new route (e.g. edition front)
  280. // but we have toc
  281. // get the first item
  282. // will be replaced by front page of edition
  283. if (!this.textid) { this.textid = this.flattoc[1] }
  284. //
  285. this.indexes = state.Corpus.editionsbyuuid[this.editionid].indexes
  286. }
  287. if (mutation.type === 'Corpus/setPaginations') {
  288. // console.log('Edition state.Coprus.editionsbyuuid', this.editionid, state.Corpus.editionsbyuuid)
  289. this.pagination = state.Corpus.editionsbyuuid[this.editionid].pagination
  290. }
  291. })
  292. } else {
  293. // console.log('');
  294. this.title = this.metainfotitle = this.editionsbyuuid[this.editionid].title
  295. this.biblio = this.editionsbyuuid[this.editionid].biblio
  296. this.description = this.editionsbyuuid[this.editionid].description
  297. this.date = this.editionsbyuuid[this.editionid].date
  298. this.author = this.editionsbyuuid[this.editionid].author
  299. this.toc = this.editionsbyuuid[this.editionid].toc
  300. this.flattoc = this.editionsbyuuid[this.editionid].flattoc
  301. // if no textid in new route (e.g. edition front)
  302. // but we have toc
  303. // get the first item
  304. // will be replaced by front page of edition
  305. if (!this.textid) { this.textid = this.toc[0].children[0].uuid }
  306. this.indexes = this.editionsbyuuid[this.editionid].indexes
  307. this.pagination = this.editionsbyuuid[this.editionid].pagination
  308. }
  309. },
  310. methods: {
  311. ...mapActions({
  312. getCorpuses: 'Corpus/getCorpuses'
  313. }),
  314. getTextContent (textid, $state = null, direction = 'next') {
  315. console.log('getTextContent', textid)
  316. let params = {
  317. depth: 0
  318. }
  319. let q = qs.stringify(params)
  320. REST.get(`${window.apipath}/items/${textid}?${q}`, {})
  321. .then(({ data }) => {
  322. console.log('text REST: data', data)
  323. if (direction === 'next') {
  324. this.texts.push(data)
  325. this.textsuuids.push(data.content.uuid)
  326. } else {
  327. this.texts.unshift(data)
  328. this.textsuuids.unshift(data.content.uuid)
  329. }
  330. if ($state) {
  331. $state.loaded()
  332. this.next_loaded = true
  333. }
  334. })
  335. .catch((error) => {
  336. console.warn('Issue with getTextContent', error)
  337. Promise.reject(error)
  338. // if some item don't load and if we come from infinite loading
  339. // retry with next step
  340. if ($state) {
  341. switch (direction) {
  342. case 'next':
  343. this.nextText($state, 2)
  344. break
  345. case 'prev':
  346. this.prevText($state, 2)
  347. break
  348. }
  349. }
  350. // this.$router.replace({
  351. // name: 'notfound',
  352. // query: { fullpath: this.$route.path }
  353. // })
  354. })
  355. },
  356. onCenterScrolled (e) {
  357. console.log('Edition centerScrolled(e)', e.target.scrollTop)
  358. if (!this.center_scrolled && e.target.scrollTop > this.inifinite_load_distance * 1.5) {
  359. this.center_scrolled = true
  360. // this.$store.commit('History/setOpened', false)
  361. }
  362. this.indexitem = null
  363. },
  364. nextText ($state, indent = 1) {
  365. console.log('infinite loading nextText()')
  366. let indexofnext = this.flattoc.indexOf(this.textsuuids[this.textsuuids.length - 1]) + indent
  367. if (indexofnext < this.flattoc.length) {
  368. this.getTextContent(this.flattoc[indexofnext], $state, 'next')
  369. } else {
  370. $state.complete()
  371. }
  372. },
  373. prevText ($state, indent = 1) {
  374. console.log('infinite loading prevText()')
  375. let indexofprev = this.flattoc.indexOf(this.textsuuids[0]) - indent
  376. if (indexofprev >= 0) {
  377. this.getTextContent(this.flattoc[indexofprev], $state, 'prev')
  378. } else {
  379. $state.complete()
  380. }
  381. },
  382. onHoverLink (elmt) {
  383. console.log('Edition onHoverLink(elmt)', elmt)
  384. this.tooltip_top = elmt.rect.top
  385. this.getIndexItem(elmt)
  386. },
  387. onLeaveLink () {
  388. console.log('Edition onLeaveLink()')
  389. this.indexitem = null
  390. },
  391. getIndexItem (item) {
  392. this.indexitem = 'loading'
  393. REST.get(`${window.apipath}/index${item.index.charAt(0).toUpperCase()}${item.index.slice(1)}/${item.uuid}`, {})
  394. .then(({ data }) => {
  395. console.log('index tooltip REST: data', data)
  396. if (this.indexitem === 'loading') {
  397. this.indexitem = data.content
  398. this.indexitem.index = item.index
  399. }
  400. })
  401. .catch((error) => {
  402. console.warn('Issue with index tooltip rest', error)
  403. Promise.reject(error)
  404. this.indexitem = null
  405. })
  406. },
  407. onClickTocItem (uuid) {
  408. console.log('Edition onClickTocItem', uuid, this.$refs)
  409. if (this.textsuuids.indexOf(uuid) !== -1) {
  410. // if already loaded, scroll to uuid
  411. this.reftoscrollto = `.tei[data-uuid="${uuid}"]`
  412. } else {
  413. // if not already loaded, change route
  414. this.$router.push({
  415. name: `editiontext`,
  416. params: {
  417. id: this.editionid,
  418. textid: uuid
  419. }
  420. })
  421. }
  422. },
  423. onClickPaginationItem (o) {
  424. console.log('onClickPaginationItem', o)
  425. if (this.textsuuids.indexOf(o.uuid) !== -1) {
  426. // if already loaded, scroll to uuid
  427. // this.scrollToPage(o)
  428. this.reftoscrollto = `span[role="pageBreak"][id="${o.code}"]`
  429. } else {
  430. // if not already loaded, change route
  431. this.$router.push({
  432. name: `editiontext`,
  433. params: {
  434. id: this.editionid,
  435. textid: o.uuid
  436. }
  437. })
  438. }
  439. },
  440. // scrollToPage (p) {
  441. // console.log('scrollToPage', p)
  442. //
  443. // },
  444. onOpenCloseNav (e) {
  445. console.log('onOpenCloseNav', e)
  446. this.navopened = !this.navopened
  447. },
  448. onClickTooltip (e) {
  449. console.log(`onClickTooltip index: ${e.target.dataset.index}, uuid: ${e.target.dataset.uuid}`)
  450. this.$router.push({
  451. name: e.target.dataset.index,
  452. params: { id: e.target.dataset.uuid }
  453. })
  454. },
  455. onClickManifestation (e) {
  456. console.log(`onClickManifestation`)
  457. this.$router.push({
  458. name: 'bibliographieItem',
  459. params: { type: 'manifestations', uuid: this.biblio.uuid }
  460. })
  461. }
  462. }
  463. }
  464. </script>
  465. <style lang="scss" scoped>
  466. </style>