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.

114 lines
2.9 KiB

  1. <template lang="pug">
  2. extends ./annotation.pug
  3. block annotation-area
  4. div.card.has-text-weight-bold.has-text-white.has-background-royalblue
  5. div.card-content
  6. div.content(v-if="docs[pageNumber]")
  7. span.text {{ docs[pageNumber].text }}
  8. section.todoapp
  9. header.header
  10. input.textarea.new-todo(
  11. v-model="newTodo"
  12. v-on:keyup.enter="addTodo"
  13. type="text"
  14. placeholder="What is your response?"
  15. )
  16. section.main(v-cloak="")
  17. ul.todo-list
  18. li.todo(
  19. v-for="todo in annotations[pageNumber]"
  20. v-bind:key="todo.id"
  21. v-bind:class="{ editing: todo == editedTodo }"
  22. )
  23. div.view
  24. label(v-on:dblclick="editTodo(todo)") {{ todo.text }}
  25. button.delete.destroy.is-large(v-on:click="removeTodo(todo)")
  26. input.textarea.edit(
  27. v-model="todo.text"
  28. v-todo-focus="todo == editedTodo"
  29. v-on:blur="doneEdit(todo)"
  30. v-on:keyup.enter="doneEdit(todo)"
  31. v-on:keyup.esc="cancelEdit(todo)"
  32. type="text"
  33. )
  34. </template>
  35. <script>
  36. import annotationMixin from './annotationMixin';
  37. import todoFocus from './directives';
  38. import HTTP from './http';
  39. export default {
  40. directives: { todoFocus },
  41. mixins: [annotationMixin],
  42. data: () => ({
  43. newTodo: '',
  44. editedTodo: null,
  45. }),
  46. methods: {
  47. addTodo() {
  48. const value = this.newTodo && this.newTodo.trim();
  49. if (!value) {
  50. return;
  51. }
  52. const docId = this.docs[this.pageNumber].id;
  53. const payload = {
  54. text: value,
  55. };
  56. HTTP.post(`docs/${docId}/annotations`, payload).then((response) => {
  57. this.annotations[this.pageNumber].push(response.data);
  58. });
  59. this.newTodo = '';
  60. },
  61. removeTodo(todo) {
  62. const docId = this.docs[this.pageNumber].id;
  63. HTTP.delete(`docs/${docId}/annotations/${todo.id}`).then(() => {
  64. const index = this.annotations[this.pageNumber].indexOf(todo);
  65. this.annotations[this.pageNumber].splice(index, 1);
  66. });
  67. },
  68. editTodo(todo) {
  69. this.beforeEditCache = todo.text;
  70. this.editedTodo = todo;
  71. },
  72. doneEdit(todo) {
  73. if (!this.editedTodo) {
  74. return;
  75. }
  76. this.editedTodo = null;
  77. todo.text = todo.text.trim();
  78. if (!todo.text) {
  79. this.removeTodo(todo);
  80. }
  81. const docId = this.docs[this.pageNumber].id;
  82. HTTP.put(`docs/${docId}/annotations/${todo.id}`, todo).then((response) => {
  83. console.log(response); // eslint-disable-line no-console
  84. });
  85. },
  86. cancelEdit(todo) {
  87. this.editedTodo = null;
  88. todo.text = this.beforeEditCache;
  89. },
  90. async submit() {
  91. const state = this.getState();
  92. this.url = `docs?q=${this.searchQuery}&seq2seq_annotations__isnull=${state}&offset=${this.offset}&ordering=${this.ordering}`;
  93. await this.search();
  94. this.pageNumber = 0;
  95. },
  96. },
  97. };
  98. </script>