@fto-consult/expo-ui 8.58.6 → 8.60.0
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/bin/create-app/dependencies.js +2 -1
- package/bin/create-app.js +2 -1
- package/package.json +2 -2
- package/src/components/DocumentPicker/index.js +41 -0
- package/src/components/Fab/FabItem/old/FabItem.js +0 -1
- package/src/importer/getSelectFieldValue.js +23 -0
- package/src/importer/index.js +4 -0
- package/src/importer/parseCSV.js +81 -0
- package/src/importer/run.js +400 -0
- package/src/importer/validate.js +137 -0
- package/src/media/document.js +55 -0
- package/src/media/exports.js +131 -0
- package/src/media/index.js +1 -131
- package/src/screens/Help/openLibraries.js +122 -83
package/bin/create-app.js
CHANGED
@@ -153,6 +153,7 @@ electron/**/*
|
|
153
153
|
const plugins = [
|
154
154
|
["expo-image-picker",imagePluginOptions],
|
155
155
|
["expo-camera",cameraPluginsOptions],
|
156
|
+
["expo-document-picker",{"iCloudContainerEnvironment": "Production" }]
|
156
157
|
];
|
157
158
|
appSheme = name? sanitizeFileName(name).replace(/ /g, '') : null;
|
158
159
|
const appJSONPath = path.join(projectRoot,"app.json");
|
@@ -165,7 +166,7 @@ electron/**/*
|
|
165
166
|
"slug": "${name.toLowerCase().replace(/\s\s+/g, '-')}",
|
166
167
|
"version":"${version}",
|
167
168
|
"orientation": "portrait",
|
168
|
-
"plugins":${JSON.stringify(plugins)},
|
169
|
+
"plugins":${JSON.stringify(plugins,null,2)},
|
169
170
|
"icon": "./assets/icon.png",
|
170
171
|
"jsEngine": "hermes",
|
171
172
|
"splash": {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fto-consult/expo-ui",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.60.0",
|
4
4
|
"description": "Bibliothèque de composants UI Expo,react-native",
|
5
5
|
"react-native-paper-doc": "https://github.com/callstack/react-native-paper/tree/main/docs/docs/guides",
|
6
6
|
"scripts": {
|
@@ -87,7 +87,7 @@
|
|
87
87
|
"react-native-paper": "^5.12.3",
|
88
88
|
"react-native-paper-dates": "^0.22.3",
|
89
89
|
"react-native-web": "^0.19.10",
|
90
|
-
"react-virtuoso": "^4.7.
|
90
|
+
"react-virtuoso": "^4.7.5",
|
91
91
|
"readable-stream": "^4.5.2",
|
92
92
|
"sanitize-filename": "^1.6.3",
|
93
93
|
"tippy.js": "^6.3.7",
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import Button from "$ecomponents/Button";
|
2
|
+
import React from "$react";
|
3
|
+
import PropTypes from "prop-types";
|
4
|
+
import { pickDocument } from "$emedia/document";
|
5
|
+
|
6
|
+
const DocumentPickerComponent = React.forwardRef(({pickOptions,onSuccess,onCancel,onPress,...props},ref)=>{
|
7
|
+
return <Button
|
8
|
+
onPress = {(...r)=>{
|
9
|
+
if(typeof onPress =="function" && onPress(...r) === false) return;
|
10
|
+
pickDocument(pickOptions).then((r)=>{
|
11
|
+
if(typeof onSuccess =="function"){
|
12
|
+
onSuccess(r);
|
13
|
+
}
|
14
|
+
}).catch((r)=>{
|
15
|
+
if(typeof onCancel =="function"){
|
16
|
+
onCancel(r);
|
17
|
+
}
|
18
|
+
});
|
19
|
+
}}
|
20
|
+
ref={ref} {...props}/>
|
21
|
+
});
|
22
|
+
|
23
|
+
DocumentPickerComponent.displayName = "DocumentPickerComponent";
|
24
|
+
|
25
|
+
export default DocumentPickerComponent;
|
26
|
+
|
27
|
+
DocumentPickerComponent.propTypes = {
|
28
|
+
...Object.assign({},Button.propTypes),
|
29
|
+
onSuccess : PropTypes.func,
|
30
|
+
onCancel : PropTypes.func,
|
31
|
+
/*** @see : https://docs.expo.dev/versions/latest/sdk/document-picker/#documentpickeroptions */
|
32
|
+
pickOptions : PropTypes.shape({
|
33
|
+
copyToCacheDirectory : PropTypes.bool,
|
34
|
+
multiple : PropTypes.bool,
|
35
|
+
/*** @seee : https://en.wikipedia.org/wiki/Media_type */
|
36
|
+
type : PropTypes.oneOfType([
|
37
|
+
PropTypes.string,
|
38
|
+
PropTypes.arrayOf(PropTypes.string),
|
39
|
+
])
|
40
|
+
}),
|
41
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export default function getSelectedFieldValue ({field,value}){
|
2
|
+
let hasF = false;
|
3
|
+
let itemCodes = "";
|
4
|
+
let vStr = defaultStr(value).toLowerCase().removeSpecialChars().trim();
|
5
|
+
value = defaultStr(value,typeof value =="number"? String(value) : value);
|
6
|
+
value = value.trim();
|
7
|
+
Object.map(field.items,(item,j)=>{
|
8
|
+
if(!isObj(item)) return;
|
9
|
+
let itemCode = defaultStr(item.code).trim();
|
10
|
+
if(!itemCode) return;
|
11
|
+
let rLabel = defaultStr(item.label,item.text,itemCode);
|
12
|
+
let label = rLabel.removeSpecialChars();
|
13
|
+
itemCodes+=(itemCodes?", ":"")+((label?(label+(field.multiple?(" et/ou "):" ou ")):"")+itemCode);
|
14
|
+
label = label.toLowerCase().trim();
|
15
|
+
if(itemCode == value || (itemCode.toLowerCase().trim() == vStr || label == vStr)){
|
16
|
+
hasF = true;
|
17
|
+
value = itemCode;
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
})
|
21
|
+
value = hasF ? value : false;
|
22
|
+
return {value,itemCodes};
|
23
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import {isNonNullString,defaultStr} from "$cutils";
|
2
|
+
export default function parseCSV( strData, strDelimiter ){
|
3
|
+
// Create an array to hold our data. Give the array
|
4
|
+
// a default empty first row.
|
5
|
+
let arrData = [[]];
|
6
|
+
if(!isNonNullString(strData)) return arrData;
|
7
|
+
// Check to see if the delimiter is defined. If not,
|
8
|
+
// then default to comma.
|
9
|
+
strDelimiter = defaultStr(strDelimiter,",");
|
10
|
+
|
11
|
+
// Create a regular expression to parse the CSV values.
|
12
|
+
var objPattern = new RegExp(
|
13
|
+
(
|
14
|
+
// Delimiters.
|
15
|
+
"(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
|
16
|
+
|
17
|
+
// Quoted fields.
|
18
|
+
"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
|
19
|
+
|
20
|
+
// Standard fields.
|
21
|
+
"([^\"\\" + strDelimiter + "\\r\\n]*))"
|
22
|
+
),
|
23
|
+
"gi"
|
24
|
+
);
|
25
|
+
|
26
|
+
// Create an array to hold our individual pattern
|
27
|
+
// matching groups.
|
28
|
+
var arrMatches = null;
|
29
|
+
|
30
|
+
|
31
|
+
// Keep looping over the regular expression matches
|
32
|
+
// until we can no longer find a match.
|
33
|
+
while (arrMatches = objPattern.exec( strData )){
|
34
|
+
|
35
|
+
// Get the delimiter that was found.
|
36
|
+
var strMatchedDelimiter = arrMatches[ 1 ];
|
37
|
+
|
38
|
+
// Check to see if the given delimiter has a length
|
39
|
+
// (is not the start of string) and if it matches
|
40
|
+
// field delimiter. If id does not, then we know
|
41
|
+
// that this delimiter is a row delimiter.
|
42
|
+
if (
|
43
|
+
strMatchedDelimiter.length &&
|
44
|
+
(strMatchedDelimiter != strDelimiter)
|
45
|
+
){
|
46
|
+
|
47
|
+
// Since we have reached a new row of data,
|
48
|
+
// add an empty row to our data array.
|
49
|
+
arrData.push( [] );
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
// Now that we have our delimiter out of the way,
|
55
|
+
// let's check to see which kind of value we
|
56
|
+
// captured (quoted or unquoted).
|
57
|
+
if (arrMatches[ 2 ]){
|
58
|
+
|
59
|
+
// We found a quoted value. When we capture
|
60
|
+
// this value, unescape any double quotes.
|
61
|
+
var strMatchedValue = arrMatches[ 2 ].replace(
|
62
|
+
new RegExp( "\"\"", "g" ),
|
63
|
+
"\""
|
64
|
+
);
|
65
|
+
|
66
|
+
} else {
|
67
|
+
|
68
|
+
// We found a non-quoted value.
|
69
|
+
var strMatchedValue = arrMatches[ 3 ];
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
// Now that we have our value string, let's add
|
75
|
+
// it to the data array.
|
76
|
+
arrData[ arrData.length - 1 ].push( strMatchedValue );
|
77
|
+
}
|
78
|
+
|
79
|
+
// Return the parsed data.
|
80
|
+
return arrData;
|
81
|
+
}
|
@@ -0,0 +1,400 @@
|
|
1
|
+
module.exports = (args,options)=>{
|
2
|
+
let sellersTables = APP.DATA_FILE_MANAGER.getSellersTables ();
|
3
|
+
options = defaultObj(options);
|
4
|
+
let importer = defaultObj(options.importer);
|
5
|
+
let {content,name,fileName,success,error} = defaultObj(args);
|
6
|
+
let {getDB,constants} = require("$database");
|
7
|
+
let validate = require("./validate")
|
8
|
+
let {notify} = require("$components/Dialog")
|
9
|
+
let parser = require("papaparse");
|
10
|
+
fileName = defaultStr(fileName,name);
|
11
|
+
let extraData = require("$database/data/tables/extra");
|
12
|
+
let fFields = isFunction(importer.getFields)? importer.getFields("import") : {};
|
13
|
+
let handleErrors = (errors)=>{
|
14
|
+
if(isArray(errors) && errors.length > 0){
|
15
|
+
let err = "";
|
16
|
+
let fileName = "";
|
17
|
+
let cF = 0;
|
18
|
+
let length = 0;
|
19
|
+
errors.map((e,i)=>{
|
20
|
+
if(isObj(e)){
|
21
|
+
err += "Ligne : "+e.index
|
22
|
+
+ ", Table : "+defaultStr(e.tableText,e.table)
|
23
|
+
+", Fichier : "+defaultStr(e.dbId)
|
24
|
+
+", msg : "+e.msg
|
25
|
+
+"\r\n"
|
26
|
+
if(cF < 3 && isNonNullString(e.tableText) && !fileName.contains(e.tableText)){
|
27
|
+
fileName +=(fileName? ", ":"")+e.tableText;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
cF++;
|
31
|
+
length++;
|
32
|
+
});
|
33
|
+
if(length > 0){
|
34
|
+
let s = length > 1 ? "s":"";
|
35
|
+
let errL = (length > 9? "":"0")+length.formatNumber();
|
36
|
+
fileName = sanitizeFileName(("Erreur"+s+" import-"+fileName+" au &dateheure&"))+".txt";
|
37
|
+
APP.FILE.saveText({
|
38
|
+
content : err,
|
39
|
+
fileName,
|
40
|
+
//mimeType : "text/csv",
|
41
|
+
directory : APP.getId()+"/imports/erreurs/"
|
42
|
+
}).then(({path})=>{
|
43
|
+
notify.warning({
|
44
|
+
message : "Opération d'import terminée avec "+errL+" erreur"+s+". Retrouvez le rapport dans le fichier "+(isNonNullString(path)? path:fileName)
|
45
|
+
,timeout : 8000
|
46
|
+
});
|
47
|
+
}).catch((e)=>{
|
48
|
+
console.log(e,' saving import error');
|
49
|
+
})
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
return new Promise((resolve,reject)=>{
|
54
|
+
let json = content;
|
55
|
+
let TABLES = constants.TABLES;
|
56
|
+
let STRUCT_DATA_TABLES = constants.STRUCT_DATA_TABLES;
|
57
|
+
let errors = [];
|
58
|
+
let breakLoop = undefined;
|
59
|
+
let footer = false ? [{
|
60
|
+
text :'Annuler',
|
61
|
+
icon : 'cancel',
|
62
|
+
onClick : ()=>{
|
63
|
+
breakLoop = true;
|
64
|
+
hidePreloader();
|
65
|
+
let msg = "Opération annulée";
|
66
|
+
notify.error(msg);
|
67
|
+
throw (msg);
|
68
|
+
}
|
69
|
+
}] : undefined;
|
70
|
+
let errorF = (e)=>{
|
71
|
+
hidePreloader();
|
72
|
+
resolve({status:false,errors});
|
73
|
+
handleErrors(errors);
|
74
|
+
if(isFunction(error)){
|
75
|
+
error(e,errors);
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
if(isNonNullString(e)){
|
79
|
+
notify.error(e);
|
80
|
+
}
|
81
|
+
};
|
82
|
+
let successF = (d)=>{
|
83
|
+
d = {result:d,errors};
|
84
|
+
hidePreloader();
|
85
|
+
handleErrors(errors);
|
86
|
+
if(isFunction(success)){
|
87
|
+
success(d);
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
resolve(d);
|
91
|
+
}
|
92
|
+
if(!content) {
|
93
|
+
errorF(null);
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
let dbs = {};
|
97
|
+
let preloader = "import fichier "+fileName;
|
98
|
+
showPreloader(preloader);
|
99
|
+
let docs = [];
|
100
|
+
let isCSV = false;
|
101
|
+
if(!isJSON(json)) {
|
102
|
+
let parsedData = parser.parse(json,{delimiter:defaultStr(importer.delimiter)});
|
103
|
+
if(isObj(parsedData)){
|
104
|
+
if(isArray(parsedData.errors) && parsedData.errors.length > 0){
|
105
|
+
let err = parsedData.errors[0];
|
106
|
+
let _msg = "";
|
107
|
+
if(isObj(err) && isNonNullString(err.message)){
|
108
|
+
_msg += ", message : "+err.message;
|
109
|
+
}
|
110
|
+
return errorF("Impossible d'importer le fichier "+fileName+" car celui-ci contient "+parsedData.errors.length.formatNumber()+" erreur(s)"+_msg);
|
111
|
+
} else if(isArray(parsedData.data) && isArray(importer.fields) && isNonNullString(importer.table) && isNonNullString(importer.dbId)){
|
112
|
+
let meta = parsedData.meta;
|
113
|
+
if(isObj(meta) && isNonNullString(meta.delimiter)){
|
114
|
+
let delimiter= meta.delimiter;
|
115
|
+
let arr = [];
|
116
|
+
let k = defaultNumber(importer.ignoreFirstLigne,1)? 1 : 0;
|
117
|
+
let length = parsedData.data.length;
|
118
|
+
while(k < length){
|
119
|
+
let d = parsedData.data[k];
|
120
|
+
let _d = {};
|
121
|
+
let p = false;
|
122
|
+
if(isArray(d) && d.length > 1){
|
123
|
+
importer.fields.map((f,index)=>{
|
124
|
+
_d[f] = d[index];
|
125
|
+
if(isObj(fFields[f])){
|
126
|
+
let ff = fFields[f];
|
127
|
+
if(isNonNullString(ff.piece)){
|
128
|
+
_d.piece = ff.piece;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
if(!p && _d[f] !== undefined && isNonNullString(_d[f])){
|
132
|
+
p = true;
|
133
|
+
}
|
134
|
+
})
|
135
|
+
_d.table = importer.table;
|
136
|
+
_d.dbId = importer.dbId;
|
137
|
+
}
|
138
|
+
if(p){
|
139
|
+
let tableText = defaultStr(importer.label,_d.table)
|
140
|
+
let msg = validate({data:_d,index:k,requiredFields:defaultArray(importer.fields),fields:fFields,table:_d.table,tableText});
|
141
|
+
if(isNonNullString(msg)){
|
142
|
+
errors.push({dbId:importer.dbId,index:k,msg,status:false,table:_d.table,tableText});
|
143
|
+
p = false;
|
144
|
+
} else p = !msg ? false : true;
|
145
|
+
}
|
146
|
+
if(p) arr.push(_d);
|
147
|
+
k++;
|
148
|
+
}
|
149
|
+
isCSV = true;
|
150
|
+
|
151
|
+
if(isFunction(importer.prepareData)){
|
152
|
+
json = defaultArray(importer.prepareData({docs:arr,fields:fFields,delimiter,rawDocs:parsedData.data,delimiter,table:importer.table,dbId:importer.dbId,dbName:importer.dbId}))
|
153
|
+
} else json = arr;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
} else {
|
157
|
+
errorF("Le fichier "+fileName+" est un fichier de données json invalide");
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
} else {
|
161
|
+
isCSV = false;
|
162
|
+
json = parseJSON(json);
|
163
|
+
if(isObj(json) && defaultStr(json.origin).toLowerCase() =="shared" && isNonNullString(json.provider) && isNonNullString(json.dataType)){
|
164
|
+
return require("../share/import")({success:successF,error:errorF,json});
|
165
|
+
}
|
166
|
+
}
|
167
|
+
if(isArray(json)){
|
168
|
+
json = {rows : json};
|
169
|
+
} else if(!isObj(json)) {
|
170
|
+
errorF("fichier json invalide : ")
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
let isStructData = arrayValueExists(["struct_data",'structdata'],defaultStr(json.type).toLowerCase());
|
174
|
+
if(isStructData ){
|
175
|
+
if(isObj(json.rows) && Object.size(json.rows) > 0){
|
176
|
+
docs = json.rows;
|
177
|
+
} else if(isObj(json.docs) && Object.size(json.docs) > 0){
|
178
|
+
docs = json.docs;
|
179
|
+
}
|
180
|
+
let count = 0;
|
181
|
+
if(isObj(docs)){
|
182
|
+
let {commonDB} = require("$database");
|
183
|
+
let promises = [];
|
184
|
+
for(let i in docs){
|
185
|
+
let table = i.toUpperCase();
|
186
|
+
if(table in STRUCT_DATA_TABLES && isObj(docs[i])){
|
187
|
+
for(let k in docs[i]){
|
188
|
+
let d = docs[i][k];
|
189
|
+
if(isObj(d) && isNonNullString(d.code)){
|
190
|
+
promises.push(commonDB.upsertStructData(table,d).then(()=>{
|
191
|
+
count++;
|
192
|
+
}));
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
Promise.all(promises).then(()=>{
|
198
|
+
if(count > 0){
|
199
|
+
notify.success(count+" Données de structures modifiées ");
|
200
|
+
}
|
201
|
+
})
|
202
|
+
}
|
203
|
+
///l'import des données de structure se fait autrement
|
204
|
+
return successF();
|
205
|
+
} else {
|
206
|
+
if(isArray(json.rows) && json.rows.length > 0){
|
207
|
+
docs = json.rows;
|
208
|
+
} else if(isArray(json.docs) && json.docs.length > 0){
|
209
|
+
docs = json.docs;
|
210
|
+
}
|
211
|
+
if(docs.length <= 0) {
|
212
|
+
successF()
|
213
|
+
return;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
let allDBS = APP.DATA_FILE_MANAGER.getAll();
|
217
|
+
showPreloader({content:preloader+" ...",footer});
|
218
|
+
|
219
|
+
let doc = null;
|
220
|
+
for(let j in docs){
|
221
|
+
if(!isObj(docs[j])) continue;
|
222
|
+
if(breakLoop) break;
|
223
|
+
doc = null;
|
224
|
+
if(isObj(docs[j])){
|
225
|
+
doc = docs[j];
|
226
|
+
if(isObj(docs[j].doc) && (isNonNullString(docs[j].doc._id) || isNonNullString(docs[j].doc._rev))){
|
227
|
+
doc = docs[j].doc;
|
228
|
+
}
|
229
|
+
}
|
230
|
+
if(!doc) continue;
|
231
|
+
let dbId = APP.DATA_FILE_MANAGER.sanitizeName(defaultStr(doc.dbId,json.dbName));
|
232
|
+
let dF = allDBS[dbId];
|
233
|
+
if(!isNonNullString(dbId) || !dF) {
|
234
|
+
errors.push({status:false,dbId,index:j,msg:"Impossible de faire une importation dans le "+APP.DATA_FILE_MANAGER.dataFileText+" "+dbId+" car celui-ci est innexistant",table:doc.table,tableText:doc.table})
|
235
|
+
continue;
|
236
|
+
}
|
237
|
+
let table = defaultStr(doc.table).toUpperCase();
|
238
|
+
if(!arrayValueExists(extraData.ids,doc._id) && !extraData.tables[table]){
|
239
|
+
if(!table) {
|
240
|
+
errors.push({dbId,index:j,msg:'le champ table est invalide pour la données',status:false,table});
|
241
|
+
continue;
|
242
|
+
}
|
243
|
+
let isDocStructData = dbId.trim() =='struct_data' ? true : false;
|
244
|
+
let tb = isDocStructData ? STRUCT_DATA_TABLES[table] : TABLES[table];
|
245
|
+
if(!isObj(tb)){
|
246
|
+
continue;
|
247
|
+
}
|
248
|
+
let dbType = defaultStr(dF.type,"seller").toLowerCase();
|
249
|
+
let fields = tb.fields;
|
250
|
+
if(isDocStructData){
|
251
|
+
dbType = "common";
|
252
|
+
fields = APP.extend(true,{},{
|
253
|
+
code : {
|
254
|
+
required : true,
|
255
|
+
label: 'Code',
|
256
|
+
},label:{
|
257
|
+
type : 'text',
|
258
|
+
label : 'Libelé',
|
259
|
+
required : true,
|
260
|
+
}
|
261
|
+
},fields);
|
262
|
+
}
|
263
|
+
if(!isObj(fields)){
|
264
|
+
continue;
|
265
|
+
}
|
266
|
+
if(APP.DATA_FILE_MANAGER.isCommon(tb.dbName)){
|
267
|
+
dbType = "common"
|
268
|
+
}
|
269
|
+
let tableText = defaultStr(tb.label,tb.text,table);
|
270
|
+
let _msg = undefined;
|
271
|
+
if(dbType == 'common'){
|
272
|
+
if(isDocStructData){
|
273
|
+
if(dbId !== 'struct_data'){
|
274
|
+
_msg = "Impossible d'insérer les données de structure dans le fichier "+dbId;
|
275
|
+
}
|
276
|
+
} else if(!APP.DATA_FILE_MANAGER.isCommon(dbId)) {
|
277
|
+
_msg = "Impossible d'insérer ce type de données dans le "+APP.DATA_FILE_MANAGER.dataFileText+" communes";
|
278
|
+
}
|
279
|
+
} else if(dbType =='project' && dbId !=='project'){
|
280
|
+
_msg = "Impossible d'insérer ce type de données dans le "+APP.DATA_FILE_MANAGER.dataFileText+" des projets";
|
281
|
+
} else {
|
282
|
+
if((dbType ==='seller' || dbType =='pos') && !arrayValueExists(sellersTables,table)){
|
283
|
+
_msg = "Impossible d'enregistrer ce type de données dans un "+APP.DATA_FILE_MANAGER.dataFileText+" commercial";
|
284
|
+
}
|
285
|
+
}
|
286
|
+
if(_msg){
|
287
|
+
errors.push({dbId,index:j,msg:_msg,status:false,table,tableText});
|
288
|
+
continue;
|
289
|
+
}
|
290
|
+
if(!doc["has-validate-content-imp"]){
|
291
|
+
let vArgs = {data:doc,index:j,fields,requiredFields:defaultArray(tb.import && tb.import.requiredFields? tb.import.requiredFields:[]),table,tableText};
|
292
|
+
let msg = validate(vArgs);
|
293
|
+
if(isNonNullString(msg)){
|
294
|
+
errors.push({dbId,index:j,msg,status:false,table,tableText});
|
295
|
+
continue;
|
296
|
+
} else if(!msg) continue;
|
297
|
+
}
|
298
|
+
delete doc["has-validate-content-imp"];
|
299
|
+
doc.table = table;
|
300
|
+
doc.dbId = dbId;
|
301
|
+
}
|
302
|
+
doc.dbId = dbId;
|
303
|
+
dbs[dbId] = defaultArray(dbs[dbId]);
|
304
|
+
dbs[dbId].push(doc);
|
305
|
+
}
|
306
|
+
if(Object.size(dbs) <= 0){
|
307
|
+
return successF();
|
308
|
+
}
|
309
|
+
let count = 0;
|
310
|
+
///les données sont insérées par base de données;
|
311
|
+
for(let dbName in dbs){
|
312
|
+
count++;
|
313
|
+
if(breakLoop) break;
|
314
|
+
getDB(dbName).then(({db})=>{
|
315
|
+
let _docs = dbs[dbName];
|
316
|
+
let dLen = _docs.length;
|
317
|
+
let sLen = dLen.formatNumber()
|
318
|
+
let preloadP = preloader+"["+dbName+"]";
|
319
|
+
showPreloader({content:preloadP+"...",footer});
|
320
|
+
let promises = [];
|
321
|
+
let length = 0;
|
322
|
+
let c = 0;
|
323
|
+
for(let j in _docs){
|
324
|
+
let doc = _docs[j];
|
325
|
+
doc.table = defaultStr(doc.table).toUpperCase();
|
326
|
+
let table = doc.table;
|
327
|
+
let isDocStructData = doc.dbId.trim() =='struct_data' ? true : false;
|
328
|
+
let tb = isDocStructData ? STRUCT_DATA_TABLES[table] : TABLES[table] || {};
|
329
|
+
let tableText = defaultStr(tb.label,tb.text,table);
|
330
|
+
let mutator = isCSV ? (isFunction(importer.mutator)? importer.mutator:undefined) : isObj(tb.import) && isFunction(tb.import.mutator)? tb.import.mutator : undefined;
|
331
|
+
let dbId = doc.dbId;
|
332
|
+
if(mutator){
|
333
|
+
doc = mutator({doc,db,dbId,table,tableText});
|
334
|
+
}
|
335
|
+
if(isNonNullString(doc)){
|
336
|
+
errors.push({dbId,index:j,msg:doc,status:false,table,tableText});
|
337
|
+
continue;
|
338
|
+
} else if(!isObj(doc) || !isNonNullString(doc.table)){
|
339
|
+
errors.push({dbId,index:j,msg:"Document non valide, car la table de données est manquante",status:false,table,tableText});
|
340
|
+
continue;
|
341
|
+
}
|
342
|
+
doc._id = db.uniqid({data:doc}).id;
|
343
|
+
/**** la fonction de muter la données au moment de la mise à jour */
|
344
|
+
let upsertMutator = isCSV ? (isFunction(importer.upsertMutator)? importer.upsertMutator:undefined) : isObj(tb.import) && isFunction(tb.import.upsertMutator)? tb.import.upsertMutator : undefined;
|
345
|
+
promises.push(
|
346
|
+
db.upsert(
|
347
|
+
doc._id,
|
348
|
+
(_doc)=>{
|
349
|
+
let ret = isCSV? APP.extend({},_doc,doc):APP.extend(true,{},_doc,doc);
|
350
|
+
if(upsertMutator){
|
351
|
+
return upsertMutator({doc:ret,old:_doc,new:doc,db,dbId:doc.dbId,table,tableText});
|
352
|
+
}
|
353
|
+
return ret;
|
354
|
+
},{updatedBy:false,updatedHour:false,updatedDate:false}
|
355
|
+
).then((u)=>{
|
356
|
+
c++;
|
357
|
+
showPreloader({
|
358
|
+
content : preloadP+", "+(c.formatNumber()+" sur "+sLen+" traités, "+(Math.floor(c*100/dLen)+"%")),
|
359
|
+
footer
|
360
|
+
}
|
361
|
+
)
|
362
|
+
return u;
|
363
|
+
}).catch((e)=>{
|
364
|
+
c++;
|
365
|
+
return e;
|
366
|
+
})
|
367
|
+
);
|
368
|
+
length++;
|
369
|
+
}
|
370
|
+
Promise.all(promises).then((a)=>{
|
371
|
+
successF(a);
|
372
|
+
showPreloader(preloader+", 100% traités");
|
373
|
+
let dF = APP.DATA_FILE_MANAGER.get(dbName);
|
374
|
+
if(dF){
|
375
|
+
dbName = dF.label;
|
376
|
+
}
|
377
|
+
let dbPref = " le "+APP.DATA_FILE_MANAGER.dataFileText+" ["+dbName+"]";
|
378
|
+
if(promises.length>0){
|
379
|
+
notify.success(promises.length+" modification(s) effectuée(s) dans "+dbPref);
|
380
|
+
} else {
|
381
|
+
notify.success("Auccune modification apportée au "+dbPref);
|
382
|
+
}
|
383
|
+
setTimeout(()=>{
|
384
|
+
hidePreloader();
|
385
|
+
},1000);
|
386
|
+
}).catch((e)=>{
|
387
|
+
if(length >= _docs.length){
|
388
|
+
hidePreloader();
|
389
|
+
errorF(e);
|
390
|
+
}
|
391
|
+
})
|
392
|
+
}).catch((e)=>{
|
393
|
+
if(count >= Object.size(dbs)){
|
394
|
+
hidePreloader();
|
395
|
+
errorF(e);
|
396
|
+
}
|
397
|
+
})
|
398
|
+
}
|
399
|
+
})
|
400
|
+
}
|