Browse Source

Merge pull request #251 from clarus/remove-some-for-loops

Remove some for loops
pull/254/head
Hiroki Nakayama 5 years ago
committed by GitHub
parent
commit
9ce28abe81
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 16 deletions
  1. 6
      app/server/static/components/annotationMixin.js
  2. 16
      app/server/static/components/document_classification.vue

6
app/server/static/components/annotationMixin.js

@ -90,11 +90,7 @@ export default {
this.next = response.data.next;
this.prev = response.data.previous;
this.count = response.data.count;
this.annotations = [];
for (let i = 0; i < this.docs.length; i++) {
const doc = this.docs[i];
this.annotations.push(doc.annotations);
}
this.annotations = this.docs.map(doc => doc.annotations);
this.offset = getOffsetFromUrl(this.url);
});
},

16
app/server/static/components/document_classification.vue

@ -58,14 +58,8 @@ export default {
mixins: [annotationMixin],
methods: {
isIn(label) {
for (let i = 0; i < this.annotations[this.pageNumber].length; i++) {
const a = this.annotations[this.pageNumber][i];
if (a.label === label.id) {
return a;
}
}
return false;
getAnnotation(label) {
return this.annotations[this.pageNumber].find(annotation => annotation.label === label.id);
},
async submit() {
@ -76,9 +70,9 @@ export default {
},
async addLabel(label) {
const a = this.isIn(label);
if (a) {
this.removeLabel(a);
const annotation = this.getAnnotation(label);
if (annotation) {
this.removeLabel(annotation);
} else {
const docId = this.docs[this.pageNumber].id;
const payload = {

Loading…
Cancel
Save