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.

90 lines
2.7 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="replaceNull(shortcutKey(label))"
  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
  20. kbd {{ shortcutKey(label) | simpleShortcut }}
  21. div.card-content
  22. div.field.is-grouped.is-grouped-multiline
  23. div.control(v-for="annotation in annotations[pageNumber]")
  24. div.tags.has-addons(v-if="id2label[annotation.label]")
  25. span.tag.is-medium(
  26. v-bind:style="{ \
  27. color: id2label[annotation.label].text_color, \
  28. backgroundColor: id2label[annotation.label].background_color \
  29. }"
  30. ) {{ id2label[annotation.label].text }}
  31. button.delete.is-small(v-on:click="removeLabel(annotation)")
  32. hr
  33. div.content
  34. div.text.scrollable(ref="textbox", v-if="docs[pageNumber]") {{ docs[pageNumber].text }}
  35. </template>
  36. <style scoped>
  37. hr {
  38. margin: 0.8rem 0;
  39. }
  40. .card-header-title {
  41. padding: 1.5rem;
  42. }
  43. </style>
  44. <script>
  45. import annotationMixin from './annotationMixin';
  46. import HTTP from './http';
  47. import { simpleShortcut } from './filter';
  48. export default {
  49. filters: { simpleShortcut },
  50. mixins: [annotationMixin],
  51. methods: {
  52. async submit() {
  53. const state = this.getState();
  54. this.url = `docs?q=${this.searchQuery}&doc_annotations__isnull=${state}&offset=${this.offset}&ordering=${this.ordering}`;
  55. await this.search();
  56. this.pageNumber = 0;
  57. },
  58. async addLabel(label) {
  59. const annotations = this.annotations[this.pageNumber];
  60. const annotation = annotations.find(item => item.label === label.id);
  61. if (annotation) {
  62. this.removeLabel(annotation);
  63. } else {
  64. if (this.singleClassClassification && annotations.length >= 1) {
  65. await Promise.all(annotations.map(item => this.removeLabel(item)));
  66. }
  67. const docId = this.docs[this.pageNumber].id;
  68. const payload = {
  69. label: label.id,
  70. };
  71. await HTTP.post(`docs/${docId}/annotations`, payload).then((response) => {
  72. this.annotations[this.pageNumber].push(response.data);
  73. });
  74. }
  75. },
  76. },
  77. };
  78. </script>