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.

117 lines
3.5 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. picked: 'all',
  18. }
  19. },
  20. methods: {
  21. nextPage: async function () {
  22. this.cur += 1;
  23. if (this.cur == this.items.length) {
  24. if (this.next) {
  25. this.url = this.next;
  26. await this.search();
  27. this.cur = 0;
  28. } else {
  29. this.cur = this.items.length - 1;
  30. }
  31. }
  32. this.showMessage(this.cur);
  33. },
  34. prevPage: async function () {
  35. this.cur -= 1;
  36. if (this.cur == -1) {
  37. if (this.prev) {
  38. this.url = this.prev;
  39. await this.search();
  40. this.cur = this.items.length - 1;
  41. } else {
  42. this.cur = 0;
  43. }
  44. }
  45. this.showMessage(this.cur);
  46. },
  47. search: async function () {
  48. await HTTP.get(this.url).then(response => {
  49. this.items = response.data['results'];
  50. this.next = response.data['next'];
  51. this.prev = response.data['previous'];
  52. })
  53. },
  54. showMessage: function (index) {
  55. this.cur = index;
  56. },
  57. getState: function () {
  58. if (this.picked == 'all') {
  59. return ''
  60. } else if (this.picked == 'active') {
  61. return 'true'
  62. } else {
  63. return 'false'
  64. }
  65. },
  66. submit: async function () {
  67. var state = this.getState();
  68. this.url = `docs/?q=${this.searchQuery}&is_checked=${state}`;
  69. await this.search();
  70. this.cur = 0;
  71. },
  72. updateProgress: function () {
  73. HTTP.get('progress').then(response => {
  74. this.total = response.data['total'];
  75. this.remaining = response.data['remaining'];
  76. })
  77. },
  78. deleteLabel: async function (index) {
  79. var doc_id = this.items[this.cur].id;
  80. var annotation_id = this.items[this.cur]['labels'][index].id;
  81. HTTP.delete(`docs/${doc_id}/annotations/${annotation_id}`).then(response => {
  82. this.items[this.cur]['labels'].splice(index, 1)
  83. });
  84. this.updateProgress();
  85. }
  86. },
  87. watch: {
  88. picked: function (){
  89. this.submit();
  90. }
  91. },
  92. created: function () {
  93. HTTP.get('labels').then(response => {
  94. this.labels = response.data
  95. });
  96. this.updateProgress();
  97. this.submit();
  98. },
  99. computed: {
  100. achievement: function () {
  101. var done = this.total - this.remaining;
  102. var percentage = Math.round(done / this.total * 100);
  103. return this.total > 0 ? percentage : 0;
  104. },
  105. progressColor: function () {
  106. if (this.achievement < 30) {
  107. return 'is-danger'
  108. } else if (this.achievement < 70) {
  109. return 'is-warning'
  110. } else {
  111. return 'is-primary'
  112. }
  113. }
  114. }
  115. };
  116. export default annotationMixin;