pict-section-form 1.0.127 → 1.0.128

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-form",
3
- "version": "1.0.127",
3
+ "version": "1.0.128",
4
4
  "description": "Pict dynamic form sections",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -7,6 +7,10 @@ const libPictViewDynamicForm = require('./Pict-View-DynamicForm.js');
7
7
  // TODO: Manage view lifecycle internally, including destruction of views if they are flagged to not be needed.
8
8
  // Why? This allows us to dynamically add and remove sections without having to reload the application.
9
9
 
10
+ const PENDING_ASYNC_OPERATION_TYPE = 'PendingAsyncOperation';
11
+ const TRANSACTION_COMPLETE_CALLBACK_TYPE = 'onTransactionComplete';
12
+ const READY_TO_FINALIZE_TYPE = 'ReadyToFinalize';
13
+
10
14
  /**
11
15
  * @typedef {(a: any, b: any) => number} SortFunction
12
16
  */
@@ -940,6 +944,146 @@ class PictFormMetacontroller extends libPictViewClass
940
944
  }
941
945
  }
942
946
 
947
+ /**
948
+ * @param {string} pTransactionGUID - The transaction GUID.
949
+ * @param {string} pAsyncOperationHash - The hash of the async operation.
950
+ */
951
+ registerEventTransactionAsyncOperation(pTransactionGUID, pAsyncOperationHash)
952
+ {
953
+ this.pict.TransactionTracking.pushToTransactionQueue(pTransactionGUID, pAsyncOperationHash, PENDING_ASYNC_OPERATION_TYPE);
954
+ }
955
+
956
+ /**
957
+ * @param {string} pTransactionGUID - The transaction GUID.
958
+ * @param {string} pAsyncOperationHash - The hash of the async operation.
959
+ *
960
+ * @return {boolean} - Returns true if the async operation was found and marked as complete, otherwise false.
961
+ */
962
+ eventTransactionAsyncOperationComplete(pTransactionGUID, pAsyncOperationHash)
963
+ {
964
+ const tmpQueue = this.pict.TransactionTracking.checkTransactionQueue(pTransactionGUID);
965
+ let tmpPendingAsyncOperationCount = 0;
966
+ let tmpMarkedOperationCount = 0;
967
+ let tmpFinalized = false;
968
+ for (let i = 0; i < tmpQueue.length; i++)
969
+ {
970
+ const tmpQueueItem = tmpQueue[i];
971
+ if (tmpQueueItem.Type === PENDING_ASYNC_OPERATION_TYPE)
972
+ {
973
+ if (tmpQueueItem.Data === pAsyncOperationHash)
974
+ {
975
+ tmpQueue.splice(i, 1);
976
+ ++tmpMarkedOperationCount;
977
+ --i;
978
+ }
979
+ else
980
+ {
981
+ ++tmpPendingAsyncOperationCount;
982
+ }
983
+ }
984
+ if (tmpQueueItem.Type === READY_TO_FINALIZE_TYPE)
985
+ {
986
+ tmpFinalized = true;
987
+ }
988
+ }
989
+ if (tmpPendingAsyncOperationCount === 0)
990
+ {
991
+ for (const tmpQueueItem of tmpQueue)
992
+ {
993
+ if (tmpQueueItem.Type === TRANSACTION_COMPLETE_CALLBACK_TYPE)
994
+ {
995
+ if (typeof tmpQueueItem.Data !== 'function')
996
+ {
997
+ this.log.error(`PICT View Metatemplate Helper eventTransactionAsyncOperationComplete transaction callback was not a function.`);
998
+ continue;
999
+ }
1000
+ try
1001
+ {
1002
+ tmpQueueItem.Data();
1003
+ }
1004
+ catch (pError)
1005
+ {
1006
+ this.log.error(`PICT View Metatemplate Helper eventTransactionAsyncOperationComplete transaction callback error: ${pError}`, { Stack: pError.stack });
1007
+ }
1008
+ }
1009
+ }
1010
+ }
1011
+ return tmpMarkedOperationCount > 0;
1012
+ }
1013
+
1014
+ /**
1015
+ * @param {string} pTransactionGUID - The transaction GUID.
1016
+ *
1017
+ * @return {boolean} - Returns true if the transaction was found and able to be finalized, otherwise false.
1018
+ */
1019
+ finalizeTransaction(pTransactionGUID)
1020
+ {
1021
+ this.pict.TransactionTracking.pushToTransactionQueue(pTransactionGUID, null, READY_TO_FINALIZE_TYPE);
1022
+
1023
+ const tmpQueue = this.pict.TransactionTracking.checkTransactionQueue(pTransactionGUID);
1024
+ let tmpPendingAsyncOperationCount = 0;
1025
+ for (const tmpQueueItem of tmpQueue)
1026
+ {
1027
+ if (tmpQueueItem.Type === PENDING_ASYNC_OPERATION_TYPE)
1028
+ {
1029
+ ++tmpPendingAsyncOperationCount;
1030
+ }
1031
+ }
1032
+ if (tmpPendingAsyncOperationCount > 0)
1033
+ {
1034
+ this.pict.log.info(`PICT View Metatemplate Helper finalizeTransaction ${pTransactionGUID} is waiting on ${tmpPendingAsyncOperationCount} pending async operations.`);
1035
+ return false;
1036
+ }
1037
+ for (const tmpQueueItem of tmpQueue)
1038
+ {
1039
+ if (tmpQueueItem.Type === TRANSACTION_COMPLETE_CALLBACK_TYPE)
1040
+ {
1041
+ if (typeof tmpQueueItem.Data !== 'function')
1042
+ {
1043
+ this.log.error(`PICT View Metatemplate Helper eventTransactionAsyncOperationComplete transaction callback was not a function.`);
1044
+ continue;
1045
+ }
1046
+ try
1047
+ {
1048
+ tmpQueueItem.Data();
1049
+ }
1050
+ catch (pError)
1051
+ {
1052
+ this.log.error(`PICT View Metatemplate Helper eventTransactionAsyncOperationComplete transaction callback error: ${pError}`, { Stack: pError.stack });
1053
+ }
1054
+ }
1055
+ }
1056
+ //TODO: figure out how to safely clean up old transactions
1057
+ //delete this.pict.TransactionTracking.transactions[pTransactionGUID];
1058
+ return true;
1059
+ }
1060
+
1061
+ /**
1062
+ * @param {string} pTransactionGUID - The transaction GUID.
1063
+ * @param {Function} fCallback - The callback to call when the transaction is complete.
1064
+ */
1065
+ registerOnTransactionCompleteCallback(pTransactionGUID, fCallback)
1066
+ {
1067
+ const tmpQueue = this.pict.TransactionTracking.checkTransactionQueue(pTransactionGUID);
1068
+ let tmpFinalized = false;
1069
+ for (const tmpQueueItem of tmpQueue)
1070
+ {
1071
+ if (tmpQueueItem.Type === READY_TO_FINALIZE_TYPE)
1072
+ {
1073
+ tmpFinalized = true;
1074
+ break;
1075
+ }
1076
+ }
1077
+ if (tmpFinalized)
1078
+ {
1079
+ fCallback();
1080
+ }
1081
+ else
1082
+ {
1083
+ this.pict.TransactionTracking.pushToTransactionQueue(pTransactionGUID, fCallback, TRANSACTION_COMPLETE_CALLBACK_TYPE);
1084
+ }
1085
+ }
1086
+
943
1087
  /**
944
1088
  * Returns whether the object is a Pict Metacontroller.
945
1089
  *
@@ -44,10 +44,10 @@ declare class PictDynamicFormsSolverBehaviors extends libPictProvider {
44
44
  * @param {string} pInputHash - The hash of the input to color.
45
45
  * @param {string} pColor - The HTML hex color to apply (e.g. #FF0000 for red).
46
46
  * @param {string} pApplyChange - If "0", the change will not be applied.
47
- * @param {string} [pClassTarget] - Optional. If provided, the color will be applied to the closest element with this class instead of the input itself.
47
+ * @param {string} [pCSSSelector] - Optional. If provided, the color will be applied to the closest element matching this selector instead of the input itself.
48
48
  * @returns {boolean} - Returns true if the color was applied successfully or if the change was skipped for pApplyChange equal to "0", false otherwise.
49
49
  */
50
- colorInputBackground(pSectionHash: string, pInputHash: string, pColor: string, pApplyChange: string, pClassTarget?: string): boolean;
50
+ colorInputBackground(pSectionHash: string, pInputHash: string, pColor: string, pApplyChange: string, pCSSSelector?: string): boolean;
51
51
  logValues(...args: any[]): any;
52
52
  }
53
53
  declare namespace PictDynamicFormsSolverBehaviors {
@@ -160,6 +160,29 @@ declare class PictFormMetacontroller extends libPictViewClass {
160
160
  * @param {string} [pTransactionGUID] - (optional) The transaction GUID to use for the event.
161
161
  */
162
162
  triggerGlobalInputEvent(pEvent: string, pTransactionGUID?: string): void;
163
+ /**
164
+ * @param {string} pTransactionGUID - The transaction GUID.
165
+ * @param {string} pAsyncOperationHash - The hash of the async operation.
166
+ */
167
+ registerEventTransactionAsyncOperation(pTransactionGUID: string, pAsyncOperationHash: string): void;
168
+ /**
169
+ * @param {string} pTransactionGUID - The transaction GUID.
170
+ * @param {string} pAsyncOperationHash - The hash of the async operation.
171
+ *
172
+ * @return {boolean} - Returns true if the async operation was found and marked as complete, otherwise false.
173
+ */
174
+ eventTransactionAsyncOperationComplete(pTransactionGUID: string, pAsyncOperationHash: string): boolean;
175
+ /**
176
+ * @param {string} pTransactionGUID - The transaction GUID.
177
+ *
178
+ * @return {boolean} - Returns true if the transaction was found and able to be finalized, otherwise false.
179
+ */
180
+ finalizeTransaction(pTransactionGUID: string): boolean;
181
+ /**
182
+ * @param {string} pTransactionGUID - The transaction GUID.
183
+ * @param {Function} fCallback - The callback to call when the transaction is complete.
184
+ */
185
+ registerOnTransactionCompleteCallback(pTransactionGUID: string, fCallback: Function): void;
163
186
  /**
164
187
  * Returns whether the object is a Pict Metacontroller.
165
188
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Pict-View-Form-Metacontroller.d.ts","sourceRoot":"","sources":["../../../source/views/Pict-View-Form-Metacontroller.js"],"names":[],"mappings":";AASA;;GAEG;AAEH;;;;;;GAMG;AACH;IAEC,2DAaC;IALA,yBAA2B;IAE3B,wBAAsF;IAEtF,cAAkC;IAQnC,wCAGC;IARD,kCAGC;IAOD;;;;OAIG;IACH,qBAFa,GAAG,CAaf;IAED;;;;OAIG;IACH,mBAFa,GAAG,CAaf;IAED,yCAYC;IAED;;;;;OAKG;IACH,kCAHW,aAAa,GACX,IAAI,CAsBhB;IAwBD;;;;OAIG;IACH,WAFa,GAAG,CAMf;IAED,gDAGC;IAED,+CAGC;IAED;;;;OAIG;IACH,2DAJW,MAAM,GAEL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAW9B;IAED;;;OAGG;IACH,0BAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,sBACnB,MAAM,QAiChB;IAED;;;;;;;;;OASG;IACH,kCALW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,UACnB,MAAM,GAEL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAsC9B;IAED;;;;OAIG;IACH,uCAJW,KAAK,CAAC,MAAM,CAAC,sBACb,MAAM,UACN,MAAM,QAahB;IAED;;;OAGG;IACH,6CAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,sBACnB,MAAM,SAehB;IAED;;;;;;;;OAQG;IACH,wDAHW,YAAY,SAoHtB;IAED;;;;;;;OAOG;IACH,4CAHW,MAAM,GACJ,IAAI,CAShB;IAED;;;;OAIG;IACH,6BAFa,IAAI,CAQhB;IAED;;;;;;;OAOG;IACH,+DAFW,YAAY,QAatB;IAED;;;;;OAKG;IACH,8EAFW,YAAY,QAmBtB;IAED;;;;;;OAMG;IACH,oEAHW,YAAY,GACV,IAAI,CAkDhB;IAED;;;;;;;OAOG;IACH,uEAJW,YAAY,GAEX,IAAI,CAsFf;IAED;;;;;OAKG;IACH,qCAHW,MAAM,GACJ,MAAM,GAAC,OAAO,CA2C1B;IAED,+CAeC;IAED;;;;;;;OAOG;IACH,kFAJW,MAAM,GAEJ,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAoLtC;IA5JC,gCAA0D;IAC1D,yBAAiD;IA6JnD;;;;OAIG;IACH,gCAHW,MAAM,qBACN,MAAM,QA0BhB;IAED;;;;OAIG;IACH,4BAFa,OAAO,CAKnB;CACD;;;;;qCAGU,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;oBAh7BjB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,MAAM"}
1
+ {"version":3,"file":"Pict-View-Form-Metacontroller.d.ts","sourceRoot":"","sources":["../../../source/views/Pict-View-Form-Metacontroller.js"],"names":[],"mappings":";AAaA;;GAEG;AAEH;;;;;;GAMG;AACH;IAEC,2DAaC;IALA,yBAA2B;IAE3B,wBAAsF;IAEtF,cAAkC;IAQnC,wCAGC;IARD,kCAGC;IAOD;;;;OAIG;IACH,qBAFa,GAAG,CAaf;IAED;;;;OAIG;IACH,mBAFa,GAAG,CAaf;IAED,yCAYC;IAED;;;;;OAKG;IACH,kCAHW,aAAa,GACX,IAAI,CAsBhB;IAwBD;;;;OAIG;IACH,WAFa,GAAG,CAMf;IAED,gDAGC;IAED,+CAGC;IAED;;;;OAIG;IACH,2DAJW,MAAM,GAEL,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAW9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