@7365admin1/layer-common 4.13.2-staging.322 → 4.14.0
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/CHANGELOG.md +16 -4
- package/components/DocumentForm.vue +112 -407
- package/components/DocumentManagement.vue +12 -213
- package/components/EntryPass/QrTemplatePreview.vue +25 -21
- package/components/EntryPassInformation.vue +24 -119
- package/components/Facility/BookingSetup.vue +0 -63
- package/components/HidIntercomManagement.vue +43 -193
- package/components/HidReaderUserRoster.vue +2 -32
- package/components/HidUserEnrollment.vue +212 -771
- package/components/InvitationClientForm.vue +1 -19
- package/components/Layout/Header.vue +0 -26
- package/components/VehicleAddSelection.vue +2 -7
- package/components/VehicleManagement.vue +3 -31
- package/components/VisitorManagement.vue +5 -267
- package/composables/useAccessManagement.ts +0 -5
- package/composables/useDocument.ts +0 -7
- package/composables/useFacility.ts +0 -11
- package/composables/useHidAmico.ts +0 -97
- package/composables/useHidNavigation.ts +1 -25
- package/composables/usePeople.ts +0 -19
- package/composables/useVehicle.ts +0 -35
- package/composables/useWebUsb.ts +11 -14
- package/package.json +1 -1
- package/types/document.d.ts +0 -14
- package/types/facility.d.ts +0 -4
- package/types/people.d.ts +1 -4
- package/utils/materialSymbols.ts +0 -3
- package/components/HidProfileQrCode.vue +0 -323
- package/components/NotificationBell.vue +0 -321
- package/components/VehicleBulkAddForm.vue +0 -1392
- package/composables/useNotification.ts +0 -78
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
- package/utils/vehicle-bulk-rows.ts +0 -534
- package/utils/vehicle-bulk-sheet.ts +0 -361
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The spreadsheet a person fills in away from the screen.
|
|
3
|
-
*
|
|
4
|
-
* The bulk whitelist sheet is fastest when the typing has already been done
|
|
5
|
-
* somewhere else - a management office keeps its residents in Excel, not in a
|
|
6
|
-
* browser tab. So there are two halves here:
|
|
7
|
-
*
|
|
8
|
-
* - a TEMPLATE to download: the sheet's own columns, in the sheet's own order,
|
|
9
|
-
* with one example line so nobody has to guess how a block is spelled;
|
|
10
|
-
* - a READER for what comes back, whether it was saved as CSV (what Excel
|
|
11
|
-
* keeps when the template is edited and saved) or as a workbook (.xlsx).
|
|
12
|
-
*
|
|
13
|
-
* The file has to BE the template - the same columns in the same order - so
|
|
14
|
-
* that a row means what it says. Nothing else here judges a row: it turns a
|
|
15
|
-
* file into a grid of text in the sheet's column order; the grid then goes through the same paste path as
|
|
16
|
-
* Ctrl+V, so block, level and unit names are matched to this site's records
|
|
17
|
-
* and anything that matches nothing is left blank and marked red.
|
|
18
|
-
*
|
|
19
|
-
* A text file (CSV, or what Excel keeps when the template is saved) is read
|
|
20
|
-
* with `parsePastedGrid` - the clipboard's own reader, so a pasted block and
|
|
21
|
-
* an uploaded file cannot disagree - and a workbook with `xlsxToGrid` below.
|
|
22
|
-
* `mapUploadedGrid` then puts either one into the sheet's columns.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/** The template's column headings, in the order the sheet shows them. */
|
|
26
|
-
export const BULK_SHEET_HEADINGS = [
|
|
27
|
-
"Block",
|
|
28
|
-
"Level",
|
|
29
|
-
"Unit",
|
|
30
|
-
"NRIC",
|
|
31
|
-
"Full Name",
|
|
32
|
-
"Code",
|
|
33
|
-
"Phone Number",
|
|
34
|
-
"Vehicle No.",
|
|
35
|
-
] as const;
|
|
36
|
-
|
|
37
|
-
/** What each column may be called in a file somebody else made. */
|
|
38
|
-
const HEADING_ALIASES: string[][] = [
|
|
39
|
-
["block", "blk", "block name", "block no", "building"],
|
|
40
|
-
["level", "lvl", "floor", "storey", "level no"],
|
|
41
|
-
["unit", "unit no", "unit number", "house no", "apartment"],
|
|
42
|
-
["nric", "nric fin", "fin", "ic", "ic no", "id no", "identity no"],
|
|
43
|
-
["full name", "name", "owner", "owner name", "resident", "resident name"],
|
|
44
|
-
["code", "country code", "dial code", "dialling code", "idd", "country"],
|
|
45
|
-
[
|
|
46
|
-
"phone number",
|
|
47
|
-
"phone",
|
|
48
|
-
"phone no",
|
|
49
|
-
"mobile",
|
|
50
|
-
"mobile no",
|
|
51
|
-
"contact",
|
|
52
|
-
"contact no",
|
|
53
|
-
"contact number",
|
|
54
|
-
"handphone",
|
|
55
|
-
],
|
|
56
|
-
[
|
|
57
|
-
"vehicle no",
|
|
58
|
-
"vehicle",
|
|
59
|
-
"vehicle number",
|
|
60
|
-
"plate",
|
|
61
|
-
"plate no",
|
|
62
|
-
"plate number",
|
|
63
|
-
"car plate",
|
|
64
|
-
"carplate",
|
|
65
|
-
"iu number",
|
|
66
|
-
],
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
/** Headings compare on their letters and digits only. */
|
|
70
|
-
export function normaliseHeading(value: string): string {
|
|
71
|
-
return String(value ?? "")
|
|
72
|
-
.replace(/^/, "")
|
|
73
|
-
.toLowerCase()
|
|
74
|
-
.replace(/[^a-z0-9]+/g, " ")
|
|
75
|
-
.trim();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Where each of the sheet's columns sits in an uploaded file's header row,
|
|
80
|
-
* or -1 when that file does not carry it.
|
|
81
|
-
*/
|
|
82
|
-
export function headingIndexes(headerRow: string[]): number[] {
|
|
83
|
-
const seen = headerRow.map((cell) => normaliseHeading(cell));
|
|
84
|
-
return HEADING_ALIASES.map((aliases) =>
|
|
85
|
-
seen.findIndex((cell) => cell && aliases.includes(cell)),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function isEmptyLine(cells: string[]): boolean {
|
|
90
|
-
return cells.every((cell) => !String(cell ?? "").trim());
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export type UploadedSheet = {
|
|
94
|
-
/** Rows in the template's column order. Empty unless the columns matched. */
|
|
95
|
-
rows: string[][];
|
|
96
|
-
/** Whether the file's heading line is the template's, in the same order. */
|
|
97
|
-
matchesTemplate: boolean;
|
|
98
|
-
/** The heading line as the file spells it - for telling a person what it has. */
|
|
99
|
-
header: string[];
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Does this heading line say what the template's says?
|
|
104
|
-
*
|
|
105
|
-
* The same columns, in the same order - spelling is forgiven ("Vehicle No"
|
|
106
|
-
* for "Vehicle No.", any case or punctuation), the order is not. A file whose
|
|
107
|
-
* columns are somewhere else, or has extra ones, is a file whose rows we
|
|
108
|
-
* would be guessing at, and a guess here puts a person's phone number in the
|
|
109
|
-
* NRIC field of somebody else's car.
|
|
110
|
-
*/
|
|
111
|
-
export function headerMatchesTemplate(headerRow: string[]): boolean {
|
|
112
|
-
const cells = [...(headerRow ?? [])].map((cell) => String(cell ?? "").trim());
|
|
113
|
-
while (cells.length && !cells[cells.length - 1]) cells.pop();
|
|
114
|
-
|
|
115
|
-
if (cells.length !== BULK_SHEET_HEADINGS.length) return false;
|
|
116
|
-
|
|
117
|
-
return cells.every((cell, index) =>
|
|
118
|
-
HEADING_ALIASES[index].includes(normaliseHeading(cell)),
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Put an uploaded file's grid into the sheet's columns.
|
|
124
|
-
*
|
|
125
|
-
* The file has to be the template: its first line names the template's
|
|
126
|
-
* columns, in the template's order. Anything else comes back with
|
|
127
|
-
* `matchesTemplate: false` and no rows, for the screen to explain.
|
|
128
|
-
*/
|
|
129
|
-
export function mapUploadedGrid(grid: string[][]): UploadedSheet {
|
|
130
|
-
const lines = (grid ?? []).filter((line) => line && !isEmptyLine(line));
|
|
131
|
-
if (!lines.length) return { rows: [], matchesTemplate: false, header: [] };
|
|
132
|
-
|
|
133
|
-
const header = lines[0].map((cell) => String(cell ?? "").trim());
|
|
134
|
-
if (!headerMatchesTemplate(header)) {
|
|
135
|
-
return { rows: [], matchesTemplate: false, header };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Every line under the header is somebody's car. Nothing is dropped for
|
|
139
|
-
// looking like something else - two people in one household can have the
|
|
140
|
-
// same details but for the plate, and a repeated row is the person's to fix.
|
|
141
|
-
const rows = lines
|
|
142
|
-
.slice(1)
|
|
143
|
-
.map((line) =>
|
|
144
|
-
BULK_SHEET_HEADINGS.map((_, column) => String(line[column] ?? "").trim()),
|
|
145
|
-
)
|
|
146
|
-
.filter((line) => !isEmptyLine(line));
|
|
147
|
-
|
|
148
|
-
return { rows, matchesTemplate: true, header };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* The blank sheet to fill in, as CSV - what Excel and Sheets both open.
|
|
153
|
-
*
|
|
154
|
-
* Headings only. An example line would have to be deleted before uploading,
|
|
155
|
-
* and a file where it was not is a file that adds a car nobody owns.
|
|
156
|
-
*/
|
|
157
|
-
export function vehicleBulkTemplateCsv(): string {
|
|
158
|
-
const quote = (value: string) =>
|
|
159
|
-
/[",\n]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value;
|
|
160
|
-
|
|
161
|
-
return `${BULK_SHEET_HEADINGS.map(quote).join(",")}\r\n`;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/* ------------------------------ workbooks -------------------------------- */
|
|
165
|
-
|
|
166
|
-
const XML_ENTITIES: Record<string, string> = {
|
|
167
|
-
amp: "&",
|
|
168
|
-
lt: "<",
|
|
169
|
-
gt: ">",
|
|
170
|
-
quot: '"',
|
|
171
|
-
apos: "'",
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
function decodeXml(text: string): string {
|
|
175
|
-
return text.replace(/&(#x?[0-9a-fA-F]+|[a-z]+);/g, (whole, entity: string) => {
|
|
176
|
-
if (entity[0] === "#") {
|
|
177
|
-
const code =
|
|
178
|
-
entity[1] === "x" || entity[1] === "X"
|
|
179
|
-
? parseInt(entity.slice(2), 16)
|
|
180
|
-
: parseInt(entity.slice(1), 10);
|
|
181
|
-
return Number.isFinite(code) ? String.fromCodePoint(code) : whole;
|
|
182
|
-
}
|
|
183
|
-
return XML_ENTITIES[entity] ?? whole;
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** A1 -> 0, B1 -> 1, AA1 -> 26. */
|
|
188
|
-
export function columnFromRef(ref: string): number {
|
|
189
|
-
const letters = String(ref ?? "").match(/^[A-Z]+/)?.[0] ?? "";
|
|
190
|
-
let index = 0;
|
|
191
|
-
for (const letter of letters) index = index * 26 + (letter.charCodeAt(0) - 64);
|
|
192
|
-
return index - 1;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
type ZipEntry = { method: number; start: number; size: number };
|
|
196
|
-
|
|
197
|
-
function view(bytes: Uint8Array) {
|
|
198
|
-
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* The entries of a zip file, by name.
|
|
203
|
-
*
|
|
204
|
-
* An .xlsx IS a zip, and this reads only what one needs: where each part
|
|
205
|
-
* starts and how it was packed. Written rather than pulled in - a workbook
|
|
206
|
-
* reader is a large dependency for a layer that ships to every app, and the
|
|
207
|
-
* part of it this screen uses is the hundred lines below.
|
|
208
|
-
*/
|
|
209
|
-
function readZipEntries(bytes: Uint8Array): Map<string, ZipEntry> {
|
|
210
|
-
const data = view(bytes);
|
|
211
|
-
const entries = new Map<string, ZipEntry>();
|
|
212
|
-
|
|
213
|
-
let end = -1;
|
|
214
|
-
for (let index = bytes.length - 22; index >= 0 && index > bytes.length - 66_000; index--) {
|
|
215
|
-
if (data.getUint32(index, true) === 0x06054b50) {
|
|
216
|
-
end = index;
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
if (end < 0) throw new Error("not-a-zip");
|
|
221
|
-
|
|
222
|
-
const count = data.getUint16(end + 10, true);
|
|
223
|
-
let offset = data.getUint32(end + 16, true);
|
|
224
|
-
|
|
225
|
-
for (let item = 0; item < count; item++) {
|
|
226
|
-
if (data.getUint32(offset, true) !== 0x02014b50) break;
|
|
227
|
-
|
|
228
|
-
const method = data.getUint16(offset + 10, true);
|
|
229
|
-
const size = data.getUint32(offset + 20, true);
|
|
230
|
-
const nameLength = data.getUint16(offset + 28, true);
|
|
231
|
-
const extraLength = data.getUint16(offset + 30, true);
|
|
232
|
-
const commentLength = data.getUint16(offset + 32, true);
|
|
233
|
-
const localOffset = data.getUint32(offset + 42, true);
|
|
234
|
-
const name = new TextDecoder().decode(
|
|
235
|
-
bytes.subarray(offset + 46, offset + 46 + nameLength),
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
// The local header repeats the name and may carry more extra bytes than
|
|
239
|
-
// the central one, so the data's start is worked out from it.
|
|
240
|
-
const localNameLength = data.getUint16(localOffset + 26, true);
|
|
241
|
-
const localExtraLength = data.getUint16(localOffset + 28, true);
|
|
242
|
-
|
|
243
|
-
entries.set(name, {
|
|
244
|
-
method,
|
|
245
|
-
start: localOffset + 30 + localNameLength + localExtraLength,
|
|
246
|
-
size,
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
offset += 46 + nameLength + extraLength + commentLength;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return entries;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
async function readPart(bytes: Uint8Array, entry: ZipEntry): Promise<string> {
|
|
256
|
-
const packed = bytes.subarray(entry.start, entry.start + entry.size);
|
|
257
|
-
if (entry.method === 0) return new TextDecoder().decode(packed);
|
|
258
|
-
if (entry.method !== 8) throw new Error("unsupported-compression");
|
|
259
|
-
|
|
260
|
-
const stream = new Blob([packed as BlobPart])
|
|
261
|
-
.stream()
|
|
262
|
-
.pipeThrough(new DecompressionStream("deflate-raw"));
|
|
263
|
-
return new Response(stream).text();
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function sharedStringsOf(xml: string): string[] {
|
|
267
|
-
const strings: string[] = [];
|
|
268
|
-
const items = xml.match(/<si\b[\s\S]*?<\/si>|<si\b[^>]*\/>/g) ?? [];
|
|
269
|
-
|
|
270
|
-
for (const item of items) {
|
|
271
|
-
const texts = item.replace(/<t[^>]*\/>/g, "").match(/<t[^>]*>[\s\S]*?<\/t>/g) ?? [];
|
|
272
|
-
strings.push(
|
|
273
|
-
texts
|
|
274
|
-
.map((text) => decodeXml(text.replace(/^<t[^>]*>/, "").replace(/<\/t>$/, "")))
|
|
275
|
-
.join(""),
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return strings;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function sheetToGrid(xml: string, strings: string[]): string[][] {
|
|
283
|
-
const grid: string[][] = [];
|
|
284
|
-
const rows = xml.match(/<row\b[\s\S]*?<\/row>|<row\b[^>]*\/>/g) ?? [];
|
|
285
|
-
let cursor = 0;
|
|
286
|
-
|
|
287
|
-
for (const row of rows) {
|
|
288
|
-
const rowNumber = Number(row.match(/<row[^>]*\sr="(\d+)"/)?.[1] ?? 0);
|
|
289
|
-
const line: string[] = [];
|
|
290
|
-
const cells =
|
|
291
|
-
row.match(/<c\b[^>]*\/>|<c\b[^>]*>[\s\S]*?<\/c>/g) ?? [];
|
|
292
|
-
|
|
293
|
-
for (const cell of cells) {
|
|
294
|
-
const attributes = cell.match(/^<c\b([^>]*)>/)?.[1] ?? "";
|
|
295
|
-
const reference = attributes.match(/\sr="([A-Z]+\d+)"/)?.[1] ?? "";
|
|
296
|
-
const type = attributes.match(/\st="([^"]+)"/)?.[1] ?? "n";
|
|
297
|
-
const column = reference ? columnFromRef(reference) : line.length;
|
|
298
|
-
|
|
299
|
-
let value = "";
|
|
300
|
-
if (type === "inlineStr") {
|
|
301
|
-
const texts =
|
|
302
|
-
cell.replace(/<t[^>]*\/>/g, "").match(/<t[^>]*>[\s\S]*?<\/t>/g) ?? [];
|
|
303
|
-
value = texts
|
|
304
|
-
.map((text) => decodeXml(text.replace(/^<t[^>]*>/, "").replace(/<\/t>$/, "")))
|
|
305
|
-
.join("");
|
|
306
|
-
} else {
|
|
307
|
-
const raw = cell.match(/<v[^>]*>([\s\S]*?)<\/v>/)?.[1];
|
|
308
|
-
if (raw !== undefined) {
|
|
309
|
-
value =
|
|
310
|
-
type === "s"
|
|
311
|
-
? (strings[Number(decodeXml(raw))] ?? "")
|
|
312
|
-
: decodeXml(raw);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
while (line.length < column) line.push("");
|
|
317
|
-
line[column] = value;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// A workbook may skip empty rows; keep the alignment they had.
|
|
321
|
-
const target = rowNumber > 0 ? rowNumber - 1 : cursor;
|
|
322
|
-
while (grid.length < target) grid.push([]);
|
|
323
|
-
grid[target] = line;
|
|
324
|
-
cursor = target + 1;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
return grid;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* The first worksheet of an .xlsx workbook, as a grid of text.
|
|
332
|
-
*
|
|
333
|
-
* Only what a filled-in template carries is read: text, numbers as they were
|
|
334
|
-
* typed, and shared or inline strings. Formatting, formulas' cached values
|
|
335
|
-
* aside, and everything else a workbook can hold are of no interest here.
|
|
336
|
-
*/
|
|
337
|
-
export async function xlsxToGrid(data: ArrayBuffer | Uint8Array): Promise<string[][]> {
|
|
338
|
-
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
339
|
-
const entries = readZipEntries(bytes);
|
|
340
|
-
|
|
341
|
-
const sheetName = [...entries.keys()]
|
|
342
|
-
.filter((name) => /^xl\/worksheets\/sheet\d+\.xml$/.test(name))
|
|
343
|
-
.sort(
|
|
344
|
-
(a, b) =>
|
|
345
|
-
Number(a.match(/(\d+)\.xml$/)![1]) - Number(b.match(/(\d+)\.xml$/)![1]),
|
|
346
|
-
)[0];
|
|
347
|
-
|
|
348
|
-
if (!sheetName) throw new Error("no-worksheet");
|
|
349
|
-
|
|
350
|
-
const sharedEntry = entries.get("xl/sharedStrings.xml");
|
|
351
|
-
const strings = sharedEntry
|
|
352
|
-
? sharedStringsOf(await readPart(bytes, sharedEntry))
|
|
353
|
-
: [];
|
|
354
|
-
|
|
355
|
-
return sheetToGrid(await readPart(bytes, entries.get(sheetName)!), strings);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/** True for a file that has to be unzipped rather than read as text. */
|
|
359
|
-
export function isWorkbookName(name: string): boolean {
|
|
360
|
-
return /\.(xlsx|xlsm)$/i.test(String(name ?? ""));
|
|
361
|
-
}
|