@topconsultnpm/sdkui-react 6.21.0-t3 → 6.21.0-t4
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/lib/components/NewComponents/ContextMenu/TMContextMenu.js +23 -18
- package/lib/components/base/TMPopUp.js +3 -3
- package/lib/components/base/TMTreeView.d.ts +16 -13
- package/lib/components/base/TMTreeView.js +230 -64
- package/lib/components/choosers/TMDistinctValues.js +1 -1
- package/lib/components/editors/TMTextBox.d.ts +1 -0
- package/lib/components/editors/TMTextBox.js +2 -1
- package/lib/components/features/documents/TMDcmtForm.d.ts +2 -0
- package/lib/components/features/documents/TMDcmtForm.js +2 -1
- package/lib/components/features/documents/TMDcmtIcon.d.ts +3 -1
- package/lib/components/features/documents/TMDcmtIcon.js +5 -32
- package/lib/components/features/documents/TMFileUploader.js +1 -1
- package/lib/components/features/documents/TMMasterDetailDcmts.d.ts +2 -0
- package/lib/components/features/documents/TMMasterDetailDcmts.js +54 -14
- package/lib/components/features/documents/TMMergeToPdfForm.d.ts +2 -1
- package/lib/components/features/documents/TMMergeToPdfForm.js +91 -48
- package/lib/components/features/documents/TMRelationViewer.d.ts +12 -10
- package/lib/components/features/documents/TMRelationViewer.js +401 -96
- package/lib/components/features/documents/copyAndMergeDcmtsShared.d.ts +4 -3
- package/lib/components/features/documents/copyAndMergeDcmtsShared.js +47 -23
- package/lib/components/features/documents/mergePdfUtils.d.ts +52 -0
- package/lib/components/features/documents/mergePdfUtils.js +268 -0
- package/lib/components/features/search/TMSearch.d.ts +2 -0
- package/lib/components/features/search/TMSearch.js +2 -2
- package/lib/components/features/search/TMSearchResult.d.ts +2 -0
- package/lib/components/features/search/TMSearchResult.js +58 -9
- package/lib/components/viewers/TMTidViewer.js +14 -2
- package/lib/helper/Enum_Localizator.js +1 -0
- package/lib/helper/SDKUI_Globals.d.ts +1 -0
- package/lib/helper/SDKUI_Globals.js +1 -0
- package/lib/helper/SDKUI_Localizator.d.ts +34 -0
- package/lib/helper/SDKUI_Localizator.js +352 -12
- package/lib/helper/TMUtils.d.ts +33 -1
- package/lib/helper/TMUtils.js +104 -1
- package/lib/helper/certificateImportHelper.d.ts +43 -0
- package/lib/helper/certificateImportHelper.js +403 -0
- package/lib/helper/helpers.js +9 -0
- package/lib/helper/index.d.ts +1 -0
- package/lib/helper/index.js +1 -0
- package/lib/hooks/useDcmtOperations.d.ts +2 -1
- package/lib/hooks/useDcmtOperations.js +10 -2
- package/lib/hooks/useDocumentOperations.d.ts +2 -0
- package/lib/hooks/useDocumentOperations.js +28 -6
- package/lib/services/platform_services.d.ts +1 -1
- package/lib/ts/types.d.ts +2 -1
- package/lib/ts/types.js +1 -0
- package/package.json +3 -2
|
@@ -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
|
|
36
|
-
export declare const formatMetadataValue: (value: string) => string;
|
|
37
|
-
/** Recupera i metadati filtrati
|
|
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
|
|
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 (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
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
|
|
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
|
-
|
|
181
|
-
|
|
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 */
|
|
@@ -201,6 +224,7 @@ export const generateTargetFileName = async (file, dcmtInfo, options) => {
|
|
|
201
224
|
case 'onlyCustomMetadata': {
|
|
202
225
|
try {
|
|
203
226
|
const filteredMetadata = await getFilteredMetadata(dcmtInfo.TID, dcmtInfo.DID, separatorChar);
|
|
227
|
+
console.log("filteredMetadata for TID:", dcmtInfo.TID, "DID:", dcmtInfo.DID, "is", filteredMetadata);
|
|
204
228
|
if (filteredMetadata) {
|
|
205
229
|
if (fileNamingMode === 'documentTypeAndCustomMetadata') {
|
|
206
230
|
const typeName = await getTypeName(dcmtInfo.TID);
|
|
@@ -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,268 @@
|
|
|
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
|
+
// Mappa per lookup veloce di FILECOUNT da selectedItemsFull (usato solo per isMetadataOnly)
|
|
21
|
+
const fileCountMap = new Map(selectedItemsFull.map(d => [`${d.TID}_${d.DID}`, d.FILECOUNT]));
|
|
22
|
+
// Pre-calcolo delle informazioni sui documenti selezionati
|
|
23
|
+
const docs = showTMRelationViewer
|
|
24
|
+
? selectedItemsRelationViewer
|
|
25
|
+
.filter(i => i.isDcmt)
|
|
26
|
+
.map(i => {
|
|
27
|
+
const ext = i.fileExt ?? undefined;
|
|
28
|
+
return {
|
|
29
|
+
key: `${i.tid}_${i.did}`,
|
|
30
|
+
ext,
|
|
31
|
+
isPdf: isPdfExt(ext),
|
|
32
|
+
isConvertible: isConvertibleToPdfExt(ext),
|
|
33
|
+
isMetadataOnly: isMetadataOnlyDcmt(ext, null)
|
|
34
|
+
};
|
|
35
|
+
})
|
|
36
|
+
: selectedDcmtInfos.map(d => {
|
|
37
|
+
const ext = d.FILEEXT ?? undefined;
|
|
38
|
+
const key = `${d.TID}_${d.DID}`;
|
|
39
|
+
const fileCount = fileCountMap.get(key);
|
|
40
|
+
return {
|
|
41
|
+
key,
|
|
42
|
+
ext,
|
|
43
|
+
isPdf: isPdfExt(ext),
|
|
44
|
+
isConvertible: isConvertibleToPdfExt(ext),
|
|
45
|
+
isMetadataOnly: isMetadataOnlyDcmt(ext, fileCount)
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
// Elementi convertibili: file con estensione convertibile (esclusi documenti di soli metadati)
|
|
49
|
+
const convertibleSelectedItems = docs
|
|
50
|
+
.filter(i => i.isConvertible && !i.isMetadataOnly)
|
|
51
|
+
.map(i => ({ key: i.key, ext: i.ext }));
|
|
52
|
+
// Elementi NON PDF e NON convertibili (esclusi documenti di soli metadati)
|
|
53
|
+
const nonPdfSelectedItems = docs
|
|
54
|
+
.filter(i => !i.isPdf && !i.isConvertible && !i.isMetadataOnly)
|
|
55
|
+
.map(i => ({ key: i.key, ext: i.ext }));
|
|
56
|
+
// Documenti di soli metadati (senza file allegato)
|
|
57
|
+
const metadataOnlySelectedItems = docs
|
|
58
|
+
.filter(i => i.isMetadataOnly)
|
|
59
|
+
.map(i => ({ key: i.key, ext: i.ext }));
|
|
60
|
+
// Conteggio file unibili: PDF nativi + convertibili + documenti di soli metadati
|
|
61
|
+
const mergeableSelectedCount = docs
|
|
62
|
+
.filter(i => i.isPdf || i.isConvertible || i.isMetadataOnly).length;
|
|
63
|
+
return {
|
|
64
|
+
convertibleSelectedItems,
|
|
65
|
+
hasConvertibleSelected: convertibleSelectedItems.length > 0,
|
|
66
|
+
nonPdfSelectedItems,
|
|
67
|
+
hasNonPdfSelected: nonPdfSelectedItems.length > 0,
|
|
68
|
+
metadataOnlySelectedItems,
|
|
69
|
+
hasMetadataOnlySelected: metadataOnlySelectedItems.length > 0,
|
|
70
|
+
mergeableSelectedCount,
|
|
71
|
+
hasEnoughPdfForMerge: mergeableSelectedCount >= MIN_PDF_FOR_MERGE,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
// LAZY LOADING pdf-lib
|
|
75
|
+
let pdfLibModule = null;
|
|
76
|
+
const loadPdfLib = async () => {
|
|
77
|
+
if (!pdfLibModule) {
|
|
78
|
+
pdfLibModule = await import('pdf-lib');
|
|
79
|
+
}
|
|
80
|
+
return pdfLibModule;
|
|
81
|
+
};
|
|
82
|
+
// HELPER FUNCTIONS
|
|
83
|
+
/** Ottiene label localizzata del metadato (customName > nameLoc > name) */
|
|
84
|
+
const getMetadataLabel = (md, customName) => {
|
|
85
|
+
if (customName)
|
|
86
|
+
return customName;
|
|
87
|
+
if (!md)
|
|
88
|
+
return '';
|
|
89
|
+
return md.nameLoc || md.name || '';
|
|
90
|
+
};
|
|
91
|
+
/** Formatta valore metadato per PDF (null/undefined -> stringa vuota, datetime -> dd/MM/yyyy HH:mm) */
|
|
92
|
+
const formatMetadataValueForPdf = (value, md) => {
|
|
93
|
+
if (value === undefined || value === null)
|
|
94
|
+
return '';
|
|
95
|
+
// Se il metadato è di tipo DateTime, formatta in modo leggibile usando Globalization
|
|
96
|
+
if (md?.dataType === MetadataDataTypes.DateTime) {
|
|
97
|
+
return Globalization.getDateTimeDisplayValueCompact(value, undefined, md.format?.format);
|
|
98
|
+
}
|
|
99
|
+
return value.toString().trim();
|
|
100
|
+
};
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// CREAZIONE PDF DA METADATI DOCUMENTO
|
|
103
|
+
// ============================================================================
|
|
104
|
+
/** Crea PDF con metadati documento (header + lista label=valore). Supporta wrapping e paginazione.
|
|
105
|
+
* @param dcmtInfo - Informazioni del documento
|
|
106
|
+
* @param showSystemMetadata - Se true, include i metadati di sistema (mid < 100). Default: false
|
|
107
|
+
*/
|
|
108
|
+
export const createMetadataPdfFromDocument = async (dcmtInfo, showSystemMetadata = false) => {
|
|
109
|
+
// Configurazione ottimale per PDF A4
|
|
110
|
+
const pageWidth = 595; // A4 width in points
|
|
111
|
+
const pageHeight = 842; // A4 height in points
|
|
112
|
+
const margin = 50; // Margine confortevole
|
|
113
|
+
const titleFontSize = 14; // Titolo leggibile ma non troppo grande
|
|
114
|
+
const contentFontSize = 10; // Font contenuto ottimale per leggibilità
|
|
115
|
+
try {
|
|
116
|
+
// Recupera i metadati del documento
|
|
117
|
+
const metadata = await SDK_Globals.tmSession?.NewSearchEngine().GetMetadataAsync(dcmtInfo.TID, dcmtInfo.DID, true);
|
|
118
|
+
if (!metadata) {
|
|
119
|
+
console.warn('createMetadataPdfFromDocument: impossibile recuperare i metadati');
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const dtdResult = metadata.dtdResult;
|
|
123
|
+
const rows = dtdResult?.rows?.[0] ?? [];
|
|
124
|
+
const mids = metadata.selectMIDs;
|
|
125
|
+
// Recupera il tipo documento con metadati
|
|
126
|
+
const dtdWithMetadata = await DcmtTypeListCacheService.GetWithNotGrantedAsync(dcmtInfo.TID, dcmtInfo.DID, metadata);
|
|
127
|
+
if (!dtdWithMetadata) {
|
|
128
|
+
console.warn('createMetadataPdfFromDocument: impossibile recuperare il tipo documento');
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const mdList = dtdWithMetadata.metadata ?? [];
|
|
132
|
+
// Converte i metadati in formato leggibile
|
|
133
|
+
const metadataList = searchResultToMetadataValues(dcmtInfo.TID, dtdResult, rows, mids, mdList, LayoutModes.Update);
|
|
134
|
+
// Ottiene il nome del tipo documento (localizzato se abilitato)
|
|
135
|
+
const dcmtTypeName = dtdWithMetadata.nameLoc || dtdWithMetadata.name || 'Documento';
|
|
136
|
+
// Prepara la lista di metadati chiave-valore
|
|
137
|
+
const metadataKeyValues = metadataList
|
|
138
|
+
.filter(mvd => mvd.md && mvd.mid && mvd.mid > 0) // Filtra solo metadati validi
|
|
139
|
+
.filter(mvd => showSystemMetadata || (mvd.mid && mvd.mid >= 100)) // Filtra metadati di sistema se showSystemMetadata è false
|
|
140
|
+
.map(mvd => ({
|
|
141
|
+
label: getMetadataLabel(mvd.md, mvd.customName),
|
|
142
|
+
value: formatMetadataValueForPdf(mvd.value, mvd.md)
|
|
143
|
+
}))
|
|
144
|
+
.filter(kv => kv.label.length > 0); // Rimuovi metadati senza label
|
|
145
|
+
// Carica pdf-lib on-demand
|
|
146
|
+
const { PDFDocument, StandardFonts, rgb } = await loadPdfLib();
|
|
147
|
+
// Crea il documento PDF
|
|
148
|
+
const pdfDoc = await PDFDocument.create();
|
|
149
|
+
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
|
150
|
+
const helveticaBoldFont = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
|
|
151
|
+
// Calcola dimensioni
|
|
152
|
+
const contentWidth = pageWidth - (margin * 2);
|
|
153
|
+
const lineHeight = contentFontSize + 5;
|
|
154
|
+
const titleLineHeight = titleFontSize + 6;
|
|
155
|
+
// Funzione per aggiungere una nuova pagina
|
|
156
|
+
const addPage = () => {
|
|
157
|
+
const page = pdfDoc.addPage([pageWidth, pageHeight]);
|
|
158
|
+
return { page, yPosition: pageHeight - margin };
|
|
159
|
+
};
|
|
160
|
+
// Funzione per calcolare la larghezza del testo
|
|
161
|
+
const getTextWidth = (text, font, size) => {
|
|
162
|
+
try {
|
|
163
|
+
return font.widthOfTextAtSize(text, size);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Fallback per caratteri non supportati
|
|
167
|
+
return text.length * size * 0.5;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
// Funzione per spezzare il testo in righe che entrano nella larghezza disponibile
|
|
171
|
+
const wrapText = (text, font, fontSize, maxWidth) => {
|
|
172
|
+
const lines = [];
|
|
173
|
+
const words = text.split(' ');
|
|
174
|
+
let currentLine = '';
|
|
175
|
+
for (const word of words) {
|
|
176
|
+
const testLine = currentLine ? `${currentLine} ${word}` : word;
|
|
177
|
+
const testWidth = getTextWidth(testLine, font, fontSize);
|
|
178
|
+
if (testWidth > maxWidth && currentLine) {
|
|
179
|
+
lines.push(currentLine);
|
|
180
|
+
currentLine = word;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
currentLine = testLine;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (currentLine) {
|
|
187
|
+
lines.push(currentLine);
|
|
188
|
+
}
|
|
189
|
+
// Se una singola parola è troppo lunga, spezzala in più righe (carattere per carattere)
|
|
190
|
+
const result = [];
|
|
191
|
+
for (const line of lines) {
|
|
192
|
+
if (getTextWidth(line, font, fontSize) <= maxWidth) {
|
|
193
|
+
result.push(line);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
// Spezza la parola/linea troppo lunga carattere per carattere
|
|
197
|
+
let chunk = '';
|
|
198
|
+
for (const char of line) {
|
|
199
|
+
const testChunk = chunk + char;
|
|
200
|
+
if (getTextWidth(testChunk, font, fontSize) > maxWidth && chunk) {
|
|
201
|
+
result.push(chunk);
|
|
202
|
+
chunk = char;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
chunk = testChunk;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (chunk) {
|
|
209
|
+
result.push(chunk);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
// Sanitizza testo per Helvetica (solo ASCII)
|
|
216
|
+
const sanitize = (text) => text.replace(/[^\x20-\x7E]/g, '_');
|
|
217
|
+
let { page, yPosition } = addPage();
|
|
218
|
+
// Header (titolo centrato)
|
|
219
|
+
const titleText = sanitize(`${dcmtTypeName}`);
|
|
220
|
+
const titleWidth = getTextWidth(titleText, helveticaBoldFont, titleFontSize);
|
|
221
|
+
const titleX = Math.max(margin, margin + (contentWidth - titleWidth) / 2);
|
|
222
|
+
page.drawText(titleText, { x: titleX, y: yPosition, size: titleFontSize, font: helveticaBoldFont, color: rgb(0, 0, 0) });
|
|
223
|
+
yPosition -= titleLineHeight + 8;
|
|
224
|
+
// Metadati (label in grassetto, valore normale)
|
|
225
|
+
for (const kv of metadataKeyValues) {
|
|
226
|
+
const labelText = sanitize(kv.label) + ': ';
|
|
227
|
+
const labelWidth = getTextWidth(labelText, helveticaBoldFont, contentFontSize);
|
|
228
|
+
const valueMaxWidth = contentWidth - labelWidth;
|
|
229
|
+
const continuationIndent = labelWidth; // Indentazione per righe successive
|
|
230
|
+
// Wrappa il valore
|
|
231
|
+
const valueText = sanitize(kv.value);
|
|
232
|
+
const valueLines = wrapText(valueText, helveticaFont, contentFontSize, valueMaxWidth);
|
|
233
|
+
// Prima riga: label (bold) + primo pezzo di valore
|
|
234
|
+
if (yPosition < margin + lineHeight) {
|
|
235
|
+
({ page, yPosition } = addPage());
|
|
236
|
+
}
|
|
237
|
+
page.drawText(labelText, { x: margin, y: yPosition, size: contentFontSize, font: helveticaBoldFont, color: rgb(0, 0, 0) });
|
|
238
|
+
if (valueLines.length > 0) {
|
|
239
|
+
page.drawText(valueLines[0], { x: margin + labelWidth, y: yPosition, size: contentFontSize, font: helveticaFont, color: rgb(0, 0, 0) });
|
|
240
|
+
}
|
|
241
|
+
yPosition -= lineHeight;
|
|
242
|
+
// Righe successive del valore (indentate)
|
|
243
|
+
for (let i = 1; i < valueLines.length; i++) {
|
|
244
|
+
if (yPosition < margin + lineHeight) {
|
|
245
|
+
({ page, yPosition } = addPage());
|
|
246
|
+
}
|
|
247
|
+
page.drawText(valueLines[i], { x: margin + continuationIndent, y: yPosition, size: contentFontSize, font: helveticaFont, color: rgb(0, 0, 0) });
|
|
248
|
+
yPosition -= lineHeight;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Salva il PDF
|
|
252
|
+
const pdfBytes = await pdfDoc.save();
|
|
253
|
+
// Converte in Blob e File
|
|
254
|
+
const pdfBuffer = pdfBytes.buffer.slice(pdfBytes.byteOffset, pdfBytes.byteOffset + pdfBytes.byteLength);
|
|
255
|
+
const blob = new Blob([pdfBuffer], { type: 'application/pdf' });
|
|
256
|
+
const finalFileName = `${dcmtTypeName}_${dcmtInfo.DID}.pdf`;
|
|
257
|
+
const file = new File([blob], finalFileName, { type: 'application/pdf' });
|
|
258
|
+
return {
|
|
259
|
+
file,
|
|
260
|
+
blob,
|
|
261
|
+
bytes: pdfBytes
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
console.error('createMetadataPdfFromDocument: errore durante la creazione del PDF', error);
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
};
|
|
@@ -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>;
|