diff --git a/app/server/static/components/annotationMixin.js b/app/server/static/components/annotationMixin.js index 61e7314e..d0eb175b 100644 --- a/app/server/static/components/annotationMixin.js +++ b/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); }); }, diff --git a/app/server/static/components/document_classification.vue b/app/server/static/components/document_classification.vue index ac9278eb..e95d994b 100644 --- a/app/server/static/components/document_classification.vue +++ b/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 = {