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.

101 lines
3.1 KiB

  1. import HTTP from './http.js';
  2. var annotationMixin = {
  3. data: function () {
  4. return {
  5. cur: 0,
  6. items: [{
  7. id: null,
  8. text: '',
  9. labels: []
  10. }],
  11. labels: [],
  12. guideline: 'Here is the Annotation Guideline Text',
  13. total: 0,
  14. remaining: 0,
  15. searchQuery: '',
  16. url: '',
  17. }
  18. },
  19. methods: {
  20. nextPage: async function () {
  21. this.cur += 1;
  22. if (this.cur == this.items.length) {
  23. if (this.next) {
  24. this.url = this.next;
  25. await this.search();
  26. this.cur = 0;
  27. } else {
  28. this.cur = this.items.length - 1;
  29. }
  30. }
  31. this.showMessage(this.cur);
  32. },
  33. prevPage: async function () {
  34. this.cur -= 1;
  35. if (this.cur == -1) {
  36. if (this.prev) {
  37. this.url = this.prev;
  38. await this.search();
  39. this.cur = this.items.length - 1;
  40. } else {
  41. this.cur = 0;
  42. }
  43. }
  44. this.showMessage(this.cur);
  45. },
  46. search: async function () {
  47. await HTTP.get(this.url).then(response => {
  48. this.items = response.data['results'];
  49. this.next = response.data['next'];
  50. this.prev = response.data['previous'];
  51. })
  52. },
  53. showMessage: function (index) {
  54. this.cur = index;
  55. },
  56. submit: async function () {
  57. this.url = `docs/?q=${this.searchQuery}`;
  58. await this.search();
  59. this.cur = 0;
  60. },
  61. updateProgress: function () {
  62. HTTP.get('progress').then(response => {
  63. this.total = response.data['total'];
  64. this.remaining = response.data['remaining'];
  65. })
  66. },
  67. deleteLabel: async function (index) {
  68. var doc_id = this.items[this.cur].id;
  69. var annotation_id = this.items[this.cur]['labels'][index].id;
  70. HTTP.delete(`docs/${doc_id}/annotations/${annotation_id}`).then(response => {
  71. this.items[this.cur]['labels'].splice(index, 1)
  72. });
  73. this.updateProgress();
  74. }
  75. },
  76. created: function () {
  77. HTTP.get('labels').then(response => {
  78. this.labels = response.data
  79. });
  80. this.updateProgress();
  81. this.submit();
  82. },
  83. computed: {
  84. achievement: function () {
  85. var done = this.total - this.remaining;
  86. var percentage = Math.round(done / this.total * 100);
  87. return this.total > 0 ? percentage : 0;
  88. },
  89. progressColor: function () {
  90. if (this.achievement < 30) {
  91. return 'is-danger'
  92. } else if (this.achievement < 70) {
  93. return 'is-warning'
  94. } else {
  95. return 'is-primary'
  96. }
  97. }
  98. }
  99. };
  100. export default annotationMixin;