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.

88 lines
2.6 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. getAnnotation(label) {
  53. return this.annotations[this.pageNumber].find(annotation => annotation.label === label.id);
  54. },
  55. async submit() {
  56. const state = this.getState();
  57. this.url = `docs?q=${this.searchQuery}&doc_annotations__isnull=${state}&offset=${this.offset}&ordering=${this.ordering}`;
  58. await this.search();
  59. this.pageNumber = 0;
  60. },
  61. async addLabel(label) {
  62. const annotation = this.getAnnotation(label);
  63. if (annotation) {
  64. this.removeLabel(annotation);
  65. } else {
  66. const docId = this.docs[this.pageNumber].id;
  67. const payload = {
  68. label: label.id,
  69. };
  70. await HTTP.post(`docs/${docId}/annotations`, payload).then((response) => {
  71. this.annotations[this.pageNumber].push(response.data);
  72. });
  73. }
  74. },
  75. },
  76. };
  77. </script>