ResultItem.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <article class="result item">
  3. <h1>
  4. <a
  5. :href="'/texts/'+result.textId+'/'+result.uuid+'/'+searchedkeys"
  6. @click.prevent="onclick"
  7. @keyup.enter="onclick"
  8. v-html="shorted_title"
  9. />
  10. </h1>
  11. <h2>
  12. <a
  13. :href="'/texts/'+result.textId+'/'+result.uuid+'/'+searchedkeys"
  14. @click.prevent="onclick"
  15. @keyup.enter="onclick"
  16. v-html="editionTitle"
  17. />
  18. </h2>
  19. <!-- <p v-if="preview" class="preview" v-html="preview" /> -->
  20. <aside>
  21. <span>{{ result.pages.prefix }} {{ result.pages.range }}</span> | <span>{{ result.size.quantity }} {{ result.size.unit }}</span>
  22. </aside>
  23. </article>
  24. </template>
  25. <script>
  26. import { mapState, mapActions } from 'vuex'
  27. export default {
  28. name: 'ResultItem',
  29. props: {
  30. result: {
  31. type: Object,
  32. required: true
  33. },
  34. searchedkeys: {
  35. type: String
  36. }
  37. },
  38. // data: () => ({
  39. // preview: ''
  40. // }),
  41. computed: {
  42. ...mapState({
  43. editionsbyuuid: state => state.Corpus.editionsbyuuid
  44. }),
  45. editionTitle () {
  46. return this.editionsbyuuid[this.result.textId].title
  47. }
  48. },
  49. created () {
  50. let max = 40
  51. if (this.result.title) {
  52. if (this.result.title.length > max) {
  53. let subString = this.result.title.substr(0, max)
  54. this.shorted_title = subString.substr(0, subString.lastIndexOf(' ')) + '&nbsp&hellip;'
  55. } else {
  56. this.shorted_title = this.result.title
  57. }
  58. } else {
  59. console.warn(`no result title for ${this.result.uuid}`, this.result)
  60. }
  61. // if (this.result.extract) {
  62. // const subString = this.result.extract.substr(0, 80)
  63. // this.preview = subString.substr(0, subString.lastIndexOf(' ')) + ' &hellip;'
  64. // } else {
  65. // console.warn(`No extract for ${this.result.textId}/${this.result.uuid}`)
  66. // }
  67. },
  68. methods: {
  69. ...mapActions({
  70. addHistoryItem: 'History/addItem'
  71. }),
  72. onclick () {
  73. console.log('clicked on result item', this.result)
  74. this.addHistoryItem({
  75. id: this.result.textId,
  76. textid: this.result.uuid,
  77. title: this.result.title,
  78. editionTitle: this.editionTitle,
  79. pages: this.result.pages,
  80. size: this.result.size
  81. })
  82. // this.$router.push({
  83. // name: `editiontextextract`,
  84. // params: {
  85. // id: this.result.textId,
  86. // textid: this.result.uuid,
  87. // extract: this.searchedkeys
  88. // }
  89. // })
  90. this.$router.push({ path: `/texts/${this.result.textId}/${this.result.uuid}/${this.searchedkeys}` })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. </style>