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.

136 lines
3.0 KiB

  1. const annotationMixin = {
  2. data() {
  3. return {
  4. pageNumber: 0,
  5. docs: [],
  6. annotations: [],
  7. labels: [],
  8. tmp_docs: [],
  9. tmp_annotations: [],
  10. guideline: 'You can see annotation guideline here.',
  11. searchQuery: '',
  12. picked: 'all',
  13. annotationId: 100,
  14. isActive: false,
  15. };
  16. },
  17. methods: {
  18. nextPage() {
  19. this.pageNumber = Math.min(this.pageNumber + 1, this.docs.length - 1);
  20. },
  21. prevPage() {
  22. this.pageNumber = Math.max(this.pageNumber - 1, 0);
  23. },
  24. search() {
  25. this.docs = [];
  26. this.annotations = [];
  27. for (let i = 0; i < this.tmp_docs.length; i++) {
  28. if (this.tmp_docs[i].text.indexOf(this.searchQuery) !== -1) {
  29. if (this.picked === 'all') {
  30. this.docs.push(this.tmp_docs[i]);
  31. this.annotations.push(this.tmp_annotations[i]);
  32. }
  33. if (this.picked === 'active') {
  34. if (this.tmp_annotations[i].length === 0) {
  35. this.docs.push(this.tmp_docs[i]);
  36. this.annotations.push(this.tmp_annotations[i]);
  37. }
  38. }
  39. if (this.picked === 'completed') {
  40. if (this.tmp_annotations[i].length !== 0) {
  41. this.docs.push(this.tmp_docs[i]);
  42. this.annotations.push(this.tmp_annotations[i]);
  43. }
  44. }
  45. }
  46. }
  47. },
  48. getState() {
  49. if (this.picked === 'all') {
  50. return '';
  51. }
  52. if (this.picked === 'active') {
  53. return 'true';
  54. }
  55. return 'false';
  56. },
  57. submit() {
  58. this.search();
  59. this.pageNumber = 0;
  60. },
  61. removeLabel(annotation) {
  62. const index = this.annotations[this.pageNumber].indexOf(annotation);
  63. this.annotations[this.pageNumber].splice(index, 1);
  64. },
  65. },
  66. watch: {
  67. picked() {
  68. this.submit();
  69. },
  70. },
  71. created() {
  72. this.tmp_docs = this.docs;
  73. this.tmp_annotations = this.annotations;
  74. },
  75. computed: {
  76. total() {
  77. return this.tmp_docs.length;
  78. },
  79. count() {
  80. return this.docs.length;
  81. },
  82. compiledMarkdown() {
  83. return marked(this.guideline, {
  84. sanitize: true,
  85. });
  86. },
  87. remaining() {
  88. let cnt = 0;
  89. for (let i = 0; i < this.tmp_annotations.length; i++) {
  90. if (this.tmp_annotations[i].length === 0) {
  91. cnt += 1;
  92. }
  93. }
  94. return cnt;
  95. },
  96. achievement() {
  97. const done = this.total - this.remaining;
  98. const percentage = Math.round(done / this.total * 100);
  99. return this.total > 0 ? percentage : 0;
  100. },
  101. id2label() {
  102. let id2label = {};
  103. for (let i = 0; i < this.labels.length; i++) {
  104. const label = this.labels[i];
  105. id2label[label.id] = label;
  106. }
  107. return id2label;
  108. },
  109. progressColor() {
  110. if (this.achievement < 30) {
  111. return 'is-danger';
  112. }
  113. if (this.achievement < 70) {
  114. return 'is-warning';
  115. }
  116. return 'is-primary';
  117. },
  118. },
  119. };
  120. export default annotationMixin;