NodeViewTitle.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <component
  3. :is="tag"
  4. class="node-view-title"
  5. :class="{ block }"
  6. >
  7. <component
  8. :is="link ? 'a' : 'div'"
  9. @click="onTitleClick"
  10. class="node-view-title-container"
  11. >
  12. <slot name="default" />
  13. <span>
  14. <strong>{{ authors }}</strong>,
  15. <button-url v-if="url && node.piece && node.piece.url" :link="node.piece" />
  16. <button-url v-if="url && node.link && node.link.url" :link="node.link" />
  17. </span>
  18. <span>
  19. <span v-if="node.preTitle" v-html="' ' + trim(node.preTitle) + ','" />
  20. <em v-html="' ' + trim(node.italTitle || node.title) || 'pas de titre ital'" />
  21. <span v-if="(edition && node.edition) || (!noDate && node.date)">, </span>
  22. </span>
  23. <span v-if="!noDate && node.date" class="edition">
  24. {{ node.date.start }}
  25. </span>
  26. <div v-if="edition && node.edition" class="edition">
  27. {{ node.edition.map(ed => ed.name).join(' ') }}
  28. </div>
  29. </component>
  30. </component>
  31. </template>
  32. <script>
  33. import { trim, toCommaList } from '@/helpers/common'
  34. export default {
  35. name: 'NodeViewTitle',
  36. props: {
  37. node: { type: Object, required: true },
  38. tag: { type: String, default: 'h6' },
  39. link: { type: Boolean, default: false },
  40. block: { type: Boolean, default: false },
  41. edition: { type: Boolean, default: false },
  42. noDate: { type: Boolean, default: false },
  43. url: { type: Boolean, default: false },
  44. firstChar: { type: [String, null], default: null }
  45. },
  46. data () {
  47. return {
  48. }
  49. },
  50. computed: {
  51. authors () {
  52. if (!this.firstChar || this.node.authors.length < 2) return toCommaList(this.node.authors)
  53. const authors = [...this.node.authors].sort((a, b) => a.last_name.localeCompare(b.last_name))
  54. const first = this.node.authors.filter(author => author.last_name.startsWith(this.firstChar))
  55. first.forEach((author) => {
  56. const index = authors.indexOf(author)
  57. authors.splice(index, 1)
  58. authors.unshift(author)
  59. })
  60. return toCommaList(authors)
  61. }
  62. },
  63. methods: {
  64. trim,
  65. toCommaList,
  66. onTitleClick (e) {
  67. if (this.link) {
  68. e.stopPropagation()
  69. this.$emit('open-node')
  70. }
  71. }
  72. }
  73. }
  74. </script>
  75. <style lang="scss" scoped>
  76. .node-view-title {
  77. font-weight: $font-weight-normal;
  78. a {
  79. text-decoration: none;
  80. cursor: pointer;
  81. }
  82. &.block &-container {
  83. > * {
  84. display: block;
  85. }
  86. }
  87. }
  88. </style>