@topconsultnpm/sdkui-react 6.20.0-dev1.13 → 6.20.0-dev1.130
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/assets/Toppy-help-center.png +0 -0
- package/lib/assets/headergradient.svg +87 -0
- package/lib/components/NewComponents/ContextMenu/TMContextMenu.js +322 -30
- package/lib/components/NewComponents/ContextMenu/hooks.d.ts +8 -1
- package/lib/components/NewComponents/ContextMenu/hooks.js +80 -8
- package/lib/components/NewComponents/ContextMenu/index.d.ts +3 -0
- package/lib/components/NewComponents/ContextMenu/index.js +2 -0
- package/lib/components/NewComponents/ContextMenu/styles.d.ts +9 -1
- package/lib/components/NewComponents/ContextMenu/styles.js +146 -47
- package/lib/components/NewComponents/ContextMenu/types.d.ts +22 -3
- package/lib/components/NewComponents/ContextMenu/useLongPress.d.ts +21 -0
- package/lib/components/NewComponents/ContextMenu/useLongPress.js +112 -0
- package/lib/components/NewComponents/FloatingMenuBar/TMFloatingMenuBar.js +620 -125
- package/lib/components/NewComponents/FloatingMenuBar/styles.d.ts +25 -5
- package/lib/components/NewComponents/FloatingMenuBar/styles.js +215 -59
- package/lib/components/NewComponents/FloatingMenuBar/types.d.ts +12 -3
- package/lib/components/base/TMAccordionNew.js +35 -14
- package/lib/components/base/TMButton.js +6 -0
- package/lib/components/base/TMClosableList.js +4 -0
- package/lib/components/base/TMCustomButton.js +61 -17
- package/lib/components/base/TMDataGrid.d.ts +7 -4
- package/lib/components/base/TMDataGrid.js +153 -11
- package/lib/components/base/TMDropDownMenu.js +21 -18
- package/lib/components/base/TMFileManager.d.ts +4 -3
- package/lib/components/base/TMFileManager.js +32 -24
- package/lib/components/base/TMFileManagerDataGridView.d.ts +3 -2
- package/lib/components/base/TMFileManagerDataGridView.js +1 -11
- package/lib/components/base/TMFileManagerThumbnailItems.d.ts +7 -1
- package/lib/components/base/TMFileManagerThumbnailItems.js +5 -2
- package/lib/components/base/TMFileManagerThumbnailsView.d.ts +17 -4
- package/lib/components/base/TMFileManagerThumbnailsView.js +18 -6
- package/lib/components/base/TMFileManagerUtils.d.ts +0 -12
- package/lib/components/base/TMListView.js +33 -15
- package/lib/components/base/TMPanel.d.ts +1 -1
- package/lib/components/base/TMPanel.js +4 -2
- package/lib/components/base/TMPopUp.js +6 -0
- package/lib/components/base/TMToolbarCard.js +2 -0
- package/lib/components/base/TMTreeView.d.ts +2 -1
- package/lib/components/base/TMTreeView.js +33 -26
- package/lib/components/choosers/TMDataListItemChooser.d.ts +2 -0
- package/lib/components/choosers/TMDataListItemChooser.js +8 -2
- package/lib/components/choosers/TMDcmtTypeChooser.d.ts +1 -0
- package/lib/components/choosers/TMDcmtTypeChooser.js +11 -3
- package/lib/components/choosers/TMDistinctValues.js +2 -2
- package/lib/components/choosers/TMDynDataListItemChooser.d.ts +2 -0
- package/lib/components/choosers/TMDynDataListItemChooser.js +8 -2
- package/lib/components/choosers/TMInvoiceRetrieveFormats.js +1 -1
- package/lib/components/choosers/TMMetadataChooser.d.ts +2 -0
- package/lib/components/choosers/TMMetadataChooser.js +19 -4
- package/lib/components/choosers/TMOrderRetrieveFormats.js +1 -1
- package/lib/components/choosers/TMUserChooser.d.ts +2 -5
- package/lib/components/choosers/TMUserChooser.js +33 -47
- package/lib/components/editors/TMCheckBox.js +2 -0
- package/lib/components/editors/TMDateBox.js +18 -9
- package/lib/components/editors/TMEditorStyled.js +7 -0
- package/lib/components/editors/TMLocalizedTextBox.d.ts +3 -1
- package/lib/components/editors/TMLocalizedTextBox.js +16 -14
- package/lib/components/editors/TMMetadataEditor.d.ts +1 -0
- package/lib/components/editors/TMMetadataEditor.js +4 -4
- package/lib/components/editors/TMMetadataTextBox.d.ts +9 -0
- package/lib/components/editors/TMMetadataTextBox.js +92 -0
- package/lib/components/editors/TMMetadataValues.d.ts +2 -0
- package/lib/components/editors/TMMetadataValues.js +26 -8
- package/lib/components/editors/TMRadioButton.js +2 -0
- package/lib/components/editors/TMTextArea.js +18 -30
- package/lib/components/editors/TMTextBox.d.ts +1 -1
- package/lib/components/editors/TMTextBox.js +29 -4
- package/lib/components/editors/TMTextExpression.js +6 -91
- package/lib/components/features/archive/TMArchive.js +2 -2
- package/lib/components/features/assistant/TMToppyDraggableHelpCenter.d.ts +15 -0
- package/lib/components/features/assistant/TMToppyDraggableHelpCenter.js +462 -0
- package/lib/components/features/assistant/TMToppySpeechBubble.d.ts +11 -0
- package/lib/components/features/assistant/TMToppySpeechBubble.js +126 -0
- package/lib/components/features/documents/TMDcmtBlog.js +1 -1
- package/lib/components/features/documents/TMDcmtForm.d.ts +14 -2
- package/lib/components/features/documents/TMDcmtForm.js +576 -292
- package/lib/components/features/documents/TMDcmtPreview.js +42 -155
- package/lib/components/features/documents/TMDcmtTasks.js +9 -9
- package/lib/components/features/documents/TMMasterDetailDcmts.js +38 -53
- package/lib/components/features/documents/TMRelationViewer.d.ts +1 -1
- package/lib/components/features/documents/TMRelationViewer.js +2 -2
- package/lib/components/features/search/TMDcmtCheckoutInfoForm.d.ts +8 -0
- package/lib/components/features/search/{TMSearchResultCheckoutInfoForm.js → TMDcmtCheckoutInfoForm.js} +2 -2
- package/lib/components/features/search/TMSavedQuerySelector.js +72 -67
- package/lib/components/features/search/TMSearch.d.ts +3 -0
- package/lib/components/features/search/TMSearch.js +50 -11
- package/lib/components/features/search/TMSearchQueryEditor.d.ts +1 -0
- package/lib/components/features/search/TMSearchQueryEditor.js +10 -10
- package/lib/components/features/search/TMSearchQueryPanel.d.ts +1 -0
- package/lib/components/features/search/TMSearchQueryPanel.js +40 -25
- package/lib/components/features/search/TMSearchResult.d.ts +3 -0
- package/lib/components/features/search/TMSearchResult.js +370 -252
- package/lib/components/features/search/TMSearchResultsMenuItems.d.ts +3 -3
- package/lib/components/features/search/TMSearchResultsMenuItems.js +227 -171
- package/lib/components/features/search/TMSignSettingsForm.js +1 -1
- package/lib/components/features/search/TMSignatureInfoContent.d.ts +6 -0
- package/lib/components/features/search/TMSignatureInfoContent.js +140 -0
- package/lib/components/features/search/TMViewHistoryDcmt.js +47 -52
- package/lib/components/features/tasks/TMTaskForm.js +75 -25
- package/lib/components/features/tasks/TMTasksAgenda.d.ts +3 -1
- package/lib/components/features/tasks/TMTasksAgenda.js +48 -9
- package/lib/components/features/tasks/TMTasksCalendar.d.ts +2 -0
- package/lib/components/features/tasks/TMTasksCalendar.js +19 -7
- package/lib/components/features/tasks/TMTasksUtils.d.ts +2 -2
- package/lib/components/features/tasks/TMTasksUtils.js +57 -37
- package/lib/components/features/tasks/TMTasksView.js +28 -19
- package/lib/components/features/workflow/TMWorkflowPopup.d.ts +33 -2
- package/lib/components/features/workflow/TMWorkflowPopup.js +140 -34
- package/lib/components/features/workflow/diagram/DiagramItemComponent.d.ts +2 -0
- package/lib/components/features/workflow/diagram/DiagramItemComponent.js +14 -7
- package/lib/components/features/workflow/diagram/DiagramItemForm.js +1 -1
- package/lib/components/features/workflow/diagram/RecipientList.js +3 -2
- package/lib/components/features/workflow/diagram/WFDiagram.d.ts +4 -0
- package/lib/components/features/workflow/diagram/WFDiagram.js +164 -13
- package/lib/components/forms/Login/LoginValidatorService.d.ts +2 -0
- package/lib/components/forms/Login/LoginValidatorService.js +7 -2
- package/lib/components/forms/Login/TMLoginForm.js +35 -7
- package/lib/components/forms/TMChooserForm.js +1 -1
- package/lib/components/grids/TMBlogsPost.js +56 -31
- package/lib/components/grids/TMRecentsManager.js +20 -10
- package/lib/components/grids/TMValidationItemsList.js +6 -0
- package/lib/components/index.d.ts +6 -3
- package/lib/components/index.js +6 -3
- package/lib/components/layout/panelManager/TMPanelManagerContext.js +13 -5
- package/lib/components/query/TMQueryEditor.d.ts +6 -1
- package/lib/components/query/TMQueryEditor.js +105 -101
- package/lib/components/settings/SettingsAppearance.d.ts +2 -1
- package/lib/components/settings/SettingsAppearance.js +99 -30
- package/lib/components/sidebar/TMHeader.js +11 -7
- package/lib/components/sidebar/TMSidebar.d.ts +0 -1
- package/lib/components/sidebar/TMSidebar.js +16 -44
- package/lib/components/sidebar/TMSidebarItem.js +36 -17
- package/lib/components/viewers/TMDataListItemViewer.d.ts +2 -1
- package/lib/components/viewers/TMDataListItemViewer.js +35 -71
- package/lib/components/viewers/TMDataUserIdItemViewer.d.ts +8 -0
- package/lib/components/viewers/TMDataUserIdItemViewer.js +39 -0
- package/lib/css/tm-sdkui.css +1 -1
- package/lib/helper/SDKUI_Globals.d.ts +22 -0
- package/lib/helper/SDKUI_Globals.js +10 -1
- package/lib/helper/SDKUI_Localizator.d.ts +21 -3
- package/lib/helper/SDKUI_Localizator.js +196 -10
- package/lib/helper/TMCommandsContextMenu.d.ts +4 -2
- package/lib/helper/TMCommandsContextMenu.js +15 -4
- package/lib/helper/TMIcons.d.ts +4 -0
- package/lib/helper/TMIcons.js +13 -3
- package/lib/helper/TMPdfViewer.d.ts +8 -0
- package/lib/helper/TMPdfViewer.js +373 -0
- package/lib/helper/TMToppyMessage.js +4 -0
- package/lib/helper/checkinCheckoutManager.d.ts +31 -1
- package/lib/helper/checkinCheckoutManager.js +112 -30
- package/lib/helper/devextremeCustomMessages.d.ts +30 -0
- package/lib/helper/devextremeCustomMessages.js +30 -0
- package/lib/helper/helpers.d.ts +30 -2
- package/lib/helper/helpers.js +132 -4
- package/lib/helper/index.d.ts +2 -0
- package/lib/helper/index.js +2 -0
- package/lib/helper/queryHelper.d.ts +2 -2
- package/lib/helper/queryHelper.js +80 -24
- package/lib/helper/workItemsHelper.d.ts +6 -0
- package/lib/helper/workItemsHelper.js +230 -0
- package/lib/hooks/useCheckInOutOperations.d.ts +28 -0
- package/lib/hooks/useCheckInOutOperations.js +223 -0
- package/lib/hooks/useDataListItem.d.ts +12 -0
- package/lib/hooks/useDataListItem.js +132 -0
- package/lib/hooks/useDataUserIdItem.d.ts +10 -0
- package/lib/hooks/useDataUserIdItem.js +96 -0
- package/lib/hooks/useFloatingBarPinnedItems.d.ts +11 -0
- package/lib/hooks/useFloatingBarPinnedItems.js +54 -0
- package/lib/hooks/useMetadataExpression.d.ts +19 -0
- package/lib/hooks/useMetadataExpression.js +99 -0
- package/lib/hooks/useSettingsFeedback.d.ts +11 -0
- package/lib/hooks/useSettingsFeedback.js +38 -0
- package/lib/hooks/useWorkflowApprove.d.ts +4 -0
- package/lib/hooks/useWorkflowApprove.js +14 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -2
- package/lib/services/platform_services.d.ts +3 -3
- package/lib/ts/types.d.ts +61 -1
- package/lib/utils/theme.d.ts +1 -1
- package/lib/utils/theme.js +1 -1
- package/package.json +6 -5
- package/lib/components/NewComponents/Notification/Notification.d.ts +0 -4
- package/lib/components/NewComponents/Notification/Notification.js +0 -60
- package/lib/components/NewComponents/Notification/NotificationContainer.d.ts +0 -8
- package/lib/components/NewComponents/Notification/NotificationContainer.js +0 -33
- package/lib/components/NewComponents/Notification/index.d.ts +0 -2
- package/lib/components/NewComponents/Notification/index.js +0 -2
- package/lib/components/NewComponents/Notification/styles.d.ts +0 -21
- package/lib/components/NewComponents/Notification/styles.js +0 -180
- package/lib/components/NewComponents/Notification/types.d.ts +0 -18
- package/lib/components/NewComponents/Notification/types.js +0 -1
- package/lib/components/base/TMContextMenu.d.ts +0 -25
- package/lib/components/base/TMContextMenu.js +0 -109
- package/lib/components/base/TMContextMenuOLD.d.ts +0 -26
- package/lib/components/base/TMContextMenuOLD.js +0 -56
- package/lib/components/base/TMFloatingToolbar.d.ts +0 -9
- package/lib/components/base/TMFloatingToolbar.js +0 -101
- package/lib/components/features/assistant/ToppyDraggableHelpCenter.d.ts +0 -30
- package/lib/components/features/assistant/ToppyDraggableHelpCenter.js +0 -482
- package/lib/components/features/assistant/ToppySpeechBubble.d.ts +0 -9
- package/lib/components/features/assistant/ToppySpeechBubble.js +0 -117
- package/lib/components/features/search/TMSearchResultCheckoutInfoForm.d.ts +0 -8
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { SDK_Globals, WorkItemMetadataNames, SystemDataListIDs } from '@topconsultnpm/sdk-ts';
|
|
2
|
+
import { WorkflowCacheService, DataListCacheService, UserListCacheService, DcmtTypeListCacheService } from '@topconsultnpm/sdk-ts';
|
|
3
|
+
import { parseWfDiagramXml } from '../components/features/workflow/diagram/xmlParser';
|
|
4
|
+
/**
|
|
5
|
+
* Helper function per costruire IWorkItemData da un WFInstanceDescriptor
|
|
6
|
+
* Effettua le chiamate API necessarie e popola tutti i campi disponibili
|
|
7
|
+
*/
|
|
8
|
+
export const buildWorkItemsFromWFCtrl = async (wfInstance) => {
|
|
9
|
+
const { wfid, tid: mtid, did: mdid, instanceId } = wfInstance;
|
|
10
|
+
if (!wfid || !mtid || !mdid) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
// Recupera il workflow descriptor
|
|
14
|
+
const workflow = await WorkflowCacheService.GetWFCtrlInfoAsync(wfid);
|
|
15
|
+
// Recupera tutti i work items per questo workflow usando WFCtrl_RetrieveAllWIsAsync
|
|
16
|
+
const workItemsResult = await SDK_Globals.tmSession?.NewWorkflowEngine().WFCtrl_RetrieveAllWIsAsync(wfid, mtid, mdid, instanceId);
|
|
17
|
+
// Se non ci sono work items, restituisci array vuoto
|
|
18
|
+
if (!workItemsResult || workItemsResult.dcmtsFound === 0 || !workItemsResult.dtdResult?.rows) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
// Recupera la DataList degli stati del workflow
|
|
22
|
+
const dldStatus = await DataListCacheService.GetAsync(SystemDataListIDs.WIStates);
|
|
23
|
+
// Parse del diagramma del workflow per ottenere type e name dai diagramItems
|
|
24
|
+
let wfDiagram;
|
|
25
|
+
if (workflow?.diagram) {
|
|
26
|
+
try {
|
|
27
|
+
wfDiagram = parseWfDiagramXml(workflow.diagram);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.warn('Errore nel parsing del diagramma workflow:', error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Recupera il DTD per ottenere i MID dai nomi dei metadati
|
|
34
|
+
const dtd = await DcmtTypeListCacheService.GetAsync(workItemsResult.fromTID);
|
|
35
|
+
if (!dtd?.metadata) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
// Crea una mappa nome metadato -> MID
|
|
39
|
+
const metadataNameToMID = {};
|
|
40
|
+
for (const meta of dtd.metadata) {
|
|
41
|
+
if (meta.name) {
|
|
42
|
+
metadataNameToMID[meta.name] = meta.id;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const columns = workItemsResult.dtdResult.columns || [];
|
|
46
|
+
// Funzione helper per trovare l'indice di una colonna tramite MID
|
|
47
|
+
const findColumnIndexByMID = (mid) => {
|
|
48
|
+
if (mid === -1)
|
|
49
|
+
return -1;
|
|
50
|
+
return columns.findIndex(col => col.extendedProperties?.MID === mid.toString());
|
|
51
|
+
};
|
|
52
|
+
// Mappa degli indici delle colonne usando MID
|
|
53
|
+
const columnIndices = {
|
|
54
|
+
tid: 0, // TID è sempre il primo
|
|
55
|
+
did: 1, // DID è sempre il secondo
|
|
56
|
+
setID: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_SetID] ?? -1),
|
|
57
|
+
creationTime: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_CreationTime] ?? -1),
|
|
58
|
+
response: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_Response] ?? -1),
|
|
59
|
+
completionTime: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_CompletionTime] ?? -1),
|
|
60
|
+
from: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_From] ?? -1),
|
|
61
|
+
to: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_To] ?? -1),
|
|
62
|
+
or: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_Or] ?? -1),
|
|
63
|
+
status: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_Status] ?? -1),
|
|
64
|
+
category: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_Category] ?? -1),
|
|
65
|
+
description: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_Description] ?? -1),
|
|
66
|
+
setStatus: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_SetStatus] ?? -1),
|
|
67
|
+
setRule: findColumnIndexByMID(metadataNameToMID[WorkItemMetadataNames.WI_SetRule] ?? -1),
|
|
68
|
+
};
|
|
69
|
+
// Crea i WorkItemDetail
|
|
70
|
+
const details = [];
|
|
71
|
+
for (let i = 0; i < workItemsResult.dtdResult.rows.length; i++) {
|
|
72
|
+
const row = workItemsResult.dtdResult.rows[i];
|
|
73
|
+
const tid = Number(row[columnIndices.tid]);
|
|
74
|
+
const did = Number(row[columnIndices.did]);
|
|
75
|
+
const setID = columnIndices.setID !== -1 ? row[columnIndices.setID] : '';
|
|
76
|
+
const toUserID = columnIndices.to !== -1 ? Number(row[columnIndices.to]) : undefined;
|
|
77
|
+
// Risolvi l'utente usando la cache
|
|
78
|
+
let toUser = undefined;
|
|
79
|
+
if (toUserID !== undefined) {
|
|
80
|
+
try {
|
|
81
|
+
toUser = await UserListCacheService.GetAsync(toUserID);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.warn(`Impossibile recuperare l'utente con ID ${toUserID}:`, error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Calcola lo status come DataListItemDescriptor
|
|
88
|
+
let statusItem = undefined;
|
|
89
|
+
if (columnIndices.status !== -1) {
|
|
90
|
+
const rawStatusValue = row[columnIndices.status];
|
|
91
|
+
if (rawStatusValue !== undefined && rawStatusValue !== null && dldStatus?.items) {
|
|
92
|
+
statusItem = dldStatus.items.find(item => item.value === rawStatusValue);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
details.push({
|
|
96
|
+
wid: `${tid}_${did}`,
|
|
97
|
+
tid,
|
|
98
|
+
did,
|
|
99
|
+
wfid: workflow?.id ?? 0,
|
|
100
|
+
approvalVID: workflow?.approvalVID ?? 0,
|
|
101
|
+
setID,
|
|
102
|
+
creationTime: columnIndices.creationTime !== -1 && row[columnIndices.creationTime]
|
|
103
|
+
? new Date(row[columnIndices.creationTime])
|
|
104
|
+
: undefined,
|
|
105
|
+
response: columnIndices.response !== -1 ? row[columnIndices.response] : undefined,
|
|
106
|
+
completionTime: columnIndices.completionTime !== -1 && row[columnIndices.completionTime]
|
|
107
|
+
? new Date(row[columnIndices.completionTime])
|
|
108
|
+
: undefined,
|
|
109
|
+
from: columnIndices.from !== -1 ? Number(row[columnIndices.from]) : undefined,
|
|
110
|
+
to: toUserID,
|
|
111
|
+
toUser: toUser,
|
|
112
|
+
or: columnIndices.or !== -1 ? Number(row[columnIndices.or]) : undefined,
|
|
113
|
+
status: statusItem,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// Raggruppa per setID considerando il creationTime e setStatus
|
|
117
|
+
// Ordiniamo tutti i details per creationTime (ordine cronologico)
|
|
118
|
+
const sortedAllDetails = [...details].sort((a, b) => {
|
|
119
|
+
if (!a.creationTime || !b.creationTime)
|
|
120
|
+
return 0;
|
|
121
|
+
return a.creationTime.getTime() - b.creationTime.getTime();
|
|
122
|
+
});
|
|
123
|
+
// Crea una mappa detail -> setStatus per avere accesso al setStatus di ogni detail
|
|
124
|
+
const detailSetStatusMap = new Map();
|
|
125
|
+
for (const detail of details) {
|
|
126
|
+
const row = workItemsResult.dtdResult?.rows?.find(r => Number(r[columnIndices.tid]) === detail.tid &&
|
|
127
|
+
Number(r[columnIndices.did]) === detail.did);
|
|
128
|
+
if (row && columnIndices.setStatus !== -1) {
|
|
129
|
+
const setStatusValue = row[columnIndices.setStatus];
|
|
130
|
+
detailSetStatusMap.set(detail, setStatusValue?.toString() ?? '');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Logica di raggruppamento sequenziale dei workitems:
|
|
135
|
+
*
|
|
136
|
+
* Regole:
|
|
137
|
+
* 1. Primo workitem o SetID diverso => Nuovo step
|
|
138
|
+
* - Se SetStatus = "0" (Nuovo): attiva modalità aggregazione per tutti i successivi
|
|
139
|
+
*
|
|
140
|
+
* 2. Stesso SetID del precedente:
|
|
141
|
+
* - In modalità aggregazione (SetStatus = "0"): aggrega sempre nello stesso step
|
|
142
|
+
* - SetStatus != "0": raggruppa per stesso SetStatus
|
|
143
|
+
* - Stesso SetStatus => aggrega
|
|
144
|
+
* - SetStatus diverso => nuovo step
|
|
145
|
+
* - SetStatus = "0": nuovo step e attiva modalità aggregazione
|
|
146
|
+
*/
|
|
147
|
+
const groups = [];
|
|
148
|
+
let previousSetID = undefined;
|
|
149
|
+
let previousSetStatus = undefined;
|
|
150
|
+
let isInNewStatusMode = false;
|
|
151
|
+
for (const detail of sortedAllDetails) {
|
|
152
|
+
const currentSetStatus = detailSetStatusMap.get(detail) ?? '';
|
|
153
|
+
const currentSetID = detail.setID;
|
|
154
|
+
if (previousSetID === undefined || currentSetID !== previousSetID) {
|
|
155
|
+
// Nuovo SetID: crea nuovo step
|
|
156
|
+
groups.push([detail]);
|
|
157
|
+
previousSetID = currentSetID;
|
|
158
|
+
previousSetStatus = currentSetStatus;
|
|
159
|
+
isInNewStatusMode = currentSetStatus === '0';
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// Stesso SetID
|
|
163
|
+
if (isInNewStatusMode) {
|
|
164
|
+
// Modalità aggregazione attiva: aggrega sempre
|
|
165
|
+
groups[groups.length - 1].push(detail);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
if (currentSetStatus === '0') {
|
|
169
|
+
// SetStatus "Nuovo": nuovo step e attiva modalità aggregazione
|
|
170
|
+
groups.push([detail]);
|
|
171
|
+
isInNewStatusMode = true;
|
|
172
|
+
previousSetStatus = currentSetStatus;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// SetStatus diverso da "Nuovo": raggruppa per stesso SetStatus
|
|
176
|
+
if (currentSetStatus !== previousSetStatus) {
|
|
177
|
+
groups.push([detail]);
|
|
178
|
+
previousSetStatus = currentSetStatus;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
groups[groups.length - 1].push(detail);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Crea IWorkItemData per ogni gruppo con tutti i campi disponibili
|
|
188
|
+
const finalWorkItems = groups.map((groupDetails, groupIndex) => {
|
|
189
|
+
const setID = groupDetails[0].setID;
|
|
190
|
+
// Ordina per creationTime (più recente prima)
|
|
191
|
+
const sortedDetails = [...groupDetails].sort((a, b) => {
|
|
192
|
+
if (!a.creationTime || !b.creationTime)
|
|
193
|
+
return 0;
|
|
194
|
+
return b.creationTime.getTime() - a.creationTime.getTime();
|
|
195
|
+
});
|
|
196
|
+
const latest = sortedDetails[0];
|
|
197
|
+
const latestRow = workItemsResult.dtdResult?.rows?.find(row => Number(row[columnIndices.tid]) === latest.tid &&
|
|
198
|
+
Number(row[columnIndices.did]) === latest.did);
|
|
199
|
+
// Calcola il setStatus come DataListItemDescriptor
|
|
200
|
+
let setStatusItem = undefined;
|
|
201
|
+
if (latestRow && columnIndices.setStatus !== -1) {
|
|
202
|
+
const rawStatusValue = latestRow[columnIndices.setStatus];
|
|
203
|
+
if (rawStatusValue !== undefined && rawStatusValue !== null && dldStatus?.items) {
|
|
204
|
+
setStatusItem = dldStatus.items.find(item => item.value === rawStatusValue);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Cerca il diagramItem corrispondente al setID nel workflow
|
|
208
|
+
const diagramItem = wfDiagram?.DiagramItems?.find(item => item.ID === setID);
|
|
209
|
+
return {
|
|
210
|
+
wid: `group_${setID}_${groupIndex}`,
|
|
211
|
+
setID,
|
|
212
|
+
creationTime: latest.creationTime,
|
|
213
|
+
groupIndex,
|
|
214
|
+
category: latestRow && columnIndices.category !== -1 ? latestRow[columnIndices.category] : undefined,
|
|
215
|
+
type: diagramItem?.Type,
|
|
216
|
+
name: diagramItem?.ItemName,
|
|
217
|
+
description: latestRow && columnIndices.description !== -1 ? latestRow[columnIndices.description] : undefined,
|
|
218
|
+
setStatus: setStatusItem,
|
|
219
|
+
setRule: latestRow && columnIndices.setRule !== -1 ? Number(latestRow[columnIndices.setRule]) : undefined,
|
|
220
|
+
details: sortedDetails,
|
|
221
|
+
wf: workflow,
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
// Ordina i gruppi per creationTime (più recente prima)
|
|
225
|
+
return finalWorkItems.sort((a, b) => {
|
|
226
|
+
if (!a.creationTime || !b.creationTime)
|
|
227
|
+
return 0;
|
|
228
|
+
return b.creationTime.getTime() - a.creationTime.getTime();
|
|
229
|
+
});
|
|
230
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DcmtInfo, DownloadModes, DownloadTypes } from '../ts';
|
|
2
|
+
import { FileDescriptor, SearchResultDescriptor } from '@topconsultnpm/sdk-ts';
|
|
3
|
+
interface UseCheckInOutOperationsReturn {
|
|
4
|
+
showHistory: boolean;
|
|
5
|
+
showHistoryCallback: () => void;
|
|
6
|
+
hideHistoryCallback: () => void;
|
|
7
|
+
showCheckoutInformationForm: boolean;
|
|
8
|
+
showCheckoutInformationFormCallback: () => void;
|
|
9
|
+
hideCheckoutInformationFormCallback: () => void;
|
|
10
|
+
commentFormState: {
|
|
11
|
+
removeAndEditAttachment: boolean;
|
|
12
|
+
show: boolean;
|
|
13
|
+
isRequired: boolean;
|
|
14
|
+
};
|
|
15
|
+
hideCommentFormCallback: () => void;
|
|
16
|
+
copyCheckoutPathToClipboardCallback: (dcmt: DcmtInfo, filename: string) => void;
|
|
17
|
+
handleCheckOutCallback: (dcmt: DcmtInfo, checkout: boolean, filename: string, downloadDcmtsAsync: (inputDcmts: Array<DcmtInfo> | undefined, downloadType?: DownloadTypes, downloadMode?: DownloadModes, onFileDownloaded?: (dcmtFile: File) => void, confirmAttachments?: (list: FileDescriptor[]) => Promise<string[] | undefined>, skipConfirmation?: boolean) => Promise<void>, refreshCurrentDcmt?: () => Promise<void>, refreshFocusedDataRowAsync?: (tid: number | undefined, did: number | undefined, refreshUI?: boolean, metadataResult?: SearchResultDescriptor | null) => Promise<void>) => Promise<void>;
|
|
18
|
+
handleCheckInCallback: (dcmt: DcmtInfo, refreshCurrentDcmt?: () => Promise<void>, refreshFocusedDataRowAsync?: (tid: number | undefined, did: number | undefined, refreshUI?: boolean, metadataResult?: SearchResultDescriptor | null) => Promise<void>) => Promise<void>;
|
|
19
|
+
refreshPreviewTrigger: number;
|
|
20
|
+
showCicoWaitPanel: boolean;
|
|
21
|
+
cicoWaitPanelTitle: string;
|
|
22
|
+
showCicoPrimaryProgress: boolean;
|
|
23
|
+
cicoPrimaryProgressText: string;
|
|
24
|
+
cicoPrimaryProgressValue: number;
|
|
25
|
+
cicoPrimaryProgressMax: number;
|
|
26
|
+
}
|
|
27
|
+
export declare const useCheckInOutOperations: () => UseCheckInOutOperationsReturn;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { cicoDownloadFilesCallback, dcmtsFileCachePreview, getCicoDownloadFileName, getExceptionMessage, removeDcmtsFileCache, renderCicoCheckInContent, SDKUI_Globals, SDKUI_Localizator, updateCicoCheckoutStorageItem, validateCicoFileName } from '../helper';
|
|
3
|
+
import { ButtonNames, ShowAlert, TMMessageBoxManager, TMResultManager } from '../components';
|
|
4
|
+
import { ResultTypes, SDK_Globals } from '@topconsultnpm/sdk-ts';
|
|
5
|
+
let abortController = new AbortController();
|
|
6
|
+
export const useCheckInOutOperations = () => {
|
|
7
|
+
const [showHistory, setShowHistory] = useState(false);
|
|
8
|
+
// State to manage show history selected file
|
|
9
|
+
const [showCheckoutInformationForm, setShowCheckoutInformationForm] = useState(false);
|
|
10
|
+
// Stato per triggerare il refresh della preview dall'esterno
|
|
11
|
+
const [refreshPreviewTrigger, setRefreshPreviewTrigger] = useState(0);
|
|
12
|
+
// State to manage comment form
|
|
13
|
+
const [commentFormState, setCommentFormState] = useState({
|
|
14
|
+
removeAndEditAttachment: true,
|
|
15
|
+
show: false,
|
|
16
|
+
isRequired: false
|
|
17
|
+
});
|
|
18
|
+
// State variable to control the visibility of the wait panel
|
|
19
|
+
const [showCicoWaitPanel, setShowCicoWaitPanel] = useState(false);
|
|
20
|
+
// State variable to store the title of the wait panel
|
|
21
|
+
const [cicoWaitPanelTitle, setCicoWaitPanelTitle] = useState('');
|
|
22
|
+
// State variable to control the visibility of the primary section of the wait panel
|
|
23
|
+
const [showCicoPrimaryProgress, setShowCicoPrimaryProgress] = useState(false);
|
|
24
|
+
// State variable to store the primary text of the wait panel
|
|
25
|
+
const [cicoPrimaryProgressText, setCicoPrimaryProgressText] = useState('');
|
|
26
|
+
// State variable to track the current value of the primary progress indicator in the wait panel
|
|
27
|
+
const [cicoPrimaryProgressValue, setCicoPrimaryProgressValue] = useState(0);
|
|
28
|
+
// State variable to define the maximum value for the primary progress indicator in the wait panel
|
|
29
|
+
const [cicoPrimaryProgressMax, setCicoPrimaryProgressMax] = useState(0);
|
|
30
|
+
const showHistoryCallback = useCallback(() => {
|
|
31
|
+
setShowHistory(true);
|
|
32
|
+
}, []);
|
|
33
|
+
const hideHistoryCallback = useCallback(() => {
|
|
34
|
+
setShowHistory(false);
|
|
35
|
+
}, []);
|
|
36
|
+
const showCheckoutInformationFormCallback = useCallback(() => {
|
|
37
|
+
setShowCheckoutInformationForm(true);
|
|
38
|
+
}, []);
|
|
39
|
+
const hideCheckoutInformationFormCallback = useCallback(() => {
|
|
40
|
+
setShowCheckoutInformationForm(false);
|
|
41
|
+
}, []);
|
|
42
|
+
const triggerPreviewRefresh = useCallback(() => {
|
|
43
|
+
setRefreshPreviewTrigger(prev => prev + 1);
|
|
44
|
+
}, []);
|
|
45
|
+
const hideCommentFormCallback = useCallback(() => {
|
|
46
|
+
setCommentFormState(prev => ({ ...prev, show: false }));
|
|
47
|
+
}, []);
|
|
48
|
+
const copyCheckoutPathToClipboardCallback = (dcmt, filename) => {
|
|
49
|
+
const defaultCheckInOutFolder = SDKUI_Globals.userSettings.defaultCheckInOutFolder ?? "Download";
|
|
50
|
+
const wGSDraftCheckoutItemCurrentItems = [...SDKUI_Globals.userSettings.dcmtCheckoutInfo];
|
|
51
|
+
const existingItem = wGSDraftCheckoutItemCurrentItems.find((item) => item.TID === dcmt.TID.toString() && item.DID === dcmt.DID.toString());
|
|
52
|
+
const folder = existingItem && existingItem.checkoutFolder && existingItem.checkoutFolder !== "" ? existingItem.checkoutFolder : defaultCheckInOutFolder;
|
|
53
|
+
const name = existingItem?.checkoutName ?? getCicoDownloadFileName({ type: 'dcmtInfo', dcmtInfo: dcmt, originalFileName: filename }, true, false);
|
|
54
|
+
const textToCopy = folder ? `${folder}\\${name}` : name;
|
|
55
|
+
navigator.clipboard.writeText(textToCopy)
|
|
56
|
+
.then(() => {
|
|
57
|
+
ShowAlert({ message: SDKUI_Localizator.OperationSuccess, mode: 'success', duration: 5000, title: SDKUI_Localizator.CopyToClipboard });
|
|
58
|
+
})
|
|
59
|
+
.catch(err => {
|
|
60
|
+
ShowAlert({ message: err, mode: 'error', duration: 5000, title: SDKUI_Localizator.OperationResult });
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const handleCheckOutCallback = async (dcmt, checkout, filename, downloadDcmtsAsync, refreshMetadataAsync, refreshFocusedDataRowAsync) => {
|
|
64
|
+
if (!dcmt)
|
|
65
|
+
throw new Error("Document info is required");
|
|
66
|
+
const title = checkout ? 'Check out' : SDKUI_Localizator.CancelCheckOut;
|
|
67
|
+
const msg = checkout ? SDKUI_Localizator.ExecuteCheckOutQuestion : SDKUI_Localizator.ExecuteCancelCheckOutQuestion;
|
|
68
|
+
TMMessageBoxManager.show({
|
|
69
|
+
title: title,
|
|
70
|
+
message: msg,
|
|
71
|
+
buttons: [ButtonNames.YES, ButtonNames.NO],
|
|
72
|
+
onButtonClick: async (e) => {
|
|
73
|
+
if (e !== ButtonNames.YES)
|
|
74
|
+
return;
|
|
75
|
+
let result = [];
|
|
76
|
+
try {
|
|
77
|
+
setCicoWaitPanelTitle(title);
|
|
78
|
+
setShowCicoWaitPanel(true);
|
|
79
|
+
setShowCicoPrimaryProgress(true);
|
|
80
|
+
abortController = new AbortController();
|
|
81
|
+
const ue = SDK_Globals.tmSession?.NewUpdateEngineByID();
|
|
82
|
+
if (!ue)
|
|
83
|
+
throw new Error("Update Engine not available");
|
|
84
|
+
ue.TID = dcmt.TID;
|
|
85
|
+
ue.DID = dcmt.DID;
|
|
86
|
+
if (checkout) {
|
|
87
|
+
await ue.CheckOutAsync()
|
|
88
|
+
.then(async () => {
|
|
89
|
+
await cicoDownloadFilesCallback([{ type: 'dcmtInfo', dcmtInfo: dcmt, originalFileName: filename }], true, downloadDcmtsAsync);
|
|
90
|
+
result.push({ rowIndex: 1, id1: dcmt.TID, id2: dcmt.DID, description: SDKUI_Localizator.UpdateCompletedSuccessfully, resultType: ResultTypes.SUCCESS });
|
|
91
|
+
await refreshMetadataAsync?.();
|
|
92
|
+
await refreshFocusedDataRowAsync?.(dcmt.TID, dcmt.DID, true);
|
|
93
|
+
})
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
result.push({ rowIndex: 1, id1: dcmt.TID, id2: dcmt.DID, resultType: ResultTypes.ERROR, description: getExceptionMessage(error) });
|
|
96
|
+
throw error;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
await ue.UndoCheckOutAsync()
|
|
101
|
+
.then(async () => {
|
|
102
|
+
result.push({ rowIndex: 1, id1: dcmt.TID, id2: dcmt.DID, description: SDKUI_Localizator.UpdateCompletedSuccessfully, resultType: ResultTypes.SUCCESS });
|
|
103
|
+
// Remove the corresponding draft checkout item
|
|
104
|
+
updateCicoCheckoutStorageItem({ TID: dcmt.TID.toString(), DID: dcmt.DID.toString(), checkoutFolder: "", checkoutName: "" }, "dcmtInfo", "remove");
|
|
105
|
+
await refreshMetadataAsync?.();
|
|
106
|
+
await refreshFocusedDataRowAsync?.(dcmt.TID, dcmt.DID, true);
|
|
107
|
+
})
|
|
108
|
+
.catch((error) => {
|
|
109
|
+
result.push({ rowIndex: 0, id1: dcmt.TID, id2: dcmt.DID, resultType: ResultTypes.ERROR, description: getExceptionMessage(error) });
|
|
110
|
+
throw error;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
result.push({ rowIndex: 1, id1: dcmt.TID, id2: dcmt.DID, resultType: ResultTypes.ERROR, description: getExceptionMessage(error) });
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
setCicoPrimaryProgressText('');
|
|
119
|
+
setCicoPrimaryProgressMax(0);
|
|
120
|
+
setCicoPrimaryProgressValue(0);
|
|
121
|
+
setShowCicoWaitPanel(false);
|
|
122
|
+
TMResultManager.show(result, title, "ID", undefined);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
const triggerCommentOnFileAdd = (addedFiles) => {
|
|
128
|
+
if (addedFiles.length > 0) {
|
|
129
|
+
setCommentFormState({
|
|
130
|
+
show: true,
|
|
131
|
+
isRequired: true,
|
|
132
|
+
removeAndEditAttachment: false
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const handleCheckInCallback = async (dcmt, refreshMetadataAsync, refreshFocusedDataRowAsync) => {
|
|
137
|
+
if (!dcmt)
|
|
138
|
+
throw new Error("Document info is required");
|
|
139
|
+
// Create a new file input element
|
|
140
|
+
const input = document.createElement("input");
|
|
141
|
+
// Set the input type to "file" to allow file selection
|
|
142
|
+
input.type = "file";
|
|
143
|
+
// Set the accepted file types (e.g., images, PDFs, etc.)
|
|
144
|
+
input.accept = "*/*";
|
|
145
|
+
// Enable the input to accept one file at once
|
|
146
|
+
input.multiple = false;
|
|
147
|
+
// Add an event listener for when the file selection changes
|
|
148
|
+
input.addEventListener('change', async (event) => {
|
|
149
|
+
const fileInput = event.target;
|
|
150
|
+
if (!fileInput.files || fileInput.files.length === 0)
|
|
151
|
+
return;
|
|
152
|
+
const file = fileInput.files[0];
|
|
153
|
+
const validateFileName = validateCicoFileName({ type: 'dcmtInfo', dcmtInfo: dcmt, originalFileName: dcmt.fileName ?? SDKUI_Localizator.SearchResult }, file.name);
|
|
154
|
+
TMMessageBoxManager.show({
|
|
155
|
+
resizable: true,
|
|
156
|
+
buttons: [ButtonNames.YES, ButtonNames.NO],
|
|
157
|
+
message: renderCicoCheckInContent({ type: 'dcmtInfo', dcmtInfo: dcmt, originalFileName: dcmt.fileName ?? SDKUI_Localizator.SearchResult }, file, validateFileName.isValid, validateFileName.validationResults),
|
|
158
|
+
title: "Check in",
|
|
159
|
+
onButtonClick: async (e) => {
|
|
160
|
+
if (e !== ButtonNames.YES)
|
|
161
|
+
return;
|
|
162
|
+
setCicoWaitPanelTitle('Check in');
|
|
163
|
+
setShowCicoWaitPanel(true);
|
|
164
|
+
setShowCicoPrimaryProgress(true);
|
|
165
|
+
abortController = new AbortController();
|
|
166
|
+
let result = [];
|
|
167
|
+
let i = 0;
|
|
168
|
+
if (dcmt.TID && dcmt.DID) {
|
|
169
|
+
try {
|
|
170
|
+
const ue = SDK_Globals.tmSession?.NewUpdateEngineByID();
|
|
171
|
+
if (ue) {
|
|
172
|
+
ue.TID = dcmt.TID;
|
|
173
|
+
ue.DID = dcmt.DID;
|
|
174
|
+
await ue.CheckInAsync(file, "", abortController.signal);
|
|
175
|
+
// Remove the corresponding draft checkout item
|
|
176
|
+
updateCicoCheckoutStorageItem({ TID: dcmt.TID.toString(), DID: dcmt.DID.toString(), checkoutFolder: "", checkoutName: "" }, "dcmtInfo", "remove");
|
|
177
|
+
result.push({ rowIndex: i, id1: dcmt.DID, id2: dcmt.DID, description: SDKUI_Localizator.UpdateCompletedSuccessfully, resultType: ResultTypes.SUCCESS });
|
|
178
|
+
await refreshMetadataAsync?.();
|
|
179
|
+
await refreshFocusedDataRowAsync?.(dcmt.TID, dcmt.DID, true);
|
|
180
|
+
const cacheKey = `${dcmt.TID}-${dcmt.DID}`;
|
|
181
|
+
if (dcmtsFileCachePreview.has(cacheKey))
|
|
182
|
+
removeDcmtsFileCache(cacheKey);
|
|
183
|
+
triggerPreviewRefresh();
|
|
184
|
+
triggerCommentOnFileAdd([dcmt.DID]);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
result.push({ rowIndex: i, id1: i, id2: i, resultType: ResultTypes.ERROR, description: getExceptionMessage(err) });
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
setCicoPrimaryProgressText('');
|
|
192
|
+
setCicoPrimaryProgressMax(0);
|
|
193
|
+
setCicoPrimaryProgressValue(0);
|
|
194
|
+
setShowCicoWaitPanel(false);
|
|
195
|
+
TMResultManager.show(result, 'Check in', "ID", undefined, SDKUI_Localizator.CheckInSuccessMessage, 6000);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
input.click();
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
showHistory,
|
|
205
|
+
showHistoryCallback,
|
|
206
|
+
hideHistoryCallback,
|
|
207
|
+
showCheckoutInformationForm,
|
|
208
|
+
showCheckoutInformationFormCallback,
|
|
209
|
+
hideCheckoutInformationFormCallback,
|
|
210
|
+
commentFormState,
|
|
211
|
+
hideCommentFormCallback,
|
|
212
|
+
copyCheckoutPathToClipboardCallback,
|
|
213
|
+
handleCheckOutCallback,
|
|
214
|
+
handleCheckInCallback,
|
|
215
|
+
refreshPreviewTrigger,
|
|
216
|
+
showCicoWaitPanel,
|
|
217
|
+
cicoWaitPanelTitle,
|
|
218
|
+
showCicoPrimaryProgress,
|
|
219
|
+
cicoPrimaryProgressText,
|
|
220
|
+
cicoPrimaryProgressValue,
|
|
221
|
+
cicoPrimaryProgressMax,
|
|
222
|
+
};
|
|
223
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DataListItemDescriptor, DataListViewModes } from '@topconsultnpm/sdk-ts';
|
|
3
|
+
export declare const useDataListItem: () => {
|
|
4
|
+
loadDataListsAsync: (dataListIDs: Set<number>) => Promise<void>;
|
|
5
|
+
getDataListItem: (dataListID: number, value: string | number | Date) => DataListItemDescriptor | undefined;
|
|
6
|
+
clearCache: () => void;
|
|
7
|
+
hasDataList: (dataListID: number) => boolean;
|
|
8
|
+
renderDataListCell: (value: string | Date | number | undefined, dataListID: number, dataListViewMode: DataListViewModes) => React.ReactElement;
|
|
9
|
+
dataListsCache: React.MutableRefObject<Map<number, DataListItemDescriptor[]>>;
|
|
10
|
+
convertToDataListValue: (value: string | Date | number | undefined) => string;
|
|
11
|
+
convertToDataListDisplayValue: (value: string | Date | number | undefined) => string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useCallback } from 'react';
|
|
3
|
+
import { DataListCacheService, DataListViewModes } from '@topconsultnpm/sdk-ts';
|
|
4
|
+
import { IconWarning, SDKUI_Localizator, TMImageLibrary } from '../helper';
|
|
5
|
+
import { FormulaHelper, StyledDivHorizontal } from '../components';
|
|
6
|
+
import { TMColors } from '../utils/theme';
|
|
7
|
+
export const useDataListItem = () => {
|
|
8
|
+
const dataListsCacheRef = useRef(new Map());
|
|
9
|
+
/**
|
|
10
|
+
* Converte un valore in formato stringa per DataList
|
|
11
|
+
* @param value Valore da convertire
|
|
12
|
+
* @returns Stringa rappresentante il valore
|
|
13
|
+
*/
|
|
14
|
+
const convertToDataListValue = useCallback((value) => {
|
|
15
|
+
if (value instanceof Date) {
|
|
16
|
+
return value.toISOString();
|
|
17
|
+
}
|
|
18
|
+
else if (typeof value === 'number') {
|
|
19
|
+
return value.toString();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return value ?? '';
|
|
23
|
+
}
|
|
24
|
+
}, []);
|
|
25
|
+
/**
|
|
26
|
+
* Converte un valore in formato stringa per visualizzazione in DataList
|
|
27
|
+
* @param value Valore da convertire
|
|
28
|
+
* @returns Stringa formattata per visualizzazione
|
|
29
|
+
*/
|
|
30
|
+
const convertToDataListDisplayValue = useCallback((value) => {
|
|
31
|
+
if (value instanceof Date) {
|
|
32
|
+
return value.toLocaleDateString();
|
|
33
|
+
}
|
|
34
|
+
else if (typeof value === 'number') {
|
|
35
|
+
return value.toString();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return value ?? '';
|
|
39
|
+
}
|
|
40
|
+
}, []);
|
|
41
|
+
/**
|
|
42
|
+
* Carica tutte le DataList necessarie in parallelo e popola la cache
|
|
43
|
+
* @param dataListIDs Set di ID delle DataList da caricare
|
|
44
|
+
* @returns Promise che si risolve quando tutte le DataList sono state caricate
|
|
45
|
+
*/
|
|
46
|
+
const loadDataListsAsync = useCallback(async (dataListIDs) => {
|
|
47
|
+
if (dataListIDs.size === 0)
|
|
48
|
+
return;
|
|
49
|
+
try {
|
|
50
|
+
const results = await Promise.all(Array.from(dataListIDs).map(id => DataListCacheService.GetAsync(id).then(dl => ({
|
|
51
|
+
id,
|
|
52
|
+
items: dl?.items ?? []
|
|
53
|
+
}))));
|
|
54
|
+
const newCache = new Map();
|
|
55
|
+
results.forEach(({ id, items }) => newCache.set(id, items));
|
|
56
|
+
dataListsCacheRef.current = newCache;
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
console.error('Error loading DataLists:', err);
|
|
60
|
+
dataListsCacheRef.current = new Map();
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
63
|
+
/**
|
|
64
|
+
* Recupera un item dalla cache della DataList
|
|
65
|
+
* @param dataListID ID della DataList
|
|
66
|
+
* @param value Valore dell'item da cercare
|
|
67
|
+
* @returns DataListItemDescriptor se trovato, undefined altrimenti
|
|
68
|
+
*/
|
|
69
|
+
const getDataListItem = useCallback((dataListID, value) => {
|
|
70
|
+
const stringValue = convertToDataListValue(value);
|
|
71
|
+
const dataListItems = dataListsCacheRef.current.get(dataListID);
|
|
72
|
+
return dataListItems?.find(o => o.value == stringValue);
|
|
73
|
+
}, []);
|
|
74
|
+
/**
|
|
75
|
+
* Svuota completamente la cache
|
|
76
|
+
*/
|
|
77
|
+
const clearCache = useCallback(() => {
|
|
78
|
+
dataListsCacheRef.current = new Map();
|
|
79
|
+
}, []);
|
|
80
|
+
/**
|
|
81
|
+
* Verifica se una DataList è presente nella cache
|
|
82
|
+
* @param dataListID ID della DataList
|
|
83
|
+
* @returns true se la DataList è in cache, false altrimenti
|
|
84
|
+
*/
|
|
85
|
+
const hasDataList = useCallback((dataListID) => {
|
|
86
|
+
return dataListsCacheRef.current.has(dataListID);
|
|
87
|
+
}, []);
|
|
88
|
+
/**
|
|
89
|
+
* Renderizza una cella DataList con icona e testo formattato
|
|
90
|
+
* @param value Valore della cella
|
|
91
|
+
* @param dataListID ID della DataList
|
|
92
|
+
* @param dataListViewMode Modalità di visualizzazione della DataList
|
|
93
|
+
* @returns Elemento React per la cella DataList
|
|
94
|
+
*/
|
|
95
|
+
const renderDataListCell = useCallback((value, dataListID, dataListViewMode) => {
|
|
96
|
+
const stringValue = convertToDataListValue(value);
|
|
97
|
+
const showIcon = dataListViewMode !== DataListViewModes.Description;
|
|
98
|
+
const showText = dataListViewMode !== DataListViewModes.Image;
|
|
99
|
+
const dataListItem = getDataListItem(dataListID, stringValue);
|
|
100
|
+
const getIcon = () => {
|
|
101
|
+
if (!showIcon)
|
|
102
|
+
return null;
|
|
103
|
+
if (value === undefined || value === null)
|
|
104
|
+
return null;
|
|
105
|
+
if (FormulaHelper.isFormula(stringValue))
|
|
106
|
+
return null;
|
|
107
|
+
return dataListItem
|
|
108
|
+
? _jsx(TMImageLibrary, { imageID: dataListItem.imageID })
|
|
109
|
+
: _jsx(IconWarning, { color: TMColors.warning });
|
|
110
|
+
};
|
|
111
|
+
return (_jsxs(StyledDivHorizontal, { style: { width: '100%' }, title: dataListItem ? dataListItem.value : SDKUI_Localizator.ValueNotPresent, children: [getIcon(), showText && (_jsx("p", { style: {
|
|
112
|
+
textAlign: 'left',
|
|
113
|
+
marginLeft: showIcon ? '5px' : '',
|
|
114
|
+
opacity: dataListItem ? 1 : 0.5,
|
|
115
|
+
whiteSpace: 'nowrap',
|
|
116
|
+
overflow: 'hidden',
|
|
117
|
+
textOverflow: 'ellipsis',
|
|
118
|
+
flexGrow: 1,
|
|
119
|
+
minWidth: 0
|
|
120
|
+
}, children: dataListItem ? dataListItem.name : convertToDataListDisplayValue(value) }))] }));
|
|
121
|
+
}, [getDataListItem]);
|
|
122
|
+
return {
|
|
123
|
+
loadDataListsAsync,
|
|
124
|
+
getDataListItem,
|
|
125
|
+
clearCache,
|
|
126
|
+
hasDataList,
|
|
127
|
+
renderDataListCell,
|
|
128
|
+
dataListsCache: dataListsCacheRef,
|
|
129
|
+
convertToDataListValue,
|
|
130
|
+
convertToDataListDisplayValue
|
|
131
|
+
};
|
|
132
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UserDescriptor } from '@topconsultnpm/sdk-ts';
|
|
3
|
+
export declare const useDataUserIdItem: () => {
|
|
4
|
+
loadUsersAsync: (userIDs: Set<number>) => Promise<void>;
|
|
5
|
+
getUserItem: (userId: number) => UserDescriptor | undefined;
|
|
6
|
+
clearCache: () => void;
|
|
7
|
+
hasUser: (userId: number) => boolean;
|
|
8
|
+
usersCache: React.MutableRefObject<Map<number, UserDescriptor>>;
|
|
9
|
+
renderUserIdViewer: (userId: number | undefined, showIcon?: boolean, showTitile?: boolean) => React.ReactElement;
|
|
10
|
+
};
|