TextCardBase.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <b-card no-body tag="article" class="text-card">
  3. <b-overlay class="h-100" :show="loading">
  4. <div v-if="text" class="container-fill">
  5. <b-card-header header-tag="header">
  6. <h4>
  7. <template v-if="text.type === 'Textref'">
  8. <span class="text-authors d-block">{{ toCommaList(text.authors) }},</span>
  9. <span class="text-title d-block">{{ text.title }},</span>
  10. <span class="text-edition d-block">{{ text.edition ? text.edition.name : text.edition }}</span>
  11. </template>
  12. <template v-else>
  13. {{ text.families[0].name }}
  14. </template>
  15. </h4>
  16. <slot name="header-extra" :text="text" />
  17. </b-card-header>
  18. <b-card-body :class="ellipsis ? 'ellipsis' : 'overflow-auto'">
  19. <div class="text-content" v-html="text.content" />
  20. <div class="text-notes mt-5" v-if="text.notes">
  21. <div v-for="note in text.notes" :key="note.number" class="mb-4 border border-dark p-2">
  22. <p class="m-0">
  23. <span class="font-weight-bold">Numéro de note :</span> {{ note.number || 'aucun ?' }}
  24. </p>
  25. <p class="m-0 font-weight-bold">
  26. Contenu :
  27. </p>
  28. <div v-if="note.content" v-html="note.content" />
  29. <div v-else>
  30. Aucun ?
  31. </div>
  32. <p class="m-0 font-weight-bold">
  33. Liens :
  34. </p>
  35. <ul v-if="note.links">
  36. <li v-for="link in note.links" :key="link.id" class="">
  37. <span class="text-authors">{{ toCommaList(link.authors) }}</span>,
  38. <span class="text-title">{{ link.title }}</span> —
  39. <span>{{ link.families[0].name }}</span>
  40. (id: {{ link.id }})
  41. </li>
  42. </ul>
  43. <div v-else>
  44. Aucun
  45. </div>
  46. </div>
  47. </div>
  48. </b-card-body>
  49. <b-card-footer>
  50. <div class="tags">
  51. <b-badge
  52. v-for="tag in text.tags" :key="tag.id"
  53. variant="dark" pill
  54. >
  55. {{ tag.name }}
  56. </b-badge>
  57. </div>
  58. <slot name="footer-extra" v-bind="{ text, toCommaList }" />
  59. </b-card-footer>
  60. </div>
  61. </b-overlay>
  62. </b-card>
  63. </template>
  64. <script>
  65. export default {
  66. name: 'TextCardBase',
  67. props: {
  68. id: { type: Number, required: true },
  69. textData: { type: Object, default: null },
  70. ellipsis: { type: Boolean, default: false }
  71. },
  72. data () {
  73. return {
  74. loading: this.textData === null,
  75. text: this.textData
  76. }
  77. },
  78. methods: {
  79. toCommaList (arr) {
  80. // FIXME TEMP some texts doesn't have authors
  81. try {
  82. return arr.map(({ name }) => name).join(', ')
  83. } catch {
  84. return arr
  85. }
  86. }
  87. },
  88. created () {
  89. if (this.text !== null) return
  90. this.$store.dispatch('GET_TEXT', { id: this.id }).then((text) => {
  91. this.text = text
  92. this.loading = false
  93. })
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. article {
  99. height: 100%;
  100. }
  101. header {
  102. display: flex;
  103. h4 {
  104. display: flex;
  105. flex-direction: column;
  106. }
  107. }
  108. .ellipsis {
  109. max-height: 10rem;
  110. overflow: hidden;
  111. }
  112. </style>