|
47 | 47 | <script> |
48 | 48 | const barcodeScannerView = document.querySelector(".barcode-reader-view"); |
49 | 49 | const summaryView = document.querySelector(".summary-view"); |
| 50 | + const finishBtn = document.querySelector(".finish-btn"); |
50 | 51 | const backBtn = document.querySelector(".icon-back"); |
| 52 | + let totalUniqueBarcodesResult = {}; |
51 | 53 | let totalUniqueBarcodesCount = 0; |
52 | 54 |
|
53 | 55 | const launchBarcodeScanenr = () => { |
|
69 | 71 | document.querySelector(".total-count-in-this-session .count").innerText = result.barcodeResults.length; |
70 | 72 | document.querySelector(".time").innerText = getDurationTime(startTime); |
71 | 73 | readerResultList(result); |
72 | | - console.log(result); |
| 74 | + console.log("Current Scan Session Result: ", result); |
73 | 75 | }) |
74 | 76 | } |
75 | 77 |
|
|
78 | 80 | const readerResultList = (result) => { |
79 | 81 | const resultListNode = document.querySelector(".result-list"); |
80 | 82 | resultListNode.innerText = ""; |
81 | | - for (let i = 0; i < result.barcodeResults.length; i++) { |
82 | | - const item = result.barcodeResults[i]; |
| 83 | + const countResult = countByFormat(result.barcodeResults); |
| 84 | + for (let formatString in countResult) { |
83 | 85 | const itemLi = document.createElement("li"); |
84 | 86 | const itemFormatSpan = document.createElement("span"); |
85 | 87 | const itemCountSpan = document.createElement("span"); |
86 | 88 | itemFormatSpan.className = "format"; |
87 | 89 | itemCountSpan.className = "decode-count"; |
88 | | - itemFormatSpan.innerText = item.formatString; |
89 | | - itemCountSpan.innerText = item.count; |
| 90 | + itemFormatSpan.innerText = formatString; |
| 91 | + itemCountSpan.innerText = countResult[formatString]; |
90 | 92 | itemLi.append(itemFormatSpan, itemCountSpan); |
91 | 93 | resultListNode.append(itemLi); |
92 | 94 | } |
93 | 95 | } |
94 | 96 |
|
| 97 | + const countByFormat = (items) => { |
| 98 | + const result = {}; |
| 99 | + for (let i = 0; i < items.length; i++) { |
| 100 | + const item = items[i]; |
| 101 | + if (!result.hasOwnProperty(item.formatString)) { |
| 102 | + result[item.formatString] = 1; |
| 103 | + } else { |
| 104 | + result[item.formatString]++; |
| 105 | + } |
| 106 | + } |
| 107 | + mergeResult(result); |
| 108 | + console.log("Total Unique Barcodes Result: ", totalUniqueBarcodesResult); |
| 109 | + return result; |
| 110 | + } |
| 111 | + |
| 112 | + const mergeResult = (newResult) => { |
| 113 | + for (let formatString in newResult) { |
| 114 | + if(!totalUniqueBarcodesResult.hasOwnProperty(formatString)) { |
| 115 | + totalUniqueBarcodesResult[formatString] = newResult[formatString]; |
| 116 | + } else { |
| 117 | + totalUniqueBarcodesResult[formatString] += newResult[formatString]; |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + |
95 | 122 | const getDurationTime = (time) => { |
96 | 123 | const now = new Date(); |
97 | 124 | const startDate = new Date(time); |
|
0 commit comments