@fto-consult/expo-ui 8.41.0 → 8.42.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.
@@ -7,9 +7,9 @@
7
7
  "@react-native-community/netinfo": "11.1.0",
8
8
  "@react-native/assets-registry": "^0.72.0",
9
9
  "react-native-get-random-values": "~1.8.0",
10
- "@react-navigation/native": "^6.1.14",
11
- "@react-navigation/native-stack": "^6.9.22",
12
- "@react-navigation/stack": "^6.3.25",
10
+ "@react-navigation/native": "^6.1.15",
11
+ "@react-navigation/native-stack": "^6.9.24",
12
+ "@react-navigation/stack": "^6.3.27",
13
13
  "@shopify/flash-list": "1.6.3",
14
14
  "expo": "^50.0.11",
15
15
  "expo-camera": "~14.0.6",
@@ -31,6 +31,6 @@
31
31
  "react-native-gesture-handler": "~2.14.0",
32
32
  "react-native-reanimated": "~3.6.2",
33
33
  "react-native-view-shot": "3.8.0",
34
- "expo-intent-launcher" : "~10.11.0"
34
+ "expo-intent-launcher": "~10.11.0"
35
35
  };
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "8.41.0",
3
+ "version": "8.42.0",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "scripts": {
6
6
  "clear-npx-cache": "npx clear-npx-cache",
@@ -93,8 +93,7 @@
93
93
  "sharp-cli": "^2.1.0",
94
94
  "stream-browserify": "^3.0.0",
95
95
  "tippy.js": "^6.3.7",
96
- "xlsx": "^0.18.5",
97
- "expo-intent-launcher": "~10.11.0"
96
+ "xlsx": "^0.18.5"
98
97
  },
99
98
  "devDependencies": {
100
99
  "@babel/plugin-proposal-export-namespace-from": "^7.18.9",
@@ -100,6 +100,7 @@ const Provider = ({children,getTableData,handleHelpScreen,navigation,swrConfig,a
100
100
  },
101
101
  }
102
102
  Auth.setRef(auth);
103
+ console.log("has set ref auth ",auth);
103
104
  extendFormFields(customFormFields);
104
105
  structsData = isObj(structsData)? structsData : null;
105
106
  appConfig.tablesData = tablesData;
package/src/pdf/index.js CHANGED
@@ -3,11 +3,12 @@ import Preloader from "$preloader";
3
3
  import pdfMake from "$cpdf/pdfmake";
4
4
  import notify from "$cnotify";
5
5
  import DialogProvider from "$ecomponents/Form/FormData/DialogProvider";
6
- import {isNonNullString,defaultObj,defaultStr,extendObj} from "$cutils";
6
+ import {isNonNullString,defaultObj,defaultStr,extendObj,defaultNumber} from "$cutils";
7
7
  import session from "$session";
8
8
  import printPdfMake from "./print";
9
9
  import appConfig from "$capp/config";
10
10
  import Auth from "$cauth";
11
+ import DateLib from "$clib/date";
11
12
 
12
13
 
13
14
  const {createPdf} = pdfMake;
@@ -57,7 +58,7 @@ export const getFields = (config)=>{
57
58
  @paramm {multiple},
58
59
  @param {object} formDataProps, les prpops à passer au DialogProvider
59
60
  */
60
- export const getPrintSettings = ({multiple,duplicateDocOnPage,pageBreakBeforeEachDoc,sessionName,formDataProps,...rest})=>{
61
+ export const getPrintSettings = ({multiple,duplicateDocOnPage,isTableData,tableDataFields,pageBreakBeforeEachDoc,sessionName,formDataProps,...rest})=>{
61
62
  formDataProps = Object.assign({},formDataProps);
62
63
  const hasSession = isNonNullString(sessionName);
63
64
  if(hasSession){
@@ -67,11 +68,19 @@ export const getPrintSettings = ({multiple,duplicateDocOnPage,pageBreakBeforeEac
67
68
  }
68
69
  const sessionData = hasSession ? defaultObj(session.get(sessionName)) : {};
69
70
  const config = {...sessionData,...defaultObj(formDataProps.data)};
71
+ const tbFields = {}, tbPrimaryKeyFields = [];
72
+ Object.map(tableDataFields,(field,index)=>{
73
+ if(!isObj(field)) return;
74
+ tbFields[index] = field;
75
+ if(!!field.primaryKey){
76
+ tbPrimaryKeyFields.push(index);
77
+ }
78
+ });
70
79
  const fields = extendObj(true,{},formDataProps.fields,{
71
80
  duplicateDocOnPage : duplicateDocOnPage !== false ? {
72
81
  text :'Dupliquer le(s) document(s)',
73
82
  type : 'switch',
74
- defaultValue : 0,
83
+ defaultValue : 1,
75
84
  onValidate : ({value,context}) =>{
76
85
  if(context){
77
86
  const pageBreakBeforeEachDoc = context.getField("pageBreakBeforeEachDoc");
@@ -124,6 +133,49 @@ export const getPrintSettings = ({multiple,duplicateDocOnPage,pageBreakBeforeEac
124
133
  return v;
125
134
  }
126
135
  } : undefined,
136
+ ...(isTableData && tbPrimaryKeyFields.length ?{
137
+ printQRCode : {
138
+ type : "switch",
139
+ label : "Imprimer un QR Code",
140
+ tooltip : "Cochez la case pour inclure un QR Code dans la données imprimée",
141
+ defaultValue : 0,
142
+ },
143
+ qrCodeFields : {
144
+ type : "select",
145
+ label : "Champs à inclure dans le QR Code",
146
+ multiple : true,
147
+ items : tbFields,
148
+ filter : ({item,index})=>isObj(item),
149
+ itemValue : ({item,index})=>index,
150
+ defaultValue : tbPrimaryKeyFields,
151
+ onValidatorValid : ({value})=>{
152
+ if(!Array.isArray(value) || !value.length) return true;
153
+ for(let i in tbPrimaryKeyFields){
154
+ const p = tbPrimaryKeyFields[i];
155
+ if(!value.includes(p)){
156
+ return `Le champ [${p}] en temps que clé primaire doit figurer parmis les champs à imprimer dans le QR Code.`;
157
+ }
158
+ }
159
+ return true;
160
+ },
161
+ renderItem : ({item,index})=>{
162
+ return `[${index}] ${defaultStr(item.label,item.text)}`;
163
+ }
164
+ },
165
+ qrCodeAlignmentPosition : {
166
+ type : "select",
167
+ defaultValue : "center",
168
+ label : "Position du QR Code",
169
+ multiple : false,
170
+ items : [{code:"left",label:"A gauche"},{code:"center",label:"Au centre"},{code:"right",label:"A droite"}]
171
+ },
172
+ qrCodeFitSize : {
173
+ type :"number",
174
+ defaultValue : 150,
175
+ label : "Taille du QR Code",
176
+ validType : "numberGreaterThanOrEquals[100]"
177
+ },
178
+ }:{})
127
179
  },getFields(formDataProps.data))
128
180
  return new Promise((resolve,reject)=>{
129
181
  return DialogProvider.open({
@@ -157,6 +209,7 @@ export const getPrintSettings = ({multiple,duplicateDocOnPage,pageBreakBeforeEac
157
209
  @param {object<{
158
210
  table|tableName {string}, le nom de la table data à utilser pour l'impression
159
211
  print {funtion}, la fonction à utiliser pour faire l'impression, si cette fonction n'est pas définie, alors la table data lié à la table doit l'implémenter dans l'option print
212
+ perm {function|string}, la fonction permettant de vérifier l'accès à la fonction d'impression par l'utilisateur
160
213
  }>}
161
214
  @return Promise
162
215
  */
@@ -172,17 +225,49 @@ export function printTableData(data,options){
172
225
  if(!tablePrint){
173
226
  return Promise.reject({message : `La fonction d'impression n'est pas supportée par la table [${tableText}]`})
174
227
  }
175
- if(!Auth.isTableDataAllowed({table,action:'print'})){
228
+ if(typeof options.perm =="function"){
229
+ if(!options.perm({table,tableObj})) {
230
+ return Promise.reject({message:'Vous n\'etes pas autorisé à imprimer ce type de document'});
231
+ }
232
+ } else if(isNonNullString(options.perm)){
233
+ if(!Auth.isAllowedFromString(options.perm)){
234
+ return Promise.reject({message:'Vous n\'etes pas autorisé à imprimer ce type de document'});
235
+ }
236
+ } else if(!Auth.isTableDataAllowed({table,action:'print'})){
176
237
  return Promise.reject({message:'Vous n\'etes pas autorisé à imprimer ce type de document'});
177
238
  }
178
239
  const printOptions = typeof tableObj.printOptions =="function"? tableObj.printOptions({...options,table,data}) : tableObj.printOptions;
179
240
  return print(data,{
180
241
  getSettings : (options)=>{
181
- return getPrintSettings(extendObj(true,{},{sessionName:`print-${table}`},options,printOptions)).then(({data})=>{
242
+ return getPrintSettings(extendObj(true,{},{sessionName:`print-${table}`,isTableData:true,tableDataFields:defaultObj(options.tableDataFields,tableObj.printableFields,tableObj.fields)},options,printOptions)).then(({data})=>{
182
243
  return data;
183
244
  });
184
245
  },
185
- print : tablePrint,
246
+ print : (data,...rest)=>{
247
+ return Promise.resolve(tablePrint(data,...rest)).then((result)=>{
248
+ if(!!data?.printQRCode && Array.isArray(data?.qrCodeFields) && data.qrCodeFields.length && isObj(result) && Array.isArray(result.content) && isObj(data?.data)){
249
+ const qrCodeFields = data.qrCodeFields;
250
+ const printingData = data.data;
251
+ const qrCodeAlignmentPosition = defaultStr(data.qrCodeAlignmentPosition,"center");
252
+ const qrData = {};
253
+ let hasQRData = false;
254
+ qrCodeFields.map((f)=>{
255
+ if(f in printingData){
256
+ qrData[f] = ["number","boolean"].includes(typeof printingData[f])? printingData[f] : JSON.stringify(printingData[f]);
257
+ hasQRData = true;
258
+ }
259
+ });
260
+ if(hasQRData){
261
+ const uEmail = Auth.getUserEmail();
262
+ const pseudo = Auth.getUserPseudo();
263
+ const fullName = Auth.getUserFullName() || pseudo || Auth.getLoggedUserCode();
264
+ const printBy = isNonNullString(fullName)? (`${fullName}${uEmail?`[${uEmail}]`:""}`) : "";
265
+ result.content.push({ qr: JSON.stringify({data:qrData,printBy,printDate:new Date().toFormat(DateLib.defaultDateTimeFormat),foreignKeyTable:table,table}),margin:[0,8,0,5], fit: defaultNumber(data.qrCodeFitSize,150), alignment: qrCodeAlignmentPosition})
266
+ }
267
+ }
268
+ return result;
269
+ });
270
+ },
186
271
  ...Object.assign({},options),
187
272
  });
188
273
  }
@@ -1,6 +1,6 @@
1
1
  module.exports = {
2
2
  "@fto-consult/expo-ui": {
3
- "version": "8.39.0",
3
+ "version": "8.41.0",
4
4
  "url": "https://github.com/borispipo/expo-ui#readme",
5
5
  "license": "ISC"
6
6
  },
@@ -50,17 +50,17 @@ module.exports = {
50
50
  "license": "MIT"
51
51
  },
52
52
  "@react-navigation/native": {
53
- "version": "6.1.14",
53
+ "version": "6.1.15",
54
54
  "url": "https://reactnavigation.org",
55
55
  "license": "MIT"
56
56
  },
57
57
  "@react-navigation/native-stack": {
58
- "version": "6.9.22",
58
+ "version": "6.9.24",
59
59
  "url": "https://github.com/software-mansion/react-native-screens#readme",
60
60
  "license": "MIT"
61
61
  },
62
62
  "@react-navigation/stack": {
63
- "version": "6.3.25",
63
+ "version": "6.3.27",
64
64
  "url": "https://reactnavigation.org/docs/stack-navigator/",
65
65
  "license": "MIT"
66
66
  },
@@ -104,6 +104,11 @@ module.exports = {
104
104
  "url": "https://docs.expo.dev/versions/latest/sdk/imagepicker/",
105
105
  "license": "MIT"
106
106
  },
107
+ "expo-intent-launcher": {
108
+ "version": "10.11.0",
109
+ "url": "https://docs.expo.dev/versions/latest/sdk/intent-launcher/",
110
+ "license": "MIT"
111
+ },
107
112
  "expo-linking": {
108
113
  "version": "6.2.2",
109
114
  "url": "https://docs.expo.dev/versions/latest/sdk/linking",