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.

74 lines
2.0 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="annotate(label.id)"
  17. v-on:shortkey="annotate(label.id)"
  18. ) {{ label.text }}
  19. span.tag.is-medium
  20. kbd {{ shortcutKey(label) | simpleShortcut }}
  21. div.card-content
  22. div.content(v-if="docs[pageNumber] && annotations[pageNumber]")
  23. annotator(
  24. v-bind:labels="labels"
  25. v-bind:entity-positions="annotations[pageNumber]"
  26. v-bind:text="docs[pageNumber].text"
  27. v-on:remove-label="removeLabel"
  28. v-on:add-label="addLabel"
  29. ref="annotator"
  30. )
  31. </template>
  32. <style scoped>
  33. .card-header-title {
  34. padding: 1.5rem;
  35. }
  36. </style>
  37. <script>
  38. import { annotationMixin } from './mixin';
  39. import Annotator from './annotator.vue';
  40. import HTTP from './http';
  41. import { simpleShortcut } from './filter';
  42. export default {
  43. filters: { simpleShortcut },
  44. components: { Annotator },
  45. mixins: [annotationMixin],
  46. methods: {
  47. annotate(labelId) {
  48. this.$refs.annotator.addLabel(labelId);
  49. },
  50. addLabel(annotation) {
  51. const docId = this.docs[this.pageNumber].id;
  52. HTTP.post(`docs/${docId}/annotations`, annotation).then((response) => {
  53. this.annotations[this.pageNumber].push(response.data);
  54. });
  55. },
  56. async submit() {
  57. const state = this.getState();
  58. this.url = `docs?q=${this.searchQuery}&seq_annotations__isnull=${state}&offset=${this.offset}`;
  59. await this.search();
  60. this.pageNumber = 0;
  61. },
  62. },
  63. };
  64. </script>