@sankhyalabs/core 5.4.0 → 5.5.0
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/.docs/classes/Change.md +11 -11
- package/.docs/classes/DataUnit.md +88 -85
- package/.docs/classes/NumberUtils.md +45 -8
- package/.docs/classes/SelectionInfo.md +11 -11
- package/.docs/enums/ChangeOperation.md +4 -4
- package/.docs/enums/SelectionMode.md +2 -2
- package/.docs/interfaces/DUActionInterceptor.md +1 -1
- package/.docs/interfaces/PageRequest.md +3 -3
- package/.docs/interfaces/QuickFilter.md +3 -3
- package/.docs/interfaces/Record.md +4 -4
- package/.docs/interfaces/SavedRecord.md +5 -5
- package/.docs/interfaces/WaitingChange.md +3 -3
- package/dist/dataunit/DataUnit.d.ts +6 -3
- package/dist/dataunit/DataUnit.js +10 -7
- package/dist/dataunit/DataUnit.js.map +1 -1
- package/dist/utils/NumberUtils.d.ts +17 -1
- package/dist/utils/NumberUtils.js +21 -3
- package/dist/utils/NumberUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/dataunit/DataUnit.ts +10 -7
- package/src/utils/NumberUtils.ts +22 -4
|
@@ -22,12 +22,28 @@ export declare class NumberUtils {
|
|
|
22
22
|
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
23
23
|
* @param precision - Quantidade de casas decimais.
|
|
24
24
|
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
25
|
+
* @param defaultValue - Valor padrão caso o value não seja um valor numérico válido.
|
|
25
26
|
*
|
|
26
27
|
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
27
28
|
* @example
|
|
28
29
|
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
30
|
+
* Informado: (undefined, 3, 3) | Retorna: NaN
|
|
31
|
+
* Informado: (undefined, 3, 3, '0,00') | Retorna: 0,00
|
|
29
32
|
*/
|
|
30
|
-
static format: (value: string, precision: number, prettyPrecision?: number) => string;
|
|
33
|
+
static format: (value: string, precision: number, prettyPrecision?: number, defaultValue?: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Formata o numeral com a precisão informada e o valor default 0,00 caso o value não seja um numero valido.
|
|
36
|
+
*
|
|
37
|
+
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
38
|
+
* @param precision - Quantidade de casas decimais.
|
|
39
|
+
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
40
|
+
*
|
|
41
|
+
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
42
|
+
* @example
|
|
43
|
+
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
44
|
+
* Informado: (undefined, 3, 3) | Retorna: 0,00
|
|
45
|
+
*/
|
|
46
|
+
static safeFormat: (value: string, precision: number, prettyPrecision?: number) => string;
|
|
31
47
|
/**
|
|
32
48
|
* Retira os separadores de milhar de um numeral em formato de string.
|
|
33
49
|
*
|
|
@@ -105,18 +105,21 @@ NumberUtils.stringToNumber = (value) => {
|
|
|
105
105
|
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
106
106
|
* @param precision - Quantidade de casas decimais.
|
|
107
107
|
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
108
|
+
* @param defaultValue - Valor padrão caso o value não seja um valor numérico válido.
|
|
108
109
|
*
|
|
109
110
|
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
110
111
|
* @example
|
|
111
112
|
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
113
|
+
* Informado: (undefined, 3, 3) | Retorna: NaN
|
|
114
|
+
* Informado: (undefined, 3, 3, '0,00') | Retorna: 0,00
|
|
112
115
|
*/
|
|
113
|
-
NumberUtils.format = (value, precision, prettyPrecision = NaN) => {
|
|
116
|
+
NumberUtils.format = (value, precision, prettyPrecision = NaN, defaultValue = NaN.toString()) => {
|
|
114
117
|
if (value === '' || value === undefined || value === "NaN") {
|
|
115
|
-
return
|
|
118
|
+
return defaultValue;
|
|
116
119
|
}
|
|
117
120
|
const newValue = NumberUtils.stringToNumber(value);
|
|
118
121
|
if (isNaN(newValue)) {
|
|
119
|
-
return
|
|
122
|
+
return defaultValue;
|
|
120
123
|
}
|
|
121
124
|
//Validation "precision":
|
|
122
125
|
// Case1: precision < 0 => does not use precision
|
|
@@ -153,6 +156,21 @@ NumberUtils.format = (value, precision, prettyPrecision = NaN) => {
|
|
|
153
156
|
return newValueStr;
|
|
154
157
|
};
|
|
155
158
|
/**
|
|
159
|
+
* Formata o numeral com a precisão informada e o valor default 0,00 caso o value não seja um numero valido.
|
|
160
|
+
*
|
|
161
|
+
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
162
|
+
* @param precision - Quantidade de casas decimais.
|
|
163
|
+
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
164
|
+
*
|
|
165
|
+
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
166
|
+
* @example
|
|
167
|
+
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
168
|
+
* Informado: (undefined, 3, 3) | Retorna: 0,00
|
|
169
|
+
*/
|
|
170
|
+
NumberUtils.safeFormat = (value, precision, prettyPrecision = NaN) => {
|
|
171
|
+
return NumberUtils.format(value, precision, prettyPrecision, "0,00");
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
156
174
|
* Retira os separadores de milhar de um numeral em formato de string.
|
|
157
175
|
*
|
|
158
176
|
* @param value - Numeral em formato de string a ser convertido.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberUtils.js","sourceRoot":"","sources":["../../src/utils/NumberUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,mCAAmC,GAAW,qCAAqC,CAAC;AAE1F;;GAEG;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AAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;KACpC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAA;AAED;;;;;;;;;;EAUE;AACK,wBAAY,GAAG,CAAC,KAAa,EAAU,EAAE;IAC5C,0CAA0C;IAC1C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC7E,CAAC,CAAA;AAID;;;;;;;;;;;;;;EAcE;AACK,6BAAiB,GAAG,CAAC,KAAU,EAAE,YAAoB,EAAU,EAAE;IACpE,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IACvD,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAEtB,IAAI,KAAK,CAAC,KAAK,CAAC,EAAC;QACb,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC;KAC/B;IAED,OAAO,KAAK,CAAC;AAEjB,CAAC,CAAA;AAED;;;;;;EAME;AACM,0BAAc,GAAG,CAAC,KAAU,EAAU,EAAE;IAC5C,OAAO,WAAW,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;AACnD,CAAC,CAAA"}
|
package/package.json
CHANGED
package/src/dataunit/DataUnit.ts
CHANGED
|
@@ -447,11 +447,12 @@ export default class DataUnit {
|
|
|
447
447
|
* Remove o registro selecionado.
|
|
448
448
|
*
|
|
449
449
|
* @param buffered - Se será utilizado buffer na solicitação.
|
|
450
|
+
* @param silent - Define se haverá mensagem de confirmação da remoção
|
|
450
451
|
*
|
|
451
452
|
* @returns - ID's dos registros removidos.
|
|
452
453
|
*
|
|
453
454
|
*/
|
|
454
|
-
public async removeSelectedRecords(buffered: boolean = false): Promise<Array<string>> {
|
|
455
|
+
public async removeSelectedRecords(buffered: boolean = false, silent: boolean = false): Promise<Array<string>> {
|
|
455
456
|
const selection = this.getSelectionInfo();
|
|
456
457
|
if (selection) {
|
|
457
458
|
if(selection.isAllRecords()){
|
|
@@ -459,7 +460,7 @@ export default class DataUnit {
|
|
|
459
460
|
}
|
|
460
461
|
const records = selection?.records || [];
|
|
461
462
|
const recordIds = selection?.recordIds || [];
|
|
462
|
-
return this.removeRecords(recordIds, records, buffered);
|
|
463
|
+
return this.removeRecords(recordIds, records, buffered, undefined, silent);
|
|
463
464
|
}
|
|
464
465
|
return Promise.resolve([]);
|
|
465
466
|
}
|
|
@@ -472,16 +473,17 @@ export default class DataUnit {
|
|
|
472
473
|
* @param cachedRecords - Dados dos registros que serão removidos.
|
|
473
474
|
* @param buffered - Se será utilizado buffer na solicitação.
|
|
474
475
|
* @param executionCtx - Contexto de execução da remoção do registro do DataUnit.
|
|
476
|
+
* @param silent - Define se haverá mensagem de confirmação da remoção
|
|
475
477
|
*
|
|
476
478
|
* @returns - ID's dos registros removidos.
|
|
477
479
|
*
|
|
478
480
|
*/
|
|
479
|
-
public async removeRecords(recordIds: Array<string>, cachedRecords: Array<Record>, buffered: boolean = false, executionCtx?: ExecutionContext): Promise<Array<string>> {
|
|
481
|
+
public async removeRecords(recordIds: Array<string>, cachedRecords: Array<Record>, buffered: boolean = false, executionCtx?: ExecutionContext, silent: boolean = false): Promise<Array<string>> {
|
|
480
482
|
if (recordIds) {
|
|
481
483
|
if (buffered || !this.removeLoader) {
|
|
482
484
|
this.dispatchAction(Action.RECORDS_REMOVED, { records: recordIds, cachedRecords, buffered: true }, executionCtx);
|
|
483
485
|
} else {
|
|
484
|
-
if (await this.dispatchAction(Action.REMOVING_RECORDS,
|
|
486
|
+
if (await this.dispatchAction(Action.REMOVING_RECORDS, {silent}, executionCtx)) {
|
|
485
487
|
|
|
486
488
|
return new Promise((resolve, fail) => {
|
|
487
489
|
if (this.removeLoader) {
|
|
@@ -1111,13 +1113,14 @@ export default class DataUnit {
|
|
|
1111
1113
|
* Cancela edição do registro atual.
|
|
1112
1114
|
*
|
|
1113
1115
|
* @param executionCtx - Contexto de execução do cancelamento da seleção dos registros.
|
|
1116
|
+
* @param silent: Define se haverá mensagem de confirmação do cancelamento
|
|
1114
1117
|
*
|
|
1115
1118
|
*/
|
|
1116
|
-
public async cancelEdition(executionCtx?: ExecutionContext, fromParent?: boolean): Promise<boolean> {
|
|
1117
|
-
const cancelledAction = await this.dispatchAction(Action.EDITION_CANCELED, {fromParent}, executionCtx);
|
|
1119
|
+
public async cancelEdition(executionCtx?: ExecutionContext, fromParent?: boolean, silent: boolean = false): Promise<boolean> {
|
|
1120
|
+
const cancelledAction = await this.dispatchAction(Action.EDITION_CANCELED, {fromParent, silent}, executionCtx);
|
|
1118
1121
|
for (const [, dataUnit] of this._childByName) {
|
|
1119
1122
|
if(dataUnit.isDirty()){
|
|
1120
|
-
dataUnit.cancelEdition(undefined, true);
|
|
1123
|
+
dataUnit.cancelEdition(undefined, true, silent);
|
|
1121
1124
|
}
|
|
1122
1125
|
}
|
|
1123
1126
|
return Promise.resolve(cancelledAction);
|
package/src/utils/NumberUtils.ts
CHANGED
|
@@ -66,21 +66,24 @@ export class NumberUtils {
|
|
|
66
66
|
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
67
67
|
* @param precision - Quantidade de casas decimais.
|
|
68
68
|
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
69
|
+
* @param defaultValue - Valor padrão caso o value não seja um valor numérico válido.
|
|
69
70
|
*
|
|
70
71
|
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
71
72
|
* @example
|
|
72
73
|
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
74
|
+
* Informado: (undefined, 3, 3) | Retorna: NaN
|
|
75
|
+
* Informado: (undefined, 3, 3, '0,00') | Retorna: 0,00
|
|
73
76
|
*/
|
|
74
|
-
static format = (value: string, precision: number, prettyPrecision: number = NaN): string => {
|
|
77
|
+
static format = (value: string, precision: number, prettyPrecision: number = NaN, defaultValue:string = NaN.toString()): string => {
|
|
75
78
|
|
|
76
79
|
if (value === '' || value === undefined || value === "NaN") {
|
|
77
|
-
return
|
|
80
|
+
return defaultValue;
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
const newValue: number = NumberUtils.stringToNumber(value);
|
|
81
84
|
|
|
82
85
|
if (isNaN(newValue)) {
|
|
83
|
-
return
|
|
86
|
+
return defaultValue;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
//Validation "precision":
|
|
@@ -122,9 +125,24 @@ export class NumberUtils {
|
|
|
122
125
|
|
|
123
126
|
|
|
124
127
|
return newValueStr;
|
|
128
|
+
}
|
|
125
129
|
|
|
126
130
|
|
|
127
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Formata o numeral com a precisão informada e o valor default 0,00 caso o value não seja um numero valido.
|
|
133
|
+
*
|
|
134
|
+
* @param value - Numeral em formato de string a ser convertido (Importante: formato PT-BR ou já em formato numérico - sem separador de milhares: ######.##).
|
|
135
|
+
* @param precision - Quantidade de casas decimais.
|
|
136
|
+
* @param prettyPrecision - Quantidade de zeros nos decimais.
|
|
137
|
+
*
|
|
138
|
+
* @returns - Numeral em formato de String formatado em PT-BR.
|
|
139
|
+
* @example
|
|
140
|
+
* Informado: ('10,9845444', 3, 3) | Retorna: '10,985'
|
|
141
|
+
* Informado: (undefined, 3, 3) | Retorna: 0,00
|
|
142
|
+
*/
|
|
143
|
+
static safeFormat = (value: string, precision: number, prettyPrecision: number = NaN): string => {
|
|
144
|
+
return NumberUtils.format(value, precision, prettyPrecision, "0,00");
|
|
145
|
+
}
|
|
128
146
|
|
|
129
147
|
|
|
130
148
|
/**
|