@7365admin1/layer-common 1.10.7 → 1.10.9
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 +12 -0
- package/components/AccessCardAddForm.vue +1 -1
- package/components/AccessCardAssignToUnitForm.vue +1 -1
- package/components/AccessManagement.vue +1 -1
- package/components/{AddSupplyForm.vue → AddEqupmentForm.vue} +5 -5
- package/components/BuildingManagement/units.vue +2 -2
- package/components/BuildingUnitFormAdd.vue +4 -4
- package/components/BuildingUnitFormEdit.vue +114 -68
- package/components/Carousel.vue +474 -0
- package/components/DrawImage.vue +172 -0
- package/components/EntryPassInformation.vue +283 -29
- package/components/{CheckoutItemMain.vue → EquipmentItemMain.vue} +95 -87
- package/components/{SupplyManagement.vue → EquipmentManagement.vue} +3 -3
- package/components/Feedback/Form.vue +4 -4
- package/components/FeedbackMain.vue +748 -145
- package/components/FileInput.vue +289 -0
- package/components/Input/DateTimePicker.vue +17 -11
- package/components/ManageChecklistMain.vue +379 -41
- package/components/StockCard.vue +11 -7
- package/components/TableHygiene.vue +42 -452
- package/components/UnitPersonCard.vue +74 -14
- package/components/VisitorForm.vue +193 -52
- package/components/VisitorFormSelection.vue +13 -2
- package/components/VisitorManagement.vue +83 -55
- package/composables/useAccessManagement.ts +41 -18
- package/composables/useCleaningPermission.ts +7 -7
- package/composables/useDashboardData.ts +2 -2
- package/composables/useEquipment.ts +63 -0
- package/composables/{useCheckout.ts → useEquipmentItem.ts} +7 -7
- package/composables/{useCheckoutPermission.ts → useEquipmentItemPermission.ts} +13 -13
- package/composables/{useSupply.ts → useEquipmentManagement.ts} +1 -1
- package/composables/useEquipmentManagementPermission.ts +96 -0
- package/composables/{useSupplyPermission.ts → useEquipmentPermission.ts} +9 -9
- package/composables/useFeedback.ts +53 -21
- package/composables/useLocalAuth.ts +29 -1
- package/composables/useUploadFiles.ts +94 -0
- package/composables/useUtils.ts +152 -53
- package/composables/useVehicle.ts +21 -2
- package/composables/useVisitor.ts +9 -7
- package/composables/useWorkOrder.ts +25 -3
- package/package.json +2 -1
- package/types/building.d.ts +1 -1
- package/types/{checkout-item.d.ts → equipment-item.d.ts} +3 -3
- package/types/{supply.d.ts → equipment.d.ts} +2 -2
- package/types/feedback.d.ts +5 -2
- package/types/people.d.ts +3 -1
- package/types/user.d.ts +1 -0
- package/types/vehicle.d.ts +2 -0
- package/types/visitor.d.ts +2 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import useCleaningPermission from "./useCleaningPermission";
|
|
2
|
+
import { useLocalSetup } from "./useLocalSetup";
|
|
3
|
+
import usePermission from "./usePermission";
|
|
4
|
+
|
|
5
|
+
export function useEquipmentManagementPermission() {
|
|
6
|
+
const { hasPermission } = usePermission();
|
|
7
|
+
const { permissions } = useCleaningPermission();
|
|
8
|
+
const { userAppRole } = useLocalSetup();
|
|
9
|
+
|
|
10
|
+
const canViewEquipments = computed(() => {
|
|
11
|
+
if (!userAppRole.value) return true;
|
|
12
|
+
if (userAppRole.value.permissions.includes("*")) return true;
|
|
13
|
+
return hasPermission(
|
|
14
|
+
userAppRole.value,
|
|
15
|
+
permissions,
|
|
16
|
+
"supply-mgmt",
|
|
17
|
+
"see-all-supplies"
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const canAddEquipment = computed(() => {
|
|
22
|
+
if (!userAppRole.value) return true;
|
|
23
|
+
if (userAppRole.value.permissions.includes("*")) return true;
|
|
24
|
+
return hasPermission(
|
|
25
|
+
userAppRole.value,
|
|
26
|
+
permissions,
|
|
27
|
+
"supply-mgmt",
|
|
28
|
+
"add-supply"
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const canUpdateEquipment = computed(() => {
|
|
33
|
+
if (!userAppRole.value) return true;
|
|
34
|
+
if (userAppRole.value.permissions.includes("*")) return true;
|
|
35
|
+
return hasPermission(
|
|
36
|
+
userAppRole.value,
|
|
37
|
+
permissions,
|
|
38
|
+
"supply-mgmt",
|
|
39
|
+
"update-supply"
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const canDeleteEquipment = computed(() => {
|
|
44
|
+
if (!userAppRole.value) return true;
|
|
45
|
+
if (userAppRole.value.permissions.includes("*")) return true;
|
|
46
|
+
return hasPermission(
|
|
47
|
+
userAppRole.value,
|
|
48
|
+
permissions,
|
|
49
|
+
"supply-mgmt",
|
|
50
|
+
"delete-supply"
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const canAddStock = computed(() => {
|
|
55
|
+
if (!userAppRole.value) return true;
|
|
56
|
+
if (userAppRole.value.permissions.includes("*")) return true;
|
|
57
|
+
return hasPermission(
|
|
58
|
+
userAppRole.value,
|
|
59
|
+
permissions,
|
|
60
|
+
"supply-mgmt",
|
|
61
|
+
"add-stock"
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const canViewStock = computed(() => {
|
|
66
|
+
if (!userAppRole.value) return true;
|
|
67
|
+
if (userAppRole.value.permissions.includes("*")) return true;
|
|
68
|
+
return hasPermission(
|
|
69
|
+
userAppRole.value,
|
|
70
|
+
permissions,
|
|
71
|
+
"supply-mgmt",
|
|
72
|
+
"view-stock"
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const canRequestItem = computed(() => {
|
|
77
|
+
if (!userAppRole.value) return true;
|
|
78
|
+
if (userAppRole.value.permissions.includes("*")) return true;
|
|
79
|
+
return hasPermission(
|
|
80
|
+
userAppRole.value,
|
|
81
|
+
permissions,
|
|
82
|
+
"supply-mgmt",
|
|
83
|
+
"request-item"
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
canViewEquipments,
|
|
89
|
+
canAddEquipment,
|
|
90
|
+
canUpdateEquipment,
|
|
91
|
+
canDeleteEquipment,
|
|
92
|
+
canAddStock,
|
|
93
|
+
canViewStock,
|
|
94
|
+
canRequestItem,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function useEquipmentPermission() {
|
|
2
2
|
const { hasPermission } = usePermission();
|
|
3
3
|
const { permissions } = useCleaningPermission();
|
|
4
4
|
const { userAppRole } = useLocalSetup();
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const canViewEquipments = computed(() => {
|
|
7
7
|
if (!userAppRole.value) return true;
|
|
8
8
|
if (userAppRole.value.permissions.includes("*")) return true;
|
|
9
9
|
return hasPermission(
|
|
@@ -14,7 +14,7 @@ export function useSupplyPermission() {
|
|
|
14
14
|
);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const canAddEquipment = computed(() => {
|
|
18
18
|
if (!userAppRole.value) return true;
|
|
19
19
|
if (userAppRole.value.permissions.includes("*")) return true;
|
|
20
20
|
return hasPermission(
|
|
@@ -25,7 +25,7 @@ export function useSupplyPermission() {
|
|
|
25
25
|
);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const canUpdateEquipment = computed(() => {
|
|
29
29
|
if (!userAppRole.value) return true;
|
|
30
30
|
if (userAppRole.value.permissions.includes("*")) return true;
|
|
31
31
|
return hasPermission(
|
|
@@ -36,7 +36,7 @@ export function useSupplyPermission() {
|
|
|
36
36
|
);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
const
|
|
39
|
+
const canDeleteEquipment = computed(() => {
|
|
40
40
|
if (!userAppRole.value) return true;
|
|
41
41
|
if (userAppRole.value.permissions.includes("*")) return true;
|
|
42
42
|
return hasPermission(
|
|
@@ -81,10 +81,10 @@ export function useSupplyPermission() {
|
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
return {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
canViewEquipments,
|
|
85
|
+
canAddEquipment,
|
|
86
|
+
canUpdateEquipment,
|
|
87
|
+
canDeleteEquipment,
|
|
88
88
|
canAddStock,
|
|
89
89
|
canViewStock,
|
|
90
90
|
canRequestItem,
|
|
@@ -32,58 +32,90 @@ export default function useFeedback() {
|
|
|
32
32
|
})
|
|
33
33
|
);
|
|
34
34
|
|
|
35
|
+
const { currentUser } = useLocalAuth();
|
|
36
|
+
|
|
35
37
|
async function getFeedbacks({
|
|
36
38
|
page = 1,
|
|
37
|
-
site = "",
|
|
38
|
-
status = "to-do",
|
|
39
|
-
search = "",
|
|
40
39
|
limit = 10,
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
search = "",
|
|
41
|
+
site = "",
|
|
42
|
+
dateFrom = "",
|
|
43
|
+
dateTo = "",
|
|
44
|
+
date,
|
|
45
|
+
status = "",
|
|
46
|
+
provider = "",
|
|
47
|
+
service = "",
|
|
48
|
+
userId = "",
|
|
49
|
+
}: {
|
|
50
|
+
page?: number;
|
|
51
|
+
limit?: number;
|
|
52
|
+
search?: string;
|
|
53
|
+
site?: string;
|
|
54
|
+
dateFrom?: any;
|
|
55
|
+
dateTo?: any;
|
|
56
|
+
date?: any;
|
|
57
|
+
status?: string;
|
|
58
|
+
provider?: string;
|
|
59
|
+
service?: string;
|
|
60
|
+
userId?: string;
|
|
43
61
|
} = {}) {
|
|
44
62
|
try {
|
|
45
|
-
return useNuxtApp().$api<Record<string, any>>(
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
63
|
+
return useNuxtApp().$api<Record<string, any>>("/api/feedbacks2", {
|
|
64
|
+
method: "GET",
|
|
65
|
+
query: {
|
|
66
|
+
page,
|
|
67
|
+
limit,
|
|
68
|
+
search,
|
|
69
|
+
site,
|
|
70
|
+
dateFrom,
|
|
71
|
+
dateTo,
|
|
72
|
+
date,
|
|
73
|
+
status,
|
|
74
|
+
provider,
|
|
75
|
+
service,
|
|
76
|
+
...(currentUser.value.type != "site" && {
|
|
77
|
+
userId,
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
52
81
|
} catch (err) {
|
|
53
82
|
console.error("Error fetching feedbacks:", err);
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
85
|
|
|
57
86
|
function getFeedbackById(id: string) {
|
|
58
|
-
return useNuxtApp().$api<TFeedback>(`/api/
|
|
87
|
+
return useNuxtApp().$api<TFeedback>(`/api/feedbacks2/${id}`, {
|
|
59
88
|
method: "GET",
|
|
60
89
|
});
|
|
61
90
|
}
|
|
62
91
|
|
|
63
92
|
function createFeedback(payload: TFeedbackCreate) {
|
|
64
|
-
return useNuxtApp().$api<Record<string, any>>("/api/
|
|
93
|
+
return useNuxtApp().$api<Record<string, any>>("/api/feedbacks2", {
|
|
65
94
|
method: "POST",
|
|
66
95
|
body: payload,
|
|
67
96
|
});
|
|
68
97
|
}
|
|
69
98
|
|
|
70
99
|
function updateFeedback(id: string, payload: TFeedbackUpdate) {
|
|
71
|
-
return useNuxtApp().$api<Record<string, any>>(`/api/
|
|
100
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/feedbacks2/${id}`, {
|
|
72
101
|
method: "PUT",
|
|
73
102
|
body: payload,
|
|
74
103
|
});
|
|
75
104
|
}
|
|
76
105
|
|
|
77
106
|
function deleteFeedback(id: string) {
|
|
78
|
-
return useNuxtApp().$api<Record<string, any>>(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
107
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
108
|
+
`/api/feedbacks/deleted/feedback/${id}`,
|
|
109
|
+
{
|
|
110
|
+
method: "PUT",
|
|
111
|
+
// query: { id },
|
|
112
|
+
}
|
|
113
|
+
);
|
|
82
114
|
}
|
|
83
115
|
|
|
84
116
|
function updateFeedbackServiceProvider(id: string, serviceProvider: string) {
|
|
85
117
|
return useNuxtApp().$api<Record<string, any>>(
|
|
86
|
-
`/api/
|
|
118
|
+
`/api/feedbacks2/${id}/service-provider`,
|
|
87
119
|
{
|
|
88
120
|
method: "PATCH",
|
|
89
121
|
body: {
|
|
@@ -95,7 +127,7 @@ export default function useFeedback() {
|
|
|
95
127
|
|
|
96
128
|
function updateStatusComplete(id: string, payload: TFeedbackStatusComplete) {
|
|
97
129
|
return useNuxtApp().$api<Record<string, any>>(
|
|
98
|
-
`/api/
|
|
130
|
+
`/api/feedbacks2/${id}/status/complete`,
|
|
99
131
|
{
|
|
100
132
|
method: "PUT",
|
|
101
133
|
body: payload,
|
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
export default function useLocalAuth() {
|
|
2
2
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const _address = {
|
|
5
|
+
country: "",
|
|
6
|
+
address1: "",
|
|
7
|
+
address2: "",
|
|
8
|
+
city: "",
|
|
9
|
+
province: "",
|
|
10
|
+
postalCode: "",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const user = {
|
|
14
|
+
_id: "",
|
|
15
|
+
givenName: "",
|
|
16
|
+
middleName: "",
|
|
17
|
+
surname: "",
|
|
18
|
+
address: _address,
|
|
19
|
+
email: "",
|
|
20
|
+
password: "",
|
|
21
|
+
type: "",
|
|
22
|
+
createdAt: "",
|
|
23
|
+
organization: "",
|
|
24
|
+
role: "",
|
|
25
|
+
primaryPhone: "",
|
|
26
|
+
mobilePhone: "",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const currentUser = useState(
|
|
30
|
+
"currentUser",
|
|
31
|
+
(): TUser => JSON.parse(JSON.stringify(user))
|
|
32
|
+
);
|
|
5
33
|
|
|
6
34
|
async function authenticate() {
|
|
7
35
|
const user = useCookie("user", cookieConfig).value;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export default function useUploadFiles() {
|
|
2
|
+
let files = ref<any>([]);
|
|
3
|
+
|
|
4
|
+
type TFile = {
|
|
5
|
+
name: string;
|
|
6
|
+
data: File;
|
|
7
|
+
progress: number;
|
|
8
|
+
url?: string;
|
|
9
|
+
type?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const attachedFiles = useState("attachedFiles", (): TFile[] => []);
|
|
14
|
+
const filesUrlUploaded = useState(
|
|
15
|
+
"filesUrlUploaded",
|
|
16
|
+
(): Array<{ data: File }> => [],
|
|
17
|
+
);
|
|
18
|
+
const isFileUploading = useState("isFileUploading", () => false);
|
|
19
|
+
|
|
20
|
+
function uploadFile(file: any): Promise<object> {
|
|
21
|
+
isFileUploading.value = true;
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const formData = new FormData();
|
|
24
|
+
formData.append("file", file.data);
|
|
25
|
+
|
|
26
|
+
const xhr = new XMLHttpRequest();
|
|
27
|
+
xhr.open("POST", `/api/files/upload/v2?status=draft`);
|
|
28
|
+
|
|
29
|
+
xhr.upload.onprogress = (event) => {
|
|
30
|
+
if (event.lengthComputable) {
|
|
31
|
+
file.progress = Math.round((event.loaded / event.total) * 100);
|
|
32
|
+
// Handle progress (optional)
|
|
33
|
+
if (file.progress === 100)
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
isFileUploading.value = false;
|
|
36
|
+
}, 2000);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
xhr.onload = () => {
|
|
41
|
+
if (xhr.status === 200) {
|
|
42
|
+
try {
|
|
43
|
+
const response = JSON.parse(xhr.responseText);
|
|
44
|
+
resolve({ _id: response.id, name: file.name, type: file.type }); // Resolve with the id from the response
|
|
45
|
+
} catch (error) {
|
|
46
|
+
reject(new Error("Failed to parse server response"));
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
reject(new Error(`Upload failed with status ${xhr.status}`));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
xhr.onerror = () => reject(new Error("Network error"));
|
|
54
|
+
xhr.send(formData);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Use async/await to handle the file uploads
|
|
59
|
+
async function uploadFileUtil(fileString: any): Promise<any> {
|
|
60
|
+
const results: any = [];
|
|
61
|
+
// Iterate over file objects asynchronously
|
|
62
|
+
for (const file of fileString) {
|
|
63
|
+
try {
|
|
64
|
+
if (typeof file === "string") {
|
|
65
|
+
results.push(file);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const fileId = await uploadFile(file); // Await the file upload
|
|
69
|
+
results.push(fileId); // Collect the file ID
|
|
70
|
+
files.value = [];
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.log("Error occurred while attaching images.", e);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return results; // Return array of file IDs
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Show uploaded files
|
|
80
|
+
function showUploadedFiles(fileString: any) {
|
|
81
|
+
const fileStr = toRaw(fileString);
|
|
82
|
+
filesUrlUploaded.value = fileStr.map((i: { url: string }) => i.url);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
files,
|
|
87
|
+
attachedFiles,
|
|
88
|
+
filesUrlUploaded,
|
|
89
|
+
isFileUploading,
|
|
90
|
+
uploadFile,
|
|
91
|
+
uploadFileUtil,
|
|
92
|
+
showUploadedFiles,
|
|
93
|
+
};
|
|
94
|
+
}
|
package/composables/useUtils.ts
CHANGED
|
@@ -247,6 +247,18 @@ export default function useUtils() {
|
|
|
247
247
|
}
|
|
248
248
|
};
|
|
249
249
|
|
|
250
|
+
function getStatusColor(status: string) {
|
|
251
|
+
return status === "In-Progress"
|
|
252
|
+
? "#FB8C00"
|
|
253
|
+
: ["Completed", "Resolved"].includes(status)
|
|
254
|
+
? "#4CAF50"
|
|
255
|
+
: status === "Deleted"
|
|
256
|
+
? "error"
|
|
257
|
+
: status === "For Review"
|
|
258
|
+
? "primary"
|
|
259
|
+
: "grey-lighten-3";
|
|
260
|
+
}
|
|
261
|
+
|
|
250
262
|
function getOrigin() {
|
|
251
263
|
if (process.client) {
|
|
252
264
|
return window.location.origin;
|
|
@@ -272,23 +284,23 @@ export default function useUtils() {
|
|
|
272
284
|
|
|
273
285
|
// returns 16/10/2025, 15:45 format
|
|
274
286
|
function UTCToLocalTIme(UTCDateTime: string) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const formatted = local.toLocaleString("en-GB", {
|
|
279
|
-
day: "2-digit",
|
|
280
|
-
month: "2-digit",
|
|
281
|
-
year: "numeric",
|
|
282
|
-
hour: "2-digit",
|
|
283
|
-
minute: "2-digit",
|
|
284
|
-
hour12: false, // 24-hour format
|
|
285
|
-
});
|
|
287
|
+
if (!UTCDateTime) return "";
|
|
288
|
+
const local = new Date(UTCDateTime);
|
|
286
289
|
|
|
287
|
-
|
|
288
|
-
|
|
290
|
+
const formatted = local.toLocaleString("en-GB", {
|
|
291
|
+
day: "2-digit",
|
|
292
|
+
month: "2-digit",
|
|
293
|
+
year: "numeric",
|
|
294
|
+
hour: "2-digit",
|
|
295
|
+
minute: "2-digit",
|
|
296
|
+
hour12: false, // 24-hour format
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
return formatted;
|
|
300
|
+
}
|
|
289
301
|
|
|
290
|
-
// dd/mm/yyyy in local time
|
|
291
|
-
function formatDateDDMMYYYYLocal(dateString: string) {
|
|
302
|
+
// dd/mm/yyyy in local time
|
|
303
|
+
function formatDateDDMMYYYYLocal(dateString: string) {
|
|
292
304
|
if (!dateString) return "-";
|
|
293
305
|
|
|
294
306
|
const date = new Date(dateString);
|
|
@@ -297,7 +309,7 @@ function formatDateDDMMYYYYLocal(dateString: string) {
|
|
|
297
309
|
const year = date.getFullYear();
|
|
298
310
|
|
|
299
311
|
return `${day}/${month}/${year}`;
|
|
300
|
-
|
|
312
|
+
}
|
|
301
313
|
|
|
302
314
|
function formatNature(value: string): string {
|
|
303
315
|
if (!value) return "";
|
|
@@ -332,13 +344,13 @@ function formatDateDDMMYYYYLocal(dateString: string) {
|
|
|
332
344
|
}
|
|
333
345
|
|
|
334
346
|
function formatDateISO8601(date: Date): string {
|
|
335
|
-
const pad = (n: number) => n.toString().padStart(2,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
347
|
+
const pad = (n: number) => n.toString().padStart(2, "0");
|
|
348
|
+
const year = date.getFullYear();
|
|
349
|
+
const month = pad(date.getMonth() + 1);
|
|
350
|
+
const day = pad(date.getDate());
|
|
351
|
+
const hours = pad(date.getHours());
|
|
352
|
+
const minutes = pad(date.getMinutes());
|
|
353
|
+
return `${year}-${month}-${day}T${hours}:${minutes}`;
|
|
342
354
|
}
|
|
343
355
|
|
|
344
356
|
function isValidBaseURL(baseURL: string | null) {
|
|
@@ -370,39 +382,119 @@ function formatDateDDMMYYYYLocal(dateString: string) {
|
|
|
370
382
|
}
|
|
371
383
|
}
|
|
372
384
|
|
|
373
|
-
function formatCamelCaseToWords(key: string){
|
|
374
|
-
if(!key) return "";
|
|
385
|
+
function formatCamelCaseToWords(key: string) {
|
|
386
|
+
if (!key) return "";
|
|
375
387
|
return key
|
|
376
|
-
.replace(/([A-Z])/g,
|
|
377
|
-
.replace(/^./, str => str.toUpperCase());
|
|
388
|
+
.replace(/([A-Z])/g, " $1")
|
|
389
|
+
.replace(/^./, (str) => str.toUpperCase());
|
|
378
390
|
}
|
|
379
391
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
)
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
392
|
+
function calculateRemainingTime(
|
|
393
|
+
item: Date | string | number | null | undefined
|
|
394
|
+
) {
|
|
395
|
+
if (!item) return -1;
|
|
396
|
+
const _date = new Date(item);
|
|
397
|
+
if (isNaN(_date.getTime())) return -1;
|
|
398
|
+
const creationTime = _date.getTime();
|
|
399
|
+
const currentTime = Date.now();
|
|
400
|
+
const differenceInMillis = currentTime - creationTime;
|
|
401
|
+
const differenceInSeconds = Math.floor(differenceInMillis / 1000);
|
|
402
|
+
const desiredDurationInSeconds = 24 * 60 * 60;
|
|
403
|
+
const remainingTimeInSeconds =
|
|
404
|
+
desiredDurationInSeconds - differenceInSeconds;
|
|
405
|
+
console.log(remainingTimeInSeconds);
|
|
406
|
+
return remainingTimeInSeconds;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const formatTime = (seconds: number) => {
|
|
410
|
+
if (seconds <= 0 || isNaN(seconds)) return "00h 00m";
|
|
411
|
+
const hours = Math.floor(seconds / 3600);
|
|
412
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
413
|
+
return `${String(hours).padStart(2, "0")}h ${String(minutes).padStart(
|
|
414
|
+
2,
|
|
415
|
+
"0"
|
|
416
|
+
)}m`;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
function standardFormatDateTime(date: string | Date) {
|
|
420
|
+
if (!date) return "";
|
|
421
|
+
|
|
422
|
+
const today = new Date(date);
|
|
423
|
+
const year = today.getFullYear();
|
|
424
|
+
let month = today.getMonth() + 1;
|
|
425
|
+
let day = today.getDate();
|
|
426
|
+
|
|
427
|
+
let hour = today.getHours();
|
|
428
|
+
let minute =
|
|
429
|
+
today.getMinutes() <= 9 ? `0${today.getMinutes()}` : today.getMinutes();
|
|
396
430
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
431
|
+
if (day < 10) day = `0${day}`;
|
|
432
|
+
if (month < 10) month = `0${month}`;
|
|
433
|
+
|
|
434
|
+
return `${day}/${month}/${year} ${hour}:${minute}`;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function standardFormatDate(date: string | Date) {
|
|
438
|
+
const today = new Date(date);
|
|
439
|
+
const year = today.getFullYear();
|
|
440
|
+
let month = today.getMonth() + 1;
|
|
441
|
+
let day = today.getDate();
|
|
442
|
+
|
|
443
|
+
if (day < 10) day = `0${day}`;
|
|
444
|
+
if (month < 10) month = `0${month}`;
|
|
445
|
+
|
|
446
|
+
return `${day}/${month}/${year}`;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const materialColors = [
|
|
450
|
+
"red",
|
|
451
|
+
"deep-purple",
|
|
452
|
+
"light-blue",
|
|
453
|
+
"green",
|
|
454
|
+
"yellow",
|
|
455
|
+
"deep-orange",
|
|
456
|
+
"pink",
|
|
457
|
+
"indigo",
|
|
458
|
+
"cyan",
|
|
459
|
+
"light-green",
|
|
460
|
+
"amber",
|
|
461
|
+
"brown",
|
|
462
|
+
"purple",
|
|
463
|
+
"blue",
|
|
464
|
+
"teal",
|
|
465
|
+
"lime",
|
|
466
|
+
"orange",
|
|
467
|
+
"blue-grey",
|
|
468
|
+
];
|
|
469
|
+
|
|
470
|
+
function getInitial(name: string): string {
|
|
471
|
+
if (typeof name !== "string") {
|
|
472
|
+
return "";
|
|
473
|
+
}
|
|
474
|
+
const rgx: RegExp = /\b\w/g;
|
|
475
|
+
|
|
476
|
+
const initials: string[] = name?.match(rgx) || [];
|
|
477
|
+
|
|
478
|
+
return initials.join("").toUpperCase();
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const fileToBase64 = (file: any): Promise<string> => {
|
|
482
|
+
return new Promise((resolve, reject) => {
|
|
483
|
+
const reader = new FileReader();
|
|
484
|
+
reader.readAsDataURL(file);
|
|
485
|
+
reader.onload = () => resolve(reader.result as string);
|
|
486
|
+
reader.onerror = reject;
|
|
487
|
+
});
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
async function getImage(url: string) {
|
|
491
|
+
try {
|
|
492
|
+
const response = await fetch(url, { method: "GET" });
|
|
493
|
+
return response.blob();
|
|
494
|
+
} catch (error: any) {
|
|
495
|
+
console.log(error);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
406
498
|
|
|
407
499
|
return {
|
|
408
500
|
requiredRule,
|
|
@@ -427,6 +519,7 @@ const formatTime = (seconds: number) => {
|
|
|
427
519
|
redirect,
|
|
428
520
|
computeTieredCost,
|
|
429
521
|
getColorStatus,
|
|
522
|
+
getStatusColor,
|
|
430
523
|
getOrigin,
|
|
431
524
|
search,
|
|
432
525
|
formatDate,
|
|
@@ -440,6 +533,12 @@ const formatTime = (seconds: number) => {
|
|
|
440
533
|
formatCamelCaseToWords,
|
|
441
534
|
calculateRemainingTime,
|
|
442
535
|
formatTime,
|
|
443
|
-
formatDateDDMMYYYYLocal
|
|
536
|
+
formatDateDDMMYYYYLocal,
|
|
537
|
+
standardFormatDateTime,
|
|
538
|
+
materialColors,
|
|
539
|
+
getInitial,
|
|
540
|
+
fileToBase64,
|
|
541
|
+
getImage,
|
|
542
|
+
standardFormatDate,
|
|
444
543
|
};
|
|
445
544
|
}
|