@topconsultnpm/sdkui-react 6.21.0-t3 → 6.21.0-t5

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 (51) hide show
  1. package/lib/components/NewComponents/ContextMenu/TMContextMenu.js +23 -18
  2. package/lib/components/base/TMPopUp.js +3 -3
  3. package/lib/components/base/TMTreeView.d.ts +16 -13
  4. package/lib/components/base/TMTreeView.js +230 -64
  5. package/lib/components/choosers/TMDistinctValues.js +1 -1
  6. package/lib/components/editors/TMTextBox.d.ts +1 -0
  7. package/lib/components/editors/TMTextBox.js +2 -1
  8. package/lib/components/features/documents/TMDcmtForm.d.ts +2 -0
  9. package/lib/components/features/documents/TMDcmtForm.js +2 -1
  10. package/lib/components/features/documents/TMDcmtIcon.d.ts +3 -1
  11. package/lib/components/features/documents/TMDcmtIcon.js +5 -32
  12. package/lib/components/features/documents/TMFileUploader.js +1 -1
  13. package/lib/components/features/documents/TMMasterDetailDcmts.d.ts +2 -0
  14. package/lib/components/features/documents/TMMasterDetailDcmts.js +169 -14
  15. package/lib/components/features/documents/TMMergeToPdfForm.d.ts +2 -1
  16. package/lib/components/features/documents/TMMergeToPdfForm.js +95 -49
  17. package/lib/components/features/documents/TMRelationViewer.d.ts +15 -10
  18. package/lib/components/features/documents/TMRelationViewer.js +533 -179
  19. package/lib/components/features/documents/copyAndMergeDcmtsShared.d.ts +4 -3
  20. package/lib/components/features/documents/copyAndMergeDcmtsShared.js +46 -23
  21. package/lib/components/features/documents/mergePdfUtils.d.ts +52 -0
  22. package/lib/components/features/documents/mergePdfUtils.js +278 -0
  23. package/lib/components/features/search/TMSearch.d.ts +2 -0
  24. package/lib/components/features/search/TMSearch.js +2 -2
  25. package/lib/components/features/search/TMSearchResult.d.ts +2 -0
  26. package/lib/components/features/search/TMSearchResult.js +58 -9
  27. package/lib/components/features/workflow/diagram/xmlParser.js +2 -1
  28. package/lib/components/viewers/TMTidViewer.js +14 -2
  29. package/lib/helper/Enum_Localizator.js +1 -0
  30. package/lib/helper/SDKUI_Globals.d.ts +1 -0
  31. package/lib/helper/SDKUI_Globals.js +1 -0
  32. package/lib/helper/SDKUI_Localizator.d.ts +34 -0
  33. package/lib/helper/SDKUI_Localizator.js +352 -12
  34. package/lib/helper/TMIcons.d.ts +1 -0
  35. package/lib/helper/TMIcons.js +3 -0
  36. package/lib/helper/TMUtils.d.ts +33 -1
  37. package/lib/helper/TMUtils.js +104 -1
  38. package/lib/helper/certificateImportHelper.d.ts +43 -0
  39. package/lib/helper/certificateImportHelper.js +403 -0
  40. package/lib/helper/helpers.d.ts +3 -0
  41. package/lib/helper/helpers.js +29 -1
  42. package/lib/helper/index.d.ts +1 -0
  43. package/lib/helper/index.js +1 -0
  44. package/lib/hooks/useDcmtOperations.d.ts +2 -1
  45. package/lib/hooks/useDcmtOperations.js +10 -2
  46. package/lib/hooks/useDocumentOperations.d.ts +2 -0
  47. package/lib/hooks/useDocumentOperations.js +28 -6
  48. package/lib/services/platform_services.d.ts +1 -1
  49. package/lib/ts/types.d.ts +2 -1
  50. package/lib/ts/types.js +1 -0
  51. package/package.json +3 -4
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { MetadataDescriptor } from '@topconsultnpm/sdk-ts';
2
3
  import { DcmtInfo } from '../../../ts';
3
4
  import { DocumentDownloadSettings, FileNamingMode } from '../../../helper';
4
5
  import { IRelatedDcmt } from './TMMasterDetailDcmts';
@@ -32,9 +33,9 @@ export declare const fileExists: (dirHandle: FileSystemDirectoryHandle, fileName
32
33
  export declare const generateUniqueFileName: (dirHandle: FileSystemDirectoryHandle, originalName: string) => Promise<string>;
33
34
  /** Recupera il nome leggibile del tipo documento (cache) */
34
35
  export declare const getTypeName: (tid: number | undefined) => Promise<string>;
35
- /** Formatta un valore convertendo le date in formato dd-MM-yyyy [HH-mm-ss] */
36
- export declare const formatMetadataValue: (value: string) => string;
37
- /** Recupera i metadati filtrati (primi 5 con mid > 100 e valore presente), concatenati con separatorChar */
36
+ /** Formatta un valore convertendo le date secondo il formato specificato in MetadataDescriptor.format */
37
+ export declare const formatMetadataValue: (value: string, md?: MetadataDescriptor) => string;
38
+ /** Recupera i metadati filtrati usando buildDcmtDisplayName, concatenati con separatorChar */
38
39
  export declare const getFilteredMetadata: (tid: number, did: number, separatorChar: string) => Promise<string | null>;
39
40
  /** Opzioni di naming necessarie per generare il nome del file di destinazione */
40
41
  export interface IFileNamingOptions {
@@ -1,5 +1,5 @@
1
- import { DcmtTypeListCacheService, LayoutModes, SDK_Globals } from '@topconsultnpm/sdk-ts';
2
- import { searchResultToMetadataValues, DocumentDownloadSettings, getFullFileExtension } from '../../../helper';
1
+ import { DcmtTypeListCacheService, LayoutModes, MetadataDataTypes, MetadataFormats, SDK_Globals } from '@topconsultnpm/sdk-ts';
2
+ import { searchResultToMetadataValues, DocumentDownloadSettings, getFullFileExtension, buildDcmtDisplayName } from '../../../helper';
3
3
  import { TMColors } from '../../../utils/theme';
4
4
  /** Numero minimo di file PDF necessari per poterli unire in un unico documento. */
5
5
  export const MIN_PDF_FOR_MERGE = 2;
@@ -82,7 +82,7 @@ export const sanitizeFileName = (fileName, fallbackName, maxLength = 255) => {
82
82
  const illegalCharsRegex = /[<>:"/\\|?*]/g;
83
83
  const controlCharsRegex = /[\x00-\x1F\x7F]/g;
84
84
  let sanitized = fileName
85
- .replace(illegalCharsRegex, '_')
85
+ .replace(illegalCharsRegex, '-')
86
86
  .replace(controlCharsRegex, '')
87
87
  .trim();
88
88
  sanitized = sanitized.replace(/[. ]+$/, '');
@@ -146,27 +146,40 @@ export const getTypeName = async (tid) => {
146
146
  const foundDtd = typeList.find(dtd => dtd.id?.toString() === tid?.toString());
147
147
  return foundDtd?.name ?? String(tid);
148
148
  };
149
- /** Formatta un valore convertendo le date in formato dd-MM-yyyy [HH-mm-ss] */
150
- export const formatMetadataValue = (value) => {
149
+ /** Formatta un valore convertendo le date secondo il formato specificato in MetadataDescriptor.format */
150
+ export const formatMetadataValue = (value, md) => {
151
+ // Formatta come data solo se il MetadataDescriptor indica tipo DateTime
152
+ if (md?.dataType !== MetadataDataTypes.DateTime) {
153
+ return value;
154
+ }
151
155
  const date = new Date(value);
152
- if (!isNaN(date.getTime())) {
153
- const day = date.getDate().toString().padStart(2, '0');
154
- const month = (date.getMonth() + 1).toString().padStart(2, '0');
155
- const year = date.getFullYear();
156
- const hours = date.getHours();
157
- const minutes = date.getMinutes();
158
- const seconds = date.getSeconds();
159
- if (hours !== 0 || minutes !== 0 || seconds !== 0) {
160
- const hh = hours.toString().padStart(2, '0');
161
- const mm = minutes.toString().padStart(2, '0');
162
- const ss = seconds.toString().padStart(2, '0');
163
- return `${day}-${month}-${year} ${hh}-${mm}-${ss}`;
164
- }
165
- return `${day}-${month}-${year}`;
156
+ if (isNaN(date.getTime())) {
157
+ return value;
158
+ }
159
+ const format = md.format?.format;
160
+ const formatCulture = md.format?.formatCulture ?? window.navigator.language;
161
+ switch (format) {
162
+ case MetadataFormats.ShortDate:
163
+ return date.toLocaleString(formatCulture, formatCulture === "it-IT" ? { year: "numeric", month: "2-digit", day: "2-digit" } : { dateStyle: 'short' });
164
+ case MetadataFormats.ShortTime:
165
+ return date.toLocaleString(formatCulture, { timeStyle: 'short' });
166
+ case MetadataFormats.ShortDateLongTime:
167
+ return date.toLocaleString(formatCulture, formatCulture === "it-IT" ? { year: "numeric", month: "2-digit", day: "2-digit", hour: '2-digit', minute: '2-digit', second: '2-digit' } : { dateStyle: 'short', timeStyle: 'medium' }).replace(',', '');
168
+ case MetadataFormats.ShortDateShortTime:
169
+ return date.toLocaleString(formatCulture, formatCulture === "it-IT" ? { year: "numeric", month: "2-digit", day: "2-digit", hour: '2-digit', minute: '2-digit' } : { dateStyle: 'short', timeStyle: 'short' }).replace(',', '');
170
+ case MetadataFormats.LongDate:
171
+ return date.toLocaleString(formatCulture, { weekday: "long", year: "numeric", month: "long", day: "numeric" });
172
+ case MetadataFormats.LongTime:
173
+ return date.toLocaleString(formatCulture, { timeStyle: 'medium' });
174
+ case MetadataFormats.LongDateLongTime:
175
+ return date.toLocaleString(formatCulture, { weekday: "long", year: "numeric", month: "long", day: "numeric", hour: '2-digit', minute: '2-digit', second: '2-digit' });
176
+ case MetadataFormats.LongDateShortTime:
177
+ return date.toLocaleString(formatCulture, { weekday: "long", year: "numeric", month: "long", day: "numeric", hour: '2-digit', minute: '2-digit' });
178
+ default:
179
+ return date.toLocaleString(formatCulture, formatCulture === "it-IT" ? { year: "numeric", month: "2-digit", day: "2-digit" } : { dateStyle: 'short' });
166
180
  }
167
- return value;
168
181
  };
169
- /** Recupera i metadati filtrati (primi 5 con mid > 100 e valore presente), concatenati con separatorChar */
182
+ /** Recupera i metadati filtrati usando buildDcmtDisplayName, concatenati con separatorChar */
170
183
  export const getFilteredMetadata = async (tid, did, separatorChar) => {
171
184
  const metadata = await SDK_Globals.tmSession?.NewSearchEngine().GetMetadataAsync(tid, did, true);
172
185
  if (!metadata)
@@ -177,8 +190,18 @@ export const getFilteredMetadata = async (tid, did, separatorChar) => {
177
190
  const dtdWithMetadata = await DcmtTypeListCacheService.GetWithNotGrantedAsync(tid, did, metadata);
178
191
  const mdList = dtdWithMetadata?.metadata ?? [];
179
192
  const metadataList = searchResultToMetadataValues(tid, dtdResult, rows, mids, mdList, LayoutModes.Update);
180
- return metadataList
181
- .reduce((acc, md) => acc.length < 5 && md.mid && md.mid > 100 && md.value ? [...acc, formatMetadataValue(md.value)] : acc, [])
193
+ // Converte l'array di MetadataValueDescriptorEx in DcmtMetadataMap per buildDcmtDisplayName
194
+ const metadataMap = Object.fromEntries(metadataList.filter(mvd => mvd.md?.name).map(mvd => [mvd.md.name, { md: mvd.md, value: mvd.value }]));
195
+ // Usa buildDcmtDisplayName per ricavare i nomi dei metadati da visualizzare
196
+ const displayKeys = buildDcmtDisplayName(metadataMap);
197
+ if (displayKeys.length === 0)
198
+ return null;
199
+ return displayKeys
200
+ .map(key => {
201
+ const entry = metadataMap[key];
202
+ return entry?.value ? formatMetadataValue(String(entry.value), entry.md) : null;
203
+ })
204
+ .filter(Boolean)
182
205
  .join(separatorChar);
183
206
  };
184
207
  /** Genera il nome file di destinazione in base alle impostazioni di naming */
@@ -0,0 +1,52 @@
1
+ import { DcmtInfo } from '../../../ts';
2
+ import { IRelatedDcmt } from './TMMasterDetailDcmts';
3
+ /** Tipo per gli elementi con chiave e estensione */
4
+ export interface ISelectedItemInfo {
5
+ key: string;
6
+ ext: string | undefined;
7
+ }
8
+ /** Risultato delle statistiche di selezione per il merge PDF */
9
+ export interface IMergePdfSelectionStats {
10
+ /** Elementi con estensioni convertibili in PDF (non nativamente PDF) */
11
+ convertibleSelectedItems: Array<ISelectedItemInfo>;
12
+ /** True se ci sono elementi convertibili selezionati */
13
+ hasConvertibleSelected: boolean;
14
+ /** Elementi che NON sono PDF e NON sono convertibili */
15
+ nonPdfSelectedItems: Array<ISelectedItemInfo>;
16
+ /** True se ci sono elementi non-PDF selezionati */
17
+ hasNonPdfSelected: boolean;
18
+ /** Documenti di soli metadati (senza file allegato) */
19
+ metadataOnlySelectedItems: Array<ISelectedItemInfo>;
20
+ /** True se ci sono documenti di soli metadati selezionati */
21
+ hasMetadataOnlySelected: boolean;
22
+ /** Numero totale di file unibili (PDF nativi + convertibili) */
23
+ mergeableSelectedCount: number;
24
+ /** True se ci sono abbastanza file per il merge (>= MIN_PDF_FOR_MERGE) */
25
+ hasEnoughPdfForMerge: boolean;
26
+ }
27
+ /** Documento di soli metadati: FILEEXT null/undefined oppure FILECOUNT 0 (verrà convertito frontend) */
28
+ export declare const isMetadataOnlyDcmt: (fileExt: string | null | undefined, fileCount: string | number | null | undefined) => boolean;
29
+ /**
30
+ * Calcola tutte le statistiche di selezione necessarie per il merge PDF.
31
+ * Restituisce info su file convertibili, non-PDF e conteggio file unibili.
32
+ *
33
+ * @param selectedDcmtInfos - Lista dei DcmtInfo selezionati (usata se showTMRelationViewer è false)
34
+ * @param selectedItemsFull - Lista completa con FILEEXT e FILECOUNT per check documenti di soli metadati
35
+ * @param selectedItemsRelationViewer - Lista degli IRelatedDcmt selezionati nel RelationViewer
36
+ * @param showTMRelationViewer - Se true, usa selectedItemsRelationViewer, altrimenti selectedDcmtInfos
37
+ */
38
+ export declare const getMergePdfSelectionStats: (selectedDcmtInfos: Array<DcmtInfo>, selectedItemsFull: Array<any>, selectedItemsRelationViewer: Array<IRelatedDcmt>, showTMRelationViewer: boolean) => IMergePdfSelectionStats;
39
+ export interface IMetadataKeyValue {
40
+ label: string;
41
+ value: string;
42
+ }
43
+ export interface IMetadataPdfResult {
44
+ file: File;
45
+ blob: Blob;
46
+ bytes: Uint8Array;
47
+ }
48
+ /** Crea PDF con metadati documento (header + lista label=valore). Supporta wrapping e paginazione.
49
+ * @param dcmtInfo - Informazioni del documento
50
+ * @param showSystemMetadata - Se true, include i metadati di sistema (mid < 100). Default: false
51
+ */
52
+ export declare const createMetadataPdfFromDocument: (dcmtInfo: DcmtInfo, showSystemMetadata?: boolean) => Promise<IMetadataPdfResult | null>;
@@ -0,0 +1,278 @@
1
+ import { DcmtTypeListCacheService, LayoutModes, MetadataDataTypes, SDK_Globals } from '@topconsultnpm/sdk-ts';
2
+ import { Globalization, isConvertibleToPdfExt, searchResultToMetadataValues } from '../../../helper';
3
+ import { isPdfExt, MIN_PDF_FOR_MERGE } from './copyAndMergeDcmtsShared';
4
+ /** Documento di soli metadati: FILEEXT null/undefined oppure FILECOUNT 0 (verrà convertito frontend) */
5
+ export const isMetadataOnlyDcmt = (fileExt, fileCount) => {
6
+ if (!fileExt)
7
+ return true;
8
+ return Number(fileCount) === 0;
9
+ };
10
+ /**
11
+ * Calcola tutte le statistiche di selezione necessarie per il merge PDF.
12
+ * Restituisce info su file convertibili, non-PDF e conteggio file unibili.
13
+ *
14
+ * @param selectedDcmtInfos - Lista dei DcmtInfo selezionati (usata se showTMRelationViewer è false)
15
+ * @param selectedItemsFull - Lista completa con FILEEXT e FILECOUNT per check documenti di soli metadati
16
+ * @param selectedItemsRelationViewer - Lista degli IRelatedDcmt selezionati nel RelationViewer
17
+ * @param showTMRelationViewer - Se true, usa selectedItemsRelationViewer, altrimenti selectedDcmtInfos
18
+ */
19
+ export const getMergePdfSelectionStats = (selectedDcmtInfos, selectedItemsFull, selectedItemsRelationViewer, showTMRelationViewer) => {
20
+ /**
21
+ * Pre-calcola info documenti selezionati in base alla sorgente dati:
22
+ * - RelationViewer (showTMRelationViewer=true): usa IRelatedDcmt con itemsCount/fileExt
23
+ * - Griglia documenti (showTMRelationViewer=false): usa DcmtInfo + lookup FILECOUNT da selectedItemsFull
24
+ */
25
+ let docs;
26
+ if (showTMRelationViewer) {
27
+ // Sorgente: RelationViewer - itemsCount e fileExt disponibili direttamente su IRelatedDcmt
28
+ docs = selectedItemsRelationViewer
29
+ .filter(i => i.isDcmt)
30
+ .map(i => {
31
+ const ext = i.fileExt ?? undefined;
32
+ return {
33
+ key: `${i.tid}_${i.did}`,
34
+ ext,
35
+ isPdf: isPdfExt(ext),
36
+ isConvertible: isConvertibleToPdfExt(ext),
37
+ isMetadataOnly: isMetadataOnlyDcmt(ext, i.fileCount)
38
+ };
39
+ });
40
+ }
41
+ else {
42
+ // Sorgente: Griglia documenti - FILECOUNT richiede lookup da selectedItemsFull
43
+ const fileCountMap = new Map(selectedItemsFull.map(d => [`${d.TID}_${d.DID}`, d.FILECOUNT]));
44
+ docs = selectedDcmtInfos.map(d => {
45
+ const ext = d.FILEEXT ?? undefined;
46
+ const key = `${d.TID}_${d.DID}`;
47
+ return {
48
+ key,
49
+ ext,
50
+ isPdf: isPdfExt(ext),
51
+ isConvertible: isConvertibleToPdfExt(ext),
52
+ isMetadataOnly: isMetadataOnlyDcmt(ext, fileCountMap.get(key))
53
+ };
54
+ });
55
+ }
56
+ // Elementi convertibili: file con estensione convertibile (esclusi documenti di soli metadati)
57
+ const convertibleSelectedItems = docs
58
+ .filter(i => i.isConvertible && !i.isMetadataOnly)
59
+ .map(i => ({ key: i.key, ext: i.ext }));
60
+ // Elementi NON PDF e NON convertibili (esclusi documenti di soli metadati)
61
+ const nonPdfSelectedItems = docs
62
+ .filter(i => !i.isPdf && !i.isConvertible && !i.isMetadataOnly)
63
+ .map(i => ({ key: i.key, ext: i.ext }));
64
+ // Documenti di soli metadati (senza file allegato)
65
+ const metadataOnlySelectedItems = docs
66
+ .filter(i => i.isMetadataOnly)
67
+ .map(i => ({ key: i.key, ext: i.ext }));
68
+ // Conteggio file unibili: PDF nativi + convertibili + documenti di soli metadati
69
+ const mergeableSelectedCount = docs
70
+ .filter(i => i.isPdf || i.isConvertible || i.isMetadataOnly).length;
71
+ return {
72
+ convertibleSelectedItems,
73
+ hasConvertibleSelected: convertibleSelectedItems.length > 0,
74
+ nonPdfSelectedItems,
75
+ hasNonPdfSelected: nonPdfSelectedItems.length > 0,
76
+ metadataOnlySelectedItems,
77
+ hasMetadataOnlySelected: metadataOnlySelectedItems.length > 0,
78
+ mergeableSelectedCount,
79
+ // Merge possibile se: >= 2 file unibili OPPURE >= 1 file convertibile/metadata-only (verrà trasformato in PDF)
80
+ hasEnoughPdfForMerge: mergeableSelectedCount >= MIN_PDF_FOR_MERGE ||
81
+ (mergeableSelectedCount >= 1 && (convertibleSelectedItems.length > 0 || metadataOnlySelectedItems.length > 0)),
82
+ };
83
+ };
84
+ // LAZY LOADING pdf-lib
85
+ let pdfLibModule = null;
86
+ const loadPdfLib = async () => {
87
+ if (!pdfLibModule) {
88
+ pdfLibModule = await import('pdf-lib');
89
+ }
90
+ return pdfLibModule;
91
+ };
92
+ // HELPER FUNCTIONS
93
+ /** Ottiene label localizzata del metadato (customName > nameLoc > name) */
94
+ const getMetadataLabel = (md, customName) => {
95
+ if (customName)
96
+ return customName;
97
+ if (!md)
98
+ return '';
99
+ return md.nameLoc || md.name || '';
100
+ };
101
+ /** Formatta valore metadato per PDF (null/undefined -> stringa vuota, datetime -> dd/MM/yyyy HH:mm) */
102
+ const formatMetadataValueForPdf = (value, md) => {
103
+ if (value === undefined || value === null)
104
+ return '';
105
+ // Se il metadato è di tipo DateTime, formatta in modo leggibile usando Globalization
106
+ if (md?.dataType === MetadataDataTypes.DateTime) {
107
+ return Globalization.getDateTimeDisplayValueCompact(value, undefined, md.format?.format);
108
+ }
109
+ return value.toString().trim();
110
+ };
111
+ // ============================================================================
112
+ // CREAZIONE PDF DA METADATI DOCUMENTO
113
+ // ============================================================================
114
+ /** Crea PDF con metadati documento (header + lista label=valore). Supporta wrapping e paginazione.
115
+ * @param dcmtInfo - Informazioni del documento
116
+ * @param showSystemMetadata - Se true, include i metadati di sistema (mid < 100). Default: false
117
+ */
118
+ export const createMetadataPdfFromDocument = async (dcmtInfo, showSystemMetadata = false) => {
119
+ // Configurazione ottimale per PDF A4
120
+ const pageWidth = 595; // A4 width in points
121
+ const pageHeight = 842; // A4 height in points
122
+ const margin = 50; // Margine confortevole
123
+ const titleFontSize = 14; // Titolo leggibile ma non troppo grande
124
+ const contentFontSize = 10; // Font contenuto ottimale per leggibilità
125
+ try {
126
+ // Recupera i metadati del documento
127
+ const metadata = await SDK_Globals.tmSession?.NewSearchEngine().GetMetadataAsync(dcmtInfo.TID, dcmtInfo.DID, true);
128
+ if (!metadata) {
129
+ console.warn('createMetadataPdfFromDocument: impossibile recuperare i metadati');
130
+ return null;
131
+ }
132
+ const dtdResult = metadata.dtdResult;
133
+ const rows = dtdResult?.rows?.[0] ?? [];
134
+ const mids = metadata.selectMIDs;
135
+ // Recupera il tipo documento con metadati
136
+ const dtdWithMetadata = await DcmtTypeListCacheService.GetWithNotGrantedAsync(dcmtInfo.TID, dcmtInfo.DID, metadata);
137
+ if (!dtdWithMetadata) {
138
+ console.warn('createMetadataPdfFromDocument: impossibile recuperare il tipo documento');
139
+ return null;
140
+ }
141
+ const mdList = dtdWithMetadata.metadata ?? [];
142
+ // Converte i metadati in formato leggibile
143
+ const metadataList = searchResultToMetadataValues(dcmtInfo.TID, dtdResult, rows, mids, mdList, LayoutModes.Update);
144
+ // Ottiene il nome del tipo documento (localizzato se abilitato)
145
+ const dcmtTypeName = dtdWithMetadata.nameLoc || dtdWithMetadata.name || 'Documento';
146
+ // Prepara la lista di metadati chiave-valore
147
+ const metadataKeyValues = metadataList
148
+ .filter(mvd => mvd.md && mvd.mid && mvd.mid > 0) // Filtra solo metadati validi
149
+ .filter(mvd => showSystemMetadata || (mvd.mid && mvd.mid >= 100)) // Filtra metadati di sistema se showSystemMetadata è false
150
+ .map(mvd => ({
151
+ label: getMetadataLabel(mvd.md, mvd.customName),
152
+ value: formatMetadataValueForPdf(mvd.value, mvd.md)
153
+ }))
154
+ .filter(kv => kv.label.length > 0); // Rimuovi metadati senza label
155
+ // Carica pdf-lib on-demand
156
+ const { PDFDocument, StandardFonts, rgb } = await loadPdfLib();
157
+ // Crea il documento PDF
158
+ const pdfDoc = await PDFDocument.create();
159
+ const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
160
+ const helveticaBoldFont = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
161
+ // Calcola dimensioni
162
+ const contentWidth = pageWidth - (margin * 2);
163
+ const lineHeight = contentFontSize + 5;
164
+ const titleLineHeight = titleFontSize + 6;
165
+ // Funzione per aggiungere una nuova pagina
166
+ const addPage = () => {
167
+ const page = pdfDoc.addPage([pageWidth, pageHeight]);
168
+ return { page, yPosition: pageHeight - margin };
169
+ };
170
+ // Funzione per calcolare la larghezza del testo
171
+ const getTextWidth = (text, font, size) => {
172
+ try {
173
+ return font.widthOfTextAtSize(text, size);
174
+ }
175
+ catch {
176
+ // Fallback per caratteri non supportati
177
+ return text.length * size * 0.5;
178
+ }
179
+ };
180
+ // Funzione per spezzare il testo in righe che entrano nella larghezza disponibile
181
+ const wrapText = (text, font, fontSize, maxWidth) => {
182
+ const lines = [];
183
+ const words = text.split(' ');
184
+ let currentLine = '';
185
+ for (const word of words) {
186
+ const testLine = currentLine ? `${currentLine} ${word}` : word;
187
+ const testWidth = getTextWidth(testLine, font, fontSize);
188
+ if (testWidth > maxWidth && currentLine) {
189
+ lines.push(currentLine);
190
+ currentLine = word;
191
+ }
192
+ else {
193
+ currentLine = testLine;
194
+ }
195
+ }
196
+ if (currentLine) {
197
+ lines.push(currentLine);
198
+ }
199
+ // Se una singola parola è troppo lunga, spezzala in più righe (carattere per carattere)
200
+ const result = [];
201
+ for (const line of lines) {
202
+ if (getTextWidth(line, font, fontSize) <= maxWidth) {
203
+ result.push(line);
204
+ }
205
+ else {
206
+ // Spezza la parola/linea troppo lunga carattere per carattere
207
+ let chunk = '';
208
+ for (const char of line) {
209
+ const testChunk = chunk + char;
210
+ if (getTextWidth(testChunk, font, fontSize) > maxWidth && chunk) {
211
+ result.push(chunk);
212
+ chunk = char;
213
+ }
214
+ else {
215
+ chunk = testChunk;
216
+ }
217
+ }
218
+ if (chunk) {
219
+ result.push(chunk);
220
+ }
221
+ }
222
+ }
223
+ return result;
224
+ };
225
+ // Sanitizza testo per Helvetica (solo ASCII)
226
+ const sanitize = (text) => text.replace(/[^\x20-\x7E]/g, '_');
227
+ let { page, yPosition } = addPage();
228
+ // Header (titolo centrato)
229
+ const titleText = sanitize(`${dcmtTypeName}`);
230
+ const titleWidth = getTextWidth(titleText, helveticaBoldFont, titleFontSize);
231
+ const titleX = Math.max(margin, margin + (contentWidth - titleWidth) / 2);
232
+ page.drawText(titleText, { x: titleX, y: yPosition, size: titleFontSize, font: helveticaBoldFont, color: rgb(0, 0, 0) });
233
+ yPosition -= titleLineHeight + 8;
234
+ // Metadati (label in grassetto, valore normale)
235
+ for (const kv of metadataKeyValues) {
236
+ const labelText = sanitize(kv.label) + ': ';
237
+ const labelWidth = getTextWidth(labelText, helveticaBoldFont, contentFontSize);
238
+ const valueMaxWidth = contentWidth - labelWidth;
239
+ const continuationIndent = labelWidth; // Indentazione per righe successive
240
+ // Wrappa il valore
241
+ const valueText = sanitize(kv.value);
242
+ const valueLines = wrapText(valueText, helveticaFont, contentFontSize, valueMaxWidth);
243
+ // Prima riga: label (bold) + primo pezzo di valore
244
+ if (yPosition < margin + lineHeight) {
245
+ ({ page, yPosition } = addPage());
246
+ }
247
+ page.drawText(labelText, { x: margin, y: yPosition, size: contentFontSize, font: helveticaBoldFont, color: rgb(0, 0, 0) });
248
+ if (valueLines.length > 0) {
249
+ page.drawText(valueLines[0], { x: margin + labelWidth, y: yPosition, size: contentFontSize, font: helveticaFont, color: rgb(0, 0, 0) });
250
+ }
251
+ yPosition -= lineHeight;
252
+ // Righe successive del valore (indentate)
253
+ for (let i = 1; i < valueLines.length; i++) {
254
+ if (yPosition < margin + lineHeight) {
255
+ ({ page, yPosition } = addPage());
256
+ }
257
+ page.drawText(valueLines[i], { x: margin + continuationIndent, y: yPosition, size: contentFontSize, font: helveticaFont, color: rgb(0, 0, 0) });
258
+ yPosition -= lineHeight;
259
+ }
260
+ }
261
+ // Salva il PDF
262
+ const pdfBytes = await pdfDoc.save();
263
+ // Converte in Blob e File
264
+ const pdfBuffer = pdfBytes.buffer.slice(pdfBytes.byteOffset, pdfBytes.byteOffset + pdfBytes.byteLength);
265
+ const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
266
+ const finalFileName = `${dcmtTypeName}_${dcmtInfo.DID}.pdf`;
267
+ const file = new File([blob], finalFileName, { type: 'application/pdf' });
268
+ return {
269
+ file,
270
+ blob,
271
+ bytes: pdfBytes
272
+ };
273
+ }
274
+ catch (error) {
275
+ console.error('createMetadataPdfFromDocument: errore durante la creazione del PDF', error);
276
+ return null;
277
+ }
278
+ };
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { SavedQueryDescriptor, DcmtTypeDescriptor, TaskDescriptor, ObjectRef, HomeBlogPost } from '@topconsultnpm/sdk-ts';
3
+ import { IntesiCertificateData } from '../../../helper';
3
4
  import { DcmtInfo, TaskContext } from '../../../ts';
4
5
  import { TMSearchResultFloatingActionConfig } from './TMSearchResultFloatingActionButton';
5
6
  interface ITMSearchProps {
@@ -42,6 +43,7 @@ interface ITMSearchProps {
42
43
  onReferenceClick?: (ref: ObjectRef) => void;
43
44
  inputDID?: number;
44
45
  formAutoOpen?: boolean;
46
+ fetchRemoteCertificates?: (email: string) => Promise<IntesiCertificateData[]>;
45
47
  }
46
48
  declare const TMSearch: React.FunctionComponent<ITMSearchProps>;
47
49
  export default TMSearch;
@@ -20,7 +20,7 @@ var TMSearchViews;
20
20
  TMSearchViews[TMSearchViews["Search"] = 0] = "Search";
21
21
  TMSearchViews[TMSearchViews["Result"] = 1] = "Result";
22
22
  })(TMSearchViews || (TMSearchViews = {}));
23
- const TMSearch = ({ allTasks = [], getAllTasks, deleteTaskByIdsCallback, addTaskCallback, editTaskCallback, handleNavigateToWGs, handleNavigateToDossiers, openInOffice, isVisible, inputTID, inputSqdID, inputMids, isExpertMode = SDKUI_Globals.userSettings.advancedSettings.expertMode === 1, floatingActionConfig, onFileOpened, onRefreshAfterAddDcmtToFavs, onTaskCreateRequest, openWGsCopyMoveForm, editPdfForm = false, openS4TViewer, onOpenS4TViewerRequest, onOpenPdfEditorRequest, openFileUploaderPdfEditor, showTodoDcmtForm, showToppyDraggableHelpCenter = true, toppyHelpCenterUsePortal = false, passToArchiveCallback, onCurrentTIDChangedCallback, onlyShowSearchQueryPanel, onReferenceClick, refreshFavoriteSavedQueries, inputDID, formAutoOpen }) => {
23
+ const TMSearch = ({ allTasks = [], getAllTasks, deleteTaskByIdsCallback, addTaskCallback, editTaskCallback, handleNavigateToWGs, handleNavigateToDossiers, openInOffice, isVisible, inputTID, inputSqdID, inputMids, isExpertMode = SDKUI_Globals.userSettings.advancedSettings.expertMode === 1, floatingActionConfig, onFileOpened, onRefreshAfterAddDcmtToFavs, onTaskCreateRequest, openWGsCopyMoveForm, editPdfForm = false, openS4TViewer, onOpenS4TViewerRequest, onOpenPdfEditorRequest, openFileUploaderPdfEditor, showTodoDcmtForm, showToppyDraggableHelpCenter = true, toppyHelpCenterUsePortal = false, passToArchiveCallback, onCurrentTIDChangedCallback, onlyShowSearchQueryPanel, onReferenceClick, refreshFavoriteSavedQueries, inputDID, formAutoOpen, fetchRemoteCertificates }) => {
24
24
  const [allSQDs, setAllSQDs] = useState([]);
25
25
  const [filteredByTIDSQDs, setFilteredByTIDSQDs] = useState([]);
26
26
  const [currentSQD, setCurrentSQD] = useState();
@@ -266,7 +266,7 @@ const TMSearch = ({ allTasks = [], getAllTasks, deleteTaskByIdsCallback, addTask
266
266
  toolbarOptions: { icon: _jsx(IconSavedQuery, { fontSize: 24 }), visible: true, orderNumber: 4, isActive: allInitialPanelVisibility['TMSavedQuerySelector'] }
267
267
  }
268
268
  ], [tmTreeSelectorElement, showSearchResults, tmRecentsManagerElement, tmSearchQueryPanelElement, tmSavedQuerySelectorElement, fromDTD, mruTIDs]);
269
- return (_jsxs(_Fragment, { children: [showSearchResults ? _jsx(StyledMultiViewPanel, { "$isVisible": currentSearchView === TMSearchViews.Search, children: _jsx(TMPanelManagerWithPersistenceProvider, { panels: initialPanels, initialVisibility: allInitialPanelVisibility, defaultDimensions: initialPanelDimensions, initialDimensions: initialPanelDimensions, initialMobilePanelId: 'TMRecentsManager', isPersistenceEnabled: !isMobile ? hasSavedLayout() : false, persistPanelStates: !isMobile ? (state) => persistPanelStates(state) : undefined, persistedPanelStates: getPersistedPanelStates(), children: _jsx(TMPanelManagerContainer, { panels: initialPanels, direction: "horizontal", showToolbar: true, minPanelSizePx: !isMobile ? 250 : 150 }) }) }) : tmSearchQueryPanelElement, showSearchResults && _jsx(TMSearchResult, { isVisible: isVisible && currentSearchView === TMSearchViews.Result, context: SearchResultContext.METADATA_SEARCH, searchResults: searchResult, floatingActionConfig: floatingActionConfig, onRefreshAfterAddDcmtToFavs: onRefreshAfterAddDcmtToFavs, openInOffice: openInOffice, onRefreshSearchAsyncDatagrid: onRefreshSearchAsyncDatagrid, onClose: () => { onlyShowSearchQueryPanel ? setShowSearchResults(false) : setCurrentSearchView(TMSearchViews.Search); }, onFileOpened: onFileOpened, onTaskCreateRequest: onTaskCreateRequest, openWGsCopyMoveForm: openWGsCopyMoveForm, editPdfForm: editPdfForm, onOpenPdfEditorRequest: onOpenPdfEditorRequest, openS4TViewer: openS4TViewer, onOpenS4TViewerRequest: onOpenS4TViewerRequest, openFileUploaderPdfEditor: openFileUploaderPdfEditor, passToArchiveCallback: passToArchiveCallback, onSelectedTIDChanged: onCurrentTIDChangedCallback, showTodoDcmtForm: showTodoDcmtForm, showToppyDraggableHelpCenter: showToppyDraggableHelpCenter, toppyHelpCenterUsePortal: toppyHelpCenterUsePortal, onReferenceClick: onReferenceClick, allTasks: allTasks, getAllTasks: getAllTasks, deleteTaskByIdsCallback: deleteTaskByIdsCallback, addTaskCallback: addTaskCallback, editTaskCallback: editTaskCallback, handleNavigateToWGs: handleNavigateToWGs, handleNavigateToDossiers: handleNavigateToDossiers, inputDID: inputDID, formAutoOpen: formAutoOpen })] }));
269
+ return (_jsxs(_Fragment, { children: [showSearchResults ? _jsx(StyledMultiViewPanel, { "$isVisible": currentSearchView === TMSearchViews.Search, children: _jsx(TMPanelManagerWithPersistenceProvider, { panels: initialPanels, initialVisibility: allInitialPanelVisibility, defaultDimensions: initialPanelDimensions, initialDimensions: initialPanelDimensions, initialMobilePanelId: 'TMRecentsManager', isPersistenceEnabled: !isMobile ? hasSavedLayout() : false, persistPanelStates: !isMobile ? (state) => persistPanelStates(state) : undefined, persistedPanelStates: getPersistedPanelStates(), children: _jsx(TMPanelManagerContainer, { panels: initialPanels, direction: "horizontal", showToolbar: true, minPanelSizePx: !isMobile ? 250 : 150 }) }) }) : tmSearchQueryPanelElement, showSearchResults && _jsx(TMSearchResult, { isVisible: isVisible && currentSearchView === TMSearchViews.Result, context: SearchResultContext.METADATA_SEARCH, searchResults: searchResult, floatingActionConfig: floatingActionConfig, onRefreshAfterAddDcmtToFavs: onRefreshAfterAddDcmtToFavs, openInOffice: openInOffice, onRefreshSearchAsyncDatagrid: onRefreshSearchAsyncDatagrid, onClose: () => { onlyShowSearchQueryPanel ? setShowSearchResults(false) : setCurrentSearchView(TMSearchViews.Search); }, onFileOpened: onFileOpened, onTaskCreateRequest: onTaskCreateRequest, openWGsCopyMoveForm: openWGsCopyMoveForm, editPdfForm: editPdfForm, onOpenPdfEditorRequest: onOpenPdfEditorRequest, openS4TViewer: openS4TViewer, onOpenS4TViewerRequest: onOpenS4TViewerRequest, openFileUploaderPdfEditor: openFileUploaderPdfEditor, passToArchiveCallback: passToArchiveCallback, onSelectedTIDChanged: onCurrentTIDChangedCallback, showTodoDcmtForm: showTodoDcmtForm, showToppyDraggableHelpCenter: showToppyDraggableHelpCenter, toppyHelpCenterUsePortal: toppyHelpCenterUsePortal, onReferenceClick: onReferenceClick, allTasks: allTasks, getAllTasks: getAllTasks, deleteTaskByIdsCallback: deleteTaskByIdsCallback, addTaskCallback: addTaskCallback, editTaskCallback: editTaskCallback, handleNavigateToWGs: handleNavigateToWGs, handleNavigateToDossiers: handleNavigateToDossiers, inputDID: inputDID, formAutoOpen: formAutoOpen, fetchRemoteCertificates: fetchRemoteCertificates })] }));
270
270
  };
271
271
  export default TMSearch;
272
272
  const TMTreeSelectorWrapper = ({ isMobile, onSelectedTIDChanged }) => {
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { DcmtTypeDescriptor, HomeBlogPost, ObjectRef, SearchResultDescriptor, TaskDescriptor, WorkingGroupDescriptor } from '@topconsultnpm/sdk-ts';
3
+ import { IntesiCertificateData } from '../../../helper';
3
4
  import { DcmtInfo, SearchResultContext, TaskContext } from '../../../ts';
4
5
  import { TMSearchResultFloatingActionConfig } from './TMSearchResultFloatingActionButton';
5
6
  export declare const getSearchResultCountersSingleCategory: (searchResults: SearchResultDescriptor[]) => string;
@@ -51,6 +52,7 @@ interface ITMSearchResultProps {
51
52
  openFileUploaderPdfEditor?: (fromDTD?: DcmtTypeDescriptor, file?: File | null, handleFile?: (file: File) => void) => void;
52
53
  openCommentFormCallback?: (documents: Array<DcmtInfo>) => void;
53
54
  openAddDocumentForm?: () => void;
55
+ fetchRemoteCertificates?: (email: string) => Promise<IntesiCertificateData[]>;
54
56
  allTasks?: Array<TaskDescriptor>;
55
57
  getAllTasks?: () => Promise<void>;
56
58
  deleteTaskByIdsCallback?: (deletedTaskIds: Array<number>) => Promise<void>;