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.

94 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(v-if="docs[pageNumber]")
  34. span.text {{ 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 './mixin';
  46. import HTTP from './http';
  47. import { simpleShortcut } from './filter';
  48. export default {
  49. filters: { simpleShortcut },
  50. mixins: [annotationMixin],
  51. methods: {
  52. isIn(label) {
  53. for (let i = 0; i < this.annotations[this.pageNumber].length; i++) {
  54. const a = this.annotations[this.pageNumber][i];
  55. if (a.label === label.id) {
  56. return a;
  57. }
  58. }
  59. return false;
  60. },
  61. async submit() {
  62. const state = this.getState();
  63. this.url = `docs?q=${this.searchQuery}&doc_annotations__isnull=${state}&offset=${this.offset}`;
  64. await this.search();
  65. this.pageNumber = 0;
  66. },
  67. async addLabel(label) {
  68. const a = this.isIn(label);
  69. if (a) {
  70. this.removeLabel(a);
  71. } else {
  72. const docId = this.docs[this.pageNumber].id;
  73. const payload = {
  74. label: label.id,
  75. };
  76. await HTTP.post(`docs/${docId}/annotations`, payload).then((response) => {
  77. this.annotations[this.pageNumber].push(response.data);
  78. });
  79. }
  80. },
  81. },
  82. };
  83. </script>