@konfuzio/document-validation-ui 0.1.43 → 0.1.44-dev.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konfuzio/document-validation-ui",
3
- "version": "0.1.43",
3
+ "version": "0.1.44-dev.1",
4
4
  "repository": "git://github.com:konfuzio-ai/document-validation-ui.git",
5
5
  "main": "dist/app.js",
6
6
  "scripts": {
@@ -2,10 +2,10 @@
2
2
  <div>
3
3
  <b-tooltip
4
4
  :animated="false"
5
- :position="fromTable ? 'is-top' : 'is-bottom'"
6
- :class="[!fromTable && 'left-aligned', 'annotation-details']"
5
+ :position="'is-bottom'"
6
+ :class="['left-aligned', 'annotation-details']"
7
7
  >
8
- <div :class="['label-icon', fromTable && 'is-small']">
8
+ <div :class="['label-icon']">
9
9
  <div
10
10
  v-if="
11
11
  (created(annotation) || edited(annotation)) &&
@@ -180,10 +180,6 @@ export default {
180
180
  type: Object,
181
181
  default: null,
182
182
  },
183
- fromTable: {
184
- type: Boolean,
185
- default: false,
186
- },
187
183
  },
188
184
  data() {
189
185
  return {
@@ -24,7 +24,6 @@
24
24
  :annotation="annotation"
25
25
  :annotation-set="annotationSet"
26
26
  :label="label"
27
- :from-table="fromTable"
28
27
  />
29
28
  </div>
30
29
 
@@ -129,6 +128,7 @@
129
128
  :span-index="index"
130
129
  :label="label"
131
130
  :annotation-set="annotationSet"
131
+ :label-set="labelSet"
132
132
  :is-hovered="hoveredAnnotation"
133
133
  :is-missing-annotation="
134
134
  annotationIsNotFound(annotationSet, label)
@@ -137,9 +137,10 @@
137
137
  />
138
138
  </div>
139
139
  <EmptyAnnotation
140
- v-else-if="!fromTable"
140
+ v-else
141
141
  :label="label"
142
142
  :annotation-set="annotationSet"
143
+ :label-set="labelSet"
143
144
  :is-hovered="hoveredAnnotation"
144
145
  :is-missing-annotation="annotationIsNotFound(annotationSet, label)"
145
146
  @save-empty-annotation-changes="saveEmptyAnnotationChanges"
@@ -191,6 +192,10 @@ export default {
191
192
  },
192
193
  props: {
193
194
  annotationSet: {
195
+ type: Object,
196
+ default: null,
197
+ },
198
+ labelSet: {
194
199
  type: Object,
195
200
  required: true,
196
201
  },
@@ -206,10 +211,6 @@ export default {
206
211
  type: Boolean,
207
212
  default: true,
208
213
  },
209
- fromTable: {
210
- type: Boolean,
211
- default: false,
212
- },
213
214
  },
214
215
  data() {
215
216
  const checkboxValue =
@@ -284,6 +285,7 @@ export default {
284
285
  return (
285
286
  this.hoveredAnnotationSet &&
286
287
  this.hoveredAnnotationSet.type == "missing" &&
288
+ this.annotationSet &&
287
289
  !this.annotationIsNotFound(this.annotationSet, this.label) &&
288
290
  this.annotationSet.id === this.hoveredAnnotationSet.annotationSet.id &&
289
291
  this.annotationSet.label_set.id ===
@@ -417,7 +419,7 @@ export default {
417
419
  }
418
420
  },
419
421
  currentAnnotationId() {
420
- if (!this.annotationSet || !this.label) return;
422
+ if ((!this.annotationSet && !this.labelSet) || !this.label) return;
421
423
 
422
424
  if (
423
425
  this.annotation &&
@@ -426,20 +428,17 @@ export default {
426
428
  )
427
429
  return this.annotation.id;
428
430
 
429
- let emptyAnnotationId;
431
+ const setId = this.annotationSet
432
+ ? this.annotationSet.id
433
+ : this.labelSet.id;
430
434
 
431
- if (this.annotationSet.id) {
432
- emptyAnnotationId = `${this.annotationSet.id}_${this.label.id}`;
433
- } else {
434
- emptyAnnotationId = `${this.annotationSet.label_set.id}_${this.label.id}`;
435
- }
436
- return emptyAnnotationId;
435
+ return `${setId}_${this.label.id}`;
437
436
  },
438
437
  onAnnotationHoverEnter(span) {
439
438
  if (span) {
440
439
  this.$store.dispatch("document/setDocumentAnnotationSelected", {
441
440
  annotation: this.annotation,
442
- label: this.fromTable ? null : this.label,
441
+ label: this.label,
443
442
  span,
444
443
  scrollTo: false,
445
444
  });
@@ -449,9 +448,6 @@ export default {
449
448
  this.$store.dispatch("document/disableDocumentAnnotationSelected");
450
449
  },
451
450
  onAnnotationClick() {
452
- if (!this.fromTable) {
453
- this.$store.dispatch("display/showAnnSetTable", null);
454
- }
455
451
  this.$store.dispatch("document/scrollToDocumentAnnotationSelected");
456
452
  },
457
453
  hoveredEmptyLabels() {
@@ -571,7 +567,7 @@ export default {
571
567
  this.$parent.$emit(
572
568
  "handle-missing-annotation",
573
569
  this.label.id,
574
- this.annotationSet.label_set.id,
570
+ this.labelSet.id,
575
571
  this.annotationSet.id,
576
572
  false
577
573
  );
@@ -636,7 +632,7 @@ export default {
636
632
  (item) =>
637
633
  item.annotation_set === this.annotationSet.id &&
638
634
  item.label === this.label.id &&
639
- item.label_set === this.annotationSet.label_set.id
635
+ item.label_set === this.annotationSet.labelSet.id
640
636
  );
641
637
 
642
638
  this.$store
@@ -699,7 +695,7 @@ export default {
699
695
  saveEmptyAnnotationChanges() {
700
696
  let annotationToCreate;
701
697
 
702
- if (this.annotationSet.id) {
698
+ if (this.annotationSet && this.annotationSet.id) {
703
699
  annotationToCreate = {
704
700
  document: this.documentId,
705
701
  span: this.spanSelection,
@@ -714,7 +710,7 @@ export default {
714
710
  document: this.documentId,
715
711
  span: this.spanSelection,
716
712
  label: this.label.id,
717
- label_set: this.annotationSet.label_set.id,
713
+ label_set: this.labelSet.id,
718
714
  is_correct: true,
719
715
  revised: true,
720
716
  };
@@ -778,7 +774,7 @@ export default {
778
774
  this.annotationsMarkedAsMissing.map((annotation) => {
779
775
  // Check if the annotation set and label are marked as missing
780
776
  if (
781
- annotation.label_set === this.annotationSet.label_set.id &&
777
+ annotation.label_set === this.labelSet.id &&
782
778
  annotation.annotation_set === this.annotationSet.id &&
783
779
  annotation.label === this.label.id
784
780
  ) {
@@ -9,15 +9,12 @@
9
9
  :on-cancel="close"
10
10
  >
11
11
  <section class="modal-card-body">
12
- <b-loading :active="loading" :is-full-page="false">
13
- <b-icon icon="spinner" class="fa-spin loading-icon-size spinner" />
14
- </b-loading>
15
- <div v-if="!loading" class="content">
12
+ <div class="content">
16
13
  <h3>
17
14
  {{ $t("new_ann_set_title") }}
18
15
  </h3>
19
16
  <div>
20
- <div v-if="labelSets.length === 0">
17
+ <div v-if="labelSetsFilteredForAnnotationSetCreation.length === 0">
21
18
  <p v-html="$t('no_multi_ann_labelset_model')" />
22
19
  </div>
23
20
  <div v-else>
@@ -27,7 +24,7 @@
27
24
 
28
25
  <div class="label-set-list">
29
26
  <div
30
- v-for="labelSetItem in labelSets"
27
+ v-for="labelSetItem in labelSetsFilteredForAnnotationSetCreation"
31
28
  :key="labelSetItem.id"
32
29
  class="label-set-list-row"
33
30
  >
@@ -71,32 +68,20 @@
71
68
  * This component shows a modal to choose a label set from the project
72
69
  */
73
70
 
74
- import { mapGetters, mapState } from "vuex";
71
+ import { mapGetters } from "vuex";
75
72
 
76
73
  export default {
77
74
  name: "CreateAnnotationSetModal",
78
75
  data() {
79
76
  return {
80
- labelSets: [],
81
77
  show: true,
82
78
  labels: [],
83
- loading: true,
84
79
  };
85
80
  },
86
81
  computed: {
87
- ...mapState("document", ["annotationSets"]),
88
82
  ...mapGetters("project", ["labelSetsFilteredForAnnotationSetCreation"]),
89
83
  ...mapGetters("document", ["numberOfLabelSetGroup"]),
90
84
  },
91
- mounted() {
92
- this.$store.dispatch("project/fetchLabelSets").then((data) => {
93
- this.labelSets = this.labelSetsFilteredForAnnotationSetCreation(
94
- data,
95
- this.annotationSets
96
- );
97
- this.loading = false;
98
- });
99
- },
100
85
  methods: {
101
86
  submit(labelSet) {
102
87
  this.$emit("finish", labelSet);
@@ -19,13 +19,45 @@
19
19
  </div>
20
20
  </div>
21
21
 
22
- <!-- When there's no annotation sets -->
22
+ <!-- When there's no annotation sets but show label sets for annotation creation-->
23
23
  <div
24
24
  v-else-if="
25
25
  getAnnotationsFiltered.annotationSets.length === 0 &&
26
+ labelSets &&
27
+ labelSets.length > 0 &&
26
28
  !isSearchingAnnotationList
27
29
  "
28
30
  class="empty-annotation-sets"
31
+ >
32
+ <div class="annotation-set-list">
33
+ <div
34
+ v-for="labelSet in labelSets"
35
+ :key="labelSet.id"
36
+ class="annotation-set-group"
37
+ >
38
+ <div class="label-set-header">
39
+ <div class="label-set-name">
40
+ {{ `${labelSet.name}` }}
41
+ </div>
42
+ </div>
43
+
44
+ <div v-if="labelSet.labels.length > 0">
45
+ <div v-for="label in labelSet.labels" :key="label.id">
46
+ <div class="labels">
47
+ <DocumentLabel :label="label" :label-set="labelSet" />
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ </div>
54
+ <div
55
+ v-else-if="
56
+ getAnnotationsFiltered.annotationSets.length === 0 &&
57
+ !isSearchingAnnotationList &&
58
+ (!labelSets || labelSets.length === 0)
59
+ "
60
+ class="empty-annotation-sets"
29
61
  >
30
62
  <EmptyState />
31
63
  </div>
@@ -119,6 +151,7 @@
119
151
  <DocumentLabel
120
152
  :label="label"
121
153
  :annotation-set="annotationSet"
154
+ :label-set="annotationSet.label_set"
122
155
  :index-group="indexGroup"
123
156
  @handle-missing-annotation="markAnnotationsAsMissing"
124
157
  />
@@ -203,6 +236,7 @@ export default {
203
236
  "selectedDocument",
204
237
  "splittingSuggestions",
205
238
  ]),
239
+ ...mapState("project", ["labelSets"]),
206
240
  ...mapGetters("document", [
207
241
  "numberOfAnnotationSetGroup",
208
242
  "getAnnotationsFiltered",
@@ -570,7 +604,11 @@ export default {
570
604
  annotation_set: annotationSet,
571
605
  },
572
606
  ];
573
- } else if (this.editAnnotation && this.editAnnotation.id !== null) {
607
+ } else if (
608
+ this.editAnnotation &&
609
+ this.editAnnotation.id !== null &&
610
+ this.editAnnotation.annotationSet
611
+ ) {
574
612
  // if annotation is marked as missing from "delete" key
575
613
 
576
614
  missing = [
@@ -29,32 +29,41 @@
29
29
  </div>
30
30
  </div>
31
31
  </div>
32
- <div v-if="showAnnotationsGroup" class="label-group-annotation-list">
32
+ <div
33
+ v-if="annotationSet && showAnnotationsGroup"
34
+ class="label-group-annotation-list"
35
+ >
33
36
  <AnnotationRow
34
37
  v-for="annotation in label.annotations"
35
38
  :key="annotation.id"
36
39
  :annotation="annotation"
37
40
  :label="label"
38
41
  :annotation-set="annotationSet"
42
+ :label-set="annotationSet.label_set"
39
43
  />
40
44
  </div>
41
45
  </div>
42
- <div v-else-if="hasAnnotations">
46
+ <div v-else-if="annotationSet && hasAnnotations">
43
47
  <AnnotationRow
44
48
  v-for="annotation in label.annotations"
45
49
  :key="annotation.id"
46
50
  :annotation="annotation"
47
51
  :label="label"
48
52
  :annotation-set="annotationSet"
53
+ :label-set="annotationSet.label_set"
49
54
  />
50
55
  </div>
51
- <div v-else>
56
+ <div v-else-if="annotationSet">
52
57
  <AnnotationRow
53
58
  :annotation="singleAnnotation"
54
59
  :label="label"
55
60
  :annotation-set="annotationSet"
61
+ :label-set="annotationSet.label_set"
56
62
  />
57
63
  </div>
64
+ <div v-else-if="labelSet">
65
+ <AnnotationRow :label="label" :label-set="labelSet" />
66
+ </div>
58
67
  </div>
59
68
  </template>
60
69
  <script>
@@ -73,6 +82,10 @@ export default {
73
82
  required: true,
74
83
  },
75
84
  annotationSet: {
85
+ type: Object,
86
+ default: null,
87
+ },
88
+ labelSet: {
76
89
  type: Object,
77
90
  required: true,
78
91
  },
@@ -93,13 +106,13 @@ export default {
93
106
  ]),
94
107
  ...mapGetters("document", ["numberOfAcceptedAnnotationsInLabel"]),
95
108
  singleAnnotation() {
96
- if (this.label.annotations.length > 0) {
109
+ if (this.label.annotations && this.label.annotations.length > 0) {
97
110
  return this.label.annotations[0];
98
111
  }
99
112
  return null;
100
113
  },
101
114
  hasAnnotations() {
102
- return this.label.annotations.length > 0;
115
+ return this.label.annotations && this.label.annotations.length > 0;
103
116
  },
104
117
  },
105
118
  watch: {
@@ -159,6 +172,7 @@ export default {
159
172
  updateValues() {
160
173
  // more than 1 Annotation extracted for a non multiple Label
161
174
  this.nonMultipleAnnotationsExtracted =
175
+ this.label.annotations &&
162
176
  this.label.annotations.length > 1 &&
163
177
  !this.label.has_multiple_top_candidates;
164
178
 
@@ -55,6 +55,10 @@ export default {
55
55
  required: true,
56
56
  },
57
57
  annotationSet: {
58
+ type: Object,
59
+ default: null,
60
+ },
61
+ labelSet: {
58
62
  type: Object,
59
63
  required: true,
60
64
  },
@@ -118,13 +122,10 @@ export default {
118
122
 
119
123
  methods: {
120
124
  emptyAnnotationId() {
121
- if (!this.annotationSet || !this.label) return;
125
+ if ((!this.annotationSet && !this.labelSet) || !this.label) return;
122
126
 
123
- if (this.annotationSet.id) {
124
- return `${this.annotationSet.id}_${this.label.id}`;
125
- } else {
126
- return `${this.annotationSet.label_set.id}_${this.label.id}`;
127
- }
127
+ const id = this.annotationSet ? this.annotationSet.id : this.labelSet.id;
128
+ return `${id}_${this.label.id}`;
128
129
  },
129
130
  isAnnotationBeingEdited() {
130
131
  return this.isAnnotationInEditMode(this.emptyAnnotationId());
@@ -148,12 +149,11 @@ export default {
148
149
  "selection/selectElement",
149
150
  this.emptyAnnotationId()
150
151
  );
151
-
152
152
  this.$store.dispatch("document/setEditAnnotation", {
153
153
  id: this.emptyAnnotationId(),
154
154
  index: this.spanIndex,
155
155
  label: this.label,
156
- labelSet: this.annotationSet.label_set,
156
+ labelSet: this.labelSet,
157
157
  annotationSet: this.annotationSet,
158
158
  });
159
159
  }
@@ -301,13 +301,15 @@ const getters = {
301
301
  let processedAnnotationSets = [];
302
302
  let processedLabels = [];
303
303
 
304
+ const isSearching = state.annotationSearch.length > 0;
305
+
304
306
  // search feature
305
307
  const addAnnotation = (listToAdd, annotation, force) => {
306
308
  if (force) {
307
309
  listToAdd.push(annotation);
308
310
  return true;
309
311
  }
310
- if (state.annotationSearch.length > 0) {
312
+ if (isSearching) {
311
313
  if (
312
314
  annotation.offset_string &&
313
315
  state.annotationSearch.find((search) =>
@@ -333,7 +335,7 @@ const getters = {
333
335
  };
334
336
 
335
337
  const labelHasSearchText = (label) => {
336
- if (state.annotationSearch.length > 0) {
338
+ if (isSearching) {
337
339
  if (
338
340
  label.name &&
339
341
  state.annotationSearch.find((search) =>
@@ -356,7 +358,10 @@ const getters = {
356
358
  let addLabel = false;
357
359
  const labelHasSearch = labelHasSearchText(label);
358
360
  if (!label.annotations || label.annotations.length === 0) {
359
- if (state.annotationFilters.showEmpty) {
361
+ if (
362
+ state.annotationFilters.showEmpty &&
363
+ (!isSearching || labelHasSearch)
364
+ ) {
360
365
  addLabel = true;
361
366
  }
362
367
  } else if (
@@ -627,17 +632,20 @@ const getters = {
627
632
  annotationIsNotFound: (state) => (annotationSet, label) => {
628
633
  // Check if the combined label and label set have been marked as missing
629
634
  // or if the document is in public mode
630
- if (state.missingAnnotations.length === 0) {
631
- return false;
632
- } else {
633
- const found = state.missingAnnotations.filter(
634
- (el) =>
635
- el.label === label.id &&
636
- el.annotation_set === annotationSet.id &&
637
- el.label_set === annotationSet.label_set.id
638
- );
639
- return found.length !== 0;
635
+ if (annotationSet) {
636
+ if (state.missingAnnotations.length === 0) {
637
+ return false;
638
+ } else {
639
+ const found = state.missingAnnotations.filter(
640
+ (el) =>
641
+ el.label === label.id &&
642
+ el.annotation_set === annotationSet.id &&
643
+ el.label_set === annotationSet.label_set.id
644
+ );
645
+ return found.length !== 0;
646
+ }
640
647
  }
648
+ return false;
641
649
  },
642
650
 
643
651
  isAnnotationInAnnotationSet: (state) => (annotationSet, annotationId) => {
@@ -1063,6 +1071,10 @@ const actions = {
1063
1071
  if (!state.publicView) {
1064
1072
  await dispatch("fetchMissingAnnotations");
1065
1073
 
1074
+ await dispatch("project/fetchLabelSets", null, {
1075
+ root: true,
1076
+ });
1077
+
1066
1078
  await dispatch("project/fetchCurrentUser", null, {
1067
1079
  root: true,
1068
1080
  });
@@ -1280,9 +1292,7 @@ const actions = {
1280
1292
 
1281
1293
  fetchMissingAnnotations: ({ commit, state, getters }) => {
1282
1294
  return new Promise((resolve, reject) => {
1283
- return HTTP.get(
1284
- `/missing-annotations/?document=${state.documentId}`
1285
- )
1295
+ return HTTP.get(`/missing-annotations/?document=${state.documentId}`)
1286
1296
  .then((response) => {
1287
1297
  commit("SET_MISSING_ANNOTATIONS", response.data.results);
1288
1298
  resolve(true);
@@ -3,6 +3,7 @@ const HTTP = myImports.HTTP;
3
3
 
4
4
  const state = {
5
5
  projectId: null,
6
+ labelSets: null,
6
7
  currentUser: null,
7
8
  documentsListPath: null,
8
9
  documentsInProject: null,
@@ -13,24 +14,25 @@ const getters = {
13
14
  /**
14
15
  * Gets label sets for an annotation set creation
15
16
  */
16
- labelSetsFilteredForAnnotationSetCreation:
17
- (state) => (labelsSet, annotationSets) => {
18
- let returnLabels = [];
19
- if (labelsSet) {
20
- returnLabels = labelsSet.filter((labelSet) => {
21
- // check if label set has multiple and if not, if there's already an annotation set created
22
- if (!labelSet.has_multiple_annotation_sets) {
23
- const existingAnnotationSet = annotationSets.find((annSet) => {
17
+ labelSetsFilteredForAnnotationSetCreation: (state, _, rootState) => {
18
+ let returnLabels = [];
19
+ if (state.labelSets) {
20
+ returnLabels = state.labelSets.filter((labelSet) => {
21
+ // check if label set has multiple and if not, if there's already an annotation set created
22
+ if (!labelSet.has_multiple_annotation_sets) {
23
+ const existingAnnotationSet = rootState.document.annotationSets.find(
24
+ (annSet) => {
24
25
  return annSet.label_set.id === labelSet.id;
25
- });
26
- return !existingAnnotationSet;
27
- } else {
28
- return true;
29
- }
30
- });
31
- }
32
- return returnLabels;
33
- },
26
+ }
27
+ );
28
+ return !existingAnnotationSet;
29
+ } else {
30
+ return true;
31
+ }
32
+ });
33
+ }
34
+ return returnLabels;
35
+ },
34
36
  };
35
37
 
36
38
  const actions = {
@@ -52,17 +54,14 @@ const actions = {
52
54
  },
53
55
 
54
56
  // Get label sets from the project
55
- fetchLabelSets: ({ state }) => {
56
- return new Promise((resolve, reject) => {
57
- HTTP.get(`label-sets/?project=${state.projectId}`)
58
- .then((response) => {
59
- return resolve(response.data.results);
60
- })
61
- .catch((error) => {
62
- reject(error);
63
- console.log(error);
64
- });
65
- });
57
+ fetchLabelSets: ({ commit, state }) => {
58
+ return HTTP.get(`label-sets/?project=${state.projectId}`)
59
+ .then((response) => {
60
+ commit("SET_LABEL_SETS", response.data.results);
61
+ })
62
+ .catch((error) => {
63
+ console.log(error);
64
+ });
66
65
  },
67
66
 
68
67
  fetchCurrentUser: ({ commit }) => {
@@ -113,6 +112,9 @@ const mutations = {
113
112
  SET_CURRENT_USER: (state, currentUser) => {
114
113
  state.currentUser = currentUser;
115
114
  },
115
+ SET_LABEL_SETS: (state, labelSets) => {
116
+ state.labelSets = labelSets;
117
+ },
116
118
  SET_DOCUMENTS_LIST_PATH: (state, path) => {
117
119
  state.documentsListPath = path;
118
120
  },