Bibliographie.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <MainContentLayout id="biblio">
  3. <template v-if="!content" #header>
  4. <span class="loading">Loading ...</span>
  5. </template>
  6. <template #header>
  7. <h1>
  8. <router-link :to="{ name:'bibliographie'}">Bibliographie</router-link>
  9. </h1>
  10. <nav>
  11. <ul>
  12. <li>
  13. <router-link
  14. :to="{ name:'bibliographie', params: { type: 'expressions'}}"
  15. >
  16. Expressions
  17. </router-link>
  18. </li>
  19. <li>
  20. <router-link
  21. :to="{ name:'bibliographie', params: { type: 'manifestations'}}"
  22. >
  23. Manifestations
  24. </router-link>
  25. </li>
  26. </ul>
  27. </nav>
  28. </template>
  29. <!-- default slot -->
  30. <!-- expressions list -->
  31. <template v-if="!uuid && type === 'expressions'">
  32. <ul class="item-list">
  33. <li v-for="item in expressions" :key="item.uuid">
  34. <h2>
  35. <router-link
  36. v-if="item.authors"
  37. :to="{ name:'bibliographieItem', params:{ type:type, uuid:item.uuid } }"
  38. >
  39. {{ item.authors }}
  40. </router-link>
  41. <span v-else>/!\ No authors /!\</span>
  42. </h2>
  43. <p class="date">{{ item.dates }}</p>
  44. <em class="titles">{{ item.titles }}</em>
  45. <aside v-if="item.manifestations.length">
  46. <h5
  47. @click.prevent="onToggleManifs"
  48. @keyup.enter="onToggleManifs"
  49. >Manifestations</h5>
  50. <ul>
  51. <li v-for="manif in item.manifestations" :key="manif.uuid">
  52. <span class="date">{{ manif.dates }} </span>
  53. <router-link
  54. :to="{ name:'bibliographieItem', params:{ type:'manifestations', uuid:manif.uuid } }"
  55. >
  56. <em>{{ manif.titles }}</em>
  57. </router-link>
  58. </li>
  59. </ul>
  60. </aside>
  61. </li>
  62. </ul>
  63. </template>
  64. <!-- manifestations list -->
  65. <template v-if="!uuid && type === 'manifestations'">
  66. <ul class="item-list manifestations">
  67. <li
  68. v-for="item in manifestations" :key="item.uuid"
  69. :class="isInActiveAuthors(item.authors)"
  70. >
  71. <div class="wrapper">
  72. <span class="date">{{ item.dates }} </span>
  73. <router-link
  74. :to="{ name:'bibliographieItem', params:{ type:'manifestations', uuid:item.uuid } }"
  75. >
  76. <em class="titles">{{ item.titles }}</em>
  77. </router-link>
  78. <!-- <p class="authors">{{ item.authors }}</p> -->
  79. </div>
  80. </li>
  81. </ul>
  82. </template>
  83. <!-- or item -->
  84. <template v-else>
  85. <div class="biblio-item">
  86. <h2>{{ item.authors }}</h2>
  87. <p v-if="item.dates" class="date">{{ item.dates }}</p>
  88. <p class="titles">{{ item.titles }}</p>
  89. <p class="tei">{{ item.tei }}</p>
  90. <ul vi-if="item.manifestations.length" class="item-list">
  91. <li v-for="manif in item.manifestations" :key="manif.uuid">
  92. <router-link
  93. :to="{ name:'bibliographieItem', params:{ type:'manifestations', uuid:manif.uuid } }"
  94. v-html="manif.tei"
  95. />
  96. </li>
  97. </ul>
  98. <ul vi-if="item.idno.length" class="item-list">
  99. <li v-for="id in item.idno" :key="id.url">
  100. <a :href="id.url">{{ id.type }}: {{ id.url }}</a>
  101. </li>
  102. </ul>
  103. </div>
  104. </template>
  105. <template #nav>
  106. <ul v-if="!uuid && type === 'manifestations'" class="authors-filters">
  107. <li
  108. v-for="author in authors" :key="author"
  109. >
  110. <span
  111. :class="isInActiveAuthors(author)"
  112. @click.prevent="onToggleAuthors(author)"
  113. @keyup.enter="onToggleAuthors(author)"
  114. >{{ author }}</span>
  115. </li>
  116. </ul>
  117. </template>
  118. </MainContentLayout>
  119. </template>
  120. <script>
  121. import { REST } from 'api/rest-axios'
  122. import MainContentLayout from '../components/Layouts/MainContentLayout'
  123. export default {
  124. name: 'Bibliographie',
  125. components: {
  126. MainContentLayout
  127. },
  128. metaInfo: {
  129. title: 'Bibliographie'
  130. },
  131. props: {
  132. type: String,
  133. uuid: String
  134. },
  135. data: () => ({
  136. content: Array,
  137. manifestations: Array,
  138. expressions: Array,
  139. authors: Array,
  140. activeAuthors: Array,
  141. item: Array
  142. }),
  143. computed: {
  144. },
  145. watch: {
  146. $route (to, from) {
  147. console.log('watch $route to', to)
  148. // this.getContent()
  149. if (to.params.uuid) {
  150. this.getItem(to.params.type, to.params.uuid)
  151. }
  152. }
  153. },
  154. created () {
  155. // this.type = this.$route.params.type || 'expressions'
  156. // this.uuid = this.$route.params.id || null
  157. this.activeAuthors = []
  158. this.getContent()
  159. if (this.$route.params.uuid) {
  160. this.getItem(this.$route.params.type, this.$route.params.uuid)
  161. }
  162. },
  163. methods: {
  164. getContent () {
  165. REST.get(`${window.apipath}/bibliography/expressions`, {})
  166. .then(({ data }) => {
  167. console.log('Biblio REST expressions: data', data)
  168. if (data.content) {
  169. this.expressions = data.content
  170. REST.get(`${window.apipath}/bibliography/manifestations`, {})
  171. .then(({ data }) => {
  172. console.log('Biblio REST manifestations: data', data)
  173. if (data.content) {
  174. this.manifestations = data.content
  175. }
  176. this.parseContents()
  177. })
  178. .catch((error) => {
  179. console.warn('Issue with bibliographie manifestations', error)
  180. Promise.reject(error)
  181. })
  182. }
  183. })
  184. .catch((error) => {
  185. console.warn('Issue with bibliographie expressions', error)
  186. Promise.reject(error)
  187. })
  188. // // ?_format=json
  189. // REST.get(`${window.apipath}/bibliography/${this.type}/${this.uuid || ''}`, {})
  190. // .then(({ data }) => {
  191. // console.log('Biblio REST: data', data)
  192. // if (data.content) {
  193. // this.content = data.content
  194. // }
  195. // })
  196. // .catch((error) => {
  197. // console.warn('Issue with bibliographie', error)
  198. // Promise.reject(error)
  199. // })
  200. },
  201. getItem (type, uuid) {
  202. REST.get(`${window.apipath}/bibliography/${type}/${uuid}`, {})
  203. .then(({ data }) => {
  204. console.log('Biblio REST item: data', data)
  205. if (data.content) {
  206. this.item = data.content
  207. }
  208. })
  209. .catch((error) => {
  210. console.warn('Issue with bibliographie get item', error)
  211. Promise.reject(error)
  212. })
  213. },
  214. parseContents () {
  215. this.expressions = this.expressions.sort((a, b) => {
  216. let Adate = parseInt(a.dates)
  217. let Bdate = parseInt(b.dates)
  218. if (Adate < Bdate) {
  219. return -1
  220. } else if (Adate > Bdate) {
  221. return 1
  222. } else {
  223. return 0
  224. }
  225. })
  226. this.manifestations = this.manifestations.sort((a, b) => {
  227. let Adate = parseInt(a.dates)
  228. let Bdate = parseInt(b.dates)
  229. if (Adate < Bdate) {
  230. return -1
  231. } else if (Adate > Bdate) {
  232. return 1
  233. } else {
  234. return 0
  235. }
  236. })
  237. this.authors = []
  238. this.manifestations.forEach(manif => {
  239. // console.log('this.authors', this.authors)
  240. if (this.authors.indexOf(manif.authors) === -1) {
  241. this.authors.push(manif.authors)
  242. this.activeAuthors.push(manif.authors)
  243. }
  244. // console.log('authors', this.authors)
  245. })
  246. this.expressions.forEach((expr, i) => {
  247. let manifs = []
  248. this.manifestations.forEach((manif, j) => {
  249. if (manif.authors !== '' && manif.authors === expr.authors) {
  250. manifs.push(manif)
  251. }
  252. })
  253. this.expressions[i].manifestations = manifs
  254. })
  255. this.content = this.expressions
  256. // console.log(this.expressions)
  257. },
  258. onToggleManifs (e) {
  259. console.log('togle manifs', e)
  260. let aside = e.originalTarget.parentNode
  261. // console.log('aside', aside)
  262. aside.classList.toggle('opened')
  263. },
  264. isInActiveAuthors (authors) {
  265. return this.activeAuthors.indexOf(authors) !== -1 ? 'active' : null
  266. },
  267. onToggleAuthors (author) {
  268. if (this.activeAuthors.indexOf(author) === -1) {
  269. this.activeAuthors.push(author)
  270. } else {
  271. this.activeAuthors.splice(this.activeAuthors.indexOf(author), 1)
  272. }
  273. }
  274. }
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. </style>