@fctc/widget-logic 5.3.7-beta.16 → 5.3.7-beta.17
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/dist/config.d.mts +5 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +24 -0
- package/dist/config.mjs +2 -0
- package/dist/constants.d.mts +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +24 -0
- package/dist/constants.mjs +2 -0
- package/dist/environment.d.mts +1 -0
- package/dist/environment.d.ts +1 -0
- package/dist/environment.js +24 -0
- package/dist/environment.mjs +2 -0
- package/dist/hooks.d.mts +1179 -0
- package/dist/hooks.d.ts +1179 -0
- package/dist/hooks.js +977 -0
- package/dist/hooks.mjs +958 -0
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2727 -0
- package/dist/index.mjs +2814 -0
- package/dist/provider.d.mts +1 -0
- package/dist/provider.d.ts +1 -0
- package/dist/provider.js +24 -0
- package/dist/provider.mjs +2 -0
- package/dist/services.d.mts +1 -0
- package/dist/services.d.ts +1 -0
- package/dist/services.js +24 -0
- package/dist/services.mjs +2 -0
- package/dist/types.d.mts +36 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.js +24 -0
- package/dist/types.mjs +2 -0
- package/dist/utils.d.mts +21 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.js +140 -0
- package/dist/utils.mjs +104 -0
- package/dist/widget.d.mts +332 -0
- package/dist/widget.d.ts +332 -0
- package/dist/widget.js +2103 -0
- package/dist/widget.mjs +2164 -0
- package/package.json +1 -1
package/dist/widget.mjs
ADDED
|
@@ -0,0 +1,2164 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
|
|
19
|
+
// src/widget/basic/status-dropdown-field/controller.ts
|
|
20
|
+
import { useEffect as useEffect8, useRef as useRef2, useState as useState6 } from "react";
|
|
21
|
+
|
|
22
|
+
// src/environment.ts
|
|
23
|
+
var environment_exports = {};
|
|
24
|
+
__reExport(environment_exports, environment_star);
|
|
25
|
+
import * as environment_star from "@fctc/interface-logic/environment";
|
|
26
|
+
|
|
27
|
+
// src/hooks.ts
|
|
28
|
+
import {
|
|
29
|
+
useModel,
|
|
30
|
+
useButton,
|
|
31
|
+
useChangeStatus,
|
|
32
|
+
useDelete,
|
|
33
|
+
useDeleteComment,
|
|
34
|
+
useDuplicateRecord,
|
|
35
|
+
useExecuteImport,
|
|
36
|
+
useExportExcel,
|
|
37
|
+
useForgotPassword,
|
|
38
|
+
useForgotPasswordSSO,
|
|
39
|
+
useGet2FAMethods,
|
|
40
|
+
useGetAccessByCode,
|
|
41
|
+
useGetActionDetail,
|
|
42
|
+
useGetAll,
|
|
43
|
+
useGetCalendar,
|
|
44
|
+
useGetComment,
|
|
45
|
+
useGetCompanyInfo,
|
|
46
|
+
useGetConversionRate,
|
|
47
|
+
useGetCurrency,
|
|
48
|
+
useGetCurrentCompany,
|
|
49
|
+
useGetDetail,
|
|
50
|
+
useGetFieldExport,
|
|
51
|
+
useGetFieldOnChange,
|
|
52
|
+
useGetFileExcel,
|
|
53
|
+
useGetFormView,
|
|
54
|
+
useGetGroups,
|
|
55
|
+
useGetListCompany,
|
|
56
|
+
useGetListData,
|
|
57
|
+
useGetListMyBankAccount,
|
|
58
|
+
useGetMenu,
|
|
59
|
+
useGetPrintReport,
|
|
60
|
+
useGetProGressBar,
|
|
61
|
+
useGetProfile,
|
|
62
|
+
useGetProvider,
|
|
63
|
+
useGetResequence,
|
|
64
|
+
useGetSelection,
|
|
65
|
+
useGetUser,
|
|
66
|
+
useGetView,
|
|
67
|
+
useGrantAccess,
|
|
68
|
+
useIsValidToken,
|
|
69
|
+
useLoadAction,
|
|
70
|
+
useLoadMessage,
|
|
71
|
+
useLoginCredential,
|
|
72
|
+
useLoginSocial,
|
|
73
|
+
useLogout,
|
|
74
|
+
useOdooDataTransform,
|
|
75
|
+
useOnChangeForm,
|
|
76
|
+
useParsePreview,
|
|
77
|
+
usePrint,
|
|
78
|
+
useRemoveRow,
|
|
79
|
+
useRemoveTotpSetup,
|
|
80
|
+
useRequestSetupTotp,
|
|
81
|
+
useResetPassword,
|
|
82
|
+
useResetPasswordSSO,
|
|
83
|
+
useRunAction,
|
|
84
|
+
useSave,
|
|
85
|
+
useSendComment,
|
|
86
|
+
useSettingsWebRead2fa,
|
|
87
|
+
useSignInSSO,
|
|
88
|
+
useSwitchLocale,
|
|
89
|
+
useUpdatePassword,
|
|
90
|
+
useUploadFile,
|
|
91
|
+
useUploadFileExcel,
|
|
92
|
+
useUploadIdFile,
|
|
93
|
+
useUploadImage,
|
|
94
|
+
useValidateActionToken,
|
|
95
|
+
useVerify2FA,
|
|
96
|
+
useVerifyTotp,
|
|
97
|
+
useAddEntity,
|
|
98
|
+
useChangeOrderPreparationState,
|
|
99
|
+
useCheckPayment,
|
|
100
|
+
useCreateEntity,
|
|
101
|
+
useCreatePosConfig,
|
|
102
|
+
useCreateSession,
|
|
103
|
+
useDeleteEntity,
|
|
104
|
+
useGenSerialNumber,
|
|
105
|
+
useGeneratePaymentQrInfo,
|
|
106
|
+
useGetASession,
|
|
107
|
+
useGetExternalTabs,
|
|
108
|
+
useGetList,
|
|
109
|
+
useGetOrderLine,
|
|
110
|
+
useReadGroup,
|
|
111
|
+
useGetPinCode
|
|
112
|
+
} from "@fctc/interface-logic/hooks";
|
|
113
|
+
|
|
114
|
+
// src/hooks/core/use-app-provider.tsx
|
|
115
|
+
import { createContext, useContext, useMemo as useMemo4 } from "react";
|
|
116
|
+
|
|
117
|
+
// src/hooks/core/use-menu.ts
|
|
118
|
+
import { useState as useState2 } from "react";
|
|
119
|
+
|
|
120
|
+
// src/hooks/core/use-call-action.ts
|
|
121
|
+
import { useCallback, useState } from "react";
|
|
122
|
+
|
|
123
|
+
// src/provider.ts
|
|
124
|
+
var provider_exports = {};
|
|
125
|
+
__reExport(provider_exports, provider_star);
|
|
126
|
+
import * as provider_star from "@fctc/interface-logic/provider";
|
|
127
|
+
|
|
128
|
+
// src/utils.ts
|
|
129
|
+
var utils_exports = {};
|
|
130
|
+
__export(utils_exports, {
|
|
131
|
+
STORAGES: () => STORAGES,
|
|
132
|
+
countSum: () => countSum,
|
|
133
|
+
guessTypeFromUrl: () => guessTypeFromUrl,
|
|
134
|
+
isObjectEmpty: () => isObjectEmpty,
|
|
135
|
+
languages: () => languages,
|
|
136
|
+
mergeButtons: () => mergeButtons,
|
|
137
|
+
setStorageItemAsync: () => setStorageItemAsync,
|
|
138
|
+
useStorageState: () => useStorageState
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// src/utils/constants.ts
|
|
142
|
+
var languages = [
|
|
143
|
+
{ id: "vi_VN", name: "VIE" },
|
|
144
|
+
{ id: "en_US", name: "ENG" }
|
|
145
|
+
];
|
|
146
|
+
var isBlobUrl = (url) => url.startsWith("blob:");
|
|
147
|
+
|
|
148
|
+
// src/utils/function.ts
|
|
149
|
+
import { useCallback as useCallback2, useEffect, useReducer } from "react";
|
|
150
|
+
var countSum = (data, field) => {
|
|
151
|
+
if (!data || !field) return 0;
|
|
152
|
+
return data.reduce(
|
|
153
|
+
(total, item) => total + (item?.[`${field}_count`] || 0),
|
|
154
|
+
0
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
var isObjectEmpty = (obj) => {
|
|
158
|
+
return Object.keys(obj).length === 0;
|
|
159
|
+
};
|
|
160
|
+
function mergeButtons(fields) {
|
|
161
|
+
const buttons = fields?.filter((f) => f.type_co === "button");
|
|
162
|
+
const others = fields?.filter((f) => f.type_co !== "button");
|
|
163
|
+
if (buttons?.length) {
|
|
164
|
+
others.push({
|
|
165
|
+
type_co: "buttons",
|
|
166
|
+
buttons
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return others;
|
|
170
|
+
}
|
|
171
|
+
var STORAGES = {
|
|
172
|
+
TOKEN: "accessToken",
|
|
173
|
+
USER_INFO: "USER_INFO"
|
|
174
|
+
};
|
|
175
|
+
function useAsyncState(initialValue = [true, null]) {
|
|
176
|
+
return useReducer(
|
|
177
|
+
(_state, action = null) => [false, action],
|
|
178
|
+
initialValue
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
async function setStorageItemAsync(key, value) {
|
|
182
|
+
try {
|
|
183
|
+
if (value === null) {
|
|
184
|
+
localStorage.removeItem(key);
|
|
185
|
+
} else {
|
|
186
|
+
localStorage.setItem(key, value);
|
|
187
|
+
}
|
|
188
|
+
} catch (e) {
|
|
189
|
+
console.error("Local storage is unavailable:", e);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function useStorageState(key) {
|
|
193
|
+
const [state, setState] = useAsyncState();
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
try {
|
|
196
|
+
const storedValue = localStorage.getItem(key);
|
|
197
|
+
setState(storedValue);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
console.error("Local storage is unavailable:", e);
|
|
200
|
+
}
|
|
201
|
+
}, [key]);
|
|
202
|
+
const setValue = useCallback2(
|
|
203
|
+
(value) => {
|
|
204
|
+
setState(value);
|
|
205
|
+
setStorageItemAsync(key, value);
|
|
206
|
+
},
|
|
207
|
+
[key]
|
|
208
|
+
);
|
|
209
|
+
return [state, setValue];
|
|
210
|
+
}
|
|
211
|
+
var guessTypeFromUrl = (url) => {
|
|
212
|
+
const ext = url.split(".").pop()?.toLowerCase();
|
|
213
|
+
if (!ext) return null;
|
|
214
|
+
const map = {
|
|
215
|
+
jpg: "image/jpeg",
|
|
216
|
+
jpeg: "image/jpeg",
|
|
217
|
+
png: "image/png",
|
|
218
|
+
webp: "image/webp",
|
|
219
|
+
gif: "image/gif",
|
|
220
|
+
svg: "image/svg+xml",
|
|
221
|
+
bmp: "image/bmp",
|
|
222
|
+
tiff: "image/tiff",
|
|
223
|
+
pdf: "application/pdf",
|
|
224
|
+
zip: "application/zip",
|
|
225
|
+
rar: "application/x-rar-compressed",
|
|
226
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
227
|
+
xls: "application/vnd.ms-excel",
|
|
228
|
+
mp4: "video/mp4",
|
|
229
|
+
mov: "video/quicktime"
|
|
230
|
+
};
|
|
231
|
+
return map[ext] || null;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// src/utils.ts
|
|
235
|
+
__reExport(utils_exports, utils_star);
|
|
236
|
+
import * as utils_star from "@fctc/interface-logic/utils";
|
|
237
|
+
|
|
238
|
+
// src/hooks/core/use-detail.ts
|
|
239
|
+
import { useQuery } from "@tanstack/react-query";
|
|
240
|
+
import { useEffect as useEffect2 } from "react";
|
|
241
|
+
|
|
242
|
+
// src/hooks/core/use-profile.ts
|
|
243
|
+
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
244
|
+
import { useEffect as useEffect3, useMemo } from "react";
|
|
245
|
+
|
|
246
|
+
// src/hooks/core/use-view-v2.ts
|
|
247
|
+
import { useMemo as useMemo2 } from "react";
|
|
248
|
+
|
|
249
|
+
// src/hooks/core/use-company.ts
|
|
250
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
251
|
+
import { useEffect as useEffect4, useMemo as useMemo3 } from "react";
|
|
252
|
+
|
|
253
|
+
// src/hooks/core/use-app-provider.tsx
|
|
254
|
+
import { jsx } from "react/jsx-runtime";
|
|
255
|
+
var AppProviderInitialValue = {
|
|
256
|
+
user: {},
|
|
257
|
+
company: {},
|
|
258
|
+
action: {},
|
|
259
|
+
menu: {},
|
|
260
|
+
view: {}
|
|
261
|
+
};
|
|
262
|
+
var ReactContext = createContext(AppProviderInitialValue);
|
|
263
|
+
var useAppProvider = () => {
|
|
264
|
+
const context = useContext(ReactContext);
|
|
265
|
+
if (!context) {
|
|
266
|
+
return AppProviderInitialValue;
|
|
267
|
+
}
|
|
268
|
+
return context;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/hooks/core/use-config.ts
|
|
272
|
+
import { useEffect as useEffect5 } from "react";
|
|
273
|
+
|
|
274
|
+
// src/hooks/core/use-get-specification.ts
|
|
275
|
+
import { useMemo as useMemo5 } from "react";
|
|
276
|
+
var useGetSpecification = ({
|
|
277
|
+
model,
|
|
278
|
+
viewData,
|
|
279
|
+
fields
|
|
280
|
+
}) => {
|
|
281
|
+
const baseModel = useMemo5(
|
|
282
|
+
() => ({
|
|
283
|
+
name: String(model),
|
|
284
|
+
view: viewData,
|
|
285
|
+
fields
|
|
286
|
+
}),
|
|
287
|
+
[model, viewData, fields]
|
|
288
|
+
);
|
|
289
|
+
const initModel = useModel();
|
|
290
|
+
const modelInstance = useMemo5(() => {
|
|
291
|
+
if (viewData) {
|
|
292
|
+
return initModel.initModel(baseModel);
|
|
293
|
+
}
|
|
294
|
+
return null;
|
|
295
|
+
}, [baseModel, viewData, model]);
|
|
296
|
+
const specification = useMemo5(() => {
|
|
297
|
+
if (modelInstance) {
|
|
298
|
+
return modelInstance.getSpecification();
|
|
299
|
+
}
|
|
300
|
+
return null;
|
|
301
|
+
}, [modelInstance, model]);
|
|
302
|
+
return { specification };
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/hooks/core/use-list-data.ts
|
|
306
|
+
import { useMemo as useMemo6, useState as useState5 } from "react";
|
|
307
|
+
|
|
308
|
+
// src/hooks/utils/use-debounce.ts
|
|
309
|
+
import { useEffect as useEffect6, useState as useState3 } from "react";
|
|
310
|
+
function useDebounce(value, delay) {
|
|
311
|
+
const [debouncedValue, setDebouncedValue] = useState3(value);
|
|
312
|
+
useEffect6(() => {
|
|
313
|
+
const handler = setTimeout(() => {
|
|
314
|
+
setDebouncedValue(value);
|
|
315
|
+
}, delay);
|
|
316
|
+
return () => {
|
|
317
|
+
clearTimeout(handler);
|
|
318
|
+
};
|
|
319
|
+
}, [value, delay]);
|
|
320
|
+
return [debouncedValue];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// src/hooks/utils/use-get-rowids.ts
|
|
324
|
+
import { useCallback as useCallback3, useEffect as useEffect7, useRef, useState as useState4 } from "react";
|
|
325
|
+
var useGetRowIds = (tableRef) => {
|
|
326
|
+
function isElementVisible(el) {
|
|
327
|
+
const style = window.getComputedStyle(el);
|
|
328
|
+
return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
|
|
329
|
+
}
|
|
330
|
+
function arraysAreEqual(a, b) {
|
|
331
|
+
if (a.length !== b.length) return false;
|
|
332
|
+
if (a.length === 0 && b.length === 0) return true;
|
|
333
|
+
const setA = new Set(a);
|
|
334
|
+
const setB = new Set(b);
|
|
335
|
+
if (setA.size !== setB.size) return false;
|
|
336
|
+
for (const val of setA) {
|
|
337
|
+
if (!setB.has(val)) return false;
|
|
338
|
+
}
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
const [rowIds, setRowIds] = useState4([]);
|
|
342
|
+
const lastRowIdsRef = useRef([]);
|
|
343
|
+
const updateVisibleRowIds = useCallback3(() => {
|
|
344
|
+
const table = tableRef.current;
|
|
345
|
+
if (!table) return;
|
|
346
|
+
const rows = table.querySelectorAll("tr[data-row-id]");
|
|
347
|
+
const ids = [];
|
|
348
|
+
rows.forEach((row) => {
|
|
349
|
+
const el = row;
|
|
350
|
+
if (isElementVisible(el)) {
|
|
351
|
+
const id = el.getAttribute("data-row-id");
|
|
352
|
+
if (id) ids.push(id);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
const uniqueIds = Array.from(new Set(ids));
|
|
356
|
+
if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
|
|
357
|
+
lastRowIdsRef.current = uniqueIds;
|
|
358
|
+
setRowIds(uniqueIds);
|
|
359
|
+
}
|
|
360
|
+
}, [tableRef]);
|
|
361
|
+
useEffect7(() => {
|
|
362
|
+
const table = tableRef.current;
|
|
363
|
+
if (!table) return;
|
|
364
|
+
const mutationObserver = new MutationObserver(() => {
|
|
365
|
+
updateVisibleRowIds();
|
|
366
|
+
});
|
|
367
|
+
mutationObserver.observe(table, {
|
|
368
|
+
childList: true,
|
|
369
|
+
subtree: true,
|
|
370
|
+
attributes: true,
|
|
371
|
+
attributeFilter: ["style", "class"]
|
|
372
|
+
});
|
|
373
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
374
|
+
updateVisibleRowIds();
|
|
375
|
+
});
|
|
376
|
+
resizeObserver.observe(table);
|
|
377
|
+
const handleScroll = () => updateVisibleRowIds();
|
|
378
|
+
table.addEventListener("scroll", handleScroll, true);
|
|
379
|
+
updateVisibleRowIds();
|
|
380
|
+
return () => {
|
|
381
|
+
mutationObserver.disconnect();
|
|
382
|
+
resizeObserver.disconnect();
|
|
383
|
+
table.removeEventListener("scroll", handleScroll, true);
|
|
384
|
+
};
|
|
385
|
+
}, [updateVisibleRowIds, tableRef?.current]);
|
|
386
|
+
return { rowIds, refresh: updateVisibleRowIds };
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/hooks/core/use-list-data.ts
|
|
390
|
+
var useListData = ({
|
|
391
|
+
action,
|
|
392
|
+
context,
|
|
393
|
+
viewData,
|
|
394
|
+
model,
|
|
395
|
+
service,
|
|
396
|
+
xNode,
|
|
397
|
+
mode,
|
|
398
|
+
limit = 10
|
|
399
|
+
}) => {
|
|
400
|
+
const { useGetListData: useGetListData2 } = (0, provider_exports.useService)();
|
|
401
|
+
const [page, setPage] = useState5(0);
|
|
402
|
+
const [pageLimit, setPageLimit] = useState5(limit);
|
|
403
|
+
const [groupByList, setGroupByList] = useState5(null);
|
|
404
|
+
const [domain, setDomain] = useState5(null);
|
|
405
|
+
const [order, setOrder] = useState5("");
|
|
406
|
+
const [selectedRowKeys, setSelectedRowKeys] = useState5([]);
|
|
407
|
+
const [debouncedPage] = useDebounce(page, 500);
|
|
408
|
+
const [debouncedDomain] = useDebounce(domain, 500);
|
|
409
|
+
const { specification } = useGetSpecification({
|
|
410
|
+
model,
|
|
411
|
+
viewData,
|
|
412
|
+
fields: mode === "kanban" ? viewData?.views?.kanban?.fields : viewData?.views?.list?.fields
|
|
413
|
+
});
|
|
414
|
+
const listDataProps = useMemo6(() => {
|
|
415
|
+
if (!viewData || !action || !context) {
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
const domainParse = domain ? [...domain] : action?.domain ? Array.isArray(action?.domain) ? [...action?.domain] : (0, utils_exports.evalJSONDomain)(action?.domain, context) : [];
|
|
419
|
+
const limit2 = pageLimit;
|
|
420
|
+
const offset = debouncedPage * pageLimit;
|
|
421
|
+
const fields = typeof groupByList === "object" ? groupByList?.fields : void 0;
|
|
422
|
+
const groupby = typeof groupByList === "object" ? [groupByList?.contexts?.[0]?.group_by] : [];
|
|
423
|
+
const sort = order ?? (0, utils_exports.formatSortingString)(
|
|
424
|
+
(mode === "kanban" ? viewData?.views?.kanban : viewData?.views?.list)?.default_order
|
|
425
|
+
) ?? "";
|
|
426
|
+
return {
|
|
427
|
+
model: action?.res_model,
|
|
428
|
+
specification,
|
|
429
|
+
domain: domainParse,
|
|
430
|
+
limit: limit2,
|
|
431
|
+
offset,
|
|
432
|
+
fields,
|
|
433
|
+
groupby,
|
|
434
|
+
context,
|
|
435
|
+
sort,
|
|
436
|
+
mode
|
|
437
|
+
};
|
|
438
|
+
}, [
|
|
439
|
+
action,
|
|
440
|
+
groupByList,
|
|
441
|
+
order,
|
|
442
|
+
debouncedPage,
|
|
443
|
+
pageLimit,
|
|
444
|
+
debouncedDomain,
|
|
445
|
+
context,
|
|
446
|
+
model
|
|
447
|
+
]);
|
|
448
|
+
const list = useGetListData2(
|
|
449
|
+
{ ...listDataProps },
|
|
450
|
+
[
|
|
451
|
+
listDataProps?.domain,
|
|
452
|
+
listDataProps?.groupby,
|
|
453
|
+
listDataProps?.limit,
|
|
454
|
+
listDataProps?.offset,
|
|
455
|
+
listDataProps?.sort,
|
|
456
|
+
listDataProps?.context,
|
|
457
|
+
listDataProps?.specification,
|
|
458
|
+
listDataProps?.mode
|
|
459
|
+
],
|
|
460
|
+
!!listDataProps && !!specification && !isObjectEmpty(specification) && !!domain,
|
|
461
|
+
service,
|
|
462
|
+
xNode
|
|
463
|
+
);
|
|
464
|
+
return {
|
|
465
|
+
...list,
|
|
466
|
+
state: {
|
|
467
|
+
specification,
|
|
468
|
+
page,
|
|
469
|
+
order,
|
|
470
|
+
domain: listDataProps?.domain,
|
|
471
|
+
pageLimit,
|
|
472
|
+
groupByList,
|
|
473
|
+
selectedRowKeys,
|
|
474
|
+
setPage,
|
|
475
|
+
setOrder,
|
|
476
|
+
setDomain,
|
|
477
|
+
setPageLimit,
|
|
478
|
+
setGroupByList,
|
|
479
|
+
setSelectedRowKeys
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
// src/widget/basic/status-dropdown-field/controller.ts
|
|
485
|
+
var statusDropdownController = (props) => {
|
|
486
|
+
const { selection, isForm, id, model, name, state, onRefetch } = props;
|
|
487
|
+
const env = (0, environment_exports.getEnv)();
|
|
488
|
+
const colors = {
|
|
489
|
+
normal: "bg-[#e9ecef]",
|
|
490
|
+
done: "bg-primary",
|
|
491
|
+
blocked: "bg-red-500"
|
|
492
|
+
};
|
|
493
|
+
const [isOpen, setIsOpen] = useState6(false);
|
|
494
|
+
const buttonRef = useRef2(null);
|
|
495
|
+
useEffect8(() => {
|
|
496
|
+
const handleClickOutside = (event) => {
|
|
497
|
+
if (buttonRef.current && !buttonRef.current.contains(event.target)) {
|
|
498
|
+
setIsOpen(false);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
502
|
+
return () => {
|
|
503
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
504
|
+
};
|
|
505
|
+
}, []);
|
|
506
|
+
const { mutate: onSave } = useSave();
|
|
507
|
+
const handleClick = async (status) => {
|
|
508
|
+
setIsOpen(!isOpen);
|
|
509
|
+
onSave(
|
|
510
|
+
{
|
|
511
|
+
ids: id ? [id] : [],
|
|
512
|
+
model: model ?? "",
|
|
513
|
+
data: { [name ?? ""]: status },
|
|
514
|
+
context: env.context
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
onSuccess: () => {
|
|
518
|
+
onRefetch && onRefetch();
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
};
|
|
523
|
+
return {
|
|
524
|
+
handleClick,
|
|
525
|
+
buttonRef,
|
|
526
|
+
isForm,
|
|
527
|
+
setIsOpen,
|
|
528
|
+
isOpen,
|
|
529
|
+
selection,
|
|
530
|
+
state,
|
|
531
|
+
colors
|
|
532
|
+
};
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
// src/widget/basic/many2one-field/controller.ts
|
|
536
|
+
import { useCallback as useCallback4, useEffect as useEffect9, useMemo as useMemo7, useState as useState7 } from "react";
|
|
537
|
+
var MANY2ONE_EXTERNAL = "many2one_external";
|
|
538
|
+
var many2oneFieldController = (props) => {
|
|
539
|
+
const {
|
|
540
|
+
methods,
|
|
541
|
+
relation,
|
|
542
|
+
domain,
|
|
543
|
+
formValues,
|
|
544
|
+
value: propValue,
|
|
545
|
+
onChange,
|
|
546
|
+
name,
|
|
547
|
+
context: fieldContext,
|
|
548
|
+
options: fieldOptions,
|
|
549
|
+
showDetail,
|
|
550
|
+
service,
|
|
551
|
+
xNode,
|
|
552
|
+
isForm,
|
|
553
|
+
widget,
|
|
554
|
+
in_list_view,
|
|
555
|
+
isEditTable
|
|
556
|
+
} = props;
|
|
557
|
+
const { env } = (0, provider_exports.useEnv)();
|
|
558
|
+
const { action } = useAppProvider();
|
|
559
|
+
const { useGetSelection: useGetSelection2, useGetDetail: useGetDetail2 } = (0, provider_exports.useService)();
|
|
560
|
+
const [listOptions, setListOptions] = useState7([]);
|
|
561
|
+
const [inputValue, setInputValue] = useState7("");
|
|
562
|
+
const [debouncedInputValue] = useDebounce(inputValue, 1e3);
|
|
563
|
+
const [isShowModalMany2Many, setIsShowModalMany2Many] = useState7(false);
|
|
564
|
+
const [tempSelectedOption, setTempSelectedOption] = useState7(null);
|
|
565
|
+
const [domainModal, setDomainModal] = useState7(null);
|
|
566
|
+
const [domainObject, setDomainObject] = useState7(null);
|
|
567
|
+
const initValue = methods?.getValues(name);
|
|
568
|
+
const contextObject = {
|
|
569
|
+
...(typeof action?.context === "string" ? (0, utils_exports.evalJSONContext)(action?.context) : action?.context) || {},
|
|
570
|
+
...fieldContext,
|
|
571
|
+
...env?.context
|
|
572
|
+
};
|
|
573
|
+
const optionsObject = typeof fieldOptions === "string" ? (0, utils_exports.evalJSONContext)(fieldOptions, {
|
|
574
|
+
...formValues,
|
|
575
|
+
...contextObject,
|
|
576
|
+
context: contextObject,
|
|
577
|
+
parent: { ...formValues }
|
|
578
|
+
}) : fieldOptions;
|
|
579
|
+
const fetchGetDetail = useGetDetail2();
|
|
580
|
+
const data = {
|
|
581
|
+
model: widget === MANY2ONE_EXTERNAL ? optionsObject?.model : relation,
|
|
582
|
+
domain: widget === MANY2ONE_EXTERNAL ? optionsObject?.domain : domainObject,
|
|
583
|
+
context: {
|
|
584
|
+
...contextObject,
|
|
585
|
+
...optionsObject?.context
|
|
586
|
+
},
|
|
587
|
+
specification: widget === MANY2ONE_EXTERNAL ? optionsObject?.specification : {
|
|
588
|
+
id: {},
|
|
589
|
+
name: {},
|
|
590
|
+
display_name: {}
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
const {
|
|
594
|
+
data: dataOfSelection,
|
|
595
|
+
refetch,
|
|
596
|
+
isFetching
|
|
597
|
+
} = useGetSelection2({
|
|
598
|
+
data,
|
|
599
|
+
queryKey: [`data_${relation}`, domainObject],
|
|
600
|
+
enabled: false,
|
|
601
|
+
service: widget === MANY2ONE_EXTERNAL ? optionsObject?.service : service,
|
|
602
|
+
xNode
|
|
603
|
+
});
|
|
604
|
+
const selectOptions = useMemo7(() => {
|
|
605
|
+
return dataOfSelection?.records?.map((val) => ({
|
|
606
|
+
value: val?.id,
|
|
607
|
+
label: val?.display_name || val?.name,
|
|
608
|
+
...widget === MANY2ONE_EXTERNAL ? val : {}
|
|
609
|
+
})) || [];
|
|
610
|
+
}, [dataOfSelection]);
|
|
611
|
+
useEffect9(() => {
|
|
612
|
+
setListOptions(selectOptions);
|
|
613
|
+
setDomainModal(domainObject);
|
|
614
|
+
}, [selectOptions]);
|
|
615
|
+
const parsedFormValues = useMemo7(
|
|
616
|
+
() => JSON.parse(
|
|
617
|
+
JSON.stringify({
|
|
618
|
+
...formValues,
|
|
619
|
+
...contextObject,
|
|
620
|
+
context: contextObject
|
|
621
|
+
})
|
|
622
|
+
) ?? {},
|
|
623
|
+
[formValues, contextObject]
|
|
624
|
+
);
|
|
625
|
+
useEffect9(() => {
|
|
626
|
+
const newDomain = (0, utils_exports.evalJSONDomain)(domain, parsedFormValues);
|
|
627
|
+
const parsedDomain = typeof newDomain === "string" ? JSON.parse(
|
|
628
|
+
newDomain.replace(/\(/g, "[").replace(/\)/g, "]").replace(/'/g, '"')
|
|
629
|
+
) : newDomain;
|
|
630
|
+
setDomainObject((prev) => {
|
|
631
|
+
const prevStr = JSON.stringify(prev);
|
|
632
|
+
const nextStr = JSON.stringify(parsedDomain);
|
|
633
|
+
return prevStr === nextStr ? prev : parsedDomain;
|
|
634
|
+
});
|
|
635
|
+
}, [domain, parsedFormValues]);
|
|
636
|
+
useEffect9(() => {
|
|
637
|
+
if (!propValue && tempSelectedOption) {
|
|
638
|
+
methods?.setValue(name, null, { shouldDirty: true });
|
|
639
|
+
setTempSelectedOption(null);
|
|
640
|
+
} else if (propValue) {
|
|
641
|
+
if (isForm && !isEditTable && optionsObject?.service && optionsObject?.model && !propValue?.display_name && !in_list_view) {
|
|
642
|
+
fetchGetDetail.mutate(
|
|
643
|
+
{
|
|
644
|
+
model: optionsObject?.model,
|
|
645
|
+
ids: propValue?.id ?? propValue,
|
|
646
|
+
specification: widget === MANY2ONE_EXTERNAL ? optionsObject?.specification : {
|
|
647
|
+
id: {},
|
|
648
|
+
display_name: {}
|
|
649
|
+
},
|
|
650
|
+
context: { ...env.context },
|
|
651
|
+
service: optionsObject ? optionsObject?.service : service,
|
|
652
|
+
xNode
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
onSuccess: (dataResponse) => {
|
|
656
|
+
const detailData = dataResponse?.[0];
|
|
657
|
+
setTempSelectedOption({
|
|
658
|
+
value: detailData?.id,
|
|
659
|
+
label: detailData?.display_name
|
|
660
|
+
});
|
|
661
|
+
if (widget === MANY2ONE_EXTERNAL && optionsObject?.values_included) {
|
|
662
|
+
Object.keys(optionsObject?.values_included)?.forEach(
|
|
663
|
+
(field) => {
|
|
664
|
+
methods?.setValue(
|
|
665
|
+
optionsObject?.values_included[field]?.name,
|
|
666
|
+
detailData?.[field]
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
);
|
|
670
|
+
methods?.setValue(name, detailData);
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
onError: (error) => {
|
|
674
|
+
console.log("error", error);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
setTempSelectedOption({
|
|
681
|
+
value: propValue?.id,
|
|
682
|
+
label: propValue?.display_name
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
}, [propValue]);
|
|
686
|
+
const fetchMoreOptions = useCallback4(() => {
|
|
687
|
+
refetch();
|
|
688
|
+
}, [refetch]);
|
|
689
|
+
useEffect9(() => {
|
|
690
|
+
if (debouncedInputValue) {
|
|
691
|
+
const filteredDomain = [...domainObject ?? []]?.filter(
|
|
692
|
+
(d) => !(Array.isArray(d) && d[0] === "name" && d[1] === "ilike")
|
|
693
|
+
) || [];
|
|
694
|
+
const newDomain = [
|
|
695
|
+
...filteredDomain,
|
|
696
|
+
...debouncedInputValue ? [["name", "ilike", debouncedInputValue]] : []
|
|
697
|
+
];
|
|
698
|
+
setDomainObject(newDomain);
|
|
699
|
+
setTimeout(() => {
|
|
700
|
+
fetchMoreOptions();
|
|
701
|
+
}, 50);
|
|
702
|
+
}
|
|
703
|
+
}, [debouncedInputValue]);
|
|
704
|
+
const handleChooseRecord = useCallback4(
|
|
705
|
+
(idRecord) => {
|
|
706
|
+
const newOption = listOptions?.find(
|
|
707
|
+
(option) => option.value === idRecord
|
|
708
|
+
);
|
|
709
|
+
const newValue = widget === MANY2ONE_EXTERNAL && optionsObject?.field_name ? newOption?.[optionsObject?.field_name] : newOption.value;
|
|
710
|
+
if (widget === MANY2ONE_EXTERNAL && optionsObject?.values_included) {
|
|
711
|
+
Object.keys(optionsObject?.values_included)?.forEach((field) => {
|
|
712
|
+
methods?.setValue(
|
|
713
|
+
optionsObject?.values_included[field]?.name,
|
|
714
|
+
newOption?.[field],
|
|
715
|
+
{ shouldDirty: true }
|
|
716
|
+
);
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
if (newOption) {
|
|
720
|
+
methods?.setValue(
|
|
721
|
+
name,
|
|
722
|
+
{
|
|
723
|
+
...newOption,
|
|
724
|
+
id: newValue,
|
|
725
|
+
display_name: newOption?.label
|
|
726
|
+
},
|
|
727
|
+
{ shouldDirty: true }
|
|
728
|
+
);
|
|
729
|
+
setTempSelectedOption(newOption);
|
|
730
|
+
onChange && onChange(String(name), {
|
|
731
|
+
...newOption,
|
|
732
|
+
id: newValue,
|
|
733
|
+
display_name: newOption?.label
|
|
734
|
+
});
|
|
735
|
+
methods.trigger(name);
|
|
736
|
+
}
|
|
737
|
+
setIsShowModalMany2Many(false);
|
|
738
|
+
},
|
|
739
|
+
[listOptions, methods, name, onChange]
|
|
740
|
+
);
|
|
741
|
+
const handleClose = useCallback4(() => setIsShowModalMany2Many(false), []);
|
|
742
|
+
const handleSelectChange = useCallback4(
|
|
743
|
+
(selectedOption) => {
|
|
744
|
+
if (!selectedOption) {
|
|
745
|
+
if (widget === MANY2ONE_EXTERNAL && optionsObject?.values_included) {
|
|
746
|
+
Object.keys(optionsObject?.values_included)?.forEach((field) => {
|
|
747
|
+
methods?.setValue(
|
|
748
|
+
optionsObject?.values_included[field]?.name,
|
|
749
|
+
null,
|
|
750
|
+
{ shouldDirty: true }
|
|
751
|
+
);
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
methods.setValue(name, null, { shouldDirty: true });
|
|
755
|
+
setTempSelectedOption(null);
|
|
756
|
+
onChange && onChange(String(name), null);
|
|
757
|
+
methods.trigger(name);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
const newValue = widget === MANY2ONE_EXTERNAL && optionsObject?.field_name ? selectedOption?.[optionsObject?.field_name] : selectedOption.value;
|
|
761
|
+
if (widget === MANY2ONE_EXTERNAL && optionsObject?.values_included) {
|
|
762
|
+
Object.keys(optionsObject?.values_included)?.forEach((field) => {
|
|
763
|
+
methods?.setValue(
|
|
764
|
+
optionsObject?.values_included[field]?.name,
|
|
765
|
+
selectedOption?.[field],
|
|
766
|
+
{ shouldDirty: true }
|
|
767
|
+
);
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
methods?.setValue(
|
|
771
|
+
name,
|
|
772
|
+
{
|
|
773
|
+
id: newValue,
|
|
774
|
+
display_name: selectedOption?.label
|
|
775
|
+
},
|
|
776
|
+
{ shouldDirty: true }
|
|
777
|
+
);
|
|
778
|
+
setTempSelectedOption(selectedOption);
|
|
779
|
+
onChange && onChange(String(name), {
|
|
780
|
+
id: newValue,
|
|
781
|
+
display_name: selectedOption.label
|
|
782
|
+
});
|
|
783
|
+
methods.trigger(name);
|
|
784
|
+
},
|
|
785
|
+
[methods, name, onChange]
|
|
786
|
+
);
|
|
787
|
+
const allowShowDetail = showDetail && contextObject?.form_view_ref && (!optionsObject || !("no_open" in optionsObject) || optionsObject.no_open === false);
|
|
788
|
+
return {
|
|
789
|
+
isShowModalMany2Many,
|
|
790
|
+
isFetching,
|
|
791
|
+
initValue,
|
|
792
|
+
handleChooseRecord,
|
|
793
|
+
handleClose,
|
|
794
|
+
handleSelectChange,
|
|
795
|
+
domainModal,
|
|
796
|
+
setInputValue,
|
|
797
|
+
allowShowDetail,
|
|
798
|
+
contextObject: {
|
|
799
|
+
...contextObject,
|
|
800
|
+
...optionsObject?.context
|
|
801
|
+
},
|
|
802
|
+
tempSelectedOption,
|
|
803
|
+
listOptions,
|
|
804
|
+
fetchMoreOptions,
|
|
805
|
+
domainObject: widget === MANY2ONE_EXTERNAL ? optionsObject?.domain : domainObject,
|
|
806
|
+
setIsShowModalMany2Many,
|
|
807
|
+
setDomainObject,
|
|
808
|
+
options: optionsObject,
|
|
809
|
+
relation: widget === MANY2ONE_EXTERNAL ? optionsObject?.model : relation,
|
|
810
|
+
service: widget === MANY2ONE_EXTERNAL ? optionsObject?.service : service
|
|
811
|
+
};
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
// src/widget/basic/many2one-button-field/controller.ts
|
|
815
|
+
var many2oneButtonController = (props) => {
|
|
816
|
+
const { domain, methods, relation, service, xNode } = props;
|
|
817
|
+
const actionDataString = sessionStorage.getItem("actionData");
|
|
818
|
+
const env = (0, environment_exports.getEnv)();
|
|
819
|
+
const domainObject = (0, utils_exports.evalJSONDomain)(domain, methods?.getValues() || {});
|
|
820
|
+
const actionData = actionDataString && actionDataString !== "undefined" ? JSON.parse(actionDataString) : {};
|
|
821
|
+
const { data: dataOfSelection } = useGetSelection({
|
|
822
|
+
data: {
|
|
823
|
+
model: relation ?? "",
|
|
824
|
+
domain: domainObject,
|
|
825
|
+
context: { ...env.context, ...(0, utils_exports.evalJSONContext)(actionData?.context) }
|
|
826
|
+
},
|
|
827
|
+
queryKey: [`data_${relation}`, domainObject],
|
|
828
|
+
service,
|
|
829
|
+
xNode
|
|
830
|
+
});
|
|
831
|
+
const options = dataOfSelection?.records?.map((val) => ({
|
|
832
|
+
value: val.id,
|
|
833
|
+
label: val.name
|
|
834
|
+
})) || [];
|
|
835
|
+
return {
|
|
836
|
+
options
|
|
837
|
+
};
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
// src/widget/basic/many2many-field/controller.ts
|
|
841
|
+
import { useEffect as useEffect10, useMemo as useMemo8 } from "react";
|
|
842
|
+
var many2manyFieldController = (props) => {
|
|
843
|
+
const {
|
|
844
|
+
relation,
|
|
845
|
+
domain,
|
|
846
|
+
context,
|
|
847
|
+
options,
|
|
848
|
+
enabled: enabledCallAPI,
|
|
849
|
+
service,
|
|
850
|
+
validateAndParseDate,
|
|
851
|
+
moment
|
|
852
|
+
} = props;
|
|
853
|
+
const { env } = (0, provider_exports.useEnv)();
|
|
854
|
+
const { user } = useAppProvider();
|
|
855
|
+
const { useGetView: useGetView2 } = (0, provider_exports.useService)();
|
|
856
|
+
const dataUser = user?.userProfile?.data;
|
|
857
|
+
const contextObject = useMemo8(
|
|
858
|
+
() => ({
|
|
859
|
+
...env.context,
|
|
860
|
+
...context || {}
|
|
861
|
+
}),
|
|
862
|
+
[env?.context, context]
|
|
863
|
+
);
|
|
864
|
+
const viewParams = useMemo8(
|
|
865
|
+
() => ({
|
|
866
|
+
model: relation,
|
|
867
|
+
views: [
|
|
868
|
+
[false, "list"],
|
|
869
|
+
[false, "search"]
|
|
870
|
+
],
|
|
871
|
+
context: contextObject,
|
|
872
|
+
service,
|
|
873
|
+
xNode: service == "wesap" && dataUser?.x_node
|
|
874
|
+
}),
|
|
875
|
+
[relation, contextObject, service, dataUser?.x_node]
|
|
876
|
+
);
|
|
877
|
+
const { data: viewResponse } = useGetView2({
|
|
878
|
+
viewParams,
|
|
879
|
+
enabled: enabledCallAPI
|
|
880
|
+
});
|
|
881
|
+
const default_order = viewResponse && viewResponse?.views?.list?.default_order;
|
|
882
|
+
const optionsObject = useMemo8(
|
|
883
|
+
() => (options && typeof options === "string" ? (0, utils_exports.evalJSONContext)(options) : options) || {},
|
|
884
|
+
[options]
|
|
885
|
+
);
|
|
886
|
+
const {
|
|
887
|
+
data: dataResponse,
|
|
888
|
+
isFetched,
|
|
889
|
+
isLoading,
|
|
890
|
+
state,
|
|
891
|
+
isPlaceholderData
|
|
892
|
+
} = useListData({
|
|
893
|
+
action: {
|
|
894
|
+
domain,
|
|
895
|
+
res_model: relation
|
|
896
|
+
},
|
|
897
|
+
context: contextObject,
|
|
898
|
+
model: relation ?? "",
|
|
899
|
+
viewData: viewResponse,
|
|
900
|
+
service,
|
|
901
|
+
xNode: service == "wesap" && dataUser?.x_node
|
|
902
|
+
});
|
|
903
|
+
const {
|
|
904
|
+
selectedRowKeys,
|
|
905
|
+
groupByList,
|
|
906
|
+
domain: domainList,
|
|
907
|
+
page,
|
|
908
|
+
pageLimit,
|
|
909
|
+
setDomain,
|
|
910
|
+
setOrder,
|
|
911
|
+
setPage,
|
|
912
|
+
setSelectedRowKeys,
|
|
913
|
+
setGroupByList,
|
|
914
|
+
setPageLimit,
|
|
915
|
+
specification
|
|
916
|
+
} = state;
|
|
917
|
+
useEffect10(() => {
|
|
918
|
+
return () => {
|
|
919
|
+
setDomain(null);
|
|
920
|
+
setOrder("");
|
|
921
|
+
setGroupByList(null);
|
|
922
|
+
setPageLimit(10);
|
|
923
|
+
};
|
|
924
|
+
}, []);
|
|
925
|
+
const { rows, columns, typeTable, onToggleColumnOptional } = tableController({
|
|
926
|
+
data: {
|
|
927
|
+
fields: viewResponse?.views?.list?.fields,
|
|
928
|
+
records: dataResponse?.records ?? dataResponse?.groups,
|
|
929
|
+
dataModel: viewResponse?.models?.[String(relation)],
|
|
930
|
+
context: contextObject,
|
|
931
|
+
typeTable: dataResponse?.groups ? "group" : "list"
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
const searchControllers = searchController({
|
|
935
|
+
viewData: viewResponse,
|
|
936
|
+
model: relation ?? "",
|
|
937
|
+
context: contextObject,
|
|
938
|
+
domain,
|
|
939
|
+
fieldsList: [
|
|
940
|
+
...columns?.filter(
|
|
941
|
+
(col) => col?.field?.type_co === "field" && col?.optional !== "hide"
|
|
942
|
+
)?.map((col) => ({ ...col.field })) ?? []
|
|
943
|
+
],
|
|
944
|
+
validateAndParseDate,
|
|
945
|
+
moment
|
|
946
|
+
});
|
|
947
|
+
return {
|
|
948
|
+
rows,
|
|
949
|
+
columns,
|
|
950
|
+
optionsObject,
|
|
951
|
+
viewData: viewResponse,
|
|
952
|
+
totalRows: dataResponse?.length ?? 0,
|
|
953
|
+
onToggleColumnOptional,
|
|
954
|
+
typeTable,
|
|
955
|
+
isLoading,
|
|
956
|
+
isFetched,
|
|
957
|
+
isPlaceholderData,
|
|
958
|
+
page,
|
|
959
|
+
pageLimit,
|
|
960
|
+
groupByList,
|
|
961
|
+
selectedRowKeys,
|
|
962
|
+
domain: domainList,
|
|
963
|
+
setPage,
|
|
964
|
+
setDomain,
|
|
965
|
+
setPageLimit,
|
|
966
|
+
setGroupByList,
|
|
967
|
+
setSelectedRowKeys,
|
|
968
|
+
searchController: searchControllers,
|
|
969
|
+
specification
|
|
970
|
+
};
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
// src/widget/basic/many2many-tags-field/controller.ts
|
|
974
|
+
import { useCallback as useCallback5, useEffect as useEffect11, useMemo as useMemo9, useState as useState8 } from "react";
|
|
975
|
+
|
|
976
|
+
// src/constants.ts
|
|
977
|
+
var constants_exports = {};
|
|
978
|
+
__reExport(constants_exports, constants_star);
|
|
979
|
+
import * as constants_star from "@fctc/interface-logic/constants";
|
|
980
|
+
|
|
981
|
+
// src/widget/basic/many2many-tags-field/controller.ts
|
|
982
|
+
var many2manyTagsController = (props) => {
|
|
983
|
+
const {
|
|
984
|
+
relation,
|
|
985
|
+
domain,
|
|
986
|
+
options: optionsFields,
|
|
987
|
+
widget,
|
|
988
|
+
formValues,
|
|
989
|
+
service,
|
|
990
|
+
xNode,
|
|
991
|
+
context: fieldContext,
|
|
992
|
+
onChange,
|
|
993
|
+
methods,
|
|
994
|
+
name
|
|
995
|
+
} = props;
|
|
996
|
+
const isUser = relation === "res.users" || relation === "res.partner";
|
|
997
|
+
const { env } = (0, provider_exports.useEnv)();
|
|
998
|
+
const { action } = useAppProvider();
|
|
999
|
+
const { useGetSelection: useGetSelection2 } = (0, provider_exports.useService)();
|
|
1000
|
+
const [options, setOptions] = useState8([]);
|
|
1001
|
+
const [domainObject, setDomainObject] = useState8(null);
|
|
1002
|
+
const [isShowModalMany2Many, setIsShowModalMany2Many] = useState8(false);
|
|
1003
|
+
const addtionalFields = optionsFields ? (0, utils_exports.evalJSONContext)(optionsFields) : null;
|
|
1004
|
+
const contextObject = {
|
|
1005
|
+
...(0, utils_exports.evalJSONContext)(action?.context) || {},
|
|
1006
|
+
...fieldContext ?? {},
|
|
1007
|
+
...env?.context
|
|
1008
|
+
};
|
|
1009
|
+
const parsedFormValues = useMemo9(
|
|
1010
|
+
() => JSON.parse(
|
|
1011
|
+
JSON.stringify({
|
|
1012
|
+
...formValues,
|
|
1013
|
+
...contextObject,
|
|
1014
|
+
context: contextObject,
|
|
1015
|
+
parent: { ...formValues }
|
|
1016
|
+
})
|
|
1017
|
+
) ?? {},
|
|
1018
|
+
[formValues, contextObject]
|
|
1019
|
+
);
|
|
1020
|
+
useEffect11(() => {
|
|
1021
|
+
const newDomain = (0, utils_exports.evalJSONDomain)(domain, parsedFormValues);
|
|
1022
|
+
setDomainObject(
|
|
1023
|
+
(prev) => JSON.stringify(prev) === JSON.stringify(newDomain) ? prev : newDomain
|
|
1024
|
+
);
|
|
1025
|
+
}, [domain, parsedFormValues]);
|
|
1026
|
+
const data = {
|
|
1027
|
+
model: relation ?? "",
|
|
1028
|
+
domain: domainObject,
|
|
1029
|
+
specification: {
|
|
1030
|
+
id: {},
|
|
1031
|
+
name: {},
|
|
1032
|
+
display_name: {},
|
|
1033
|
+
...widget && constants_exports.WIDGETAVATAR[widget] ? { image_256: {} } : {},
|
|
1034
|
+
...widget && constants_exports.WIDGETCOLOR[widget] && addtionalFields?.color_field ? { color: {} } : {}
|
|
1035
|
+
},
|
|
1036
|
+
context: env.context
|
|
1037
|
+
};
|
|
1038
|
+
const queryKey = [`data_${relation}`, domainObject];
|
|
1039
|
+
const {
|
|
1040
|
+
data: dataOfSelection,
|
|
1041
|
+
refetch,
|
|
1042
|
+
isFetching
|
|
1043
|
+
} = useGetSelection2({
|
|
1044
|
+
data,
|
|
1045
|
+
queryKey,
|
|
1046
|
+
service,
|
|
1047
|
+
xNode,
|
|
1048
|
+
enabled: false
|
|
1049
|
+
});
|
|
1050
|
+
const selectOptions = useMemo9(() => {
|
|
1051
|
+
return dataOfSelection?.records?.map((val) => ({
|
|
1052
|
+
value: val.id,
|
|
1053
|
+
label: val.name ?? val.display_name,
|
|
1054
|
+
...val
|
|
1055
|
+
})) || [];
|
|
1056
|
+
}, [dataOfSelection]);
|
|
1057
|
+
useEffect11(() => {
|
|
1058
|
+
setOptions(selectOptions);
|
|
1059
|
+
}, [selectOptions]);
|
|
1060
|
+
const fetchMoreOptions = useCallback5(() => {
|
|
1061
|
+
refetch();
|
|
1062
|
+
}, [refetch]);
|
|
1063
|
+
const transfer = (data2) => {
|
|
1064
|
+
return data2?.map((val) => ({
|
|
1065
|
+
id: val.value,
|
|
1066
|
+
display_name: val.label
|
|
1067
|
+
})) || [];
|
|
1068
|
+
};
|
|
1069
|
+
const handleChooseRecord = useCallback5(
|
|
1070
|
+
(idRecord) => {
|
|
1071
|
+
const newOption = options.find(
|
|
1072
|
+
(option) => option.value === idRecord
|
|
1073
|
+
);
|
|
1074
|
+
setIsShowModalMany2Many(false);
|
|
1075
|
+
},
|
|
1076
|
+
[options, methods, name, onChange]
|
|
1077
|
+
);
|
|
1078
|
+
const handleClose = useCallback5(() => setIsShowModalMany2Many(false), []);
|
|
1079
|
+
return {
|
|
1080
|
+
options,
|
|
1081
|
+
transfer,
|
|
1082
|
+
isUser,
|
|
1083
|
+
isFetching,
|
|
1084
|
+
fetchMoreOptions,
|
|
1085
|
+
domainObject,
|
|
1086
|
+
setDomainObject,
|
|
1087
|
+
handleChooseRecord,
|
|
1088
|
+
handleClose,
|
|
1089
|
+
isShowModalMany2Many,
|
|
1090
|
+
setIsShowModalMany2Many
|
|
1091
|
+
};
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1094
|
+
// src/widget/basic/status-bar-field/controller.ts
|
|
1095
|
+
import { useState as useState9 } from "react";
|
|
1096
|
+
var durationController = (props) => {
|
|
1097
|
+
const { relation, domain, formValues, name, id, model, onRefetch, enabled } = props;
|
|
1098
|
+
const specification = {
|
|
1099
|
+
id: 0,
|
|
1100
|
+
name: "",
|
|
1101
|
+
fold: ""
|
|
1102
|
+
};
|
|
1103
|
+
const { useGetListData: useGetListData2, useChangeStatus: useChangeStatus2 } = (0, provider_exports.useService)();
|
|
1104
|
+
const { env } = (0, provider_exports.useEnv)();
|
|
1105
|
+
const [disabled, setDisabled] = useState9(false);
|
|
1106
|
+
const [modelStatus, setModalStatus] = useState9(false);
|
|
1107
|
+
const queryKey = [`data-status-duration`, specification];
|
|
1108
|
+
const listDataProps = {
|
|
1109
|
+
model: relation,
|
|
1110
|
+
specification,
|
|
1111
|
+
domain: (0, utils_exports.evalJSONDomain)(domain, JSON.parse(JSON.stringify(formValues))),
|
|
1112
|
+
limit: 10,
|
|
1113
|
+
offset: 0,
|
|
1114
|
+
fields: "",
|
|
1115
|
+
groupby: [],
|
|
1116
|
+
context: {
|
|
1117
|
+
lang: env.context.lang
|
|
1118
|
+
},
|
|
1119
|
+
sort: ""
|
|
1120
|
+
};
|
|
1121
|
+
const { data: dataResponse } = useGetListData2(
|
|
1122
|
+
listDataProps,
|
|
1123
|
+
queryKey,
|
|
1124
|
+
enabled
|
|
1125
|
+
);
|
|
1126
|
+
const { mutate: fetchChangeStatus } = useChangeStatus2();
|
|
1127
|
+
const handleClick = async (stage_id) => {
|
|
1128
|
+
setDisabled(true);
|
|
1129
|
+
if (stage_id) {
|
|
1130
|
+
fetchChangeStatus(
|
|
1131
|
+
{
|
|
1132
|
+
data: {
|
|
1133
|
+
stage_id,
|
|
1134
|
+
name,
|
|
1135
|
+
id,
|
|
1136
|
+
model,
|
|
1137
|
+
lang: env.context.lang
|
|
1138
|
+
}
|
|
1139
|
+
},
|
|
1140
|
+
{
|
|
1141
|
+
onSuccess: (res) => {
|
|
1142
|
+
if (res) {
|
|
1143
|
+
setDisabled(false);
|
|
1144
|
+
onRefetch && onRefetch();
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
return {
|
|
1152
|
+
dataResponse,
|
|
1153
|
+
handleClick,
|
|
1154
|
+
disabled,
|
|
1155
|
+
modelStatus,
|
|
1156
|
+
setModalStatus
|
|
1157
|
+
};
|
|
1158
|
+
};
|
|
1159
|
+
|
|
1160
|
+
// src/widget/basic/priority-field/controller.ts
|
|
1161
|
+
var priorityFieldController = (props) => {
|
|
1162
|
+
const { name, model, index, actionData, context, onChange, specification } = props;
|
|
1163
|
+
const _context = { ...(0, utils_exports.evalJSONContext)(actionData?.context) };
|
|
1164
|
+
const contextObject = { ...context, ..._context };
|
|
1165
|
+
const { useSave: useSave2 } = (0, provider_exports.useService)();
|
|
1166
|
+
const { mutateAsync: fetchSave } = useSave2();
|
|
1167
|
+
const savePriorities = async ({
|
|
1168
|
+
value,
|
|
1169
|
+
resetPriority
|
|
1170
|
+
}) => {
|
|
1171
|
+
const priorityValue = value <= 0 ? 0 : value - 1;
|
|
1172
|
+
try {
|
|
1173
|
+
fetchSave({
|
|
1174
|
+
ids: index ? [index] : [],
|
|
1175
|
+
data: { [String(name)]: String(priorityValue) },
|
|
1176
|
+
model: String(model),
|
|
1177
|
+
context: contextObject,
|
|
1178
|
+
specification
|
|
1179
|
+
});
|
|
1180
|
+
if (typeof onChange === "function") {
|
|
1181
|
+
onChange(String(name), String(priorityValue));
|
|
1182
|
+
}
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
if (resetPriority) {
|
|
1185
|
+
resetPriority();
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
return {
|
|
1190
|
+
savePriorities
|
|
1191
|
+
};
|
|
1192
|
+
};
|
|
1193
|
+
|
|
1194
|
+
// src/widget/basic/download-file-field/controller.ts
|
|
1195
|
+
import { useId, useState as useState10 } from "react";
|
|
1196
|
+
var downloadFileController = () => {
|
|
1197
|
+
const inputId = useId();
|
|
1198
|
+
const [file, setFile] = useState10(null);
|
|
1199
|
+
const handleFileChange = (e) => {
|
|
1200
|
+
setFile(e.target.files[0]);
|
|
1201
|
+
};
|
|
1202
|
+
const handleFileDownload = () => {
|
|
1203
|
+
const url = URL.createObjectURL(file);
|
|
1204
|
+
const link = document.createElement("a");
|
|
1205
|
+
link.href = url;
|
|
1206
|
+
link.download = file.name;
|
|
1207
|
+
document.body.appendChild(link);
|
|
1208
|
+
link.click();
|
|
1209
|
+
document.body.removeChild(link);
|
|
1210
|
+
};
|
|
1211
|
+
return {
|
|
1212
|
+
inputId,
|
|
1213
|
+
file,
|
|
1214
|
+
handleFileChange,
|
|
1215
|
+
handleFileDownload
|
|
1216
|
+
};
|
|
1217
|
+
};
|
|
1218
|
+
|
|
1219
|
+
// src/widget/basic/download-binary-field/controller.ts
|
|
1220
|
+
var downLoadBinaryController = (props) => {
|
|
1221
|
+
const { value, defaultValue, formValues } = props;
|
|
1222
|
+
const downloadFile = async (url, filename) => {
|
|
1223
|
+
try {
|
|
1224
|
+
const response = await fetch(url);
|
|
1225
|
+
if (!response.ok) throw new Error(`Failed to fetch ${url}`);
|
|
1226
|
+
const contentType = response.headers.get("Content-Type") || "";
|
|
1227
|
+
let ext = "";
|
|
1228
|
+
if (contentType.includes("pdf")) ext = ".pdf";
|
|
1229
|
+
else if (contentType.includes("png")) ext = ".png";
|
|
1230
|
+
else if (contentType.includes("jpeg") || contentType.includes("jpg"))
|
|
1231
|
+
ext = ".jpg";
|
|
1232
|
+
else if (contentType.includes("zip")) ext = ".zip";
|
|
1233
|
+
else if (contentType.includes("msword")) ext = ".doc";
|
|
1234
|
+
else if (contentType.includes("spreadsheet")) ext = ".xls";
|
|
1235
|
+
else if (contentType.includes("json")) ext = ".json";
|
|
1236
|
+
else if (contentType.includes("text")) ext = ".txt";
|
|
1237
|
+
else {
|
|
1238
|
+
ext = "";
|
|
1239
|
+
}
|
|
1240
|
+
const blob = await response.blob();
|
|
1241
|
+
const urlBlob = window.URL.createObjectURL(blob);
|
|
1242
|
+
const link = document.createElement("a");
|
|
1243
|
+
link.href = urlBlob;
|
|
1244
|
+
link.download = (filename || "file") + ext;
|
|
1245
|
+
document.body.appendChild(link);
|
|
1246
|
+
link.click();
|
|
1247
|
+
document.body.removeChild(link);
|
|
1248
|
+
window.URL.revokeObjectURL(urlBlob);
|
|
1249
|
+
} catch (error) {
|
|
1250
|
+
console.error("File download failed:", error);
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
const handleFileDownload = async (e) => {
|
|
1254
|
+
e.stopPropagation();
|
|
1255
|
+
await downloadFile(value || defaultValue, formValues?.name);
|
|
1256
|
+
};
|
|
1257
|
+
return {
|
|
1258
|
+
handleFileDownload
|
|
1259
|
+
};
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
// src/widget/basic/copy-link-button/controller.ts
|
|
1263
|
+
import { useState as useState11 } from "react";
|
|
1264
|
+
var copyTextToClipboard = async (text) => {
|
|
1265
|
+
if ("clipboard" in navigator) {
|
|
1266
|
+
return await navigator.clipboard.writeText(text);
|
|
1267
|
+
} else {
|
|
1268
|
+
const textArea = document.createElement("textarea");
|
|
1269
|
+
textArea.value = text;
|
|
1270
|
+
textArea.style.position = "fixed";
|
|
1271
|
+
document.body.appendChild(textArea);
|
|
1272
|
+
textArea.focus();
|
|
1273
|
+
textArea.select();
|
|
1274
|
+
try {
|
|
1275
|
+
document.execCommand("copy");
|
|
1276
|
+
} finally {
|
|
1277
|
+
document.body.removeChild(textArea);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
var copyLinkButtonController = (props) => {
|
|
1282
|
+
const { value, defaultValue } = props;
|
|
1283
|
+
const [isCopied, setIsCopied] = useState11(false);
|
|
1284
|
+
const handleCopyToClipboard = async (value2) => {
|
|
1285
|
+
await copyTextToClipboard(value2);
|
|
1286
|
+
setIsCopied(true);
|
|
1287
|
+
setTimeout(() => setIsCopied(false), 2e3);
|
|
1288
|
+
};
|
|
1289
|
+
const propValue = value || defaultValue;
|
|
1290
|
+
return {
|
|
1291
|
+
isCopied,
|
|
1292
|
+
handleCopyToClipboard,
|
|
1293
|
+
propValue
|
|
1294
|
+
};
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
// src/widget/basic/color-field/color-controller.ts
|
|
1298
|
+
var colorFieldController = (props) => {
|
|
1299
|
+
const { value, isForm, name, formValues, idForm, model, actionData } = props;
|
|
1300
|
+
const { env } = (0, provider_exports.useEnv)();
|
|
1301
|
+
const { useSave: useSave2 } = (0, provider_exports.useService)();
|
|
1302
|
+
const _context = { ...(0, utils_exports.evalJSONContext)(actionData?.context) || {} };
|
|
1303
|
+
const contextObject = { ...env.context, ..._context };
|
|
1304
|
+
const idDefault = isForm ? idForm : formValues?.id;
|
|
1305
|
+
const { mutate: onSave } = useSave2();
|
|
1306
|
+
const savePickColor = async (colorObject) => {
|
|
1307
|
+
const { id } = colorObject;
|
|
1308
|
+
if (value === id) return;
|
|
1309
|
+
try {
|
|
1310
|
+
onSave({
|
|
1311
|
+
ids: idDefault !== null ? [idDefault] : [],
|
|
1312
|
+
model: String(model),
|
|
1313
|
+
data: { [String(name)]: id },
|
|
1314
|
+
specification: {
|
|
1315
|
+
name: {},
|
|
1316
|
+
color: {}
|
|
1317
|
+
},
|
|
1318
|
+
context: contextObject
|
|
1319
|
+
});
|
|
1320
|
+
} catch (error) {
|
|
1321
|
+
console.log(error);
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
return {
|
|
1325
|
+
savePickColor
|
|
1326
|
+
};
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
// src/widget/basic/binary-field/controller.ts
|
|
1330
|
+
import { useEffect as useEffect12, useState as useState12 } from "react";
|
|
1331
|
+
var binaryFieldController = (props) => {
|
|
1332
|
+
const {
|
|
1333
|
+
name,
|
|
1334
|
+
methods,
|
|
1335
|
+
readonly = false,
|
|
1336
|
+
filename,
|
|
1337
|
+
onChange: handleOnchange,
|
|
1338
|
+
service,
|
|
1339
|
+
xNode,
|
|
1340
|
+
path,
|
|
1341
|
+
rootField,
|
|
1342
|
+
index,
|
|
1343
|
+
value
|
|
1344
|
+
} = props;
|
|
1345
|
+
const { useUploadFile: useUploadFile2 } = (0, provider_exports.useService)();
|
|
1346
|
+
const { mutateAsync } = useUploadFile2();
|
|
1347
|
+
const [url, setUrl] = useState12(value || null);
|
|
1348
|
+
const [fileInfo, setFileInfo] = useState12(null);
|
|
1349
|
+
useEffect12(() => {
|
|
1350
|
+
if (!value) {
|
|
1351
|
+
setUrl(null);
|
|
1352
|
+
setFileInfo(null);
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
fetchFileMeta(value);
|
|
1356
|
+
}, [value]);
|
|
1357
|
+
const formatSize = (bytes) => {
|
|
1358
|
+
if (bytes < 1024) return bytes + " B";
|
|
1359
|
+
let kb = bytes / 1024;
|
|
1360
|
+
if (kb < 1024) return kb.toFixed(2) + " KB";
|
|
1361
|
+
let mb = kb / 1024;
|
|
1362
|
+
if (mb < 1024) return mb.toFixed(2) + " MB";
|
|
1363
|
+
return (mb / 1024).toFixed(2) + " GB";
|
|
1364
|
+
};
|
|
1365
|
+
const fetchFileMeta = async (url2) => {
|
|
1366
|
+
try {
|
|
1367
|
+
const res = await fetch(url2, { method: "HEAD" });
|
|
1368
|
+
const size = res.headers.get("content-length") || "";
|
|
1369
|
+
let type = res.headers.get("content-type") || "";
|
|
1370
|
+
const date = res.headers.get("last-modified") || "";
|
|
1371
|
+
const guessed = guessTypeFromUrl(url2);
|
|
1372
|
+
if (guessed) type = guessed;
|
|
1373
|
+
setFileInfo({
|
|
1374
|
+
size: size ? formatSize(Number(size)) : "--",
|
|
1375
|
+
type,
|
|
1376
|
+
date: date ? new Date(date).toLocaleString() : "--"
|
|
1377
|
+
});
|
|
1378
|
+
setUrl(url2);
|
|
1379
|
+
} catch (e) {
|
|
1380
|
+
console.error(e);
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
const onUploadFile = async (formData) => {
|
|
1384
|
+
const res = await mutateAsync({
|
|
1385
|
+
formData,
|
|
1386
|
+
service,
|
|
1387
|
+
xNode,
|
|
1388
|
+
path
|
|
1389
|
+
});
|
|
1390
|
+
const url2 = res?.url;
|
|
1391
|
+
methods?.setValue(name, url2, { shouldDirty: true });
|
|
1392
|
+
handleOnchange && handleOnchange(name ?? "", url2);
|
|
1393
|
+
if (filename) {
|
|
1394
|
+
methods?.setValue(
|
|
1395
|
+
rootField ? `${rootField?.name}.${index}.${filename}` : filename,
|
|
1396
|
+
url2?.split("/").pop(),
|
|
1397
|
+
{ shouldDirty: true }
|
|
1398
|
+
);
|
|
1399
|
+
handleOnchange && handleOnchange(
|
|
1400
|
+
rootField ? `${rootField?.name}.${index}.${filename}` : filename,
|
|
1401
|
+
url2?.split("/").pop()
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
setUrl(url2);
|
|
1405
|
+
fetchFileMeta(url2);
|
|
1406
|
+
return url2;
|
|
1407
|
+
};
|
|
1408
|
+
const onDeleteFile = () => {
|
|
1409
|
+
if (filename) {
|
|
1410
|
+
methods?.setValue(
|
|
1411
|
+
rootField ? `${rootField?.name}.${index}.${filename}` : filename,
|
|
1412
|
+
null,
|
|
1413
|
+
{ shouldDirty: true }
|
|
1414
|
+
);
|
|
1415
|
+
handleOnchange && handleOnchange(
|
|
1416
|
+
rootField ? `${rootField?.name}.${index}.${filename}` : filename,
|
|
1417
|
+
null
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
setUrl(null);
|
|
1421
|
+
setFileInfo(null);
|
|
1422
|
+
methods?.setValue(name, null, { shouldDirty: true });
|
|
1423
|
+
handleOnchange && handleOnchange(name ?? "", null);
|
|
1424
|
+
};
|
|
1425
|
+
return {
|
|
1426
|
+
onUploadFile,
|
|
1427
|
+
onDeleteFile,
|
|
1428
|
+
fileInfo,
|
|
1429
|
+
url
|
|
1430
|
+
};
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
// src/widget/basic/many2many-binary-field/controller.tsx
|
|
1434
|
+
import { useId as useId2, useRef as useRef3, useState as useState13 } from "react";
|
|
1435
|
+
var many2manyBinaryController = (props) => {
|
|
1436
|
+
const {
|
|
1437
|
+
name,
|
|
1438
|
+
methods,
|
|
1439
|
+
value,
|
|
1440
|
+
onChange: handleOnchange,
|
|
1441
|
+
service,
|
|
1442
|
+
xNode,
|
|
1443
|
+
path
|
|
1444
|
+
} = props;
|
|
1445
|
+
const inputId = useId2();
|
|
1446
|
+
const { useUploadFile: useUploadFile2 } = (0, provider_exports.useService)();
|
|
1447
|
+
const { mutateAsync } = useUploadFile2();
|
|
1448
|
+
const binaryRef = useRef3(null);
|
|
1449
|
+
const [initialFiles, setInitialFiles] = useState13(
|
|
1450
|
+
Array.isArray(value) ? value : value ? [value] : []
|
|
1451
|
+
);
|
|
1452
|
+
const checkIsImageLink = (url) => {
|
|
1453
|
+
const imageExtensions = /\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff|ico)$/i;
|
|
1454
|
+
return imageExtensions.test(url) || isBase64Image(url) || isBlobUrl(url);
|
|
1455
|
+
};
|
|
1456
|
+
const sanitizeForBE = (list) => list.filter((x) => x?.datas && !isBlobUrl(x.datas)).map((x) => ({ name: x.name, datas: x.datas, mimetype: x.mimetype }));
|
|
1457
|
+
const isBase64Image = (str) => {
|
|
1458
|
+
const base64Regex = /^data:image\/(png|jpeg|jpg|gif|webp);base64,/;
|
|
1459
|
+
if (!base64Regex.test(str)) {
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
try {
|
|
1463
|
+
const base64Data = str.split(",")[1];
|
|
1464
|
+
return !!base64Data && atob(base64Data).length > 0;
|
|
1465
|
+
} catch (error) {
|
|
1466
|
+
return false;
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
const handleFileChange = async (files, e, oldValues) => {
|
|
1470
|
+
try {
|
|
1471
|
+
const uploadedUrls = await Promise.all(
|
|
1472
|
+
files.map(async (f) => {
|
|
1473
|
+
const formData = new FormData();
|
|
1474
|
+
formData.append("file", f);
|
|
1475
|
+
const res = await mutateAsync({ formData, service, xNode, path });
|
|
1476
|
+
return res?.url;
|
|
1477
|
+
})
|
|
1478
|
+
);
|
|
1479
|
+
const uploadedItems = files.map((f, i) => ({
|
|
1480
|
+
name: f.name,
|
|
1481
|
+
datas: uploadedUrls[i] ?? "",
|
|
1482
|
+
mimetype: f.type
|
|
1483
|
+
}));
|
|
1484
|
+
const finalList = [...oldValues, ...uploadedItems];
|
|
1485
|
+
methods?.setValue(name, finalList, { shouldDirty: true });
|
|
1486
|
+
const payloadForBE = sanitizeForBE(finalList);
|
|
1487
|
+
handleOnchange && handleOnchange(name ?? "", payloadForBE);
|
|
1488
|
+
} catch (err) {
|
|
1489
|
+
console.error(err);
|
|
1490
|
+
} finally {
|
|
1491
|
+
e.target.value = "";
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
const handleRemoveAt = (idx) => {
|
|
1495
|
+
const current = methods?.getValues(name) || [];
|
|
1496
|
+
const next = current.filter((_, i) => i !== idx);
|
|
1497
|
+
setInitialFiles((p) => p.filter((_, i) => i !== idx));
|
|
1498
|
+
methods?.setValue(name, next.length ? next : null, { shouldDirty: true });
|
|
1499
|
+
const payloadForBE = next.length ? sanitizeForBE(next) : null;
|
|
1500
|
+
handleOnchange && handleOnchange(name ?? "", payloadForBE);
|
|
1501
|
+
};
|
|
1502
|
+
const handleRemoveAll = () => {
|
|
1503
|
+
setInitialFiles([]);
|
|
1504
|
+
methods?.setValue(name, null, { shouldDirty: true });
|
|
1505
|
+
handleOnchange && handleOnchange(name ?? "", null);
|
|
1506
|
+
};
|
|
1507
|
+
return {
|
|
1508
|
+
inputId,
|
|
1509
|
+
initialFiles,
|
|
1510
|
+
binaryRef,
|
|
1511
|
+
handleFileChange,
|
|
1512
|
+
handleRemoveAt,
|
|
1513
|
+
handleRemoveAll,
|
|
1514
|
+
checkIsImageLink,
|
|
1515
|
+
setInitialFiles
|
|
1516
|
+
};
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
// src/widget/basic/provider-einvoice-field/controller.ts
|
|
1520
|
+
var providerEinvoiceFieldController = (props) => {
|
|
1521
|
+
const { relation, formValues, options: fieldOptions, xNode } = props;
|
|
1522
|
+
const { env } = (0, provider_exports.useEnv)();
|
|
1523
|
+
const { action } = useAppProvider();
|
|
1524
|
+
const { useGetSelection: useGetSelection2 } = (0, provider_exports.useService)();
|
|
1525
|
+
const contextObject = {
|
|
1526
|
+
...(typeof action?.context === "string" ? (0, utils_exports.evalJSONContext)(action?.context) : action?.context) || {},
|
|
1527
|
+
...env?.context
|
|
1528
|
+
};
|
|
1529
|
+
const optionsObject = typeof fieldOptions === "string" ? (0, utils_exports.evalJSONContext)(fieldOptions, {
|
|
1530
|
+
...formValues,
|
|
1531
|
+
...contextObject,
|
|
1532
|
+
context: contextObject,
|
|
1533
|
+
parent: { ...formValues }
|
|
1534
|
+
}) : fieldOptions;
|
|
1535
|
+
const data = {
|
|
1536
|
+
model: optionsObject?.model,
|
|
1537
|
+
domain: optionsObject?.domain,
|
|
1538
|
+
context: {
|
|
1539
|
+
...contextObject,
|
|
1540
|
+
...optionsObject?.context
|
|
1541
|
+
},
|
|
1542
|
+
specification: optionsObject?.specification
|
|
1543
|
+
};
|
|
1544
|
+
const { data: listDataCard } = useGetSelection2({
|
|
1545
|
+
data,
|
|
1546
|
+
queryKey: [`data_${relation}`],
|
|
1547
|
+
enabled: true,
|
|
1548
|
+
service: optionsObject?.service,
|
|
1549
|
+
xNode
|
|
1550
|
+
});
|
|
1551
|
+
return {
|
|
1552
|
+
listDataCard
|
|
1553
|
+
};
|
|
1554
|
+
};
|
|
1555
|
+
|
|
1556
|
+
// src/widget/advance/table/table-head/controller.ts
|
|
1557
|
+
import { useMemo as useMemo10, useRef as useRef4 } from "react";
|
|
1558
|
+
var tableHeadController = (props) => {
|
|
1559
|
+
const {
|
|
1560
|
+
typeTable,
|
|
1561
|
+
rows,
|
|
1562
|
+
tableRef,
|
|
1563
|
+
groupByList,
|
|
1564
|
+
selectedRowKeys,
|
|
1565
|
+
setSelectedRowKeys
|
|
1566
|
+
} = props;
|
|
1567
|
+
const { rowIds: recordIds } = useGetRowIds(tableRef);
|
|
1568
|
+
const selectedRowKeysRef = useRef4(recordIds);
|
|
1569
|
+
const isGroupTable = typeTable === "group";
|
|
1570
|
+
const recordsCheckedGroup = useMemo10(() => {
|
|
1571
|
+
if (!rows || !groupByList) return 0;
|
|
1572
|
+
const groupBy = typeof groupByList === "object" ? groupByList?.contexts?.[0]?.group_by : void 0;
|
|
1573
|
+
return countSum(rows, groupBy);
|
|
1574
|
+
}, [rows, groupByList]);
|
|
1575
|
+
const isAllGroupChecked = useMemo10(() => {
|
|
1576
|
+
if (!isGroupTable || !selectedRowKeys?.length) return false;
|
|
1577
|
+
const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
|
|
1578
|
+
const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
|
|
1579
|
+
const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
|
|
1580
|
+
return allGroupsSelected || allRecordsSelected;
|
|
1581
|
+
}, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
|
|
1582
|
+
const isAllNormalChecked = useMemo10(() => {
|
|
1583
|
+
if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
|
|
1584
|
+
return selectedRowKeys.length === rows.length && selectedRowKeys.every(
|
|
1585
|
+
(id) => rows.some((record) => record.id === id)
|
|
1586
|
+
);
|
|
1587
|
+
}, [isGroupTable, selectedRowKeys, rows]);
|
|
1588
|
+
const checkedAll = isAllGroupChecked || isAllNormalChecked;
|
|
1589
|
+
const handleCheckBoxAll = (event) => {
|
|
1590
|
+
if (event?.target?.checked && typeTable === "list") {
|
|
1591
|
+
const allRowKeys = Array.isArray(rows) ? rows.map((record) => record?.id) : [];
|
|
1592
|
+
setSelectedRowKeys(allRowKeys);
|
|
1593
|
+
} else if (event?.target?.checked && typeTable === "group") {
|
|
1594
|
+
const rowsIDs = document.querySelectorAll("tr[data-row-id]");
|
|
1595
|
+
const ids = Array.from(rowsIDs)?.map(
|
|
1596
|
+
(row) => Number(row?.getAttribute("data-row-id"))
|
|
1597
|
+
);
|
|
1598
|
+
if (ids?.length > 0) {
|
|
1599
|
+
setSelectedRowKeys(ids);
|
|
1600
|
+
} else {
|
|
1601
|
+
const sum = countSum(
|
|
1602
|
+
rows,
|
|
1603
|
+
typeof groupByList === "object" ? groupByList?.contexts?.[0]?.group_by : void 0
|
|
1604
|
+
);
|
|
1605
|
+
const keys = Array.from({ length: sum }, (_) => void 0);
|
|
1606
|
+
setSelectedRowKeys(keys);
|
|
1607
|
+
}
|
|
1608
|
+
if (selectedRowKeysRef) {
|
|
1609
|
+
selectedRowKeysRef.current = [];
|
|
1610
|
+
}
|
|
1611
|
+
} else {
|
|
1612
|
+
setSelectedRowKeys([]);
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
return {
|
|
1616
|
+
handleCheckBoxAll,
|
|
1617
|
+
checkedAll,
|
|
1618
|
+
selectedRowKeysRef
|
|
1619
|
+
};
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
// src/widget/advance/table/table-view/controller.ts
|
|
1623
|
+
import { useCallback as useCallback6, useEffect as useEffect13, useMemo as useMemo11, useState as useState14 } from "react";
|
|
1624
|
+
var tableController = ({ data }) => {
|
|
1625
|
+
const [rows, setRows] = useState14([]);
|
|
1626
|
+
const [columnVisibility, setColumnVisibility] = useState14({});
|
|
1627
|
+
const dataModelFields = useMemo11(() => {
|
|
1628
|
+
return data?.fields?.map((field) => ({
|
|
1629
|
+
...data.dataModel?.[field?.name],
|
|
1630
|
+
...field,
|
|
1631
|
+
string: field?.string || data.dataModel?.[field?.name]?.string
|
|
1632
|
+
})) ?? [];
|
|
1633
|
+
}, [data?.fields, data?.dataModel]);
|
|
1634
|
+
const mergeFields = useMemo11(
|
|
1635
|
+
() => mergeButtons(dataModelFields),
|
|
1636
|
+
[dataModelFields]
|
|
1637
|
+
);
|
|
1638
|
+
const transformData = useCallback6(
|
|
1639
|
+
(dataList) => {
|
|
1640
|
+
if (!dataList) return [];
|
|
1641
|
+
return dataList.map((item) => {
|
|
1642
|
+
const transformedItem = { ...item };
|
|
1643
|
+
Object.keys(item).forEach((field) => {
|
|
1644
|
+
if (field !== "__domain") {
|
|
1645
|
+
if (item[field] && typeof item[field] === "object" && item[field].display_name) {
|
|
1646
|
+
transformedItem[field] = item[field];
|
|
1647
|
+
} else if (Array.isArray(item[field]) && item[field].length > 0) {
|
|
1648
|
+
if (data.typeTable === "group" && item[field]?.length === 2 && typeof item[field]?.[1] === "string") {
|
|
1649
|
+
transformedItem["string"] = item[field]?.[1];
|
|
1650
|
+
}
|
|
1651
|
+
transformedItem[field] = item[field];
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
});
|
|
1655
|
+
return item.display_name ? { ...transformedItem, item: item.display_name } : transformedItem;
|
|
1656
|
+
});
|
|
1657
|
+
},
|
|
1658
|
+
[data?.typeTable]
|
|
1659
|
+
);
|
|
1660
|
+
useEffect13(() => {
|
|
1661
|
+
setRows(transformData(data?.records));
|
|
1662
|
+
}, [data?.records, transformData]);
|
|
1663
|
+
const columns = useMemo11(() => {
|
|
1664
|
+
try {
|
|
1665
|
+
return mergeFields?.filter((item) => {
|
|
1666
|
+
return item?.widget !== "details_Receive_money" && !(item?.column_invisible ? utils_exports.domainHelper.matchDomains(
|
|
1667
|
+
data.context,
|
|
1668
|
+
item?.column_invisible
|
|
1669
|
+
) : item?.invisible ? utils_exports.domainHelper.matchDomains(data.context, item?.invisible) : false);
|
|
1670
|
+
})?.map((field) => {
|
|
1671
|
+
const overridden = columnVisibility[field?.name];
|
|
1672
|
+
return {
|
|
1673
|
+
name: field?.name,
|
|
1674
|
+
optional: overridden ?? field?.optional,
|
|
1675
|
+
title: field?.type_co === "button" ? "" : field?.string,
|
|
1676
|
+
field: { ...field }
|
|
1677
|
+
};
|
|
1678
|
+
}) ?? [];
|
|
1679
|
+
} catch (error) {
|
|
1680
|
+
console.error("Error in useTable:", error);
|
|
1681
|
+
return [];
|
|
1682
|
+
}
|
|
1683
|
+
}, [mergeFields, data?.context, columnVisibility]);
|
|
1684
|
+
const onToggleColumnOptional = useCallback6((item) => {
|
|
1685
|
+
setColumnVisibility((prev) => ({
|
|
1686
|
+
...prev,
|
|
1687
|
+
[item?.name]: item?.optional === "show" ? "hide" : "show"
|
|
1688
|
+
}));
|
|
1689
|
+
}, []);
|
|
1690
|
+
return {
|
|
1691
|
+
rows,
|
|
1692
|
+
columns,
|
|
1693
|
+
onToggleColumnOptional,
|
|
1694
|
+
typeTable: data?.typeTable
|
|
1695
|
+
};
|
|
1696
|
+
};
|
|
1697
|
+
|
|
1698
|
+
// src/widget/advance/table/table-group/controller.ts
|
|
1699
|
+
import { useMemo as useMemo12, useState as useState15 } from "react";
|
|
1700
|
+
var tableGroupController = (props) => {
|
|
1701
|
+
const { env } = (0, provider_exports.useEnv)();
|
|
1702
|
+
const { useGetListData: useGetListData2 } = (0, provider_exports.useService)();
|
|
1703
|
+
const {
|
|
1704
|
+
columns,
|
|
1705
|
+
row,
|
|
1706
|
+
model,
|
|
1707
|
+
viewData,
|
|
1708
|
+
level,
|
|
1709
|
+
specification,
|
|
1710
|
+
context,
|
|
1711
|
+
checkedAll,
|
|
1712
|
+
groupByList,
|
|
1713
|
+
setSelectedRowKeys
|
|
1714
|
+
} = props;
|
|
1715
|
+
const [pageGroup, setPageGroup] = useState15(0);
|
|
1716
|
+
const [isShowGroup, setIsShowGroup] = useState15(false);
|
|
1717
|
+
const [colEmptyGroup, setColEmptyGroup] = useState15({
|
|
1718
|
+
fromStart: 1,
|
|
1719
|
+
fromEnd: 1
|
|
1720
|
+
});
|
|
1721
|
+
const domain = row?.__domain;
|
|
1722
|
+
const processedData = useMemo12(() => {
|
|
1723
|
+
const calculateColSpanEmpty = () => {
|
|
1724
|
+
const startIndex = columns.findIndex(
|
|
1725
|
+
(col) => col.field.type === "monetary" && typeof row[col.key] === "number" || col.field.aggregator === "sum"
|
|
1726
|
+
);
|
|
1727
|
+
const endIndex = columns.findLastIndex(
|
|
1728
|
+
(col) => col.field.type === "monetary" && typeof row[col.key] === "number" || col.field.aggregator !== "sum"
|
|
1729
|
+
);
|
|
1730
|
+
const fromStart = startIndex === -1 ? columns.length : startIndex;
|
|
1731
|
+
const fromEnd = endIndex === -1 ? columns.length : columns.length - 1 - endIndex;
|
|
1732
|
+
setColEmptyGroup({ fromStart: fromStart + 1, fromEnd: fromEnd + 1 });
|
|
1733
|
+
return { fromStart: fromStart + 1, fromEnd: fromEnd + 1 };
|
|
1734
|
+
};
|
|
1735
|
+
return calculateColSpanEmpty();
|
|
1736
|
+
}, [columns, row]);
|
|
1737
|
+
const shouldFetchData = useMemo12(() => {
|
|
1738
|
+
return !!isShowGroup;
|
|
1739
|
+
}, [isShowGroup]);
|
|
1740
|
+
const enabled = shouldFetchData && !!processedData;
|
|
1741
|
+
const listDataProps = {
|
|
1742
|
+
model,
|
|
1743
|
+
specification,
|
|
1744
|
+
domain,
|
|
1745
|
+
context,
|
|
1746
|
+
offset: pageGroup * 10,
|
|
1747
|
+
fields: groupByList?.fields,
|
|
1748
|
+
groupby: [groupByList?.contexts[level]?.group_by],
|
|
1749
|
+
limit: 10
|
|
1750
|
+
};
|
|
1751
|
+
const queryKey = [
|
|
1752
|
+
`data-${model}-level_${level}-row-${row?.id}`,
|
|
1753
|
+
specification,
|
|
1754
|
+
domain,
|
|
1755
|
+
pageGroup
|
|
1756
|
+
];
|
|
1757
|
+
const {
|
|
1758
|
+
data: dataGroup,
|
|
1759
|
+
isFetched: isDataGroupFetched,
|
|
1760
|
+
isLoading,
|
|
1761
|
+
isFetching,
|
|
1762
|
+
isPlaceholderData: isDataPlaceHolder
|
|
1763
|
+
} = useGetListData2(listDataProps, queryKey, enabled);
|
|
1764
|
+
const {
|
|
1765
|
+
columns: columnsGroup,
|
|
1766
|
+
rows: rowsGroup,
|
|
1767
|
+
typeTable: typeTableGroup
|
|
1768
|
+
} = tableController({
|
|
1769
|
+
data: {
|
|
1770
|
+
fields: viewData?.views?.list?.fields,
|
|
1771
|
+
records: dataGroup?.records ?? dataGroup?.groups,
|
|
1772
|
+
dataModel: viewData?.models?.[model],
|
|
1773
|
+
context: env.context,
|
|
1774
|
+
typeTable: dataGroup?.groups ? "group" : "list"
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
const group_by_field_name = groupByList?.contexts[level - 1]?.group_by;
|
|
1778
|
+
const nameGroup = Array.isArray(row[group_by_field_name]) ? row?.string ?? row[`${group_by_field_name}`][1] : viewData?.models?.[model]?.[group_by_field_name]?.selection ? viewData.models[model][group_by_field_name].selection.find(
|
|
1779
|
+
(selectItem) => selectItem?.[0] === row[group_by_field_name]
|
|
1780
|
+
)?.[1] : row[group_by_field_name];
|
|
1781
|
+
const toggleShowGroup = () => setIsShowGroup((prev) => !prev);
|
|
1782
|
+
return {
|
|
1783
|
+
// onExpandChildGroup,
|
|
1784
|
+
colEmptyGroup,
|
|
1785
|
+
isShowGroup,
|
|
1786
|
+
isDataGroupFetched,
|
|
1787
|
+
isDataPlaceHolder,
|
|
1788
|
+
// nameGroupWithCount,
|
|
1789
|
+
columnsGroup,
|
|
1790
|
+
rowsGroup,
|
|
1791
|
+
dataGroup,
|
|
1792
|
+
pageGroup,
|
|
1793
|
+
setPageGroup,
|
|
1794
|
+
typeTableGroup
|
|
1795
|
+
};
|
|
1796
|
+
};
|
|
1797
|
+
|
|
1798
|
+
// src/widget/advance/search/controller.ts
|
|
1799
|
+
import { useState as useState16, useEffect as useEffect14, useCallback as useCallback7 } from "react";
|
|
1800
|
+
var searchController = ({
|
|
1801
|
+
viewData,
|
|
1802
|
+
model,
|
|
1803
|
+
domain,
|
|
1804
|
+
context,
|
|
1805
|
+
fieldsList,
|
|
1806
|
+
validateAndParseDate,
|
|
1807
|
+
moment
|
|
1808
|
+
}) => {
|
|
1809
|
+
const { env } = (0, provider_exports.useEnv)();
|
|
1810
|
+
const [filterBy, setFilterBy] = useState16([]);
|
|
1811
|
+
const [searchBy, setSearchBy] = useState16(null);
|
|
1812
|
+
const [groupBy, setGroupBy] = useState16(null);
|
|
1813
|
+
const [selectedTags, setSelectedTags] = useState16(null);
|
|
1814
|
+
const [searchString, setSearchString] = useState16("");
|
|
1815
|
+
const [searchMap, setSearchMap] = useState16({});
|
|
1816
|
+
const [hoveredIndex, setHoveredIndex] = useState16(0);
|
|
1817
|
+
const [hoveredIndexSearchList, setHoveredIndexSearchList] = useState16(0);
|
|
1818
|
+
const actionContext = typeof context === "string" ? (0, utils_exports.evalJSONContext)(context) : context;
|
|
1819
|
+
const contextSearch = { ...env.context, ...actionContext };
|
|
1820
|
+
const domainAction = domain ? Array.isArray(domain) ? [...domain] : (0, utils_exports.evalJSONDomain)(domain, contextSearch) : [];
|
|
1821
|
+
const resetAllStateSearch = () => {
|
|
1822
|
+
setFilterBy([]);
|
|
1823
|
+
setGroupBy([]);
|
|
1824
|
+
setSearchBy([]);
|
|
1825
|
+
setSelectedTags(null);
|
|
1826
|
+
setSearchString("");
|
|
1827
|
+
setSearchMap({});
|
|
1828
|
+
};
|
|
1829
|
+
const fetchData = async () => {
|
|
1830
|
+
if (viewData) {
|
|
1831
|
+
try {
|
|
1832
|
+
const dataModel = viewData?.models?.[model];
|
|
1833
|
+
const searchViews = viewData?.views?.search;
|
|
1834
|
+
const searchByItems = searchViews?.search_by?.filter(
|
|
1835
|
+
(item) => !utils_exports.domainHelper.matchDomains(contextSearch, item.invisible)
|
|
1836
|
+
)?.map(
|
|
1837
|
+
({
|
|
1838
|
+
string,
|
|
1839
|
+
name,
|
|
1840
|
+
filter_domain,
|
|
1841
|
+
operator,
|
|
1842
|
+
widget,
|
|
1843
|
+
class: classSearchItem,
|
|
1844
|
+
placeholder
|
|
1845
|
+
}, index) => ({
|
|
1846
|
+
placeholder,
|
|
1847
|
+
class: classSearchItem,
|
|
1848
|
+
dataIndex: index,
|
|
1849
|
+
title: string ?? dataModel?.[name]?.string,
|
|
1850
|
+
name: name ?? dataModel?.[name]?.name,
|
|
1851
|
+
filter_domain,
|
|
1852
|
+
operator,
|
|
1853
|
+
widget,
|
|
1854
|
+
type: dataModel?.[name]?.type
|
|
1855
|
+
})
|
|
1856
|
+
);
|
|
1857
|
+
const filterByItems = searchViews?.filter_by.filter((item) => {
|
|
1858
|
+
return !utils_exports.domainHelper.matchDomains(contextSearch, item?.invisible);
|
|
1859
|
+
})?.map((item) => ({ ...item, active: false }));
|
|
1860
|
+
const groupByItems = searchViews?.group_by.filter(
|
|
1861
|
+
(item) => !utils_exports.domainHelper.matchDomains(contextSearch, item?.invisible)
|
|
1862
|
+
).map((item) => ({
|
|
1863
|
+
...item,
|
|
1864
|
+
string: item.string ?? viewData?.models?.[model]?.[item?.name?.split("group_by_")?.[1]]?.string
|
|
1865
|
+
}));
|
|
1866
|
+
setSearchBy(searchByItems);
|
|
1867
|
+
setFilterBy(filterByItems);
|
|
1868
|
+
setGroupBy(groupByItems);
|
|
1869
|
+
} catch (error) {
|
|
1870
|
+
console.error("Error fetching data:", error);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
useEffect14(() => {
|
|
1875
|
+
fetchData();
|
|
1876
|
+
}, [model, viewData]);
|
|
1877
|
+
const onChangeSearchInput = (search_string) => {
|
|
1878
|
+
setSearchString(search_string);
|
|
1879
|
+
};
|
|
1880
|
+
const removeKeyFromSearchMap = ({
|
|
1881
|
+
key,
|
|
1882
|
+
item
|
|
1883
|
+
}) => {
|
|
1884
|
+
const values = searchMap[key];
|
|
1885
|
+
if (!values) return searchMap;
|
|
1886
|
+
const newSearchMap = { ...searchMap };
|
|
1887
|
+
if (item) {
|
|
1888
|
+
const filtered = values.filter((value) => value.name !== item.name);
|
|
1889
|
+
if (filtered.length > 0) {
|
|
1890
|
+
newSearchMap[key] = filtered;
|
|
1891
|
+
} else {
|
|
1892
|
+
delete newSearchMap[key];
|
|
1893
|
+
}
|
|
1894
|
+
} else {
|
|
1895
|
+
delete newSearchMap[key];
|
|
1896
|
+
}
|
|
1897
|
+
setSearchMap(newSearchMap);
|
|
1898
|
+
};
|
|
1899
|
+
const updateSearchMap = ({ key, item }) => {
|
|
1900
|
+
const newSearchMap = { ...searchMap };
|
|
1901
|
+
const currentValues = searchMap[key] ?? [];
|
|
1902
|
+
newSearchMap[key] = [...currentValues, item];
|
|
1903
|
+
setSearchMap(newSearchMap);
|
|
1904
|
+
};
|
|
1905
|
+
const removeSearchItems = (key, item) => {
|
|
1906
|
+
removeKeyFromSearchMap({ key: String(key), item });
|
|
1907
|
+
};
|
|
1908
|
+
const addSearchItems = (key, newItem) => {
|
|
1909
|
+
updateSearchMap({ key, item: newItem });
|
|
1910
|
+
};
|
|
1911
|
+
const formatDomain = () => {
|
|
1912
|
+
if (domainAction) {
|
|
1913
|
+
const domain2 = [];
|
|
1914
|
+
if (Array.isArray(domainAction) && domainAction.length > 0) {
|
|
1915
|
+
if (Object.keys(searchMap).some((key) => !key.includes(constants_exports.SearchType.GROUP))) {
|
|
1916
|
+
domain2.push("&");
|
|
1917
|
+
}
|
|
1918
|
+
domainAction.forEach((domainItem) => {
|
|
1919
|
+
domain2.push(domainItem);
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
Object.keys(searchMap).forEach((key, keyIndex, keys) => {
|
|
1923
|
+
if (!key?.includes(constants_exports.SearchType.GROUP)) {
|
|
1924
|
+
if (keys.length > 1 && keyIndex < keys.length - 1) {
|
|
1925
|
+
domain2.push("&");
|
|
1926
|
+
}
|
|
1927
|
+
const valuesOfKey = searchMap[key];
|
|
1928
|
+
valuesOfKey.forEach((value, index) => {
|
|
1929
|
+
if (index < valuesOfKey.length - 1) {
|
|
1930
|
+
domain2.push("|");
|
|
1931
|
+
}
|
|
1932
|
+
if (value.domain) {
|
|
1933
|
+
domain2.push(...value.domain);
|
|
1934
|
+
return;
|
|
1935
|
+
}
|
|
1936
|
+
let valueDomainItem = value?.value;
|
|
1937
|
+
if (value?.modelType === "date") {
|
|
1938
|
+
valueDomainItem = validateAndParseDate(value?.value);
|
|
1939
|
+
} else if (value?.modelType === "datetime") {
|
|
1940
|
+
if (value?.operator === "<=" || value?.operator === "<") {
|
|
1941
|
+
const parsedDate = validateAndParseDate(value?.value, true);
|
|
1942
|
+
const hasTime = moment(value?.value).format("HH:mm:ss") !== "00:00:00";
|
|
1943
|
+
valueDomainItem = hasTime ? moment(parsedDate).format("YYYY-MM-DD HH:mm:ss") : moment(parsedDate).add(1, "day").subtract(1, "second").format("YYYY-MM-DD HH:mm:ss");
|
|
1944
|
+
} else {
|
|
1945
|
+
valueDomainItem = validateAndParseDate(value?.value, true);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
const operator = value?.modelType === "date" || value?.modelType === "datetime" || value?.modelType === "boolean" || value?.modelType === "integer" ? value?.operator ?? "=" : value.operator ?? "ilike";
|
|
1949
|
+
domain2.push([value.name, operator, valueDomainItem]);
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
});
|
|
1953
|
+
return [...domain2];
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
const setTagSearch = useCallback7(
|
|
1957
|
+
(updatedMap) => {
|
|
1958
|
+
if (!updatedMap) return;
|
|
1959
|
+
const tagsSearch = Object.entries(updatedMap).map(
|
|
1960
|
+
([key, objValues]) => {
|
|
1961
|
+
const {
|
|
1962
|
+
title,
|
|
1963
|
+
name,
|
|
1964
|
+
groupIndex,
|
|
1965
|
+
type,
|
|
1966
|
+
widget,
|
|
1967
|
+
modelType,
|
|
1968
|
+
dataIndex,
|
|
1969
|
+
date
|
|
1970
|
+
} = objValues[0];
|
|
1971
|
+
if (!key?.includes(constants_exports.SearchType.GROUP)) {
|
|
1972
|
+
const values = objValues?.map((objValue) => objValue.value);
|
|
1973
|
+
return {
|
|
1974
|
+
title,
|
|
1975
|
+
name: type === constants_exports.SearchType.SEARCH ? `${constants_exports.SearchType.SEARCH}_${String(dataIndex)}` : groupIndex ?? name,
|
|
1976
|
+
values,
|
|
1977
|
+
type,
|
|
1978
|
+
widget,
|
|
1979
|
+
modelType,
|
|
1980
|
+
date
|
|
1981
|
+
};
|
|
1982
|
+
} else {
|
|
1983
|
+
const contexts = [];
|
|
1984
|
+
let groupValues = [];
|
|
1985
|
+
objValues?.forEach((objValue) => {
|
|
1986
|
+
const { context: context2, value, active, groupIndex: groupIndex2, isDefault } = objValue;
|
|
1987
|
+
const indexAppend = groupIndex2 != null ? groupIndex2 : viewData?.views?.search?.filters_by?.length ?? 0;
|
|
1988
|
+
contexts.push(
|
|
1989
|
+
...Array.isArray(context2?.group_by) ? context2.group_by.map((item) => ({ group_by: item })) : [context2]
|
|
1990
|
+
);
|
|
1991
|
+
groupValues[indexAppend] = {
|
|
1992
|
+
contexts: [
|
|
1993
|
+
...Array.isArray(context2?.group_by) ? context2.group_by.map((item) => ({
|
|
1994
|
+
group_by: item
|
|
1995
|
+
})) : [context2]
|
|
1996
|
+
],
|
|
1997
|
+
strings: isDefault ? [value] : [...groupValues[indexAppend]?.strings ?? [], value]
|
|
1998
|
+
};
|
|
1999
|
+
});
|
|
2000
|
+
const fields = [
|
|
2001
|
+
...new Set(fieldsList?.map((item) => item?.name))
|
|
2002
|
+
];
|
|
2003
|
+
const groupByTag = {
|
|
2004
|
+
title,
|
|
2005
|
+
values: groupValues?.filter(
|
|
2006
|
+
(item) => item !== void 0
|
|
2007
|
+
),
|
|
2008
|
+
type,
|
|
2009
|
+
contexts,
|
|
2010
|
+
fields
|
|
2011
|
+
};
|
|
2012
|
+
return groupByTag;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
);
|
|
2016
|
+
setSelectedTags(tagsSearch);
|
|
2017
|
+
setSearchString("");
|
|
2018
|
+
},
|
|
2019
|
+
[searchMap]
|
|
2020
|
+
);
|
|
2021
|
+
const removeSearchItemsByType = (type) => {
|
|
2022
|
+
const newSearchMap = {};
|
|
2023
|
+
Object.entries(searchMap).forEach(([key, values]) => {
|
|
2024
|
+
const isGroup = key.includes(constants_exports.SearchType.GROUP);
|
|
2025
|
+
const isFilter = key.includes(constants_exports.SearchType.FILTER);
|
|
2026
|
+
const isSearch = key.includes(constants_exports.SearchType.SEARCH);
|
|
2027
|
+
if (type === constants_exports.SearchType.GROUP && isGroup) return;
|
|
2028
|
+
if (type === constants_exports.SearchType.FILTER && isFilter) return;
|
|
2029
|
+
if (type === constants_exports.SearchType.SEARCH && isSearch) return;
|
|
2030
|
+
newSearchMap[key] = values;
|
|
2031
|
+
});
|
|
2032
|
+
setSearchMap(newSearchMap);
|
|
2033
|
+
};
|
|
2034
|
+
useEffect14(() => {
|
|
2035
|
+
setTagSearch(searchMap);
|
|
2036
|
+
}, [searchMap]);
|
|
2037
|
+
const handleAddTagSearch = (tag) => {
|
|
2038
|
+
const { domain: domain2, groupIndex, value, type, context: context2, dataIndex } = tag;
|
|
2039
|
+
const domainFormat = new utils_exports.domainHelper.Domain(domain2);
|
|
2040
|
+
if (type === constants_exports.SearchType.FILTER) {
|
|
2041
|
+
addSearchItems(`${constants_exports.SearchType.FILTER}_${groupIndex}`, {
|
|
2042
|
+
...tag,
|
|
2043
|
+
domain: domain2 ? domainFormat.toList(context2) : null
|
|
2044
|
+
});
|
|
2045
|
+
} else if (type === constants_exports.SearchType.SEARCH) {
|
|
2046
|
+
addSearchItems(`${constants_exports.SearchType.SEARCH}_${String(dataIndex)}`, {
|
|
2047
|
+
...tag,
|
|
2048
|
+
domain: domain2 ? domainFormat.toList({
|
|
2049
|
+
...context2,
|
|
2050
|
+
self: value
|
|
2051
|
+
}) : null
|
|
2052
|
+
});
|
|
2053
|
+
} else if (type === constants_exports.SearchType.GROUP) {
|
|
2054
|
+
addSearchItems(`${constants_exports.SearchType.GROUP}`, {
|
|
2055
|
+
...tag,
|
|
2056
|
+
domain: domain2 ? domainFormat.toList({
|
|
2057
|
+
context: context2,
|
|
2058
|
+
self: value
|
|
2059
|
+
}) : null
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
};
|
|
2063
|
+
const onKeyDown = (e) => {
|
|
2064
|
+
if (!searchBy || searchBy.length === 0) return;
|
|
2065
|
+
switch (e.key) {
|
|
2066
|
+
case "Backspace": {
|
|
2067
|
+
if (!searchString && selectedTags && selectedTags.length > 0) {
|
|
2068
|
+
const lastTag = selectedTags[selectedTags.length - 1];
|
|
2069
|
+
if (!lastTag) return;
|
|
2070
|
+
const key = lastTag.type === constants_exports.SearchType.GROUP ? constants_exports.SearchType.GROUP : lastTag.name;
|
|
2071
|
+
removeKeyFromSearchMap({ key: String(key) });
|
|
2072
|
+
}
|
|
2073
|
+
break;
|
|
2074
|
+
}
|
|
2075
|
+
case "ArrowDown": {
|
|
2076
|
+
e.preventDefault();
|
|
2077
|
+
setHoveredIndex((prev) => {
|
|
2078
|
+
const maxIndex = searchBy.length - 1;
|
|
2079
|
+
const next = prev < maxIndex ? prev + 1 : prev;
|
|
2080
|
+
setHoveredIndexSearchList(next);
|
|
2081
|
+
return next;
|
|
2082
|
+
});
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
case "ArrowUp": {
|
|
2086
|
+
e.preventDefault();
|
|
2087
|
+
setHoveredIndex((prev) => {
|
|
2088
|
+
const next = prev > 0 ? prev - 1 : prev;
|
|
2089
|
+
setHoveredIndexSearchList(next);
|
|
2090
|
+
return next;
|
|
2091
|
+
});
|
|
2092
|
+
break;
|
|
2093
|
+
}
|
|
2094
|
+
case "Enter": {
|
|
2095
|
+
e.preventDefault();
|
|
2096
|
+
if (!searchString.trim()) return;
|
|
2097
|
+
const head = searchBy[hoveredIndex];
|
|
2098
|
+
if (!head) return;
|
|
2099
|
+
handleAddTagSearch({
|
|
2100
|
+
title: head.title,
|
|
2101
|
+
name: head.name,
|
|
2102
|
+
value: searchString,
|
|
2103
|
+
type: constants_exports.SearchType.SEARCH,
|
|
2104
|
+
domain: head.filter_domain,
|
|
2105
|
+
operator: head.operator,
|
|
2106
|
+
dataIndex: head.dataIndex,
|
|
2107
|
+
widget: head.widget,
|
|
2108
|
+
modelType: head.type
|
|
2109
|
+
});
|
|
2110
|
+
break;
|
|
2111
|
+
}
|
|
2112
|
+
default:
|
|
2113
|
+
break;
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
const handleMouseEnter = (index) => {
|
|
2117
|
+
setHoveredIndexSearchList(index);
|
|
2118
|
+
};
|
|
2119
|
+
const handleMouseLeave = () => {
|
|
2120
|
+
setHoveredIndexSearchList(null);
|
|
2121
|
+
};
|
|
2122
|
+
return {
|
|
2123
|
+
groupBy,
|
|
2124
|
+
searchBy,
|
|
2125
|
+
filterBy,
|
|
2126
|
+
selectedTags,
|
|
2127
|
+
searchString,
|
|
2128
|
+
setFilterBy,
|
|
2129
|
+
setGroupBy,
|
|
2130
|
+
setSearchBy,
|
|
2131
|
+
resetAllStateSearch,
|
|
2132
|
+
setSelectedTags,
|
|
2133
|
+
removeSearchItems,
|
|
2134
|
+
onSearchString: onChangeSearchInput,
|
|
2135
|
+
handleAddTagSearch,
|
|
2136
|
+
domain: formatDomain(),
|
|
2137
|
+
context: contextSearch,
|
|
2138
|
+
onKeyDown,
|
|
2139
|
+
handleMouseEnter,
|
|
2140
|
+
handleMouseLeave,
|
|
2141
|
+
hoveredIndexSearchList,
|
|
2142
|
+
removeSearchItemsByType
|
|
2143
|
+
};
|
|
2144
|
+
};
|
|
2145
|
+
export {
|
|
2146
|
+
binaryFieldController,
|
|
2147
|
+
colorFieldController,
|
|
2148
|
+
copyLinkButtonController,
|
|
2149
|
+
downLoadBinaryController,
|
|
2150
|
+
downloadFileController,
|
|
2151
|
+
durationController,
|
|
2152
|
+
many2manyBinaryController,
|
|
2153
|
+
many2manyFieldController,
|
|
2154
|
+
many2manyTagsController,
|
|
2155
|
+
many2oneButtonController,
|
|
2156
|
+
many2oneFieldController,
|
|
2157
|
+
priorityFieldController,
|
|
2158
|
+
providerEinvoiceFieldController,
|
|
2159
|
+
searchController,
|
|
2160
|
+
statusDropdownController,
|
|
2161
|
+
tableController,
|
|
2162
|
+
tableGroupController,
|
|
2163
|
+
tableHeadController
|
|
2164
|
+
};
|