@konfuzio/document-validation-ui 0.1.44 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/app.css +1 -1
- package/dist/index.html +1 -1
- package/dist/js/app.js +1 -1
- package/dist/js/app.js.map +1 -1
- package/package.json +1 -1
- package/src/api.js +34 -0
- package/src/assets/scss/document_set_chooser.scss +19 -0
- package/src/assets/scss/theme.scss +6 -0
- package/src/components/DocumentAnnotations/AnnotationDetails.vue +4 -16
- package/src/components/DocumentAnnotations/AnnotationRow.vue +6 -34
- package/src/components/DocumentPage/DocumentPage.vue +1 -3
- package/src/components/DocumentPage/EditAnnotation.vue +0 -18
- package/src/components/DocumentPage/NewAnnotation.vue +0 -19
- package/src/components/DocumentTopBar/DocumentSetChooser.vue +88 -0
- package/src/components/DocumentTopBar/DocumentTopBar.vue +8 -15
- package/src/components/DocumentsList/DocumentsList.vue +1 -1
- package/src/locales/de.json +2 -1
- package/src/locales/en.json +2 -1
- package/src/locales/es.json +2 -1
- package/src/store/category.js +5 -4
- package/src/store/document.js +133 -75
- package/src/store/project.js +12 -9
package/src/store/document.js
CHANGED
|
@@ -20,6 +20,7 @@ const state = {
|
|
|
20
20
|
annotations: null,
|
|
21
21
|
labels: [],
|
|
22
22
|
documentId: process.env.VUE_APP_DOCUMENT,
|
|
23
|
+
documentSet: null,
|
|
23
24
|
annotationId: null,
|
|
24
25
|
annotationSetId: null,
|
|
25
26
|
documentAnnotationSelected: null,
|
|
@@ -127,7 +128,7 @@ const getters = {
|
|
|
127
128
|
labelsFilteredForAnnotationCreation: (_, getters) => (set) => {
|
|
128
129
|
let availableLabels = [];
|
|
129
130
|
if (set.id && set.labels) {
|
|
130
|
-
// check if label can be multiple, if there's already an annotation created
|
|
131
|
+
// check if label can be multiple, if there's already an annotation created
|
|
131
132
|
set.labels.map((label) => {
|
|
132
133
|
// check if we already added the same label to the array
|
|
133
134
|
const found = availableLabels.find((l) => l.id === label.id);
|
|
@@ -136,17 +137,8 @@ const getters = {
|
|
|
136
137
|
|
|
137
138
|
if (label.annotations.length === 0) {
|
|
138
139
|
availableLabels.push(label);
|
|
139
|
-
} else {
|
|
140
|
-
|
|
141
|
-
availableLabels.push(label);
|
|
142
|
-
} else {
|
|
143
|
-
// if the label has negative annotations, we show the label
|
|
144
|
-
label.annotations.map((annotation) => {
|
|
145
|
-
if (getters.isNegative(annotation)) {
|
|
146
|
-
availableLabels.push(label);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
140
|
+
} else if (label.has_multiple_top_candidates) {
|
|
141
|
+
availableLabels.push(label);
|
|
150
142
|
}
|
|
151
143
|
});
|
|
152
144
|
} else if (set.labels) {
|
|
@@ -432,7 +424,7 @@ const getters = {
|
|
|
432
424
|
},
|
|
433
425
|
|
|
434
426
|
/* Process annotations and extract labels and sets */
|
|
435
|
-
processAnnotationSets: () => (annotationSets) => {
|
|
427
|
+
processAnnotationSets: (_, getters) => (annotationSets) => {
|
|
436
428
|
// group annotations for sidebar
|
|
437
429
|
let annotations = [];
|
|
438
430
|
let labels = [];
|
|
@@ -445,7 +437,12 @@ const getters = {
|
|
|
445
437
|
const labelAnnotations = [];
|
|
446
438
|
|
|
447
439
|
// add annotations to the document array
|
|
448
|
-
|
|
440
|
+
// remove negative annotations
|
|
441
|
+
label.annotations.forEach((ann) => {
|
|
442
|
+
if (!getters.isNegative(ann)) {
|
|
443
|
+
labelAnnotations.push(ann);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
449
446
|
labels.push({ ...label, annotations: labelAnnotations });
|
|
450
447
|
processedLabels.push(label);
|
|
451
448
|
annotations.push(...labelAnnotations);
|
|
@@ -510,6 +507,22 @@ const getters = {
|
|
|
510
507
|
return "";
|
|
511
508
|
},
|
|
512
509
|
|
|
510
|
+
/**
|
|
511
|
+
* Checks the number of current document in the document set
|
|
512
|
+
*/
|
|
513
|
+
numberOfDocumentInSet: (state) => (documentId) => {
|
|
514
|
+
let index = -1;
|
|
515
|
+
if (state.documentSet && state.documentSet.documents) {
|
|
516
|
+
state.documentSet.documents.forEach((docTemp, indexTemp) => {
|
|
517
|
+
if (docTemp.id == documentId) {
|
|
518
|
+
index = indexTemp;
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
return index === -1 ? "" : `${index + 1}`;
|
|
524
|
+
},
|
|
525
|
+
|
|
513
526
|
/**
|
|
514
527
|
* Checks if theres a group of annotation sets with this label set
|
|
515
528
|
*/
|
|
@@ -638,11 +651,7 @@ const getters = {
|
|
|
638
651
|
annotationSet.label_set.id === l.label_set
|
|
639
652
|
);
|
|
640
653
|
|
|
641
|
-
|
|
642
|
-
getters.isNegative(annotation)
|
|
643
|
-
);
|
|
644
|
-
|
|
645
|
-
if (!foundMissing && (label.annotations.length === 0 || foundNegative)) {
|
|
654
|
+
if (!foundMissing && label.annotations.length === 0) {
|
|
646
655
|
pendingEmpty.push(label);
|
|
647
656
|
}
|
|
648
657
|
});
|
|
@@ -726,7 +735,7 @@ const getters = {
|
|
|
726
735
|
|
|
727
736
|
// if all annotations are correct
|
|
728
737
|
// and if there are no empty annotations or
|
|
729
|
-
// all empty annotations
|
|
738
|
+
// all empty annotations were marked as missing,
|
|
730
739
|
// we can finish the review
|
|
731
740
|
if (
|
|
732
741
|
!emptyAnnotations ||
|
|
@@ -1026,9 +1035,10 @@ const actions = {
|
|
|
1026
1035
|
*/
|
|
1027
1036
|
fetchDocument: async (
|
|
1028
1037
|
{ commit, state, dispatch, rootState, getters },
|
|
1029
|
-
|
|
1038
|
+
fetchedDocument = null
|
|
1030
1039
|
) => {
|
|
1031
1040
|
let projectId = null;
|
|
1041
|
+
let documentSetId = null;
|
|
1032
1042
|
let categoryId = null;
|
|
1033
1043
|
let isRecalculatingAnnotations = false;
|
|
1034
1044
|
|
|
@@ -1038,56 +1048,56 @@ const actions = {
|
|
|
1038
1048
|
dispatch("display/updateCurrentPage", initialPage, {
|
|
1039
1049
|
root: true,
|
|
1040
1050
|
});
|
|
1051
|
+
try {
|
|
1052
|
+
if (!fetchedDocument) {
|
|
1053
|
+
const response = await HTTP.get(`documents/${state.documentId}/`);
|
|
1054
|
+
fetchedDocument = response.data;
|
|
1055
|
+
}
|
|
1041
1056
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
if (response.data) {
|
|
1045
|
-
const { labels, annotations, annotationSets } =
|
|
1046
|
-
getters.processAnnotationSets(response.data.annotation_sets);
|
|
1057
|
+
const { labels, annotations, annotationSets } =
|
|
1058
|
+
getters.processAnnotationSets(fetchedDocument.annotation_sets);
|
|
1047
1059
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1060
|
+
// load first page
|
|
1061
|
+
if (fetchedDocument.pages.length > 0) {
|
|
1062
|
+
dispatch("fetchDocumentPage", initialPage);
|
|
1063
|
+
}
|
|
1052
1064
|
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1065
|
+
// set information on the store
|
|
1066
|
+
commit("SET_ANNOTATION_SETS", annotationSets);
|
|
1067
|
+
commit("SET_ANNOTATIONS", annotations);
|
|
1068
|
+
commit("SET_LABELS", labels);
|
|
1069
|
+
commit("SET_SELECTED_DOCUMENT", fetchedDocument);
|
|
1058
1070
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1071
|
+
if (fetchedDocument.project) {
|
|
1072
|
+
projectId = fetchedDocument.project;
|
|
1061
1073
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1074
|
+
dispatch("project/setProjectId", projectId, {
|
|
1075
|
+
root: true,
|
|
1076
|
+
});
|
|
1065
1077
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1072
|
-
);
|
|
1078
|
+
dispatch(
|
|
1079
|
+
"project/setShowAnnotationTranslations",
|
|
1080
|
+
fetchedDocument.enable_translated_strings,
|
|
1081
|
+
{
|
|
1082
|
+
root: true,
|
|
1073
1083
|
}
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1074
1086
|
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1087
|
+
if (getters.documentHasProposedSplit(fetchedDocument)) {
|
|
1088
|
+
commit("SET_SPLITTING_SUGGESTIONS", fetchedDocument.proposed_split);
|
|
1089
|
+
}
|
|
1078
1090
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
dispatch("display/setPageError", error.response.data.detail, {
|
|
1087
|
-
root: true,
|
|
1088
|
-
});
|
|
1089
|
-
return;
|
|
1091
|
+
documentSetId = fetchedDocument.document_set;
|
|
1092
|
+
categoryId = fetchedDocument.category;
|
|
1093
|
+
isRecalculatingAnnotations = fetchedDocument.labeling_available !== 1;
|
|
1094
|
+
} catch (error) {
|
|
1095
|
+
console.log(error, "Could not fetch document details from the backend");
|
|
1096
|
+
dispatch("display/setPageError", error.response.data.detail, {
|
|
1097
|
+
root: true,
|
|
1090
1098
|
});
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1091
1101
|
|
|
1092
1102
|
if (!state.publicView) {
|
|
1093
1103
|
await dispatch("fetchMissingAnnotations");
|
|
@@ -1109,6 +1119,10 @@ const actions = {
|
|
|
1109
1119
|
dispatch("edit/setRenameAndCategorize", true, { root: true });
|
|
1110
1120
|
}
|
|
1111
1121
|
|
|
1122
|
+
if (documentSetId) {
|
|
1123
|
+
await dispatch("fetchDocumentSet", documentSetId);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1112
1126
|
if (projectId) {
|
|
1113
1127
|
await dispatch("category/fetchCategories", projectId, {
|
|
1114
1128
|
root: true,
|
|
@@ -1125,7 +1139,7 @@ const actions = {
|
|
|
1125
1139
|
{
|
|
1126
1140
|
categoryId,
|
|
1127
1141
|
user: rootState.project.currentUser.username,
|
|
1128
|
-
poll:
|
|
1142
|
+
poll: false,
|
|
1129
1143
|
},
|
|
1130
1144
|
{
|
|
1131
1145
|
root: true,
|
|
@@ -1151,6 +1165,22 @@ const actions = {
|
|
|
1151
1165
|
});
|
|
1152
1166
|
},
|
|
1153
1167
|
|
|
1168
|
+
// Set document set data
|
|
1169
|
+
setDocumentSet: ({ commit }, documentSet) => {
|
|
1170
|
+
commit("SET_DOC_SET", documentSet);
|
|
1171
|
+
},
|
|
1172
|
+
|
|
1173
|
+
// Get document set data
|
|
1174
|
+
fetchDocumentSet: ({ commit, state }, documentSetId) => {
|
|
1175
|
+
return HTTP.get(`document-sets/${documentSetId}/`)
|
|
1176
|
+
.then((response) => {
|
|
1177
|
+
commit("SET_DOC_SET", response.data);
|
|
1178
|
+
})
|
|
1179
|
+
.catch((error) => {
|
|
1180
|
+
console.log(error);
|
|
1181
|
+
});
|
|
1182
|
+
},
|
|
1183
|
+
|
|
1154
1184
|
setDocumentAnnotationSelected: (
|
|
1155
1185
|
{ commit },
|
|
1156
1186
|
{ annotation, label, span, scrollTo = false }
|
|
@@ -1173,10 +1203,7 @@ const actions = {
|
|
|
1173
1203
|
commit("SET_DOCUMENT_ANNOTATION_SELECTED", null);
|
|
1174
1204
|
},
|
|
1175
1205
|
|
|
1176
|
-
createAnnotation: (
|
|
1177
|
-
{ commit, getters, dispatch },
|
|
1178
|
-
{ annotation, negativeAnnotationId }
|
|
1179
|
-
) => {
|
|
1206
|
+
createAnnotation: ({ commit, getters, dispatch }, { annotation }) => {
|
|
1180
1207
|
return new Promise((resolve, reject) => {
|
|
1181
1208
|
HTTP.post(`/annotations/`, annotation)
|
|
1182
1209
|
.then(async (response) => {
|
|
@@ -1197,9 +1224,6 @@ const actions = {
|
|
|
1197
1224
|
if (response.data && response.data.id) {
|
|
1198
1225
|
dispatch("setAnnotationId", response.data.id);
|
|
1199
1226
|
}
|
|
1200
|
-
if (negativeAnnotationId) {
|
|
1201
|
-
commit("DELETE_ANNOTATION", negativeAnnotationId);
|
|
1202
|
-
}
|
|
1203
1227
|
}
|
|
1204
1228
|
|
|
1205
1229
|
resolve(response);
|
|
@@ -1309,9 +1333,13 @@ const actions = {
|
|
|
1309
1333
|
|
|
1310
1334
|
fetchMissingAnnotations: ({ commit, state, getters }) => {
|
|
1311
1335
|
return new Promise((resolve, reject) => {
|
|
1312
|
-
return
|
|
1313
|
-
.
|
|
1314
|
-
|
|
1336
|
+
return myImports
|
|
1337
|
+
.makeGetPaginatedRequest(
|
|
1338
|
+
`/missing-annotations/?document=${state.documentId}`,
|
|
1339
|
+
true
|
|
1340
|
+
)
|
|
1341
|
+
.then((results) => {
|
|
1342
|
+
commit("SET_MISSING_ANNOTATIONS", results);
|
|
1315
1343
|
resolve(true);
|
|
1316
1344
|
})
|
|
1317
1345
|
.catch((error) => {
|
|
@@ -1471,17 +1499,33 @@ const actions = {
|
|
|
1471
1499
|
window.open(fullUrl, "_blank");
|
|
1472
1500
|
},
|
|
1473
1501
|
|
|
1474
|
-
changeCurrentDocument: (
|
|
1502
|
+
changeCurrentDocument: (
|
|
1503
|
+
{ commit, state, dispatch, rootState },
|
|
1504
|
+
{ document, documentId }
|
|
1505
|
+
) => {
|
|
1475
1506
|
// reset splitting suggestions
|
|
1476
1507
|
if (state.splittingSuggestions) {
|
|
1477
1508
|
commit("SET_SPLITTING_SUGGESTIONS", null);
|
|
1478
1509
|
}
|
|
1510
|
+
|
|
1511
|
+
if (rootState.edit.editMode) {
|
|
1512
|
+
// Reset edit mode when changing the document,
|
|
1513
|
+
// in case the change was made from the arrows in the Edit Mode
|
|
1514
|
+
// so that the user does not get stuck in this interface
|
|
1515
|
+
dispatch("edit/disableEditMode", null, {
|
|
1516
|
+
root: true,
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1479
1520
|
commit("SET_RECALCULATING_ANNOTATIONS", false);
|
|
1480
1521
|
|
|
1481
1522
|
if (getURLQueryParam("document") || getURLPath("d")) {
|
|
1482
|
-
navigateToNewDocumentURL(state.selectedDocument.id,
|
|
1523
|
+
navigateToNewDocumentURL(state.selectedDocument.id, documentId);
|
|
1524
|
+
} else if (document) {
|
|
1525
|
+
commit("SET_DOC_ID", document.id);
|
|
1526
|
+
dispatch("fetchDocument", document);
|
|
1483
1527
|
} else {
|
|
1484
|
-
commit("SET_DOC_ID",
|
|
1528
|
+
commit("SET_DOC_ID", documentId);
|
|
1485
1529
|
dispatch("fetchDocument");
|
|
1486
1530
|
}
|
|
1487
1531
|
},
|
|
@@ -1496,6 +1540,20 @@ const mutations = {
|
|
|
1496
1540
|
state.documentId = id;
|
|
1497
1541
|
}
|
|
1498
1542
|
},
|
|
1543
|
+
SET_DOC_SET: (state, documentSet) => {
|
|
1544
|
+
// assuming that documents in document set are ordered from new to old
|
|
1545
|
+
let documents = [];
|
|
1546
|
+
if (documentSet && documentSet.documents) {
|
|
1547
|
+
documents = documentSet.documents.slice().reverse();
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
const orderedDocumentSet = {
|
|
1551
|
+
...documentSet,
|
|
1552
|
+
documents,
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
state.documentSet = orderedDocumentSet;
|
|
1556
|
+
},
|
|
1499
1557
|
SET_ANNOTATION_ID: (state, id) => {
|
|
1500
1558
|
state.annotationId = id;
|
|
1501
1559
|
},
|
package/src/store/project.js
CHANGED
|
@@ -30,9 +30,10 @@ const actions = {
|
|
|
30
30
|
|
|
31
31
|
// Get label sets from the project
|
|
32
32
|
fetchLabelSets: ({ commit, state }) => {
|
|
33
|
-
return
|
|
34
|
-
.
|
|
35
|
-
|
|
33
|
+
return myImports
|
|
34
|
+
.makeGetPaginatedRequest(`label-sets/?project=${state.projectId}`, true)
|
|
35
|
+
.then((results) => {
|
|
36
|
+
commit("SET_LABEL_SETS", results);
|
|
36
37
|
})
|
|
37
38
|
.catch((error) => {
|
|
38
39
|
console.log(error);
|
|
@@ -66,12 +67,14 @@ const actions = {
|
|
|
66
67
|
},
|
|
67
68
|
|
|
68
69
|
fetchDocumentList: ({ commit, state }, parameters) => {
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
return myImports
|
|
71
|
+
.makeGetPaginatedRequest(
|
|
72
|
+
`documents/?project=${state.projectId}&${parameters}`,
|
|
73
|
+
true
|
|
74
|
+
)
|
|
75
|
+
.then((results) => {
|
|
76
|
+
if (results) {
|
|
77
|
+
commit("SET_DOCUMENTS_IN_PROJECT", results);
|
|
75
78
|
}
|
|
76
79
|
})
|
|
77
80
|
.catch((error) => {
|