You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1 KiB

  1. <template>
  2. <v-card
  3. v-if="currentDoc && items"
  4. v-shortkey="multiKeys"
  5. @shortkey="addOrRemoveLabel"
  6. >
  7. <v-card-title>
  8. <multi-class-classification
  9. :labels="items"
  10. :annotations="currentDoc.annotations"
  11. :add-label="addLabel"
  12. :delete-label="removeLabel"
  13. />
  14. </v-card-title>
  15. <v-card-text class="title">
  16. {{ currentDoc.text }}
  17. </v-card-text>
  18. </v-card>
  19. </template>
  20. <script>
  21. import Vue from 'vue'
  22. import { mapActions, mapGetters, mapState } from 'vuex'
  23. import MultiClassClassification from '@/components/organisms/annotation/MultiClassClassification'
  24. Vue.use(require('vue-shortkey'))
  25. export default {
  26. components: {
  27. MultiClassClassification
  28. },
  29. computed: {
  30. ...mapState('labels', ['items']),
  31. ...mapGetters('documents', ['currentDoc']),
  32. multiKeys() {
  33. const multiKeys = {}
  34. for (const item of this.items) {
  35. multiKeys[item.id] = [item.suffix_key]
  36. }
  37. return multiKeys
  38. }
  39. },
  40. created() {
  41. this.getLabelList({
  42. projectId: this.$route.params.id
  43. })
  44. },
  45. methods: {
  46. ...mapActions('labels', ['getLabelList']),
  47. ...mapActions('documents', ['getDocumentList', 'deleteAnnotation', 'updateAnnotation', 'addAnnotation']),
  48. removeLabel(annotationId) {
  49. const payload = {
  50. annotationId,
  51. projectId: this.$route.params.id
  52. }
  53. this.deleteAnnotation(payload)
  54. },
  55. updateLabel(labelId, annotationId) {
  56. const payload = {
  57. annotationId,
  58. label: labelId,
  59. projectId: this.$route.params.id
  60. }
  61. this.updateAnnotation(payload)
  62. },
  63. addLabel(labelId) {
  64. const payload = {
  65. label: labelId,
  66. projectId: this.$route.params.id
  67. }
  68. this.addAnnotation(payload)
  69. },
  70. addOrRemoveLabel(event) {
  71. const label = this.items.find(item => item.id === parseInt(event.srcKey, 10))
  72. const annotation = this.currentDoc.annotations.find(item => item.label === label.id)
  73. if (annotation) {
  74. this.removeLabel(annotation.id)
  75. } else {
  76. this.addLabel(label.id)
  77. }
  78. }
  79. }
  80. }
  81. </script>