Bibliographie.vue 9.1 KB

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