@fctc/interface-logic 5.1.0 → 5.1.3
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/chunk-6ARYI77N.mjs +127 -0
- package/dist/chunk-6HWZ3NGD.mjs +6759 -0
- package/dist/chunk-6LSKTACC.js +687 -0
- package/dist/chunk-ACSPOGTI.mjs +316 -0
- package/dist/chunk-B432GFRR.mjs +606 -0
- package/dist/chunk-BPJZ3QRN.mjs +3025 -0
- package/dist/chunk-C5QQGBN4.js +131 -0
- package/dist/chunk-GGNOJ77I.js +2 -0
- package/dist/chunk-JDXUTKMX.js +3065 -0
- package/dist/chunk-NTTHLOQ5.js +6933 -0
- package/dist/chunk-Q5YXX4OR.js +322 -0
- package/dist/chunk-QOXPJWSN.mjs +114 -0
- package/dist/chunk-RPWKWEMA.js +116 -0
- package/dist/chunk-VBYRP2P7.mjs +303 -0
- package/dist/chunk-WAXGOBY2.mjs +1 -0
- package/dist/chunk-WBGK2SHU.js +320 -0
- package/dist/configs.js +7 -2577
- package/dist/configs.mjs +3 -2545
- package/dist/constants.js +65 -356
- package/dist/constants.mjs +1 -319
- package/dist/environment.js +16 -2704
- package/dist/environment.mjs +4 -2670
- package/dist/hooks.js +613 -10420
- package/dist/hooks.mjs +6 -10238
- package/dist/index.js +1235 -12656
- package/dist/index.mjs +8 -12319
- package/dist/models.js +7 -143
- package/dist/models.mjs +2 -120
- package/dist/provider.js +37 -10968
- package/dist/provider.mjs +6 -10936
- package/dist/services.js +40 -8174
- package/dist/services.mjs +6 -8142
- package/dist/store.js +320 -817
- package/dist/store.mjs +1 -717
- package/dist/types.js +3 -17
- package/dist/types.mjs +1 -0
- package/dist/utils.js +134 -3094
- package/dist/utils.mjs +2 -3030
- package/package.json +93 -92
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkJDXUTKMX_js = require('./chunk-JDXUTKMX.js');
|
|
4
|
+
var axios = require('axios');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
9
|
+
|
|
10
|
+
function removeLanguages(acceptLang, removeList) {
|
|
11
|
+
return acceptLang.split(",").map((x) => x.trim()).filter((item) => !removeList?.some((lang) => item?.startsWith(lang))).join(",");
|
|
12
|
+
}
|
|
13
|
+
var axiosClient = {
|
|
14
|
+
init(config) {
|
|
15
|
+
const localStorage = config?.localStorageUtils ?? chunkJDXUTKMX_js.localStorageUtils();
|
|
16
|
+
const sessionStorage = config?.sessionStorageUtils ?? chunkJDXUTKMX_js.sessionStorageUtils;
|
|
17
|
+
const db = config?.db;
|
|
18
|
+
const database = config?.config?.database;
|
|
19
|
+
const isSupabaseMode = config?.isSupaMode;
|
|
20
|
+
let isRefreshing = false;
|
|
21
|
+
let failedQueue = [];
|
|
22
|
+
const processQueue = (error, token = null) => {
|
|
23
|
+
failedQueue?.forEach((prom) => {
|
|
24
|
+
if (error) {
|
|
25
|
+
prom.reject(error);
|
|
26
|
+
} else {
|
|
27
|
+
prom.resolve(token);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
failedQueue = [];
|
|
31
|
+
};
|
|
32
|
+
const instance = axios__default.default.create({
|
|
33
|
+
adapter: axios__default.default.defaults.adapter,
|
|
34
|
+
baseURL: config?.baseUrl,
|
|
35
|
+
timeout: 5e4,
|
|
36
|
+
paramsSerializer: (params) => new URLSearchParams(params).toString()
|
|
37
|
+
});
|
|
38
|
+
instance.interceptors.request.use(async (configReq) => {
|
|
39
|
+
const rawLang = navigator.languages?.join(",") || navigator.language;
|
|
40
|
+
const useRefreshToken = configReq.headers["X-Use-Refresh-Token"] === "true";
|
|
41
|
+
const useActionToken = configReq.headers["X-Use-Action-Token"] === "true";
|
|
42
|
+
const actionToken = configReq.headers["X-Action-Token"];
|
|
43
|
+
const cleaned = removeLanguages(rawLang, config?.excludeLanguages);
|
|
44
|
+
let token = null;
|
|
45
|
+
if (useActionToken && actionToken) {
|
|
46
|
+
token = actionToken;
|
|
47
|
+
} else {
|
|
48
|
+
const getToken = useRefreshToken ? localStorage.getRefreshToken : localStorage.getAccessToken;
|
|
49
|
+
token = await getToken?.();
|
|
50
|
+
}
|
|
51
|
+
if (token) {
|
|
52
|
+
configReq.headers["Authorization"] = `Bearer ${token}`;
|
|
53
|
+
}
|
|
54
|
+
if (database) {
|
|
55
|
+
configReq.headers["DATABASE"] = database;
|
|
56
|
+
}
|
|
57
|
+
configReq.headers["Accept-Language"] = cleaned;
|
|
58
|
+
return configReq;
|
|
59
|
+
}, Promise.reject);
|
|
60
|
+
const buildRefreshUrl = () => {
|
|
61
|
+
if (!config.refreshTokenEndpoint) {
|
|
62
|
+
return `${getBaseUrl(config?.baseUrl)}${"/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`;
|
|
63
|
+
}
|
|
64
|
+
const ep = String(config.refreshTokenEndpoint);
|
|
65
|
+
if (/^https?:\/\//i.test(ep)) return ep;
|
|
66
|
+
const cleanBase = String(config?.baseUrl || "").replace(/\/$/, "");
|
|
67
|
+
const cleanEp = ep.startsWith("/") ? ep : `/${ep}`;
|
|
68
|
+
return `${cleanBase}${cleanEp}`;
|
|
69
|
+
};
|
|
70
|
+
instance.interceptors.response.use(
|
|
71
|
+
(response) => handleResponse(response),
|
|
72
|
+
async (error) => {
|
|
73
|
+
const handleError2 = async (err) => {
|
|
74
|
+
if (!err.response) return err;
|
|
75
|
+
const { data } = err.response;
|
|
76
|
+
if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
|
|
77
|
+
await clearAuthToken();
|
|
78
|
+
}
|
|
79
|
+
return data;
|
|
80
|
+
};
|
|
81
|
+
const originalRequest = error.config;
|
|
82
|
+
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
|
|
83
|
+
error.response.data.code
|
|
84
|
+
)) {
|
|
85
|
+
if (isRefreshing) {
|
|
86
|
+
return new Promise(function(resolve, reject) {
|
|
87
|
+
failedQueue.push({ resolve, reject });
|
|
88
|
+
}).then((newToken) => {
|
|
89
|
+
originalRequest.headers["Authorization"] = "Bearer " + newToken;
|
|
90
|
+
originalRequest.data = chunkJDXUTKMX_js.updateTokenParamInOriginalRequest(
|
|
91
|
+
originalRequest,
|
|
92
|
+
newToken
|
|
93
|
+
);
|
|
94
|
+
return instance.request(originalRequest);
|
|
95
|
+
}).catch(async (err) => {
|
|
96
|
+
if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
|
|
97
|
+
await clearAuthToken();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const browserSession = await sessionStorage.getBrowserSession();
|
|
102
|
+
const refreshToken = await localStorage.getRefreshToken();
|
|
103
|
+
const accessTokenExp = await localStorage.getAccessToken();
|
|
104
|
+
isRefreshing = true;
|
|
105
|
+
if (!refreshToken && (!browserSession || browserSession == "unActive")) {
|
|
106
|
+
await clearAuthToken();
|
|
107
|
+
} else {
|
|
108
|
+
const payload = Object.fromEntries(
|
|
109
|
+
Object.entries({
|
|
110
|
+
refresh_token: refreshToken,
|
|
111
|
+
grant_type: "refresh_token",
|
|
112
|
+
client_id: config.config.clientId,
|
|
113
|
+
client_secret: config.config.clientSecret
|
|
114
|
+
}).filter(([_, v]) => !!v)
|
|
115
|
+
);
|
|
116
|
+
const refreshUrl = buildRefreshUrl();
|
|
117
|
+
return new Promise(function(resolve) {
|
|
118
|
+
axios__default.default.post(refreshUrl, payload, {
|
|
119
|
+
headers: {
|
|
120
|
+
"Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
|
|
121
|
+
Authorization: `Bearer ${accessTokenExp}`
|
|
122
|
+
}
|
|
123
|
+
}).then(async (res) => {
|
|
124
|
+
const data = res.data;
|
|
125
|
+
await localStorage.setToken(data.access_token);
|
|
126
|
+
await localStorage.setRefreshToken(data.refresh_token);
|
|
127
|
+
axios__default.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
|
|
128
|
+
originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
|
|
129
|
+
originalRequest.data = chunkJDXUTKMX_js.updateTokenParamInOriginalRequest(
|
|
130
|
+
originalRequest,
|
|
131
|
+
data.access_token
|
|
132
|
+
);
|
|
133
|
+
processQueue(null, data.access_token);
|
|
134
|
+
resolve(instance.request(originalRequest));
|
|
135
|
+
}).catch(async (err) => {
|
|
136
|
+
if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_2FA_006")) {
|
|
137
|
+
await clearAuthToken();
|
|
138
|
+
}
|
|
139
|
+
if (err && err.response) {
|
|
140
|
+
const { error_code } = err.response?.data || {};
|
|
141
|
+
const { code } = err;
|
|
142
|
+
if (error_code === "AUTHEN_FAIL" || code === "ERR_2FA_006") {
|
|
143
|
+
await clearAuthToken();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
processQueue(err, null);
|
|
147
|
+
}).finally(() => {
|
|
148
|
+
isRefreshing = false;
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return Promise.reject(await handleError2(error));
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
instance.interceptors.response.use(
|
|
157
|
+
(response) => {
|
|
158
|
+
return handleResponse(response);
|
|
159
|
+
},
|
|
160
|
+
async (error) => {
|
|
161
|
+
const handleError2 = async (error2) => {
|
|
162
|
+
if (!error2.response) {
|
|
163
|
+
return error2;
|
|
164
|
+
}
|
|
165
|
+
const { data } = error2.response;
|
|
166
|
+
if (data && data.code === 400 && ["invalid_grant"].includes(data.data?.error)) {
|
|
167
|
+
await clearAuthToken();
|
|
168
|
+
}
|
|
169
|
+
return data;
|
|
170
|
+
};
|
|
171
|
+
const originalRequest = error.config;
|
|
172
|
+
if ((error.response?.status === 403 || error.response?.status === 401 || error.response?.status === 404) && ["TOKEN_EXPIRED", "AUTHEN_FAIL", 401, "ERR_2FA_006"].includes(
|
|
173
|
+
error.response.data.code
|
|
174
|
+
)) {
|
|
175
|
+
if (isRefreshing) {
|
|
176
|
+
return new Promise(function(resolve, reject) {
|
|
177
|
+
failedQueue.push({ resolve, reject });
|
|
178
|
+
}).then((token) => {
|
|
179
|
+
originalRequest.headers["Authorization"] = "Bearer " + token;
|
|
180
|
+
originalRequest.data = chunkJDXUTKMX_js.updateTokenParamInOriginalRequest(
|
|
181
|
+
originalRequest,
|
|
182
|
+
token
|
|
183
|
+
);
|
|
184
|
+
return instance.request(originalRequest);
|
|
185
|
+
}).catch(async (err) => {
|
|
186
|
+
if ((err.response?.status === 400 || err.response?.status === 401) && ["invalid_grant"].includes(err.response.data.error)) {
|
|
187
|
+
await clearAuthToken();
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
const browserSession = await sessionStorage.getBrowserSession();
|
|
192
|
+
const refreshToken = await localStorage.getRefreshToken();
|
|
193
|
+
const accessTokenExp = await localStorage.getAccessToken();
|
|
194
|
+
isRefreshing = true;
|
|
195
|
+
if (!refreshToken && (!browserSession || browserSession == "unActive")) {
|
|
196
|
+
await clearAuthToken();
|
|
197
|
+
} else {
|
|
198
|
+
const payload = Object.fromEntries(
|
|
199
|
+
Object.entries({
|
|
200
|
+
refresh_token: refreshToken,
|
|
201
|
+
grant_type: "refresh_token",
|
|
202
|
+
client_id: config.config.clientId,
|
|
203
|
+
client_secret: config.config.clientSecret
|
|
204
|
+
}).filter(([_, value]) => !!value)
|
|
205
|
+
);
|
|
206
|
+
return new Promise(function(resolve) {
|
|
207
|
+
axios__default.default.post(
|
|
208
|
+
`${config?.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
|
|
209
|
+
payload,
|
|
210
|
+
{
|
|
211
|
+
headers: {
|
|
212
|
+
"Content-Type": config.refreshTokenEndpoint ? "application/x-www-form-urlencoded" : "multipart/form-data",
|
|
213
|
+
Authorization: `Bearer ${accessTokenExp}`
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
).then(async (res) => {
|
|
217
|
+
const data = res.data;
|
|
218
|
+
await localStorage.setToken(data.access_token);
|
|
219
|
+
await localStorage.setRefreshToken(data.refresh_token);
|
|
220
|
+
axios__default.default.defaults.headers.common["Authorization"] = "Bearer " + data.access_token;
|
|
221
|
+
originalRequest.headers["Authorization"] = "Bearer " + data.access_token;
|
|
222
|
+
originalRequest.data = chunkJDXUTKMX_js.updateTokenParamInOriginalRequest(
|
|
223
|
+
originalRequest,
|
|
224
|
+
data.access_token
|
|
225
|
+
);
|
|
226
|
+
processQueue(null, data.access_token);
|
|
227
|
+
resolve(instance.request(originalRequest));
|
|
228
|
+
}).catch(async (err) => {
|
|
229
|
+
console.log("catch error: ", err);
|
|
230
|
+
if (err && (err?.error_code === "AUTHEN_FAIL" || err?.error_code === "TOKEN_EXPIRED" || err?.error_code === "TOKEN_INCORRECT" || err?.code === "ERR_2FA_006")) {
|
|
231
|
+
await clearAuthToken();
|
|
232
|
+
}
|
|
233
|
+
if (err && err.response) {
|
|
234
|
+
console.log("err response code: ", err);
|
|
235
|
+
console.log("err response: ", err.response);
|
|
236
|
+
const { error_code } = err.response?.data || {};
|
|
237
|
+
const { code } = err;
|
|
238
|
+
if (error_code === "AUTHEN_FAIL" || code === "ERR_2FA_006") {
|
|
239
|
+
await clearAuthToken();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
processQueue(err, null);
|
|
243
|
+
}).finally(() => {
|
|
244
|
+
isRefreshing = false;
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return Promise.reject(await handleError2(error));
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
const handleResponse = (res) => {
|
|
253
|
+
if (res && res.data) {
|
|
254
|
+
return res.data;
|
|
255
|
+
}
|
|
256
|
+
return res;
|
|
257
|
+
};
|
|
258
|
+
const clearAuthToken = async () => {
|
|
259
|
+
await localStorage.clearToken();
|
|
260
|
+
if (typeof window !== "undefined") {
|
|
261
|
+
window.location.href = `/login`;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
function formatUrl(url, db2) {
|
|
265
|
+
return url + (db2 ? "?db=" + db2 : "");
|
|
266
|
+
}
|
|
267
|
+
const getBaseUrl = (baseUrl, hardService) => {
|
|
268
|
+
return isSupabaseMode ? "" : `${baseUrl.replace(/\/$/, "")}/${hardService || sessionStorage.getMenuFocus().service || config?.default_service}/api/v2`;
|
|
269
|
+
};
|
|
270
|
+
const getHeaders = (header) => {
|
|
271
|
+
const headers = {
|
|
272
|
+
headers: {
|
|
273
|
+
...header.headers,
|
|
274
|
+
...sessionStorage.getXNode() ? { "X-Node": sessionStorage.getXNode() } : {}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
return headers;
|
|
278
|
+
};
|
|
279
|
+
const responseBody = (response) => response;
|
|
280
|
+
const requests = {
|
|
281
|
+
get: (url, headers, hardService) => instance.get(
|
|
282
|
+
formatUrl(getBaseUrl(config?.baseUrl, hardService) + url, db),
|
|
283
|
+
getHeaders(headers)
|
|
284
|
+
).then(responseBody),
|
|
285
|
+
post: async (url, body, headers, hardService) => instance.post(
|
|
286
|
+
formatUrl(getBaseUrl(config?.baseUrl, hardService) + url, db),
|
|
287
|
+
body,
|
|
288
|
+
getHeaders(headers)
|
|
289
|
+
).then(responseBody),
|
|
290
|
+
post_excel: (url, body, headers, hardService) => instance.post(
|
|
291
|
+
formatUrl(getBaseUrl(config?.baseUrl, hardService) + url, db),
|
|
292
|
+
body,
|
|
293
|
+
{
|
|
294
|
+
responseType: "arraybuffer",
|
|
295
|
+
headers: {
|
|
296
|
+
"Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
|
|
297
|
+
Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
298
|
+
...headers,
|
|
299
|
+
...sessionStorage.getXNode() ? { "X-Node": sessionStorage.getXNode() } : {}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
).then(responseBody),
|
|
303
|
+
put: (url, body, headers, hardService) => instance.put(
|
|
304
|
+
formatUrl(getBaseUrl(config?.baseUrl, hardService) + url, db),
|
|
305
|
+
body,
|
|
306
|
+
getHeaders(headers)
|
|
307
|
+
).then(responseBody),
|
|
308
|
+
patch: (url, body, headers, hardService) => instance.patch(
|
|
309
|
+
formatUrl(getBaseUrl(config?.baseUrl, hardService) + url, db),
|
|
310
|
+
body,
|
|
311
|
+
getHeaders(headers)
|
|
312
|
+
).then(responseBody),
|
|
313
|
+
delete: (url, headers, hardService) => instance.delete(
|
|
314
|
+
formatUrl(getBaseUrl(config?.baseUrl, hardService) + url, db),
|
|
315
|
+
getHeaders(headers)
|
|
316
|
+
).then(responseBody)
|
|
317
|
+
};
|
|
318
|
+
return requests;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
exports.axiosClient = axiosClient;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { WIDGETAVATAR } from './chunk-VBYRP2P7.mjs';
|
|
2
|
+
|
|
3
|
+
// src/models/base-model/index.ts
|
|
4
|
+
var BaseModel = class {
|
|
5
|
+
name;
|
|
6
|
+
view;
|
|
7
|
+
fields;
|
|
8
|
+
constructor(init) {
|
|
9
|
+
this.name = init.name;
|
|
10
|
+
this.view = init.view;
|
|
11
|
+
this.fields = init.fields;
|
|
12
|
+
}
|
|
13
|
+
getSpecificationByFields({
|
|
14
|
+
fields = [],
|
|
15
|
+
specification = {},
|
|
16
|
+
modelsData,
|
|
17
|
+
model,
|
|
18
|
+
modelRoot
|
|
19
|
+
}) {
|
|
20
|
+
if (Array.isArray(fields)) {
|
|
21
|
+
let spec = { ...specification };
|
|
22
|
+
fields.forEach((field) => {
|
|
23
|
+
if (!field?.type_co || field?.name && field?.type_co === "field" /* FIELD */) {
|
|
24
|
+
if (modelsData?.[model]?.[field?.name]) {
|
|
25
|
+
if (modelsData?.[model]?.[field?.name]?.type === "one2many" /* ONE2MANY */ || modelsData?.[model]?.[field?.name]?.type === "many2many" /* MANY2MANY */) {
|
|
26
|
+
const relation = modelsData?.[model]?.[field?.name]?.relation;
|
|
27
|
+
const modelRelation = modelsData?.[relation];
|
|
28
|
+
if (modelRelation) {
|
|
29
|
+
spec[field?.name] = {
|
|
30
|
+
fields: {}
|
|
31
|
+
};
|
|
32
|
+
if (modelRoot && modelRoot === relation) {
|
|
33
|
+
spec[field?.name].fields = { id: {} };
|
|
34
|
+
} else {
|
|
35
|
+
spec[field?.name].fields = this.getSpecificationByFields({
|
|
36
|
+
fields: Object.values(modelRelation),
|
|
37
|
+
specification: { id: {}, display_name: {} },
|
|
38
|
+
modelsData,
|
|
39
|
+
model: relation,
|
|
40
|
+
modelRoot: model
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
spec[field?.name] = {
|
|
45
|
+
fields: {
|
|
46
|
+
id: {},
|
|
47
|
+
display_name: {},
|
|
48
|
+
...field?.widget === "many2many_binary" ? { mimetype: {} } : {},
|
|
49
|
+
...field?.widget === "many2many_binary" && relation === "ir.attachment" ? { datas: {} } : {}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
} else if (modelsData?.[model]?.[field?.name]?.type === "many2one" /* MANY2ONE */) {
|
|
54
|
+
spec[field?.name] = {
|
|
55
|
+
fields: {
|
|
56
|
+
id: {},
|
|
57
|
+
display_name: {},
|
|
58
|
+
...WIDGETAVATAR[field?.widget] ? { image_256: {} } : {},
|
|
59
|
+
...field?.name === "currency_id" && fields?.find((item) => item?.widget === "monetary") ? { symbol: {} } : {},
|
|
60
|
+
...field?.widget === "many2many_binary" ? { mimetype: {} } : {}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
64
|
+
spec[field?.name] = {};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else if (field?.type_co === "group" /* GROUP */ || field?.type_co === "div" /* DIV */ || field?.type_co === "span" /* SPAN */) {
|
|
68
|
+
const specGroup = this.getSpecificationByFields({
|
|
69
|
+
fields: field?.fields,
|
|
70
|
+
specification: spec,
|
|
71
|
+
modelsData,
|
|
72
|
+
model
|
|
73
|
+
});
|
|
74
|
+
spec = { ...spec, ...specGroup };
|
|
75
|
+
} else if (field?.type_co === "tree" /* TREE */ || field?.type_co === "list" /* LIST */ || field?.type_co === "kanban" /* KANBAN */) {
|
|
76
|
+
const relation = modelsData?.[model]?.[field?.name]?.relation;
|
|
77
|
+
const specTreee = this.getSpecificationByFields({
|
|
78
|
+
fields: field?.fields,
|
|
79
|
+
specification: {},
|
|
80
|
+
modelsData,
|
|
81
|
+
model: relation,
|
|
82
|
+
modelRoot: model
|
|
83
|
+
});
|
|
84
|
+
spec = { ...spec, [field?.name]: { fields: specTreee } };
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return spec;
|
|
88
|
+
} else {
|
|
89
|
+
console.warn("fields is not array");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
getTreeProps() {
|
|
93
|
+
const props = this.view?.views?.list || {};
|
|
94
|
+
return props;
|
|
95
|
+
}
|
|
96
|
+
getTreeFields() {
|
|
97
|
+
const fields = this.view?.views?.list?.fields || [];
|
|
98
|
+
return fields;
|
|
99
|
+
}
|
|
100
|
+
getSpecification() {
|
|
101
|
+
const specInit = {};
|
|
102
|
+
const modelData = this.view?.models || {};
|
|
103
|
+
const specification = this.getSpecificationByFields({
|
|
104
|
+
fields: this.fields,
|
|
105
|
+
specification: specInit,
|
|
106
|
+
modelsData: modelData,
|
|
107
|
+
model: this.name,
|
|
108
|
+
modelRoot: ""
|
|
109
|
+
});
|
|
110
|
+
return specification;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { BaseModel };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkWBGK2SHU_js = require('./chunk-WBGK2SHU.js');
|
|
4
|
+
|
|
5
|
+
// src/models/base-model/index.ts
|
|
6
|
+
var BaseModel = class {
|
|
7
|
+
name;
|
|
8
|
+
view;
|
|
9
|
+
fields;
|
|
10
|
+
constructor(init) {
|
|
11
|
+
this.name = init.name;
|
|
12
|
+
this.view = init.view;
|
|
13
|
+
this.fields = init.fields;
|
|
14
|
+
}
|
|
15
|
+
getSpecificationByFields({
|
|
16
|
+
fields = [],
|
|
17
|
+
specification = {},
|
|
18
|
+
modelsData,
|
|
19
|
+
model,
|
|
20
|
+
modelRoot
|
|
21
|
+
}) {
|
|
22
|
+
if (Array.isArray(fields)) {
|
|
23
|
+
let spec = { ...specification };
|
|
24
|
+
fields.forEach((field) => {
|
|
25
|
+
if (!field?.type_co || field?.name && field?.type_co === "field" /* FIELD */) {
|
|
26
|
+
if (modelsData?.[model]?.[field?.name]) {
|
|
27
|
+
if (modelsData?.[model]?.[field?.name]?.type === "one2many" /* ONE2MANY */ || modelsData?.[model]?.[field?.name]?.type === "many2many" /* MANY2MANY */) {
|
|
28
|
+
const relation = modelsData?.[model]?.[field?.name]?.relation;
|
|
29
|
+
const modelRelation = modelsData?.[relation];
|
|
30
|
+
if (modelRelation) {
|
|
31
|
+
spec[field?.name] = {
|
|
32
|
+
fields: {}
|
|
33
|
+
};
|
|
34
|
+
if (modelRoot && modelRoot === relation) {
|
|
35
|
+
spec[field?.name].fields = { id: {} };
|
|
36
|
+
} else {
|
|
37
|
+
spec[field?.name].fields = this.getSpecificationByFields({
|
|
38
|
+
fields: Object.values(modelRelation),
|
|
39
|
+
specification: { id: {}, display_name: {} },
|
|
40
|
+
modelsData,
|
|
41
|
+
model: relation,
|
|
42
|
+
modelRoot: model
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
spec[field?.name] = {
|
|
47
|
+
fields: {
|
|
48
|
+
id: {},
|
|
49
|
+
display_name: {},
|
|
50
|
+
...field?.widget === "many2many_binary" ? { mimetype: {} } : {},
|
|
51
|
+
...field?.widget === "many2many_binary" && relation === "ir.attachment" ? { datas: {} } : {}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
} else if (modelsData?.[model]?.[field?.name]?.type === "many2one" /* MANY2ONE */) {
|
|
56
|
+
spec[field?.name] = {
|
|
57
|
+
fields: {
|
|
58
|
+
id: {},
|
|
59
|
+
display_name: {},
|
|
60
|
+
...chunkWBGK2SHU_js.WIDGETAVATAR[field?.widget] ? { image_256: {} } : {},
|
|
61
|
+
...field?.name === "currency_id" && fields?.find((item) => item?.widget === "monetary") ? { symbol: {} } : {},
|
|
62
|
+
...field?.widget === "many2many_binary" ? { mimetype: {} } : {}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
spec[field?.name] = {};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} else if (field?.type_co === "group" /* GROUP */ || field?.type_co === "div" /* DIV */ || field?.type_co === "span" /* SPAN */) {
|
|
70
|
+
const specGroup = this.getSpecificationByFields({
|
|
71
|
+
fields: field?.fields,
|
|
72
|
+
specification: spec,
|
|
73
|
+
modelsData,
|
|
74
|
+
model
|
|
75
|
+
});
|
|
76
|
+
spec = { ...spec, ...specGroup };
|
|
77
|
+
} else if (field?.type_co === "tree" /* TREE */ || field?.type_co === "list" /* LIST */ || field?.type_co === "kanban" /* KANBAN */) {
|
|
78
|
+
const relation = modelsData?.[model]?.[field?.name]?.relation;
|
|
79
|
+
const specTreee = this.getSpecificationByFields({
|
|
80
|
+
fields: field?.fields,
|
|
81
|
+
specification: {},
|
|
82
|
+
modelsData,
|
|
83
|
+
model: relation,
|
|
84
|
+
modelRoot: model
|
|
85
|
+
});
|
|
86
|
+
spec = { ...spec, [field?.name]: { fields: specTreee } };
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return spec;
|
|
90
|
+
} else {
|
|
91
|
+
console.warn("fields is not array");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
getTreeProps() {
|
|
95
|
+
const props = this.view?.views?.list || {};
|
|
96
|
+
return props;
|
|
97
|
+
}
|
|
98
|
+
getTreeFields() {
|
|
99
|
+
const fields = this.view?.views?.list?.fields || [];
|
|
100
|
+
return fields;
|
|
101
|
+
}
|
|
102
|
+
getSpecification() {
|
|
103
|
+
const specInit = {};
|
|
104
|
+
const modelData = this.view?.models || {};
|
|
105
|
+
const specification = this.getSpecificationByFields({
|
|
106
|
+
fields: this.fields,
|
|
107
|
+
specification: specInit,
|
|
108
|
+
modelsData: modelData,
|
|
109
|
+
model: this.name,
|
|
110
|
+
modelRoot: ""
|
|
111
|
+
});
|
|
112
|
+
return specification;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
exports.BaseModel = BaseModel;
|