TextCardBase.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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>{{ toCommaList(text.authors) }},</span>
  9. <span>{{ text.title }},</span>
  10. <span>{{ text.edition }}</span>
  11. </template>
  12. <template v-else>
  13. {{ text.title }}
  14. </template>
  15. </h4>
  16. <slot name="header-extra" :text="text" />
  17. </b-card-header>
  18. <b-card-body v-html="text.content" :class="ellipsis ? 'ellipsis' : 'overflow-auto'" />
  19. <b-card-footer>
  20. <b-badge
  21. v-for="tag in text.tags" :key="tag.id"
  22. variant="dark" pill
  23. >
  24. {{ tag.name }}
  25. </b-badge>
  26. <slot name="footer-extra" v-bind="{ text, toCommaList }" />
  27. </b-card-footer>
  28. </div>
  29. </b-overlay>
  30. </b-card>
  31. </template>
  32. <script>
  33. export default {
  34. name: 'TextCardBase',
  35. props: {
  36. id: { type: Number, required: true },
  37. textData: { type: Object, default: null },
  38. ellipsis: { type: Boolean, default: false }
  39. },
  40. data () {
  41. return {
  42. loading: this.textData === null,
  43. text: this.textData
  44. }
  45. },
  46. methods: {
  47. toCommaList (arr) {
  48. // FIXME TEMP some texts doesn't have authors
  49. try {
  50. return arr.map(({ name }) => name).join(', ')
  51. } catch {
  52. return arr
  53. }
  54. }
  55. },
  56. created () {
  57. if (this.text !== null) return
  58. this.$store.dispatch('GET_TEXT', { id: this.id }).then((text) => {
  59. this.text = text
  60. this.loading = false
  61. })
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. article {
  67. height: 100%;
  68. }
  69. header {
  70. display: flex;
  71. h4 {
  72. display: flex;
  73. flex-direction: column;
  74. }
  75. }
  76. .ellipsis {
  77. max-height: 10rem;
  78. overflow: hidden;
  79. }
  80. </style>