ResultItem.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.length > max) {
  52. let subString = this.result.title.substr(0, max)
  53. this.shorted_title = subString.substr(0, subString.lastIndexOf(' ')) + '&nbsp&hellip;'
  54. } else {
  55. this.shorted_title = this.result.title
  56. }
  57. // if (this.result.extract) {
  58. // const subString = this.result.extract.substr(0, 80)
  59. // this.preview = subString.substr(0, subString.lastIndexOf(' ')) + ' &hellip;'
  60. // } else {
  61. // console.warn(`No extract for ${this.result.textId}/${this.result.uuid}`)
  62. // }
  63. },
  64. methods: {
  65. ...mapActions({
  66. addHistoryItem: 'History/addItem'
  67. }),
  68. onclick () {
  69. console.log('clicked on result item', this.result)
  70. this.addHistoryItem({
  71. id: this.result.textId,
  72. textid: this.result.uuid,
  73. title: this.result.title,
  74. editionTitle: this.editionTitle,
  75. pages: this.result.pages,
  76. size: this.result.size
  77. })
  78. // this.$router.push({
  79. // name: `editiontextextract`,
  80. // params: {
  81. // id: this.result.textId,
  82. // textid: this.result.uuid,
  83. // extract: this.searchedkeys
  84. // }
  85. // })
  86. this.$router.push({ path: `/texts/${this.result.textId}/${this.result.uuid}/${this.searchedkeys}` })
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. </style>