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.

139 lines
3.1 KiB

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