@konfuzio/document-validation-ui 0.1.5-automatic-document-splitting-2 → 0.1.5-pre-release-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.
Files changed (38) hide show
  1. package/dist/css/app.css +1 -1
  2. package/dist/index.html +1 -1
  3. package/dist/js/app.js +1 -1
  4. package/dist/js/app.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/assets/images/ServerImage.vue +2 -2
  7. package/src/assets/images/SplitZigZag.vue +14 -47
  8. package/src/assets/scss/document_category.scss +1 -0
  9. package/src/assets/scss/document_dashboard.scss +0 -6
  10. package/src/assets/scss/document_edit.scss +46 -131
  11. package/src/assets/scss/document_top_bar.scss +1 -1
  12. package/src/assets/scss/variables.scss +3 -63
  13. package/src/components/DocumentAnnotations/AnnotationContent.vue +1 -1
  14. package/src/components/DocumentAnnotations/CategorizeModal.vue +2 -22
  15. package/src/components/DocumentAnnotations/DocumentAnnotations.vue +3 -11
  16. package/src/components/DocumentCategory.vue +5 -13
  17. package/src/components/DocumentDashboard.vue +6 -17
  18. package/src/components/DocumentEdit/DocumentEdit.vue +69 -207
  19. package/src/components/DocumentEdit/EditPages.vue +18 -29
  20. package/src/components/DocumentEdit/EditSidebar.vue +45 -95
  21. package/src/components/DocumentEdit/SplitOverview.vue +5 -4
  22. package/src/components/{DocumentModals/DocumentErrorModal.vue → DocumentError.vue} +4 -3
  23. package/src/components/DocumentPage/ScrollingDocument.vue +2 -2
  24. package/src/components/DocumentTopBar/DocumentTopBarButtons.vue +20 -6
  25. package/src/components/{DocumentModals/NotOptimizedViewportModal.vue → NotOptimizedViewportModal.vue} +2 -2
  26. package/src/locales/de.json +2 -15
  27. package/src/locales/en.json +1 -15
  28. package/src/locales/es.json +1 -14
  29. package/src/store/document.js +19 -49
  30. package/src/store/edit.js +48 -66
  31. package/src/store/project.js +14 -14
  32. package/src/assets/images/MagicWandIcon.vue +0 -16
  33. package/src/assets/images/StarIcon.vue +0 -16
  34. package/src/assets/scss/splitting_confirmation_modal.scss +0 -41
  35. package/src/components/DocumentEdit/EditConfirmationModal.vue +0 -54
  36. package/src/components/DocumentEdit/SidebarButtons.vue +0 -53
  37. package/src/components/DocumentEdit/SplitInfoBar.vue +0 -19
  38. package/src/components/DocumentModals/SplittingSuggestionsModal.vue +0 -121
@@ -2,16 +2,12 @@
2
2
  <div :class="['document-edit', splitOverview && 'split-overview-component']">
3
3
  <div v-if="!splitOverview" class="pages-section">
4
4
  <EditPages
5
- :splitting-lines="splittingLines"
6
- :split-suggestions-enabled="splitSuggestionsEnabled"
5
+ :active-splitting-lines="activeSplittingLines"
7
6
  @change-page="changePage"
8
7
  @handle-splitting-lines="handleSplittingLines"
9
8
  @check-move="checkMove"
10
9
  @handle-drag-end="handleDragEnd"
11
10
  />
12
- <div class="info-bar">
13
- <SplitInfoBar v-if="splitSuggestionsEnabled" />
14
- </div>
15
11
  </div>
16
12
  <div v-else class="split-overview-section">
17
13
  <SplitOverview
@@ -26,13 +22,8 @@
26
22
  @rotate-right="rotatePage"
27
23
  @rotate-all-left="handleRotationsToTheLeft"
28
24
  @rotate-all-right="handleRotationsToTheRight"
29
- @handle-splitting-suggestions="applySplittingSuggestions"
30
- :split-suggestions-enabled="splitSuggestionsEnabled"
31
25
  />
32
26
  </div>
33
- <div class="confirmation-modal-container">
34
- <EditConfirmationModal @save-changes="saveEditChanges" />
35
- </div>
36
27
  </div>
37
28
  </template>
38
29
  <script>
@@ -40,8 +31,6 @@ import { mapState } from "vuex";
40
31
  import EditSidebar from "./EditSidebar";
41
32
  import SplitOverview from "./SplitOverview";
42
33
  import EditPages from "./EditPages";
43
- import SplitInfoBar from "./SplitInfoBar";
44
- import EditConfirmationModal from "./EditConfirmationModal";
45
34
 
46
35
  /**
47
36
  * This component shows a document thumbnail grid view and sidebar, to be able to edit the document.
@@ -52,29 +41,22 @@ export default {
52
41
  EditSidebar,
53
42
  SplitOverview,
54
43
  EditPages,
55
- SplitInfoBar,
56
- EditConfirmationModal,
57
44
  },
58
45
  data() {
59
46
  return {
60
- fileName: null,
47
+ fileName: [],
61
48
  fileExtension: null,
62
- splittingLines: [],
49
+ activeSplittingLines: [],
63
50
  dragging: false,
64
51
  prevPageAtIndex: null,
65
- splitSuggestionsEnabled: false,
66
52
  };
67
53
  },
68
54
  computed: {
69
- ...mapState("document", [
70
- "recalculatingAnnotations",
71
- "selectedDocument",
72
- "splittingSuggestions",
73
- ]),
55
+ ...mapState("document", ["recalculatingAnnotations", "selectedDocument"]),
74
56
  ...mapState("display", ["currentPage"]),
75
57
  ...mapState("edit", [
76
58
  "editMode",
77
- "pagesForPostprocess",
59
+ "documentPagesListForEditMode",
78
60
  "updatedDocument",
79
61
  "splitOverview",
80
62
  "selectedPages",
@@ -83,7 +65,6 @@ export default {
83
65
  watch: {
84
66
  pages() {
85
67
  if (!this.selectedDocument) return;
86
-
87
68
  this.setPages();
88
69
  },
89
70
  splitOverview(newValue) {
@@ -91,18 +72,9 @@ export default {
91
72
  this.splitFileNameFromExtension();
92
73
  }
93
74
  },
94
- pagesForPostprocess(newValue) {
75
+ documentPagesListForEditMode(newValue) {
95
76
  if (newValue) {
96
- this.saveUpdatedDocuments();
97
- }
98
- },
99
- splittingLines(newValue) {
100
- const aiSplit = newValue.find((item) => item.origin === "AI");
101
-
102
- // If there are no AI suggestions left, because of being manually removed by the user
103
- // the Smart Split switch should be turned off
104
- if (!aiSplit) {
105
- this.splitSuggestionsEnabled = false;
77
+ this.saveUpdatedDocument();
106
78
  }
107
79
  },
108
80
  },
@@ -114,30 +86,16 @@ export default {
114
86
  if (!this.selectedDocument) {
115
87
  return;
116
88
  }
117
-
118
- // set array of pages only with the data we need for postprocessing the document
119
- this.$store.dispatch(
120
- "edit/setPagesForPostprocess",
121
- this.createPagesForPostprocess()
89
+ // set array of pages only with the data we need
90
+ const pages = this.createDocumentPagesListForEditMode();
91
+ this.$store.dispatch("edit/setDocumentPagesListForEditMode", pages);
92
+ // create array to handle the splitting
93
+ // length - 1 because of how many lines to split we need (last one not necessary)
94
+ this.activeSplittingLines = new Array(
95
+ this.selectedDocument.pages.length - 1
122
96
  );
123
-
124
- // Create array with placeholder data for the splitting points
125
- if (this.selectedDocument.pages.length > 0) {
126
- this.selectedDocument.pages.map((page) => {
127
- if (page.number === this.selectedDocument.pages.length) {
128
- this.setSplittingArray(page.number, null);
129
- return;
130
- }
131
- this.setSplittingArray(0, null);
132
- });
133
-
134
- if (this.splittingSuggestions) {
135
- this.splitSuggestionsEnabled = true;
136
- this.setAutomaticSplitting();
137
- }
138
- }
139
97
  },
140
- createPagesForPostprocess() {
98
+ createDocumentPagesListForEditMode() {
141
99
  return this.selectedDocument.pages.map((page) => {
142
100
  return {
143
101
  id: page.id,
@@ -179,44 +137,12 @@ export default {
179
137
  },
180
138
 
181
139
  /** SPLIT */
182
- setAutomaticSplitting() {
183
- // map over splitting suggestions to find the page number based on the page id
184
- // to update the splittingLines array with this data
185
-
186
- this.splittingSuggestions.map((item) => {
187
- const firstPage = this.selectedDocument.pages.find(
188
- (page) => page.id === item.pages[0].id
189
- );
190
-
191
- if (firstPage.number === 1) {
192
- // only add the active splitting line from the 1st page of the second document
193
- // since it's the first splitting point
194
- return;
195
- }
196
-
197
- this.handleSplittingLines(firstPage.number, "AI");
198
- });
199
- },
200
- applySplittingSuggestions(value) {
201
- // Show information bar
202
- this.splitSuggestionsEnabled = value;
203
-
204
- // Apply or remove split lines
205
- this.setAutomaticSplitting();
206
- },
207
- setSplittingArray(pageNumber, splittingOrigin) {
208
- // This function sets the splittingLines array
209
- // based on splitting suggestions or no suggestions
210
- this.splittingLines.push({
211
- page: pageNumber,
212
- origin: splittingOrigin,
213
- });
214
- },
215
140
  splitFileNameFromExtension() {
216
141
  if (!this.selectedDocument) return;
217
142
 
218
143
  // Save the file name and the extension in different variables
219
144
  // to be used in the next step of the splitting
145
+
220
146
  if (this.selectedDocument.data_file_name) {
221
147
  this.fileName = this.selectedDocument.data_file_name
222
148
  .split(".")
@@ -230,76 +156,57 @@ export default {
230
156
  .at(-1);
231
157
  }
232
158
  },
233
- handleSplittingLines(page, origin) {
234
- // To select and deselect the division lines
235
- // Add page number & origin to specific index
236
- // Or replace it with 0 (to keep the same index & array length) if it exists
237
- const found = this.splittingLines.find((item) => item.page === page);
238
-
239
- // new line added or removed based on the page clicked:
240
- const newPage = { page: page, origin: origin };
241
- const removedPage = { page: 0, origin: origin };
242
-
243
- if (
244
- page === this.splittingLines.length ||
245
- (!this.splitSuggestionsEnabled && !found && origin === "AI")
246
- ) {
247
- // check if it's the last item to keep unchanged
248
- // Or if splitting is switched off, but some of the suggestion lines
249
- // were removed manually
250
- return;
251
- } else if (this.splitSuggestionsEnabled && origin === "AI") {
252
- // if manual suggestions were added but we enable automatic splitting,
253
- // this last one takes over
254
- this.splittingLines.splice(page - 1, 1, newPage);
255
- } else if (found) {
256
- // If splitting is switched off and we have manual splits,
257
- // those should stay unchanged
258
- if (!this.splitSuggestionsEnabled && found.origin !== origin) {
259
- return;
260
- }
159
+ handleSplittingLines(page) {
160
+ // For splitting line purposes
161
+ // Add page number to specific index
162
+ // Or replace it with 0 (to keep the same index) if it exists
163
+ const found = this.activeSplittingLines.find(
164
+ (item) => item === page.number
165
+ );
261
166
 
262
- this.splittingLines.splice(page - 1, 1, removedPage);
167
+ if (found) {
168
+ this.activeSplittingLines.splice(page.number - 1, 1, 0);
263
169
  } else {
264
- this.splittingLines.splice(page - 1, 1, newPage);
170
+ this.activeSplittingLines.splice(page.number - 1, 1, page.number);
265
171
  }
266
172
 
267
- this.saveUpdatedDocuments();
173
+ this.saveUpdatedDocument();
268
174
  },
269
- saveUpdatedDocuments() {
175
+ saveUpdatedDocument() {
270
176
  this.splitFileNameFromExtension();
271
177
 
272
- const clickedLines = this.splittingLines.filter(
273
- (item) => item.page !== 0
178
+ // Check how many sub docs we have
179
+ const subDocuments = this.activeSplittingLines.filter(
180
+ (item) => item !== 0
274
181
  );
275
182
 
276
- const newDocuments = this.createEachNewDocument(
277
- clickedLines,
278
- clickedLines.length
279
- );
280
-
281
- // // Set the state to the created array
282
- this.$store.dispatch("edit/setUpdatedDocument", newDocuments);
283
- },
284
- createEachNewDocument(clickedLines, length) {
285
- const documents = new Array(length);
286
-
287
- for (let i = 0; i < length; i++) {
288
- const newDocument = {
289
- name: this.handleNewDocumentName(i),
290
- category: this.handleNewDocumentCategory(i, clickedLines),
291
- pages: this.handleNewDocumentPages(i, clickedLines),
183
+ // Create array of objects
184
+ // with a fixed size based on how many sub documents are currently
185
+ const pageObjectArray = new Array(subDocuments.length + 1);
186
+
187
+ // Loop over the created array
188
+ // for each iteration we create the page object with the correponding data
189
+ for (let i = 0; i < pageObjectArray.length; i++) {
190
+ const pageObject = {
191
+ name: this.handleFileName(i),
192
+ category: this.selectedDocument.category,
193
+ pages: this.handleSubPages(i, subDocuments),
292
194
  };
293
195
 
294
- // we replace the "undefined" with the created object
295
- documents.splice(i, 1, newDocument);
196
+ // Then we replace the "undefined" with the created object
197
+ pageObjectArray.splice(i, 1, pageObject);
296
198
  }
297
199
 
298
- return documents;
200
+ // Set the state to the created array
201
+ this.$store.dispatch("edit/setUpdatedDocument", pageObjectArray);
299
202
  },
300
- handleNewDocumentName(index) {
203
+ handleFileName(index) {
301
204
  let newFileName;
302
205
 
206
+ // Return original file name,
207
+ // file name + copy,
208
+ // or file name + copy + number
209
+ // based on where the object will be located in the array
303
210
  if (index === 0) {
304
211
  newFileName = this.selectedDocument.data_file_name;
305
212
  } else if (index === 1) {
@@ -309,95 +216,50 @@ export default {
309
216
  }
310
217
  return newFileName;
311
218
  },
312
- handleNewDocumentCategory(index, clickedLines) {
313
- if (clickedLines[index].origin && clickedLines[index].origin === "AI") {
314
- // get the index of the new document in the splitting suggestions
315
- // to return its category
316
- const i = this.indexOfSplittingSuggestion(index, clickedLines);
317
-
318
- return this.splittingSuggestions[i].category;
319
- } else {
320
- return this.selectedDocument.category;
321
- }
322
- },
323
- handleNewDocumentPages(index, clickedLines) {
324
- // assign the correct pages to each new document
219
+ handleSubPages(index, splittingLine) {
220
+ // assign the correct pages to each object
325
221
  let pages;
326
222
 
327
223
  if (index === 0) {
328
- pages = this.pagesForPostprocess.slice(0, clickedLines[index].page);
224
+ pages = this.documentPagesListForEditMode.slice(
225
+ 0,
226
+ splittingLine[index]
227
+ );
329
228
  } else {
330
- if (!clickedLines[index].page) {
331
- pages = this.pagesForPostprocess.slice(clickedLines[index - 1].page);
229
+ if (!splittingLine[index]) {
230
+ pages = this.documentPagesListForEditMode.slice(
231
+ splittingLine[index - 1]
232
+ );
332
233
  } else {
333
- pages = this.pagesForPostprocess.slice(
334
- clickedLines[index - 1].page,
335
- clickedLines[index].page
234
+ pages = this.documentPagesListForEditMode.slice(
235
+ splittingLine[index - 1],
236
+ splittingLine[index]
336
237
  );
337
238
  }
338
239
  }
339
-
340
240
  return pages;
341
241
  },
342
- indexOfSplittingSuggestion(index, clickedLines) {
343
- const foundPage = this.selectedDocument.pages.find(
344
- (page) => page.number === clickedLines[index].page
345
- );
346
-
347
- const singleSplittingSuggestion = this.splittingSuggestions.find(
348
- (item) => item.pages[0].id === foundPage.id
349
- );
350
-
351
- return this.splittingSuggestions.indexOf(singleSplittingSuggestion);
352
- },
353
242
 
354
243
  /** SORT */
355
244
  checkMove(e) {
356
245
  // Save the page placed originally where the page we are dragging will go
357
- this.prevPageAtIndex = this.pagesForPostprocess.find(
246
+ this.prevPageAtIndex = this.documentPagesListForEditMode.find(
358
247
  (page) =>
359
- this.pagesForPostprocess.indexOf(page) ===
248
+ this.documentPagesListForEditMode.indexOf(page) ===
360
249
  e.draggedContext.futureIndex
361
250
  );
362
251
  },
363
252
  handleDragEnd() {
364
253
  // Update page numbers
365
- const pages = this.pagesForPostprocess.map((page) => {
366
- const index = this.pagesForPostprocess.indexOf(page);
254
+ const pages = this.documentPagesListForEditMode.map((page) => {
255
+ const index = this.documentPagesListForEditMode.indexOf(page);
367
256
  return {
368
257
  ...page,
369
258
  number: index + 1,
370
259
  };
371
260
  });
372
261
 
373
- this.$store.dispatch("edit/setPagesForPostprocess", pages);
374
- },
375
-
376
- /** SUBMIT CHANGES */
377
- // Send update request to the backend
378
- saveEditChanges() {
379
- this.$store
380
- .dispatch("edit/editDocument", this.updatedDocument)
381
- .catch((error) => {
382
- this.$store.dispatch("document/createErrorMessage", {
383
- error,
384
- serverErrorMessage: this.$t("server_error"),
385
- defaultErrorMessage: this.$t("edit_error"),
386
- });
387
- });
388
-
389
- this.closeEditMode();
390
- },
391
-
392
- closeEditMode() {
393
- this.$store.dispatch("edit/disableEditMode");
394
- this.$store.dispatch("edit/setSplitOverview", false);
395
- this.$store.dispatch("edit/setUpdatedDocument", null);
396
- this.$store.dispatch("edit/setSelectedPages", null);
397
- this.$nextTick(() => {
398
- // reset to first page
399
- this.$store.dispatch("display/updateCurrentPage", 1);
400
- });
262
+ this.$store.dispatch("edit/setDocumentPagesListForEditMode", pages);
401
263
  },
402
264
  },
403
265
  };
@@ -48,29 +48,23 @@
48
48
  <div
49
49
  :class="[
50
50
  'splitting-lines',
51
- splittingLines &&
52
- splittingLines[index].page === page.number &&
51
+ activeSplittingLines &&
52
+ activeSplittingLines[index] === page.number &&
53
53
  'active-split',
54
54
  ]"
55
- @click="handleSplittingLines(page.number, 'manual')"
55
+ @click="handleSplittingLines(page)"
56
56
  >
57
57
  <div class="scissors-icon">
58
58
  <b-icon icon="scissors" class="is-small" />
59
59
  </div>
60
60
  <div
61
- v-if="splittingLines && splittingLines[index].page === page.number"
61
+ v-if="
62
+ activeSplittingLines &&
63
+ activeSplittingLines[index] === page.number
64
+ "
62
65
  class="lines"
63
66
  >
64
- <SplitZigZag
65
- :color="
66
- splittingLines &&
67
- splittingLines[index].origin &&
68
- splittingLines[index].origin === 'AI' &&
69
- splitSuggestionsEnabled
70
- ? 'green'
71
- : 'dark'
72
- "
73
- />
67
+ <SplitZigZag />
74
68
  </div>
75
69
  <div v-else class="lines">
76
70
  <SplitLines />
@@ -104,14 +98,10 @@ export default {
104
98
  draggable,
105
99
  },
106
100
  props: {
107
- splittingLines: {
101
+ activeSplittingLines: {
108
102
  type: Array,
109
103
  default: null,
110
104
  },
111
- splitSuggestionsEnabled: {
112
- type: Boolean,
113
- default: false,
114
- },
115
105
  },
116
106
  data() {
117
107
  return {
@@ -119,41 +109,39 @@ export default {
119
109
  selected: null,
120
110
  };
121
111
  },
122
-
123
112
  computed: {
124
113
  ...mapState("document", [
125
114
  "pages",
126
115
  "recalculatingAnnotations",
127
116
  "selectedDocument",
128
- "splittingSuggestions",
129
117
  ]),
130
118
  ...mapState("edit", [
131
119
  "editMode",
132
- "pagesForPostprocess",
120
+ "documentPagesListForEditMode",
133
121
  "splitOverview",
134
122
  "selectedPages",
135
123
  "splitOverview",
136
124
  ]),
137
125
  },
138
126
  watch: {
139
- pagesForPostprocess(newValue, oldValue) {
127
+ documentPagesListForEditMode(newValue, oldValue) {
140
128
  if (newValue !== oldValue) {
141
129
  this.editPages = newValue;
142
130
  }
143
131
  },
144
132
  editPages(newValue, oldValue) {
145
133
  if (newValue !== oldValue) {
146
- this.$store.dispatch("edit/setPagesForPostprocess", newValue);
134
+ this.$store.dispatch("edit/setDocumentPagesListForEditMode", newValue);
147
135
  }
148
136
  },
149
137
  splitOverview(newValue) {
150
138
  if (newValue) {
151
- this.editPages = this.pagesForPostprocess;
139
+ this.editPages = this.documentPagesListForEditMode;
152
140
  }
153
141
  },
154
142
  },
155
143
  mounted() {
156
- this.editPages = this.pagesForPostprocess;
144
+ this.editPages = this.documentPagesListForEditMode;
157
145
  },
158
146
  methods: {
159
147
  handlePageChange(pageNumber) {
@@ -196,10 +184,11 @@ export default {
196
184
  },
197
185
  getRotation(pageId) {
198
186
  // rotate page
199
- return this.pagesForPostprocess?.find((p) => p.id === pageId)?.angle;
187
+ return this.documentPagesListForEditMode?.find((p) => p.id === pageId)
188
+ ?.angle;
200
189
  },
201
- handleSplittingLines(page, origin) {
202
- this.$emit("handle-splitting-lines", page, origin);
190
+ handleSplittingLines(page) {
191
+ this.$emit("handle-splitting-lines", page);
203
192
  },
204
193
  checkMove(event) {
205
194
  this.$emit("check-move", event);