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.

83 lines
2.2 KiB

  1. <template lang="pug">
  2. extends ../annotation.pug
  3. block annotation-area
  4. div.card
  5. header.card-header
  6. div.card-header-title.has-background-royalblue
  7. div.field.is-grouped.is-grouped-multiline
  8. div.control(v-for="label in labels")
  9. div.tags.has-addons
  10. a.tag.is-medium(
  11. v-shortkey.once="[ label.shortcut ]"
  12. v-bind:style="{ \
  13. color: label.text_color, \
  14. backgroundColor: label.background_color \
  15. }"
  16. v-on:click="addLabel(label)"
  17. v-on:shortkey="addLabel(label)"
  18. ) {{ label.text }}
  19. span.tag.is-medium {{ label.shortcut }}
  20. div.card-content
  21. div.field.is-grouped.is-grouped-multiline
  22. div.control(v-for="annotation in annotations[pageNumber]")
  23. div.tags.has-addons
  24. span.tag.is-medium(
  25. v-bind:style="{ \
  26. color: id2label[annotation.label].text_color, \
  27. backgroundColor: id2label[annotation.label].background_color \
  28. }"
  29. ) {{ id2label[annotation.label].text }}
  30. button.delete.is-small(v-on:click="removeLabel(annotation)")
  31. hr
  32. div.content(v-if="docs[pageNumber]") {{ docs[pageNumber].text }}
  33. </template>
  34. <style scoped>
  35. .card-header-title {
  36. padding: 1.5rem;
  37. }
  38. hr {
  39. margin: 0.8rem 0;
  40. }
  41. </style>
  42. <script>
  43. import annotationMixin from './demo_mixin';
  44. import { demoTextClassification } from './demo_data';
  45. export default {
  46. mixins: [annotationMixin],
  47. data: () => ({ ...demoTextClassification }),
  48. methods: {
  49. isIn(label) {
  50. for (let i = 0; i < this.annotations[this.pageNumber].length; i++) {
  51. const a = this.annotations[this.pageNumber][i];
  52. if (a.label === label.id) {
  53. return a;
  54. }
  55. }
  56. return false;
  57. },
  58. addLabel(label) {
  59. const a = this.isIn(label);
  60. if (a) {
  61. this.removeLabel(a);
  62. } else {
  63. const annotation = {
  64. id: this.annotationId++,
  65. label: label.id,
  66. };
  67. this.annotations[this.pageNumber].push(annotation);
  68. console.log(this.annotations); // eslint-disable-line no-console
  69. }
  70. },
  71. },
  72. };
  73. </script>