Bibliographie.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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.type }}</h2>
  90. <p class="author">Auteur: {{ item.authors }}</p>
  91. <p v-if="item.dates" class="date">Dates : {{ item.dates }}</p>
  92. <h3>Liste des manifestations :</h3>
  93. <ul vi-if="item.manifestations.length" class="item-list">
  94. <li v-for="manif in item.manifestations" :key="manif.uuid">
  95. <p v-html="manif.tei"/>
  96. <router-link
  97. :to="{ name:'bibliographieItem', params:{ type:'manifestations', uuid:manif.uuid } }"
  98. v-html="manif.path"
  99. />
  100. </li>
  101. </ul>
  102. <ul vi-if="item.idno.length" class="item-list">
  103. <li v-for="id in item.idno" :key="id.url">
  104. <a :href="id.url">{{ id.type }}: {{ id.url }}</a>
  105. </li>
  106. </ul>
  107. </div>
  108. </template>
  109. <template v-if="!uuid && type === 'manifestations'" #nav>
  110. <ul class="authors-filters">
  111. <li
  112. v-for="author in authors" :key="author"
  113. >
  114. <span
  115. :class="isInActiveAuthors(author)"
  116. @click.prevent="onToggleAuthors(author)"
  117. @keyup.enter="onToggleAuthors(author)"
  118. >{{ author }}</span>
  119. </li>
  120. </ul>
  121. </template>
  122. <template v-else #nav>
  123. <aside class="expression-links">
  124. <p>
  125. Permalien:<br/><a :href="`${item.url}`">{{ item.url }}</a>
  126. </p>
  127. <p>
  128. JSON:<br/><a :href="`${apipath}${item.path}${item.uuid}`">{{ apipath }}{{ item.path }}{{ item.uuid }}</a>
  129. </p>
  130. </aside>
  131. </template>
  132. </MainContentLayout>
  133. </template>
  134. <script>
  135. import { REST } from 'api/rest-axios'
  136. import MainContentLayout from '../components/Layouts/MainContentLayout'
  137. export default {
  138. name: 'Bibliographie',
  139. components: {
  140. MainContentLayout
  141. },
  142. metaInfo: {
  143. title: 'Bibliographie'
  144. },
  145. props: {
  146. type: String,
  147. uuid: String
  148. },
  149. data: () => ({
  150. content: Array,
  151. manifestations: Array,
  152. expressions: Array,
  153. authors: Array,
  154. activeAuthors: Array,
  155. item: Array
  156. }),
  157. computed: {
  158. apipath () {
  159. return window.apipath
  160. }
  161. },
  162. watch: {
  163. $route (to, from) {
  164. console.log('watch $route to', to)
  165. // this.getContent()
  166. if (to.params.uuid) {
  167. this.getItem(to.params.type, to.params.uuid)
  168. }
  169. }
  170. },
  171. created () {
  172. // this.type = this.$route.params.type || 'expressions'
  173. // this.uuid = this.$route.params.id || null
  174. this.activeAuthors = []
  175. this.getContent()
  176. if (this.$route.params.uuid) {
  177. this.getItem(this.$route.params.type, this.$route.params.uuid)
  178. }
  179. },
  180. methods: {
  181. getContent () {
  182. REST.get(`${window.apipath}/bibliography/expressions`, {})
  183. .then(({ data }) => {
  184. console.log('Biblio REST expressions: data', data)
  185. if (data.content) {
  186. this.expressions = data
  187. REST.get(`${window.apipath}/bibliography/manifestations`, {})
  188. .then(({ data }) => {
  189. console.log('Biblio REST manifestations: data', data)
  190. if (data.content) {
  191. this.manifestations = data
  192. }
  193. this.parseContents()
  194. })
  195. .catch((error) => {
  196. console.warn('Issue with bibliographie manifestations', error)
  197. Promise.reject(error)
  198. })
  199. }
  200. })
  201. .catch((error) => {
  202. console.warn('Issue with bibliographie expressions', error)
  203. Promise.reject(error)
  204. })
  205. // // ?_format=json
  206. // REST.get(`${window.apipath}/bibliography/${this.type}/${this.uuid || ''}`, {})
  207. // .then(({ data }) => {
  208. // console.log('Biblio REST: data', data)
  209. // if (data.content) {
  210. // this.content = data.content
  211. // }
  212. // })
  213. // .catch((error) => {
  214. // console.warn('Issue with bibliographie', error)
  215. // Promise.reject(error)
  216. // })
  217. },
  218. getItem (type, uuid) {
  219. REST.get(`${window.apipath}/bibliography/${type}/${uuid}`, {})
  220. .then(({ data }) => {
  221. console.log('Biblio REST item: data', data)
  222. if (data.content) {
  223. this.item = data.content
  224. }
  225. })
  226. .catch((error) => {
  227. console.warn('Issue with bibliographie get item', error)
  228. Promise.reject(error)
  229. })
  230. },
  231. parseContents () {
  232. this.expressions.content = this.expressions.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.manifestations.content = this.manifestations.content.sort((a, b) => {
  244. let Adate = parseInt(a.dates)
  245. let Bdate = parseInt(b.dates)
  246. if (Adate < Bdate) {
  247. return -1
  248. } else if (Adate > Bdate) {
  249. return 1
  250. } else {
  251. return 0
  252. }
  253. })
  254. this.authors = []
  255. this.manifestations.content.forEach(manif => {
  256. // console.log('this.authors', this.authors)
  257. if (this.authors.indexOf(manif.authors) === -1) {
  258. this.authors.push(manif.authors)
  259. this.activeAuthors.push(manif.authors)
  260. }
  261. // console.log('authors', this.authors)
  262. })
  263. this.expressions.content.forEach((expr, i) => {
  264. let manifs = []
  265. this.manifestations.content.forEach((manif, j) => {
  266. if (manif.authors !== '' && manif.authors === expr.authors) {
  267. manifs.push(manif)
  268. }
  269. })
  270. this.expressions.content[i].manifestations = manifs
  271. })
  272. this.content = this.expressions.content
  273. console.log('content parsed', this.expressions, this.manifestations)
  274. },
  275. onToggleManifs (e) {
  276. console.log('togle manifs', e)
  277. let aside = e.originalTarget.parentNode
  278. // console.log('aside', aside)
  279. aside.classList.toggle('opened')
  280. },
  281. isInActiveAuthors (authors) {
  282. return this.activeAuthors.indexOf(authors) !== -1 ? 'active' : null
  283. },
  284. onToggleAuthors (author) {
  285. if (this.activeAuthors.indexOf(author) === -1) {
  286. this.activeAuthors.push(author)
  287. } else {
  288. this.activeAuthors.splice(this.activeAuthors.indexOf(author), 1)
  289. }
  290. }
  291. }
  292. }
  293. </script>
  294. <style lang="scss" scoped>
  295. </style>