@fto-consult/expo-ui 8.25.13 → 8.25.14

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/pdf/index.js +45 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "8.25.13",
3
+ "version": "8.25.14",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "scripts": {
6
6
  "clear-npx-cache": "npx clear-npx-cache",
@@ -68,7 +68,7 @@
68
68
  "dependencies": {
69
69
  "@emotion/react": "^11.11.1",
70
70
  "@faker-js/faker": "^8.0.2",
71
- "@fto-consult/common": "^4.25.23",
71
+ "@fto-consult/common": "^4.26.1",
72
72
  "@fto-consult/node-utils": "^1.4.7",
73
73
  "apexcharts": "^3.45.2",
74
74
  "crypto-browserify": "^3.12.0",
package/src/pdf/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import {createPDF as cCreatePdf,print as cPrint,fields as pdfFields} from "$cpdf";
2
2
  import Preloader from "$preloader";
3
- import {extendObj} from "$cutils";
4
3
  import pdfMake from "$cpdf/pdfmake";
5
4
  import notify from "$cnotify";
6
5
  import DialogProvider from "$ecomponents/Form/FormData/DialogProvider";
7
- import {isNonNullString,defaultObj,defaultStr} from "$cutils";
6
+ import {isNonNullString,defaultObj,defaultStr,extendObj} from "$cutils";
8
7
  import session from "$session";
9
8
  import printPdfMake from "./print";
9
+ import appConfig from "$capp/config";
10
+ import Auth from "$cauth";
11
+
10
12
 
11
13
  const {createPdf} = pdfMake;
12
14
  pdfMake.createPdf = (docDefinition,...rest)=>{
@@ -140,9 +142,47 @@ export const getPrintSettings = ({multiple,duplicateDocOnPage,pageBreakBeforeEac
140
142
  session.set(sessionName,sessionD);
141
143
  }
142
144
  DialogProvider.close();
143
- resolve({...opts,data,fields});
145
+ resolve({...opts,data:{...config,...data},fields});
146
+ },
147
+ onCancel : (e)=>{
148
+ reject(e);
149
+ Preloader.close();
144
150
  },
145
- onCancel : reject,
146
151
  })
147
152
  });
148
- }
153
+ }
154
+
155
+ /**** permet d'imprimer une table data
156
+ @param {Array<object>||object}, la/les donnée(s) à imprimer
157
+ @param {object<{
158
+ table|tableName {string}, le nom de la table data à utilser pour l'impression
159
+ 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
160
+ }>}
161
+ @return Promise
162
+ */
163
+ export function printTableData(data,options){
164
+ options = Object.assign({},options);
165
+ const table = defaultStr(options.table,options.tableName);
166
+ const tableObj = appConfig.getTable(table);
167
+ if(!table || !tableObj){
168
+ return Promise.reject({message:`Vous devez spécifier la table pour laquelle vous souhaitez effectuer l'impression des données`})
169
+ }
170
+ const tableText = defaultStr(tableObj.label,tableObj.text,table);
171
+ const tablePrint = typeof options.print =="function"? options.print : typeof tableObj.print =="function"? tableObj.print : undefined;
172
+ if(!tablePrint){
173
+ return Promise.reject({message : `La fonction d'impression n'est pas supportée par la table [${tableText}]`})
174
+ }
175
+ if(!Auth.isTableDataAllowed({table,action:'print'})){
176
+ return Promise.reject({message:'Vous n\'etes pas autorisé à imprimer ce type de document'});
177
+ }
178
+ const printOptions = typeof tableObj.printOptions =="function"? tableObj.printOptions({...options,table,data}) : tableObj.printOptions;
179
+ return print(data,{
180
+ getSettings : (options)=>{
181
+ return getPrintSettings(extendObj(true,{},{sessionName:`print-${table}`},options,printOptions)).then(({data})=>{
182
+ return data;
183
+ });
184
+ },
185
+ print : tablePrint,
186
+ ...Object.assign({},options),
187
+ });
188
+ }