ResultItem.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <article class="result item">
  3. <h1>
  4. <a
  5. :href="'/edition/'+result.textId+'/'+result.uuid"
  6. @click.prevent="onclick"
  7. @keyup.enter="onclick"
  8. v-html="result.title"
  9. />
  10. </h1>
  11. <h2>
  12. <a
  13. :href="'/edition/'+result.textId+'/'+result.uuid"
  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. },
  35. data: () => ({
  36. preview: ''
  37. }),
  38. computed: {
  39. ...mapState({
  40. editionsbyuuid: state => state.Corpus.editionsbyuuid
  41. }),
  42. editionTitle () {
  43. return this.editionsbyuuid[this.result.textId].title
  44. }
  45. },
  46. created () {
  47. if (this.result.extract) {
  48. const subString = this.result.extract.substr(0, 80)
  49. this.preview = subString.substr(0, subString.lastIndexOf(' ')) + ' &hellip;'
  50. } else {
  51. console.warn(`No extract for ${this.result.textId}/${this.result.uuid}`)
  52. }
  53. },
  54. methods: {
  55. ...mapActions({
  56. addHistoryItem: 'History/addItem'
  57. }),
  58. onclick () {
  59. console.log('clicked on result item', this.result)
  60. this.addHistoryItem({
  61. id: this.result.textId,
  62. textid: this.result.uuid,
  63. title: this.result.title[0],
  64. editionTitle: this.editionTitle
  65. })
  66. this.$router.push({
  67. name: `editiontext`,
  68. params: {
  69. id: this.result.textId,
  70. textid: this.result.uuid
  71. }
  72. })
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. </style>