@7365admin1/layer-common 4.97.1-staging.516 → 4.97.1-staging.518
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 +4 -4
- package/assets/css/screens.css +11 -0
- package/components/Nfc/NFCPatrolReportMain.vue +61 -72
- package/components/Nfc/NFCPatrolRouteMain.vue +21 -31
- package/components/Nfc/NFCRouteScheduleTimes.vue +83 -0
- package/components/Nfc/PatrolReport/DailyReportTab.vue +24 -3
- package/components/Nfc/PatrolReport/MonthlyReportTab.vue +32 -3
- package/components/Nfc/PatrolReport/MonthlyReportTable.vue +29 -1
- package/components/Nfc/PatrolReport/PatrolActivityTable.vue +24 -2
- package/components/Nfc/PatrolReport/PatrolMonthDialog.vue +195 -0
- package/components/Nfc/PatrolReport/PatrolReportTab.vue +11 -2
- package/components/Nfc/PatrolReport/PatrolRouteDetailsDialog.vue +214 -0
- package/components/Nfc/PatrolReport/ReportLocationHeader.vue +4 -1
- package/components/Nfc/PatrolReport/SkipPhotoDetails.vue +137 -0
- package/components/Nfc/PatrolReport/SkipPhotoThumb.vue +132 -0
- package/components/Nfc/PatrolReport/SummaryReportTable.vue +42 -1
- package/components/OnlineFormFill.vue +11 -0
- package/composables/useNFCPatrolDailyReport.ts +4 -18
- package/composables/useNFCPatrolMonthlyReport.ts +34 -5
- package/composables/useReportPdf.ts +220 -0
- package/package.json +1 -1
- package/types/nfc-patrol-report.ts +14 -0
- package/utils/nfc-patrol-report.ts +239 -1
- package/utils/nfc-patrol-schedule.ts +73 -0
- package/utils/online-form-submission.ts +48 -0
- package/utils/report-export.ts +120 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The photo a guard attached when skipping a checkpoint (`skippedPhotoFileId`
|
|
3
|
+
on the log's checkpoint): a thumbnail that opens the photo full size, with
|
|
4
|
+
the guard's remarks under it. Used by the Patrol Activity table and the
|
|
5
|
+
Patrol Route Details dialog.
|
|
6
|
+
|
|
7
|
+
The thumbnail's click stops at the button: in the Patrol Activity table the
|
|
8
|
+
whole skipped row already opens the remarks dialog.
|
|
9
|
+
|
|
10
|
+
The thumbnail is a cropped background, not a `v-img`: it crops the same in
|
|
11
|
+
html2canvas (which ignores `object-fit`) and loads without being scrolled
|
|
12
|
+
into view. The PDF itself leaves this column out and draws the photo full
|
|
13
|
+
size under its checkpoint (`SkipPhotoDetails`).
|
|
14
|
+
-->
|
|
15
|
+
<template>
|
|
16
|
+
<span class="skip-photo">
|
|
17
|
+
<button
|
|
18
|
+
v-if="activity.skippedPhotoFileId"
|
|
19
|
+
type="button"
|
|
20
|
+
class="skip-photo__thumb"
|
|
21
|
+
:aria-label="`View skip photo for ${activity.checkpoint}`"
|
|
22
|
+
@click.stop="open = true"
|
|
23
|
+
>
|
|
24
|
+
<span
|
|
25
|
+
class="skip-photo__img"
|
|
26
|
+
role="img"
|
|
27
|
+
:aria-label="`Skip photo for ${activity.checkpoint}`"
|
|
28
|
+
:style="{
|
|
29
|
+
width: `${size}px`,
|
|
30
|
+
height: `${size}px`,
|
|
31
|
+
backgroundImage: `url('${getFileUrl(activity.skippedPhotoFileId)}')`,
|
|
32
|
+
}"
|
|
33
|
+
/>
|
|
34
|
+
</button>
|
|
35
|
+
<span v-else-if="activity.status === 'Skipped'" class="screen-hint">No photo</span>
|
|
36
|
+
<span v-else>-</span>
|
|
37
|
+
|
|
38
|
+
<v-dialog v-if="activity.skippedPhotoFileId" v-model="open" max-width="820">
|
|
39
|
+
<v-card class="screen-modal">
|
|
40
|
+
<div class="skip-photo__head">
|
|
41
|
+
<v-card-title class="pa-0">Skip Photo: {{ activity.checkpoint }}</v-card-title>
|
|
42
|
+
<v-btn
|
|
43
|
+
class="screen-modal__close"
|
|
44
|
+
icon="mdi-close"
|
|
45
|
+
variant="flat"
|
|
46
|
+
aria-label="Close"
|
|
47
|
+
@click="open = false"
|
|
48
|
+
/>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<div class="screen-modal__body px-6 pb-6">
|
|
52
|
+
<v-img
|
|
53
|
+
:src="getFileUrl(activity.skippedPhotoFileId)"
|
|
54
|
+
:alt="`Skip photo for ${activity.checkpoint}`"
|
|
55
|
+
max-height="70vh"
|
|
56
|
+
contain
|
|
57
|
+
/>
|
|
58
|
+
<p class="skip-photo__remarks">
|
|
59
|
+
<span class="skip-photo__label">Remarks</span>
|
|
60
|
+
{{ activity.remarks || "No remarks provided" }}
|
|
61
|
+
</p>
|
|
62
|
+
<a :href="getFileUrl(activity.skippedPhotoFileId)" target="_blank" rel="noopener">
|
|
63
|
+
Open full size
|
|
64
|
+
</a>
|
|
65
|
+
</div>
|
|
66
|
+
</v-card>
|
|
67
|
+
</v-dialog>
|
|
68
|
+
</span>
|
|
69
|
+
</template>
|
|
70
|
+
|
|
71
|
+
<script setup lang="ts">
|
|
72
|
+
import type { NFCPatrolActivity } from "../../../types/nfc-patrol-report";
|
|
73
|
+
|
|
74
|
+
withDefaults(
|
|
75
|
+
defineProps<{
|
|
76
|
+
activity: NFCPatrolActivity;
|
|
77
|
+
size?: number;
|
|
78
|
+
}>(),
|
|
79
|
+
{ size: 56 },
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const { getFileUrl } = useFile();
|
|
83
|
+
|
|
84
|
+
const open = ref(false);
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<style scoped>
|
|
88
|
+
.skip-photo__thumb {
|
|
89
|
+
display: block;
|
|
90
|
+
padding: 0;
|
|
91
|
+
border: 1px solid var(--border);
|
|
92
|
+
border-radius: var(--r-inner);
|
|
93
|
+
overflow: hidden;
|
|
94
|
+
background: none;
|
|
95
|
+
cursor: zoom-in;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.skip-photo__img {
|
|
99
|
+
display: block;
|
|
100
|
+
background-size: cover;
|
|
101
|
+
background-position: center;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.skip-photo__thumb:focus-visible {
|
|
105
|
+
outline: 2px solid var(--accent);
|
|
106
|
+
outline-offset: 2px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.skip-photo__head {
|
|
110
|
+
display: flex;
|
|
111
|
+
align-items: flex-start;
|
|
112
|
+
justify-content: space-between;
|
|
113
|
+
gap: 12px;
|
|
114
|
+
padding: 20px 24px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.skip-photo__remarks {
|
|
118
|
+
margin: 16px 0 8px;
|
|
119
|
+
color: var(--text);
|
|
120
|
+
white-space: pre-line;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.skip-photo__label {
|
|
124
|
+
display: block;
|
|
125
|
+
margin-bottom: 4px;
|
|
126
|
+
font-size: var(--fs-section-label);
|
|
127
|
+
font-weight: var(--fw-section-label);
|
|
128
|
+
text-transform: uppercase;
|
|
129
|
+
letter-spacing: 0.04em;
|
|
130
|
+
color: var(--muted);
|
|
131
|
+
}
|
|
132
|
+
</style>
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
swapping them to `StatusChip` would be a meaning change, not a restyle:
|
|
13
13
|
`utils/status.ts` does not name "Missed", so the shared map would render it
|
|
14
14
|
NEUTRAL and a missed patrol would stop being red. Raised, not decided here.
|
|
15
|
+
|
|
16
|
+
In the PDF each patrol run's skipped checkpoints - photo, time, remarks -
|
|
17
|
+
are drawn in a row of their own right under that run (`SkipPhotoDetails`),
|
|
18
|
+
so a day of many runs keeps every photo with the run it was taken on.
|
|
15
19
|
-->
|
|
16
20
|
<template>
|
|
17
21
|
<div class="table-card table-card__shrink mb-6">
|
|
@@ -33,7 +37,15 @@
|
|
|
33
37
|
</tr>
|
|
34
38
|
</thead>
|
|
35
39
|
<tbody>
|
|
36
|
-
<
|
|
40
|
+
<template v-for="row in rows" :key="row.id">
|
|
41
|
+
<tr
|
|
42
|
+
:class="{ 'summary-table__row--link': row.detail }"
|
|
43
|
+
:data-pdf-keep-with-next="skipped(row).length > 0 || undefined"
|
|
44
|
+
:tabindex="row.detail ? 0 : undefined"
|
|
45
|
+
:title="row.detail ? 'View patrol route details' : undefined"
|
|
46
|
+
@click="row.detail && emit('select', row)"
|
|
47
|
+
@keydown.enter="row.detail && emit('select', row)"
|
|
48
|
+
>
|
|
37
49
|
<td>{{ row.routeName }}</td>
|
|
38
50
|
<td>
|
|
39
51
|
<v-icon size="small" class="mr-1">mdi-clock-outline</v-icon>
|
|
@@ -47,6 +59,7 @@
|
|
|
47
59
|
:alt="`${row.guardName || worker.one} signature`"
|
|
48
60
|
class="guard-signature"
|
|
49
61
|
contain
|
|
62
|
+
eager
|
|
50
63
|
/>
|
|
51
64
|
<span v-else>-</span>
|
|
52
65
|
</td>
|
|
@@ -58,6 +71,12 @@
|
|
|
58
71
|
</span>
|
|
59
72
|
</td>
|
|
60
73
|
</tr>
|
|
74
|
+
<tr v-if="skipped(row).length" data-pdf-only>
|
|
75
|
+
<td colspan="7" class="summary-table__skips">
|
|
76
|
+
<SkipPhotoDetails :activities="skipped(row)" />
|
|
77
|
+
</td>
|
|
78
|
+
</tr>
|
|
79
|
+
</template>
|
|
61
80
|
</tbody>
|
|
62
81
|
</v-table>
|
|
63
82
|
</div>
|
|
@@ -70,6 +89,7 @@ import type {
|
|
|
70
89
|
NFCPatrolReportSummaryRow,
|
|
71
90
|
NFCPatrolReportSummaryStatus,
|
|
72
91
|
} from "../../../types/nfc-patrol-report";
|
|
92
|
+
import SkipPhotoDetails from "./SkipPhotoDetails.vue";
|
|
73
93
|
|
|
74
94
|
const worker = useWorkerTerm();
|
|
75
95
|
defineProps<{
|
|
@@ -77,8 +97,16 @@ defineProps<{
|
|
|
77
97
|
rows: NFCPatrolReportSummaryRow[];
|
|
78
98
|
}>();
|
|
79
99
|
|
|
100
|
+
const emit = defineEmits<{
|
|
101
|
+
select: [row: NFCPatrolReportSummaryRow];
|
|
102
|
+
}>();
|
|
103
|
+
|
|
80
104
|
const { getFileUrl } = useFile();
|
|
81
105
|
|
|
106
|
+
function skipped(row: NFCPatrolReportSummaryRow) {
|
|
107
|
+
return row.detail?.activities.filter((activity) => activity.status === "Skipped") ?? [];
|
|
108
|
+
}
|
|
109
|
+
|
|
82
110
|
function statusClass(status: NFCPatrolReportSummaryStatus) {
|
|
83
111
|
return status === "Completed" ? "text-success" : "text-error";
|
|
84
112
|
}
|
|
@@ -90,6 +118,19 @@ function statusClass(status: NFCPatrolReportSummaryStatus) {
|
|
|
90
118
|
border-bottom: 1px solid var(--border);
|
|
91
119
|
}
|
|
92
120
|
|
|
121
|
+
.summary-table__skips {
|
|
122
|
+
padding-top: 0 !important;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.summary-table__row--link {
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.summary-table__row--link:focus-visible {
|
|
130
|
+
outline: 2px solid var(--accent);
|
|
131
|
+
outline-offset: -2px;
|
|
132
|
+
}
|
|
133
|
+
|
|
93
134
|
.guard-signature {
|
|
94
135
|
width: 80px;
|
|
95
136
|
height: 40px;
|
|
@@ -9,6 +9,15 @@
|
|
|
9
9
|
<slot name="title-actions" />
|
|
10
10
|
</v-card-title>
|
|
11
11
|
|
|
12
|
+
<v-alert
|
|
13
|
+
v-if="notice"
|
|
14
|
+
type="info"
|
|
15
|
+
variant="tonal"
|
|
16
|
+
density="compact"
|
|
17
|
+
class="mx-6 mt-2"
|
|
18
|
+
data-test="online-form-notice"
|
|
19
|
+
>{{ notice }}</v-alert>
|
|
20
|
+
|
|
12
21
|
<!-- Submission metadata bar (readonly only). Shown for an actual
|
|
13
22
|
submission (submissionStatus) OR a pure template preview that
|
|
14
23
|
requires payment — a preview has no submission yet, but should
|
|
@@ -481,6 +490,8 @@ const props = defineProps({
|
|
|
481
490
|
submissionStatus: { type: String, default: "" },
|
|
482
491
|
submissionUnit: { type: String, default: "" },
|
|
483
492
|
approvalMode: { type: Boolean, default: false },
|
|
493
|
+
/** A short note above the form, e.g. that its template was deleted. */
|
|
494
|
+
notice: { type: String, default: "" },
|
|
484
495
|
initialManagementValues: { type: Object as PropType<Record<string, string>>, default: () => ({}) },
|
|
485
496
|
formType: { type: String, default: "" },
|
|
486
497
|
paymentAmount: { type: Number, default: 0 },
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
} from "../types/nfc-patrol-report";
|
|
6
6
|
import useNFCPatrolLog from "./useNFCPatrolLog";
|
|
7
7
|
import useSite from "./useSite";
|
|
8
|
+
import { mapLogToSummaryRow } from "../utils/nfc-patrol-report";
|
|
8
9
|
|
|
9
10
|
interface NFCPatrolLogListResponse {
|
|
10
11
|
items?: Record<string, any>[];
|
|
@@ -25,23 +26,6 @@ function buildAddress(address?: Record<string, string>) {
|
|
|
25
26
|
return parts.length ? parts.join(", ") : undefined;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
function mapLogToSummaryRow(log: Record<string, any>, index: number): NFCPatrolSummaryRow {
|
|
29
|
-
const checkpoints: Record<string, any>[] = log.checkPoints ?? [];
|
|
30
|
-
const checked = checkpoints.filter((cp) => cp.status === "Completed").length;
|
|
31
|
-
const missed = checkpoints.filter((cp) => cp.status === "Skipped").length;
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
id: log._id,
|
|
35
|
-
routeName: `${index + 1}. ${log.route?.name ?? "-"}`,
|
|
36
|
-
securityCheckSchedule: log.route?.startTime ?? "-",
|
|
37
|
-
guardName: log.sign?.guardName,
|
|
38
|
-
guardSignatureFileId: log.sign?.guardSignatureFileId,
|
|
39
|
-
checked,
|
|
40
|
-
missed,
|
|
41
|
-
status: missed === 0 ? "Completed" : "Incomplete",
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
29
|
export function useNFCPatrolDailyReport(
|
|
46
30
|
filters: NFCPatrolReportFilters,
|
|
47
31
|
site: string,
|
|
@@ -94,7 +78,9 @@ export function useNFCPatrolDailyReport(
|
|
|
94
78
|
address: buildAddress(siteInfo.address),
|
|
95
79
|
},
|
|
96
80
|
title: `Patrol Route Summary: ${routeName}`,
|
|
97
|
-
rows: logs.map(
|
|
81
|
+
rows: logs.map((log, index) =>
|
|
82
|
+
mapLogToSummaryRow(log, index, (siteInfo as { timezone?: string }).timezone),
|
|
83
|
+
),
|
|
98
84
|
};
|
|
99
85
|
} else {
|
|
100
86
|
report.value = null;
|
|
@@ -6,7 +6,12 @@ import type {
|
|
|
6
6
|
} from "../types/nfc-patrol-report";
|
|
7
7
|
import useNFCPatrolLog from "./useNFCPatrolLog";
|
|
8
8
|
import useSite from "./useSite";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
collectAllPages,
|
|
11
|
+
mapLogsToMonthlyRows,
|
|
12
|
+
mapLogsToMonthRuns,
|
|
13
|
+
monthIndexOf,
|
|
14
|
+
} from "../utils/nfc-patrol-report";
|
|
10
15
|
|
|
11
16
|
interface NFCPatrolLogListResponse {
|
|
12
17
|
items?: Record<string, any>[];
|
|
@@ -48,9 +53,15 @@ export function useNFCPatrolMonthlyReport(
|
|
|
48
53
|
*/
|
|
49
54
|
const failed = ref(false);
|
|
50
55
|
|
|
56
|
+
// The year's patrol logs, kept so a month's row can open its list without
|
|
57
|
+
// asking the server again. Not deep-reactive: nothing edits them.
|
|
58
|
+
const logs = shallowRef<Record<string, any>[]>([]);
|
|
59
|
+
let siteTimezone: string | undefined;
|
|
60
|
+
|
|
51
61
|
async function fetchReport() {
|
|
52
62
|
if (!site || !filters.route) {
|
|
53
63
|
report.value = null;
|
|
64
|
+
logs.value = [];
|
|
54
65
|
notFound.value = false;
|
|
55
66
|
failed.value = false;
|
|
56
67
|
return;
|
|
@@ -63,7 +74,7 @@ export function useNFCPatrolMonthlyReport(
|
|
|
63
74
|
try {
|
|
64
75
|
// The whole year, not page one of it. `collectAllPages` reads the page
|
|
65
76
|
// count out of the first reply and walks the rest.
|
|
66
|
-
const [
|
|
77
|
+
const [yearLogs, siteInfo] = await Promise.all([
|
|
67
78
|
collectAllPages((page) =>
|
|
68
79
|
getPatrolLogs({
|
|
69
80
|
page,
|
|
@@ -77,8 +88,16 @@ export function useNFCPatrolMonthlyReport(
|
|
|
77
88
|
getSiteById(site),
|
|
78
89
|
]);
|
|
79
90
|
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
logs.value = yearLogs;
|
|
92
|
+
siteTimezone = (siteInfo as { timezone?: string }).timezone;
|
|
93
|
+
|
|
94
|
+
if (yearLogs.length) {
|
|
95
|
+
const routeName = yearLogs[0]?.route?.name ?? "-";
|
|
96
|
+
const runs = Array<number>(12).fill(0);
|
|
97
|
+
for (const log of yearLogs) {
|
|
98
|
+
const month = monthIndexOf(log);
|
|
99
|
+
if (!Number.isNaN(month)) runs[month]++;
|
|
100
|
+
}
|
|
82
101
|
|
|
83
102
|
report.value = {
|
|
84
103
|
location: {
|
|
@@ -86,7 +105,10 @@ export function useNFCPatrolMonthlyReport(
|
|
|
86
105
|
address: buildAddress(siteInfo.address),
|
|
87
106
|
},
|
|
88
107
|
title: `Patrol Route Summary: ${routeName}`,
|
|
89
|
-
rows: mapLogsToMonthlyRows(
|
|
108
|
+
rows: mapLogsToMonthlyRows(yearLogs).map((row, month) => ({
|
|
109
|
+
...row,
|
|
110
|
+
runs: runs[month],
|
|
111
|
+
})),
|
|
90
112
|
};
|
|
91
113
|
} else {
|
|
92
114
|
report.value = null;
|
|
@@ -94,6 +116,7 @@ export function useNFCPatrolMonthlyReport(
|
|
|
94
116
|
}
|
|
95
117
|
} catch {
|
|
96
118
|
report.value = null;
|
|
119
|
+
logs.value = [];
|
|
97
120
|
notFound.value = false;
|
|
98
121
|
failed.value = true;
|
|
99
122
|
} finally {
|
|
@@ -101,8 +124,14 @@ export function useNFCPatrolMonthlyReport(
|
|
|
101
124
|
}
|
|
102
125
|
}
|
|
103
126
|
|
|
127
|
+
/** The patrol runs of one month (0-11), in the order they ran. */
|
|
128
|
+
function monthRuns(monthIndex: number) {
|
|
129
|
+
return mapLogsToMonthRuns(logs.value, monthIndex, siteTimezone);
|
|
130
|
+
}
|
|
131
|
+
|
|
104
132
|
return {
|
|
105
133
|
report,
|
|
134
|
+
monthRuns,
|
|
106
135
|
loading,
|
|
107
136
|
notFound,
|
|
108
137
|
failed,
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import html2canvas from "html2canvas";
|
|
2
|
+
import jsPDF from "jspdf";
|
|
3
|
+
import { formatGeneratedAt, planPdfPages, type PdfTable } from "../utils/report-export";
|
|
4
|
+
|
|
5
|
+
export type ReportPdfMeta = {
|
|
6
|
+
/** "Patrol Report" */
|
|
7
|
+
title: string;
|
|
8
|
+
site?: string;
|
|
9
|
+
address?: string;
|
|
10
|
+
/** Shown top right of every page: Route, Date, Time... */
|
|
11
|
+
details: Array<{ label: string; value: string }>;
|
|
12
|
+
fileName: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A report area (`.report-export`) as an A4 PDF.
|
|
17
|
+
*
|
|
18
|
+
* The area is drawn the way the old export drew it - html2canvas, one tall
|
|
19
|
+
* image - but onto a page rather than across it:
|
|
20
|
+
*
|
|
21
|
+
* - laid out at one width whatever the screen, so a PDF from a laptop and
|
|
22
|
+
* one from a 4K monitor read the same, and always in the light theme;
|
|
23
|
+
* - inside margins, under a header (report, site, route, date) and over a
|
|
24
|
+
* footer (when it was made, page X of Y) drawn as real text on every page;
|
|
25
|
+
* - cut only between rows, photos and sections (`planPdfPages`), repeating a
|
|
26
|
+
* table's header row on the page it carries on to;
|
|
27
|
+
* - without the on-screen site card and dividers: the header says it.
|
|
28
|
+
*
|
|
29
|
+
* Everything PDF-only happens on html2canvas's clone of the page, so the
|
|
30
|
+
* screen never changes. `report-export--pdf` marks that clone: under it
|
|
31
|
+
* `data-pdf-only` shows (hidden on screen by screens.css) and `data-pdf-hide`
|
|
32
|
+
* goes. A row marked `data-pdf-keep-with-next` is never the last on a page,
|
|
33
|
+
* so a checkpoint stays with the skip photo drawn under it.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
const RENDER_WIDTH = 1000; // CSS px the report is laid out at for the PDF
|
|
37
|
+
const SCALE = 2;
|
|
38
|
+
|
|
39
|
+
// A4 portrait, in mm.
|
|
40
|
+
const PAGE_W = 210;
|
|
41
|
+
const PAGE_H = 297;
|
|
42
|
+
const MARGIN = 12;
|
|
43
|
+
const CONTENT_TOP = 38;
|
|
44
|
+
const CONTENT_BOTTOM = PAGE_H - MARGIN - 9;
|
|
45
|
+
const CONTENT_W = PAGE_W - MARGIN * 2;
|
|
46
|
+
const DETAILS_LABEL_X = 134;
|
|
47
|
+
const DETAILS_VALUE_X = 150;
|
|
48
|
+
|
|
49
|
+
const INK: [number, number, number] = [20, 22, 26];
|
|
50
|
+
const MUTED: [number, number, number] = [100, 104, 112];
|
|
51
|
+
const RULE: [number, number, number] = [220, 222, 226];
|
|
52
|
+
|
|
53
|
+
const PDF_CSS = `
|
|
54
|
+
.report-export--pdf { width: ${RENDER_WIDTH}px !important; max-width: none !important; background: #fff; }
|
|
55
|
+
.report-export--pdf > .v-divider, .report-export--pdf [data-pdf-hide] { display: none !important; }
|
|
56
|
+
.report-export--pdf tr[data-pdf-only] { display: table-row !important; }
|
|
57
|
+
.report-export--pdf [data-pdf-only]:not(tr) { display: block !important; }
|
|
58
|
+
.report-export--pdf tr[data-pdf-keep-with-next] > td { border-bottom-color: transparent !important; }
|
|
59
|
+
.report-export--pdf .table-card, .report-export--pdf .app-card { box-shadow: none !important; }
|
|
60
|
+
.report-export--pdf .v-table__wrapper { overflow: visible !important; }
|
|
61
|
+
.report-export--pdf tbody tr:hover > td { background: transparent !important; }
|
|
62
|
+
/* html2canvas draws digits at their plain widths but places them where the
|
|
63
|
+
page laid out tabular ones, so "10:33" came out "10 :33". */
|
|
64
|
+
.report-export--pdf * { font-variant-numeric: normal !important; }
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
/** Where the report can be cut, and where its tables are, measured on the clone. */
|
|
68
|
+
function measure(clone: HTMLElement) {
|
|
69
|
+
const origin = clone.getBoundingClientRect().top;
|
|
70
|
+
const top = (el: Element) => el.getBoundingClientRect().top - origin;
|
|
71
|
+
const bottom = (el: Element) => el.getBoundingClientRect().bottom - origin;
|
|
72
|
+
|
|
73
|
+
// Between sections, between table rows (the last row ends with its card,
|
|
74
|
+
// and a row stays with the skip photos under it), and between lines of
|
|
75
|
+
// skip photos. Never right under a heading.
|
|
76
|
+
const breaks = [
|
|
77
|
+
...Array.from(clone.children),
|
|
78
|
+
...Array.from(clone.querySelectorAll("tbody tr:not(:last-child):not([data-pdf-keep-with-next])")),
|
|
79
|
+
...Array.from(clone.querySelectorAll(".skip-details__item")),
|
|
80
|
+
].map(bottom);
|
|
81
|
+
|
|
82
|
+
const tables: PdfTable[] = Array.from(clone.querySelectorAll("table")).flatMap((table) => {
|
|
83
|
+
const head = table.querySelector("thead");
|
|
84
|
+
return head
|
|
85
|
+
? [{ top: top(table), bottom: bottom(table), head: { top: top(head), bottom: bottom(head) } }]
|
|
86
|
+
: [];
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return { height: clone.getBoundingClientRect().height, breaks, tables };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function drawHeader(pdf: jsPDF, meta: ReportPdfMeta) {
|
|
93
|
+
pdf.setTextColor(...INK);
|
|
94
|
+
pdf.setFont("helvetica", "bold");
|
|
95
|
+
pdf.setFontSize(15);
|
|
96
|
+
pdf.text(meta.title, MARGIN, MARGIN + 5);
|
|
97
|
+
|
|
98
|
+
let y = MARGIN + 11.5;
|
|
99
|
+
if (meta.site) {
|
|
100
|
+
pdf.setFontSize(10);
|
|
101
|
+
pdf.text(pdf.splitTextToSize(meta.site, DETAILS_LABEL_X - MARGIN - 6)[0], MARGIN, y);
|
|
102
|
+
y += 4.5;
|
|
103
|
+
}
|
|
104
|
+
if (meta.address) {
|
|
105
|
+
pdf.setFont("helvetica", "normal");
|
|
106
|
+
pdf.setFontSize(8.5);
|
|
107
|
+
pdf.setTextColor(...MUTED);
|
|
108
|
+
pdf.text(pdf.splitTextToSize(meta.address, DETAILS_LABEL_X - MARGIN - 6).slice(0, 2), MARGIN, y);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let dy = MARGIN + 4;
|
|
112
|
+
for (const { label, value } of meta.details) {
|
|
113
|
+
pdf.setFont("helvetica", "normal");
|
|
114
|
+
pdf.setFontSize(8.5);
|
|
115
|
+
pdf.setTextColor(...MUTED);
|
|
116
|
+
pdf.text(label, DETAILS_LABEL_X, dy);
|
|
117
|
+
|
|
118
|
+
const lines: string[] = pdf.splitTextToSize(value || "-", PAGE_W - MARGIN - DETAILS_VALUE_X);
|
|
119
|
+
pdf.setFont("helvetica", "bold");
|
|
120
|
+
pdf.setTextColor(...INK);
|
|
121
|
+
pdf.text(lines.length > 1 ? `${lines[0].replace(/\s+$/, "")}…` : lines[0], DETAILS_VALUE_X, dy);
|
|
122
|
+
dy += 5;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
pdf.setDrawColor(...RULE);
|
|
126
|
+
pdf.setLineWidth(0.3);
|
|
127
|
+
pdf.line(MARGIN, CONTENT_TOP - 4, PAGE_W - MARGIN, CONTENT_TOP - 4);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function drawFooter(pdf: jsPDF, page: number, pages: number, generatedAt: string) {
|
|
131
|
+
const y = PAGE_H - MARGIN;
|
|
132
|
+
pdf.setDrawColor(...RULE);
|
|
133
|
+
pdf.setLineWidth(0.3);
|
|
134
|
+
pdf.line(MARGIN, y - 5, PAGE_W - MARGIN, y - 5);
|
|
135
|
+
|
|
136
|
+
pdf.setFont("helvetica", "normal");
|
|
137
|
+
pdf.setFontSize(8);
|
|
138
|
+
pdf.setTextColor(...MUTED);
|
|
139
|
+
pdf.text(`Generated ${generatedAt}`, MARGIN, y);
|
|
140
|
+
pdf.text(`Page ${page} of ${pages}`, PAGE_W - MARGIN, y, { align: "right" });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export default function useReportPdf() {
|
|
144
|
+
async function exportReportPdf(report: HTMLElement, meta: ReportPdfMeta) {
|
|
145
|
+
let layout = { height: 0, breaks: [] as number[], tables: [] as PdfTable[] };
|
|
146
|
+
|
|
147
|
+
const canvas = await html2canvas(report, {
|
|
148
|
+
scale: SCALE,
|
|
149
|
+
useCORS: true,
|
|
150
|
+
backgroundColor: "#fff",
|
|
151
|
+
windowWidth: Math.max(window.innerWidth, RENDER_WIDTH + 200),
|
|
152
|
+
onclone: (doc, clone) => {
|
|
153
|
+
// A PDF is read on white: the dark theme's tokens hang off this class.
|
|
154
|
+
doc.querySelectorAll(".v-theme--dark").forEach((el) => {
|
|
155
|
+
el.classList.replace("v-theme--dark", "v-theme--light");
|
|
156
|
+
});
|
|
157
|
+
const style = doc.createElement("style");
|
|
158
|
+
style.textContent = PDF_CSS;
|
|
159
|
+
doc.head.appendChild(style);
|
|
160
|
+
clone.classList.add("report-export--pdf");
|
|
161
|
+
layout = measure(clone);
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Canvas px per report px, and report px per mm on the page.
|
|
166
|
+
const k = canvas.height / layout.height;
|
|
167
|
+
const pxPerMm = canvas.width / k / CONTENT_W;
|
|
168
|
+
const pages = planPdfPages(
|
|
169
|
+
layout.height,
|
|
170
|
+
(CONTENT_BOTTOM - CONTENT_TOP) * pxPerMm,
|
|
171
|
+
layout.breaks,
|
|
172
|
+
layout.tables,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const pdf = new jsPDF({ unit: "mm", format: "a4", orientation: "portrait" });
|
|
176
|
+
|
|
177
|
+
pages.forEach((page, index) => {
|
|
178
|
+
if (index > 0) pdf.addPage();
|
|
179
|
+
|
|
180
|
+
const headPx = page.head ? page.head.bottom - page.head.top : 0;
|
|
181
|
+
const bodyPx = page.bottom - page.top;
|
|
182
|
+
const part = document.createElement("canvas");
|
|
183
|
+
part.width = canvas.width;
|
|
184
|
+
part.height = Math.max(1, Math.round((headPx + bodyPx) * k));
|
|
185
|
+
|
|
186
|
+
const ctx = part.getContext("2d");
|
|
187
|
+
if (!ctx) return;
|
|
188
|
+
ctx.fillStyle = "#fff";
|
|
189
|
+
ctx.fillRect(0, 0, part.width, part.height);
|
|
190
|
+
if (page.head) {
|
|
191
|
+
const h = Math.round(headPx * k);
|
|
192
|
+
ctx.drawImage(canvas, 0, Math.round(page.head.top * k), canvas.width, h, 0, 0, canvas.width, h);
|
|
193
|
+
}
|
|
194
|
+
const bodyTop = Math.round(page.top * k);
|
|
195
|
+
const bodyH = Math.round(page.bottom * k) - bodyTop;
|
|
196
|
+
ctx.drawImage(canvas, 0, bodyTop, canvas.width, bodyH, 0, Math.round(headPx * k), canvas.width, bodyH);
|
|
197
|
+
|
|
198
|
+
pdf.addImage(
|
|
199
|
+
part.toDataURL("image/jpeg", 0.92),
|
|
200
|
+
"JPEG",
|
|
201
|
+
MARGIN,
|
|
202
|
+
CONTENT_TOP,
|
|
203
|
+
CONTENT_W,
|
|
204
|
+
part.height / k / pxPerMm,
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const generatedAt = formatGeneratedAt();
|
|
209
|
+
const total = pdf.getNumberOfPages();
|
|
210
|
+
for (let page = 1; page <= total; page++) {
|
|
211
|
+
pdf.setPage(page);
|
|
212
|
+
drawHeader(pdf, meta);
|
|
213
|
+
drawFooter(pdf, page, total, generatedAt);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
pdf.save(meta.fileName);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return { exportReportPdf };
|
|
220
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.97.1-staging.
|
|
5
|
+
"version": "4.97.1-staging.518",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
|
@@ -53,6 +53,14 @@ export interface NFCPatrolActivity {
|
|
|
53
53
|
endTime: string;
|
|
54
54
|
status: NFCPatrolActivityStatus;
|
|
55
55
|
remarks?: string;
|
|
56
|
+
/** Photo the guard attached when skipping (an uploaded file's id). */
|
|
57
|
+
skippedPhotoFileId?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** One patrol run: its schedule-vs-actual and its checkpoints. */
|
|
61
|
+
export interface NFCPatrolRunDetail {
|
|
62
|
+
routeSummary: NFCPatrolRouteSummary;
|
|
63
|
+
activities: NFCPatrolActivity[];
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
export interface NFCPatrolReport {
|
|
@@ -65,6 +73,8 @@ export type NFCPatrolReportSummaryStatus = "Completed" | "Incomplete";
|
|
|
65
73
|
|
|
66
74
|
export interface NFCPatrolReportSummaryRow {
|
|
67
75
|
id: string;
|
|
76
|
+
/** The patrol's day, "YYYY-MM-DD". */
|
|
77
|
+
date?: string;
|
|
68
78
|
routeName: string;
|
|
69
79
|
securityCheckSchedule: string;
|
|
70
80
|
guardName?: string;
|
|
@@ -72,6 +82,8 @@ export interface NFCPatrolReportSummaryRow {
|
|
|
72
82
|
checked: number;
|
|
73
83
|
missed: number;
|
|
74
84
|
status: NFCPatrolReportSummaryStatus;
|
|
85
|
+
/** The run behind the row, opened in the route details dialog. */
|
|
86
|
+
detail?: NFCPatrolRunDetail;
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
export interface NFCPatrolSummaryReport {
|
|
@@ -82,6 +94,8 @@ export interface NFCPatrolSummaryReport {
|
|
|
82
94
|
|
|
83
95
|
export interface NFCPatrolMonthlyReportRow {
|
|
84
96
|
month: string;
|
|
97
|
+
/** Patrol runs that month; a month with none has no list to open. */
|
|
98
|
+
runs?: number;
|
|
85
99
|
checked: number;
|
|
86
100
|
/** `null` when no checkpoint was due that month - see `utils/nfc-patrol-report.ts`. */
|
|
87
101
|
checkedPercentage: number | null;
|