-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboo.html
179 lines (152 loc) · 6.27 KB
/
boo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<html lang="en">
<head>
<title>ARMOURY/CENTRIC SUPER DUPER MAGICAL COMPARATOR</title>
<script src="https://cdn.jsdelivr.net/npm/ag-grid-community/dist/ag-grid-community.min.js"></script>
<script src="https://unpkg.com/[email protected]/bundle/read-excel-file.min.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="flex flex-col h-screen">
<div id="app">
<div class="mb-4 px-8 py-6 border-b relative">
<h1 class="text-3xl font-black mb-2">ARMOURY/CENTRIC SUPER DUPER MAGICAL COMPARATOR</h1>
<div>
Made with ❤️ by Husband.
</div>
<div class="mt-4">
<div class="border inline-block p-2 mr-2"> <input type="file" ref="file" /></div>
<a class="bg-blue-600 text-white p-3 rounded-full text-sm font-bold px-6 cursor-pointer" @click="onCompare">WOW Magic buttan</a>
</div>
<div class="w-48 absolute bottom-0 right-2">
<img src="https://media0.giphy.com/media/v1.Y2lkPTc5MGI3NjExaGZhb2xneGZ2cm9ibXVoejduYWY0ZnF2MTRlbmI3bXVpM3Q1a281aSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/IBFvMzgB6fFmysKsmP/giphy.webp" />
</div>
</div>
</div>
<div class="px-4 mb-4 font-semibold">
<i>Values shown below are from Armoury.</i>
<div class="items-center inline-block ml-8 font-normal">
Centric Action:
<div class="h-3 w-3 bg-red-300 ml-4 mr-1 inline-block"></div> Delete
<div class="h-3 w-3 bg-yellow-300 ml-4 mr-1 inline-block"></div> Update
<div class="h-3 w-3 bg-green-300 ml-4 mr-1 inline-block"></div> Add
<div class="h-3 w-3 bg-purple-400 ml-4 mr-1 inline-block"></div> Duplicate
</div>
</div>
<div id="myGrid" class="ag-theme-material flex-1"></div>
</div>
<script>
const myGridElement = document.querySelector('#myGrid');
const grid = agGrid.createGrid(myGridElement, {});
grid.hideOverlay()
</script>
<script type="module">
import { createApp } from 'https://unpkg.com/petite-vue?module'
const numberToFraction = function (amount) {
// This is a whole number and doesn't need modification.
if (parseFloat(amount) === parseInt(amount)) {
return amount;
}
// Next 12 lines are cribbed from https://stackoverflow.com/a/23575406.
var gcd = function (a, b) {
if (b < 0.0000001) {
return a;
}
return gcd(b, Math.floor(a % b));
};
var len = amount.toString().length - 2;
var denominator = Math.pow(10, len);
var numerator = amount * denominator;
var divisor = gcd(numerator, denominator);
numerator /= divisor;
denominator /= divisor;
var base = 0;
// In a scenario like 3/2, convert to 1 1/2
// by pulling out the base number and reducing the numerator.
if (numerator > denominator) {
base = Math.floor(numerator / denominator);
numerator -= base * denominator;
}
amount = Math.floor(numerator) + '/' + Math.floor(denominator);
if (base) {
amount = base + ' ' + amount;
}
return amount;
};
const cellStyleComp = (params) => {
if (params.data.duplicates?.includes(params.colDef.field)) return { backgroundColor: '#C084FC' }
if (params.data.yellow?.includes(params.colDef.field)) return { backgroundColor: '#FDE047' }
if (params.data.green?.includes(params.colDef.field)) return { backgroundColor: '#86EFAC' }
if (params.data.red?.includes(params.colDef.field)) return { backgroundColor: '#FCA5A5' }
return null
}
const COLUMN_DEFS = [
{ "field": "Index", width: 100, cellStyle: { "background-color": "#fafafa" }, pinned: true },
{ "field": "Name", width: 100, cellStyle: { "background-color": "#fafafa" }, pinned: true },
{ "field": "Description", width: 320, cellStyle: cellStyleComp },
{ "field": "Tol(+)", "width": 100, cellStyle: cellStyleComp },
{ "field": "Tol(-)", "width": 100, cellStyle: cellStyleComp },
{ "field": "XS", "width": 100, cellStyle: cellStyleComp },
{ "field": "SM", "width": 100, cellStyle: cellStyleComp },
{ "field": "MD", "width": 100, cellStyle: cellStyleComp },
{ "field": "LG", "width": 100, cellStyle: cellStyleComp },
{ "field": "XL", "width": 100, cellStyle: cellStyleComp },
{ "field": "XXL", "width": 100, cellStyle: cellStyleComp }
]
createApp({
async onCompare() {
const file = this.$refs['file'].files[0]
this.compare(
await readXlsxFile(file, { sheet: 1 }),
await readXlsxFile(file, { sheet: 2 })
)
},
transformArr(arr) {
const header = arr[0]
return arr.slice(1).map((row, idx) => {
const obj = {
Index: idx + 1
}
row.forEach((cell, idx) => {
obj[header[idx]] = idx > 1 ? Math.abs(parseFloat(eval(cell.toString()))) : cell.toString()
})
return obj
})
},
compare(armoury, centric) {
const armouryRows = this.transformArr(armoury)
const centricRows = this.transformArr(centric)
const header = armoury[0]
const tableRows = []
armouryRows.forEach((x) => {
const aRows = armouryRows.filter((a) => a.Name === x.Name)
const aIdx = aRows.findIndex((ar) => ar.Index === x.Index)
const c = centricRows.filter((c) => c.Name === x.Name)[aIdx]
const row = JSON.parse(JSON.stringify(x))
if (c) {
header.forEach((h) => {
if (x[h] !== c[h]) {
row.yellow = row.yellow || []
row.yellow.push(h)
}
row[h] = isNaN(x[h]) ? x[h].toString() : numberToFraction(x[h]).toString()
})
}
else row.green = header.slice()
if (aRows.length > 1) row.duplicates = header.slice()
tableRows.push(row)
})
centricRows.forEach((x) => {
const a = armouryRows.find((a) => a.Name === x.Name)
const row = JSON.parse(JSON.stringify(x))
if (!a) {
row.red = header.slice()
tableRows.push(row)
}
})
grid.setGridOption('columnDefs', COLUMN_DEFS)
grid.setGridOption('rowData', tableRows)
}
}).mount('#app')
</script>
</body>
</html>