@7365admin1/layer-common 4.9.1-staging.306 → 4.9.1-staging.307
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/components/ManageChecklistMain.vue +35 -34
- package/package.json +1 -1
- package/utils/checklist-set.ts +28 -0
|
@@ -254,7 +254,7 @@
|
|
|
254
254
|
|
|
255
255
|
<v-card-text class="screen-modal__body pa-4">
|
|
256
256
|
<v-row>
|
|
257
|
-
<v-col cols="12">
|
|
257
|
+
<v-col v-if="canAddRemarks" cols="12">
|
|
258
258
|
<InputLabel title="Remarks" :required="false" class="mb-2" />
|
|
259
259
|
<!-- `.filter-field` is the design's field on a `v-textarea`: the
|
|
260
260
|
10px corner and 13.5px type, without taking the binding away. -->
|
|
@@ -458,6 +458,7 @@
|
|
|
458
458
|
|
|
459
459
|
<script setup lang="ts">
|
|
460
460
|
import { readListPage } from "../utils/list-page";
|
|
461
|
+
import { isPhotoRefusal, isSetFinished } from "../utils/checklist-set";
|
|
461
462
|
import useCleaningSchedules from "../composables/useCleaningSchedules";
|
|
462
463
|
import useCustomerSite from "../composables/useCustomerSite";
|
|
463
464
|
import useFile from "../composables/useFile";
|
|
@@ -526,12 +527,13 @@ function getKey(item: any, set?: number): string {
|
|
|
526
527
|
}
|
|
527
528
|
|
|
528
529
|
function isGroupComplete(group: { set: number; items: any[] }): boolean {
|
|
529
|
-
return (
|
|
530
|
-
group.items.
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
item.
|
|
534
|
-
|
|
530
|
+
return isSetFinished(
|
|
531
|
+
group.items.map((item: any) =>
|
|
532
|
+
item.approve === true
|
|
533
|
+
? "approve"
|
|
534
|
+
: item.reject === true
|
|
535
|
+
? "reject"
|
|
536
|
+
: activeActions[getKey(item, group.set)]
|
|
535
537
|
)
|
|
536
538
|
);
|
|
537
539
|
}
|
|
@@ -555,11 +557,12 @@ function getGroupCompletedByName(group: {
|
|
|
555
557
|
);
|
|
556
558
|
}
|
|
557
559
|
|
|
558
|
-
|
|
560
|
+
/** Every unit approved or rejected, counting this screen's pending ticks. */
|
|
561
|
+
function isSetFinishedLocally(setNumber: number): boolean {
|
|
559
562
|
const group = items.value.find((g: any) => g.set === setNumber);
|
|
560
563
|
if (!group) return false;
|
|
561
|
-
return (
|
|
562
|
-
(unit: any) => activeActions[getKey(unit, setNumber)]
|
|
564
|
+
return isSetFinished(
|
|
565
|
+
(group.units || []).map((unit: any) => activeActions[getKey(unit, setNumber)])
|
|
563
566
|
);
|
|
564
567
|
}
|
|
565
568
|
|
|
@@ -671,7 +674,8 @@ const modalData = reactive({
|
|
|
671
674
|
*/
|
|
672
675
|
const isModalValid = computed(() => {
|
|
673
676
|
return (
|
|
674
|
-
modalData.remark?.trim().length > 0 &&
|
|
677
|
+
(!canAddRemarks.value || modalData.remark?.trim().length > 0) &&
|
|
678
|
+
modalData.photoIds.length > 0
|
|
675
679
|
);
|
|
676
680
|
});
|
|
677
681
|
|
|
@@ -851,23 +855,9 @@ function openCompletionDialog({
|
|
|
851
855
|
return;
|
|
852
856
|
}
|
|
853
857
|
|
|
854
|
-
//
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
_updateUnitChecklist({
|
|
858
|
-
remark: "",
|
|
859
|
-
photos: [],
|
|
860
|
-
photoIds: [],
|
|
861
|
-
approvedItems,
|
|
862
|
-
lastApprovedKey,
|
|
863
|
-
setNumber,
|
|
864
|
-
}).catch((err) => {
|
|
865
|
-
console.error("Error auto-approving set:", err);
|
|
866
|
-
showMessage(err?.message || "Failed to approve set", "error");
|
|
867
|
-
});
|
|
868
|
-
return;
|
|
869
|
-
}
|
|
870
|
-
|
|
858
|
+
// Every role gets the dialog: finishing a set needs a photo. A role without
|
|
859
|
+
// add-remarks used to skip it and auto-approve with no photo, which the
|
|
860
|
+
// server refuses. That role sees no remarks field (see `isModalValid`).
|
|
871
861
|
modalData.currentSet = setNumber;
|
|
872
862
|
modalData.approvedItems = approvedItems;
|
|
873
863
|
modalData.lastApprovedKey = lastApprovedKey;
|
|
@@ -961,7 +951,7 @@ async function handleItemActionClick(
|
|
|
961
951
|
// Approve: check if this completes the entire set
|
|
962
952
|
lastApprovedKey.value = key;
|
|
963
953
|
|
|
964
|
-
if (
|
|
954
|
+
if (isSetFinishedLocally(set) && !completedSets.value.has(set)) {
|
|
965
955
|
const newApprovedItems = getNewApprovedItemsForSet(set);
|
|
966
956
|
if (newApprovedItems.length > 0) {
|
|
967
957
|
completedSets.value.add(set);
|
|
@@ -1012,11 +1002,22 @@ async function _callUpdateUnitChecklist(
|
|
|
1012
1002
|
);
|
|
1013
1003
|
await getUnitCleanerChecklistRefresh();
|
|
1014
1004
|
} catch (error: any) {
|
|
1005
|
+
const reason = error?.data?.message || error?.message;
|
|
1006
|
+
if (action === "approve" && isPhotoRefusal(reason)) {
|
|
1007
|
+
// This screen's view was out of date (someone else ticked the rest of
|
|
1008
|
+
// the set), so this tick finishes it. Ask for the photo, don't fail.
|
|
1009
|
+
const key = getKey(item, set);
|
|
1010
|
+
activeActions[key] = "approve";
|
|
1011
|
+
completedSets.value.add(set);
|
|
1012
|
+
openCompletionDialog({
|
|
1013
|
+
setNumber: set,
|
|
1014
|
+
approvedItems: [{ key, item: { ...item, set }, action: "approve" }],
|
|
1015
|
+
lastApprovedKey: key,
|
|
1016
|
+
});
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1015
1019
|
console.error("Error updating unit checklist:", error);
|
|
1016
|
-
showMessage(
|
|
1017
|
-
error?.data?.message || error?.message || "Failed to update checklist",
|
|
1018
|
-
"error"
|
|
1019
|
-
);
|
|
1020
|
+
showMessage(reason || "Failed to update checklist", "error");
|
|
1020
1021
|
} finally {
|
|
1021
1022
|
submitting.value = false;
|
|
1022
1023
|
if (action === "approve") {
|
|
@@ -1045,7 +1046,7 @@ async function _updateUnitChecklist({
|
|
|
1045
1046
|
throw new Error("No items to approve");
|
|
1046
1047
|
}
|
|
1047
1048
|
|
|
1048
|
-
if (!remark?.trim()) {
|
|
1049
|
+
if (canAddRemarks.value && !remark?.trim()) {
|
|
1049
1050
|
throw new Error("Remark is required");
|
|
1050
1051
|
}
|
|
1051
1052
|
|
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.9.1-staging.
|
|
5
|
+
"version": "4.9.1-staging.307",
|
|
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.",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHICH TICK FINISHES A CHECKLIST SET — the one rule shared with the server and
|
|
3
|
+
* the five field apps.
|
|
4
|
+
*
|
|
5
|
+
* A task is a SET of units. A unit is done once it is approved OR rejected, and
|
|
6
|
+
* the set is finished when every unit is done. The server decides the same way
|
|
7
|
+
* (module-hygiene `readCompletion`, and the units list's `isFullyActioned`), and
|
|
8
|
+
* it requires a photo on the approve that finishes the set.
|
|
9
|
+
*
|
|
10
|
+
* This screen used to count approvals only. In a set holding a rejected unit it
|
|
11
|
+
* never saw the set as finished, so it sent the last approve without the photo
|
|
12
|
+
* dialog, and the server refused it.
|
|
13
|
+
*/
|
|
14
|
+
export type UnitAction = "approve" | "reject" | undefined;
|
|
15
|
+
|
|
16
|
+
export function isSetFinished(actions: UnitAction[]): boolean {
|
|
17
|
+
return (
|
|
18
|
+
actions.length > 0 &&
|
|
19
|
+
actions.every((action) => action === "approve" || action === "reject")
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The server's refusal for want of a photo (module-hygiene `COMPLETION_PHOTO_MESSAGE`). */
|
|
24
|
+
const PHOTO_REFUSAL = /photo is required to complete/i;
|
|
25
|
+
|
|
26
|
+
export function isPhotoRefusal(message: unknown): boolean {
|
|
27
|
+
return typeof message === "string" && PHOTO_REFUSAL.test(message);
|
|
28
|
+
}
|