@7365admin1/layer-common 1.10.8 → 1.10.10
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/BulletinBoardManagement.vue +18 -8
- package/components/Carousel.vue +474 -0
- package/components/DeliveryCompany.vue +240 -0
- package/components/DrawImage.vue +172 -0
- package/components/EntryPassInformation.vue +70 -10
- package/components/EquipmentItemMain.vue +9 -4
- package/components/Feedback/Form.vue +4 -4
- package/components/FeedbackMain.vue +734 -146
- package/components/FileInput.vue +289 -0
- package/components/IncidentReport/Authorities.vue +189 -151
- package/components/IncidentReport/IncidentInformation.vue +14 -10
- package/components/IncidentReport/IncidentInformationDownload.vue +212 -0
- package/components/IncidentReport/affectedEntities.vue +8 -57
- package/components/SiteSettings.vue +285 -0
- package/components/StockCard.vue +11 -7
- package/components/Tooltip/Info.vue +33 -0
- package/components/VisitorForm.vue +176 -45
- package/components/VisitorManagement.vue +23 -6
- package/composables/useAccessManagement.ts +60 -18
- package/composables/useBulletin.ts +8 -3
- package/composables/useBulletinBoardPermission.ts +48 -0
- package/composables/useCleaningPermission.ts +2 -0
- package/composables/useCommonPermission.ts +29 -1
- package/composables/useEquipmentManagement.ts +63 -0
- package/composables/useFeedback.ts +53 -21
- package/composables/useFile.ts +6 -0
- package/composables/useLocalAuth.ts +29 -1
- package/composables/useSiteSettings.ts +1 -1
- package/composables/useUploadFiles.ts +94 -0
- package/composables/useUtils.ts +152 -53
- package/composables/useVisitor.ts +9 -6
- package/constants/app.ts +12 -0
- package/nuxt.config.ts +2 -0
- package/package.json +3 -1
- package/plugins/vue-draggable-next.client.ts +5 -0
- package/types/feedback.d.ts +5 -2
- package/types/site.d.ts +2 -1
- package/types/user.d.ts +1 -0
|
@@ -192,8 +192,35 @@ export function useCommonPermissions() {
|
|
|
192
192
|
description:
|
|
193
193
|
"Allows the user to remove a building unit from the system permanently.",
|
|
194
194
|
},
|
|
195
|
+
|
|
195
196
|
};
|
|
196
197
|
|
|
198
|
+
|
|
199
|
+
const bulletinBoardPermissions: Record<string, TPermission> = {
|
|
200
|
+
"add-bulletin-board": {
|
|
201
|
+
check: true,
|
|
202
|
+
description: "Allows the user to add a new bulletin board to the system.",
|
|
203
|
+
},
|
|
204
|
+
"see-all-bulletin-boards": {
|
|
205
|
+
check: true,
|
|
206
|
+
description: "Allows the user to view the list of all bulletin boards.",
|
|
207
|
+
},
|
|
208
|
+
"see-bulletin-board-details": {
|
|
209
|
+
check: true,
|
|
210
|
+
description:
|
|
211
|
+
"Allows the user to view the details of a specific bulletin board.",
|
|
212
|
+
},
|
|
213
|
+
"update-bulletin-board": {
|
|
214
|
+
check: true,
|
|
215
|
+
description: "Allows the user to update bulletin board details.",
|
|
216
|
+
},
|
|
217
|
+
"delete-bulletin-board": {
|
|
218
|
+
check: true,
|
|
219
|
+
description:
|
|
220
|
+
"Allows the user to remove a bulletin board from the system permanently.",
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
|
|
197
224
|
return {
|
|
198
225
|
invitationPermissions,
|
|
199
226
|
memberPermissions,
|
|
@@ -202,6 +229,7 @@ export function useCommonPermissions() {
|
|
|
202
229
|
workOrderPermissions,
|
|
203
230
|
visitorManagementPermissions,
|
|
204
231
|
buildingManagementPermissions,
|
|
205
|
-
buildingUnitManagementPermissions
|
|
232
|
+
buildingUnitManagementPermissions,
|
|
233
|
+
bulletinBoardPermissions,
|
|
206
234
|
};
|
|
207
235
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export default function useEquipmentManagement() {
|
|
2
|
+
function getSupplies({ page = 1, search = "", limit = 10, site = "" } = {}) {
|
|
3
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
4
|
+
`/api/hygiene-supplies/site/${site}`,
|
|
5
|
+
{
|
|
6
|
+
method: "GET",
|
|
7
|
+
query: { page, search, limit, site },
|
|
8
|
+
}
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getSupplyById(id: string) {
|
|
13
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
14
|
+
`/api/hygiene-supplies/id/${id}`,
|
|
15
|
+
{
|
|
16
|
+
method: "GET",
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createSupply(payload: TSupplyCreate, site: string) {
|
|
22
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
23
|
+
`/api/hygiene-supplies/site/${site}`,
|
|
24
|
+
{
|
|
25
|
+
method: "POST",
|
|
26
|
+
body: {
|
|
27
|
+
name: payload.name,
|
|
28
|
+
unitOfMeasurement: payload.unitOfMeasurement,
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function updateSupply(id: string, payload: TSupplyCreate) {
|
|
35
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
36
|
+
`/api/hygiene-supplies/id/${id}`,
|
|
37
|
+
{
|
|
38
|
+
method: "PATCH",
|
|
39
|
+
body: {
|
|
40
|
+
name: payload.name,
|
|
41
|
+
unitOfMeasurement: payload.unitOfMeasurement,
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function deleteSupply(id: string) {
|
|
48
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
49
|
+
`/api/hygiene-supplies/id/${id}`,
|
|
50
|
+
{
|
|
51
|
+
method: "DELETE",
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
getSupplies,
|
|
58
|
+
getSupplyById,
|
|
59
|
+
createSupply,
|
|
60
|
+
updateSupply,
|
|
61
|
+
deleteSupply,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -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,
|
package/composables/useFile.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export default function useFile() {
|
|
2
2
|
const baseUrl = useRuntimeConfig().public.API_DO_STORAGE_ENDPOINT;
|
|
3
|
+
const baseUrlAnpr = useRuntimeConfig().public.API_DO_STORAGE_ENDPOINT_ANPR;
|
|
3
4
|
|
|
4
5
|
function addFile(file: File | null) {
|
|
5
6
|
if (!file) {
|
|
@@ -19,6 +20,10 @@ export default function useFile() {
|
|
|
19
20
|
return `${baseUrl}/${id}`;
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
function getFileUrlAnpr(id: string) {
|
|
24
|
+
return `${baseUrlAnpr}/${id}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
async function urlToFile(url: string, filename: string): Promise<File> {
|
|
23
28
|
const response = await fetch(url);
|
|
24
29
|
const blob = await response.blob();
|
|
@@ -49,5 +54,6 @@ export default function useFile() {
|
|
|
49
54
|
urlToFile,
|
|
50
55
|
getFileUrl,
|
|
51
56
|
getFileById,
|
|
57
|
+
getFileUrlAnpr
|
|
52
58
|
};
|
|
53
59
|
}
|
|
@@ -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;
|
|
@@ -38,7 +38,7 @@ export default function () {
|
|
|
38
38
|
}
|
|
39
39
|
async function updateSitebyId(
|
|
40
40
|
siteId: string,
|
|
41
|
-
payload: { field
|
|
41
|
+
payload: { field?: string; value?: number, deliveryCompanyList?: string[] }
|
|
42
42
|
) {
|
|
43
43
|
return await useNuxtApp().$api<Record<string, any>>(
|
|
44
44
|
`/api/sites/id/${siteId}`,
|
|
@@ -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
|
}
|