diff --git a/src/components/DocumentAnnotations/ChooseLabelSetModal.vue b/src/components/DocumentAnnotations/ChooseLabelSetModal.vue index 979a9793..ea1440ca 100644 --- a/src/components/DocumentAnnotations/ChooseLabelSetModal.vue +++ b/src/components/DocumentAnnotations/ChooseLabelSetModal.vue @@ -75,12 +75,13 @@ export default { data() { return { show: true, - labels: [], }; }, computed: { - ...mapGetters("project", ["labelSetsFilteredForAnnotationSetCreation"]), - ...mapGetters("document", ["numberOfLabelSetGroup"]), + ...mapGetters("document", [ + "numberOfLabelSetGroup", + "labelSetsFilteredForAnnotationSetCreation", + ]), }, methods: { submit(labelSet) { diff --git a/src/components/DocumentAnnotations/DocumentAnnotations.vue b/src/components/DocumentAnnotations/DocumentAnnotations.vue index 413035e1..d5a80b7e 100644 --- a/src/components/DocumentAnnotations/DocumentAnnotations.vue +++ b/src/components/DocumentAnnotations/DocumentAnnotations.vue @@ -18,46 +18,12 @@ - -
-
-
-
-
- {{ `${labelSet.name}` }} -
-
- -
-
-
- -
-
-
-
-
-
-
@@ -236,7 +202,6 @@ export default { "selectedDocument", "splittingSuggestions", ]), - ...mapState("project", ["labelSets"]), ...mapGetters("document", [ "numberOfAnnotationSetGroup", "getAnnotationsFiltered", diff --git a/src/components/DocumentPage/NewAnnotation.vue b/src/components/DocumentPage/NewAnnotation.vue index 942b9633..8dda6114 100644 --- a/src/components/DocumentPage/NewAnnotation.vue +++ b/src/components/DocumentPage/NewAnnotation.vue @@ -329,12 +329,21 @@ export default { }); }, chooseLabelSet(labelSet) { + // check if there's already a new entry for that label set to be created + const existsIndex = this.setsList.findIndex((set) => { + return set.id === null && set.label_set.id === labelSet.id; + }); + const newSet = { label_set: labelSet, labels: labelSet.labels, id: null, }; - this.setsList.push(newSet); + if (existsIndex >= 0) { + this.setsList[existsIndex] = newSet; + } else { + this.setsList.push(newSet); + } this.selectedSet = newSet; }, openAnnotationSetCreation() { diff --git a/src/store/document.js b/src/store/document.js index 3b707b3b..5326b41b 100644 --- a/src/store/document.js +++ b/src/store/document.js @@ -440,19 +440,17 @@ const getters = { let processedLabels = []; annotationSets.forEach((annotationSet) => { - if (annotationSet.id) { - labels = []; - annotationSet.labels.forEach((label) => { - const labelAnnotations = []; + labels = []; + annotationSet.labels.forEach((label) => { + const labelAnnotations = []; - // add annotations to the document array - labelAnnotations.push(...label.annotations); - labels.push({ ...label, annotations: labelAnnotations }); - processedLabels.push(label); - annotations.push(...labelAnnotations); - }); - processedAnnotationSets.push({ ...annotationSet, labels }); - } + // add annotations to the document array + labelAnnotations.push(...label.annotations); + labels.push({ ...label, annotations: labelAnnotations }); + processedLabels.push(label); + annotations.push(...labelAnnotations); + }); + processedAnnotationSets.push({ ...annotationSet, labels }); }); return { annotationSets: processedAnnotationSets, @@ -523,20 +521,43 @@ const getters = { orderedAnnotationSets.sort((a, b) => { return a.id - b.id || a.label_set.name.localeCompare(b.label_set.name); }); - orderedAnnotationSets.map((annotationSetTemp) => { + orderedAnnotationSets.forEach((annotationSetTemp) => { if ( annotationSetTemp.label_set.id === labelSet.id && annotationSetTemp.label_set.name === labelSet.name ) { found = true; - index++; + // check if annotation set exists, otherwise it will be new + if (annotationSetTemp.id) { + index++; + } } }); - return found ? `${index + 1}` : ""; + return found ? (index === 0 ? "" : `${index + 1}`) : ""; } return ""; }, + /** + * Gets label sets for an annotation set creation + */ + labelSetsFilteredForAnnotationSetCreation: (state) => { + let returnLabelSets = []; + if (state.annotationSets) { + state.annotationSets.forEach((annotationSet) => { + if ( + annotationSet.id == null || + annotationSet.label_set.has_multiple_annotation_sets + ) { + const labelSet = { ...annotationSet.label_set }; + labelSet.labels = [...annotationSet.labels]; + returnLabelSets.push(labelSet); + } + }); + } + return returnLabelSets; + }, + /** * Get label with annotations filtered if the label supports multiple or not */ @@ -1071,10 +1092,6 @@ const actions = { if (!state.publicView) { await dispatch("fetchMissingAnnotations"); - await dispatch("project/fetchLabelSets", null, { - root: true, - }); - await dispatch("project/fetchCurrentUser", null, { root: true, }); diff --git a/src/store/project.js b/src/store/project.js index 07e45dd3..4f4028f5 100644 --- a/src/store/project.js +++ b/src/store/project.js @@ -10,31 +10,6 @@ const state = { showAnnotationTranslations: false, }; -const getters = { - /** - * Gets label sets for an annotation set creation - */ - labelSetsFilteredForAnnotationSetCreation: (state, _, rootState) => { - let returnLabels = []; - if (state.labelSets) { - returnLabels = state.labelSets.filter((labelSet) => { - // check if label set has multiple and if not, if there's already an annotation set created - if (!labelSet.has_multiple_annotation_sets) { - const existingAnnotationSet = rootState.document.annotationSets.find( - (annSet) => { - return annSet.label_set.id === labelSet.id; - } - ); - return !existingAnnotationSet; - } else { - return true; - } - }); - } - return returnLabels; - }, -}; - const actions = { setProjectId: ({ commit }, projectId) => { commit("SET_PROJECT_ID", projectId); @@ -131,5 +106,4 @@ export default { state, actions, mutations, - getters, };