ngx-t-forms-types 0.0.35 → 0.0.36
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/dist/interfaces/Form/index.d.ts +2 -2
- package/dist/interfaces/FormBuilder/DefaultEelement.js +2 -2
- package/dist/interfaces/FormBuilder/inputConfig/ElementEditConfig.js +25 -3
- package/dist/interfaces/environment/IStoreFunctions.d.ts +42 -2
- package/dist/interfaces/environment/environment.d.ts +156 -0
- package/dist/interfaces/environment/environment.js +12 -1
- package/dist/interfaces/environment/index.d.ts +2 -2
- package/dist/interfaces/environment/index.js +2 -1
- package/dist/interfaces/formInput/BasicFormInputInterface.d.ts +15 -0
- package/dist/interfaces/formInput/calculatedFieldRules.d.ts +31 -1
- package/dist/interfaces/formInput/calculatedFieldRules.js +16 -1
- package/dist/interfaces/formInput/index.d.ts +2 -2
- package/dist/interfaces/formInput/index.js +2 -1
- package/dist/schemas/CalculatedFieldRulesSchema.js +2 -1
- package/dist/schemas/FormInputSchema.js +3 -1
- package/dist/schemas/tests/FormInputValidator.spec.js +27 -0
- package/dist/skillet/extra-members.d.ts +1 -1
- package/dist/skillet/input-members.d.ts +1 -1
- package/dist/skillet/input-members.js +1 -1
- package/dist/skillet/members/calculated-field.d.ts +4 -4
- package/dist/skillet/members/calculated-field.js +6 -5
- package/dist/skillet/members/table.d.ts +1 -1
- package/dist/skillet/shared-types.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NgxTFormsConfig } from "../environment/environment.js";
|
|
1
|
+
import { ImportTemplateConfig, NgxTFormsConfig } from "../environment/environment.js";
|
|
2
2
|
import { FormColumnInputs } from "../formInput/BasicFormInputInterface.js";
|
|
3
3
|
import { FormInterfaceMigration, IAllInputs, OLD_FormInterface } from "../upgradeFunctions/interfaces/init-form.js";
|
|
4
4
|
import { IArrayFunction } from "./ArrayFunctions.js";
|
|
@@ -9,5 +9,5 @@ import { IFormActions, InClassFormUtilsInterface, InClassFormUtilsWithSectionsIn
|
|
|
9
9
|
import { FormInterface, DatabaseFormInterface, MainFormInterface } from "./formInterface.js";
|
|
10
10
|
import { FormSubmissionHandleInterface, IReportDataSources } from "./formSubmissionHandleInterface.js";
|
|
11
11
|
import { FormListSection, FormStateErrors, IFormsInitStateInterface, LocalFormStateSelectorInterface } from "./IFormsInitStateInterface.js";
|
|
12
|
-
export { CustomConfigInterface, InClassFormUtilsInterface, InClassFormUtilsWithSectionsInterface, FormInterface, MainFormInterface, DatabaseFormInterface, FormSubmissionHandleInterface, FormColumnInputs, IFormActions, NgxTFormsConfig, FileUploadFn, FileData, FormListSection, LocalFormStateSelectorInterface, IFormsInitStateInterface, FormStateErrors, IArrayFunction, OLD_FormInterface, FormInterfaceMigration, IAllInputs, IFormChangeHistory, IReportDataSources };
|
|
12
|
+
export { CustomConfigInterface, InClassFormUtilsInterface, InClassFormUtilsWithSectionsInterface, FormInterface, MainFormInterface, DatabaseFormInterface, FormSubmissionHandleInterface, FormColumnInputs, IFormActions, NgxTFormsConfig, ImportTemplateConfig, FileUploadFn, FileData, FormListSection, LocalFormStateSelectorInterface, IFormsInitStateInterface, FormStateErrors, IArrayFunction, OLD_FormInterface, FormInterfaceMigration, IAllInputs, IFormChangeHistory, IReportDataSources };
|
|
13
13
|
export { FunctionTypes } from "./ArrayFunctions.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CurrenciesList } from "../../../Configs/currencies.js";
|
|
2
2
|
import { DatePipeOptions } from "../../../Configs/datePipes.js";
|
|
3
3
|
import { AdjudicationSteps, AutocompleteOptions, ElementTypes, InputDataTypes, InputPipeTypes, InputTypes } from "../../formInput/index.js";
|
|
4
|
+
import { ROUNDING_MODES, ROUNDING_MODE_LABELS } from "../../formInput/calculatedFieldRules.js";
|
|
4
5
|
import { DataSources } from "../../formInput/APIDataFetchingConfigurationInterface.js";
|
|
5
6
|
import { OptionSelectTypes } from "../../formInput/BasicFormInputInterface.js";
|
|
6
7
|
import { InputFileType } from "../../formInput/FileUploadInputInterface.js";
|
|
@@ -1130,8 +1131,8 @@ export var ElementConfig = {
|
|
|
1130
1131
|
{
|
|
1131
1132
|
name: SpecialElementKeys.Default,
|
|
1132
1133
|
editType: ElementEditorTypes.ChipSelect,
|
|
1133
|
-
label: '
|
|
1134
|
-
hint: "
|
|
1134
|
+
label: 'Number format',
|
|
1135
|
+
hint: "How the number is presented. Currency, decimal and integer also set the precision the value is kept at: it is rounded when typed, imported or calculated, and the rounded value is what is saved and shown. The other formats only change the display.",
|
|
1135
1136
|
deepBind: ['pipe', 'pipeType'],
|
|
1136
1137
|
additionalTest: [
|
|
1137
1138
|
{
|
|
@@ -1147,6 +1148,7 @@ export var ElementConfig = {
|
|
|
1147
1148
|
editType: ElementEditorTypes.OptionSelect,
|
|
1148
1149
|
deepBind: ['pipe', 'param'],
|
|
1149
1150
|
label: 'Select currency to apply',
|
|
1151
|
+
hint: "Amounts are kept to the currency's minor unit (2 decimals for ZAR) and rounded half to even — banker's rounding — unless you choose another rounding below.",
|
|
1150
1152
|
options: CurrenciesList,
|
|
1151
1153
|
id: "209d2295-cbaa-4f99-98d2-15c4515581b8",
|
|
1152
1154
|
additionalTest: [
|
|
@@ -1177,7 +1179,8 @@ export var ElementConfig = {
|
|
|
1177
1179
|
{
|
|
1178
1180
|
name: SpecialElementKeys.Default,
|
|
1179
1181
|
editType: ElementEditorTypes.Input,
|
|
1180
|
-
label: 'Decimal
|
|
1182
|
+
label: 'Decimal places',
|
|
1183
|
+
hint: 'How many decimal places to keep, for example 2. The value is rounded to this precision when typed, imported or calculated, and the rounded value is saved.',
|
|
1181
1184
|
deepBind: ['pipe', 'param'],
|
|
1182
1185
|
additionalTest: [
|
|
1183
1186
|
{
|
|
@@ -1191,6 +1194,25 @@ export var ElementConfig = {
|
|
|
1191
1194
|
],
|
|
1192
1195
|
id: "d0771f0e-eaec-457c-a2f4-e454fd9092c7"
|
|
1193
1196
|
},
|
|
1197
|
+
{
|
|
1198
|
+
name: SpecialElementKeys.Default,
|
|
1199
|
+
editType: ElementEditorTypes.ChipSelect,
|
|
1200
|
+
label: 'Rounding',
|
|
1201
|
+
hint: "Which way a value past the precision rounds. Banker's sends a tie (…5) to the even neighbour and is the default for currency; Nearest sends a tie away from zero and is the default otherwise; Round down and Round up always move toward the lower or the higher value.",
|
|
1202
|
+
deepBind: ['pipe', 'rounding'],
|
|
1203
|
+
options: ROUNDING_MODES.map((mode) => ({ label: ROUNDING_MODE_LABELS[mode], value: mode })),
|
|
1204
|
+
additionalTest: [
|
|
1205
|
+
{
|
|
1206
|
+
expression: `type === ${InputTypes.Number}`,
|
|
1207
|
+
deepBind: ['type'],
|
|
1208
|
+
},
|
|
1209
|
+
{
|
|
1210
|
+
expression: `pipeType === ${InputPipeTypes.Currency} || pipeType === ${InputPipeTypes.Decimal} || pipeType === ${InputPipeTypes.Integer}`,
|
|
1211
|
+
deepBind: ['pipe', 'pipeType'],
|
|
1212
|
+
},
|
|
1213
|
+
],
|
|
1214
|
+
id: "5f3c9b1e-2a74-4d08-b6e1-9c0d7a4f28e3"
|
|
1215
|
+
},
|
|
1194
1216
|
{
|
|
1195
1217
|
name: SpecialElementKeys.Default,
|
|
1196
1218
|
editType: ElementEditorTypes.Input,
|
|
@@ -6,7 +6,7 @@ import { FormListSection } from "../Form/IFormsInitStateInterface.js";
|
|
|
6
6
|
import { IUserSignature, PointGroup } from "../formInput/userSignature.js";
|
|
7
7
|
import { IWorkflowDocListCols, IWorkflowStepOption } from "../FormBuilder/workflowSelectionConfig.js";
|
|
8
8
|
import { IDocumentPage, IDocumentQueryRequest } from "../formInput/WorkflowDocumentPicker.js";
|
|
9
|
-
import {
|
|
9
|
+
import { GlobalVariables } from "./environment.js";
|
|
10
10
|
export interface DialogConfig {
|
|
11
11
|
title: string;
|
|
12
12
|
message: string;
|
|
@@ -49,7 +49,47 @@ export interface IStoreFunctions {
|
|
|
49
49
|
toastError: (message: string) => void;
|
|
50
50
|
workflows: () => Observable<IWorkflowOption[]>;
|
|
51
51
|
getWorkflowCols: (workflowId: string) => Observable<IWorkflowDocListCols[]>;
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Values the application injects into every form as read-only system inputs —
|
|
54
|
+
* the current financial cycle, the open transaction's id, the signed-in user's
|
|
55
|
+
* department, anything a form may need to read or a formula may need to use
|
|
56
|
+
* without asking the user for it. Replaces `getFinacialCycles`, which fixed
|
|
57
|
+
* the set of variables to financial cycles.
|
|
58
|
+
*
|
|
59
|
+
* Each entry becomes one system input whose control name is the key, placed in
|
|
60
|
+
* the form's first section and listed in the builder's pickers under a
|
|
61
|
+
* "System:" label, so an author can reference it in formulas, conditions,
|
|
62
|
+
* required-input rules and submission payloads like any other control.
|
|
63
|
+
*
|
|
64
|
+
* Keys are control names: letters, digits and underscores, not starting with a
|
|
65
|
+
* digit (`^[A-Za-z_][A-Za-z0-9_]*$`). Prefer SCREAMING_SNAKE_CASE — an authored
|
|
66
|
+
* control is lowerCamelCase, so the two can never collide. A key an open form
|
|
67
|
+
* already uses for an authored control is not injected: the authored control
|
|
68
|
+
* wins. A key outside the pattern is not injected either.
|
|
69
|
+
*
|
|
70
|
+
* Values decide the input: a `Date` or a `DateLike` (a Moment, a Day.js
|
|
71
|
+
* instance — anything with `toDate()`) becomes a date picker; a number a
|
|
72
|
+
* number input; a boolean a toggle; a string a text input. `null`,
|
|
73
|
+
* `undefined`, an empty string, a non-finite number and an invalid date mean
|
|
74
|
+
* "no value" and the input is not injected. Nested objects and arrays are not
|
|
75
|
+
* accepted — a system input is a single form control.
|
|
76
|
+
*
|
|
77
|
+
* The engine reads the FIRST emission when a form initialises and keeps it for
|
|
78
|
+
* that form's life; the builder follows every emission. The observable must
|
|
79
|
+
* emit at least once or the form never finishes initialising. A failure is
|
|
80
|
+
* tolerated: the form renders with no system inputs.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* getGlobalVariables: () =>
|
|
84
|
+
* combineLatest([org$, route$]).pipe(map(([org, route]) => ({
|
|
85
|
+
* CURRENT_FINANCIAL_CYCLE: org.cycleLabel, // text
|
|
86
|
+
* CURRENT_FINANCIAL_CYCLE_START_DATE: org.cycleStart, // Moment → date picker
|
|
87
|
+
* CURRENT_TRANSACTION_ID: route.docId, // null off the detail screen → not injected
|
|
88
|
+
* IS_PILOT_ORGANISATION: org.pilot, // toggle
|
|
89
|
+
* VAT_RATE: 0.15, // number
|
|
90
|
+
* })))
|
|
91
|
+
*/
|
|
92
|
+
getGlobalVariables: () => Observable<GlobalVariables>;
|
|
53
93
|
getCurrentFormAvailableInputOptions: () => Observable<Array<FormColumnInputs>>;
|
|
54
94
|
getSelectedDocument: (documentId: string) => Observable<any>;
|
|
55
95
|
getScoaTree: () => Observable<IGetTreeResponse>;
|
|
@@ -1,6 +1,39 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
1
2
|
import { IStoreFunctions } from "./IStoreFunctions.js";
|
|
2
3
|
import { Moment } from 'moment';
|
|
3
4
|
import type { FormSubmissionHandleInterface } from "../Form/formSubmissionHandleInterface.js";
|
|
5
|
+
import type { RoundingMode } from "../formInput/calculatedFieldRules.js";
|
|
6
|
+
/**
|
|
7
|
+
* Anything that yields a JavaScript `Date` — a Moment, a Day.js instance, or any
|
|
8
|
+
* object with a `toDate()` method. The library calls `toDate()` once and keeps
|
|
9
|
+
* the `Date` it returns; an invalid date (`NaN` time) counts as no value.
|
|
10
|
+
*/
|
|
11
|
+
export interface DateLike {
|
|
12
|
+
toDate(): Date;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* One value the application injects as a system input. Only scalars and dates:
|
|
16
|
+
* a system input is a form control the engine renders, so there is nothing a
|
|
17
|
+
* nested object or an array could become. `null` and `undefined` mean "no value"
|
|
18
|
+
* and the input is not injected at all.
|
|
19
|
+
*/
|
|
20
|
+
export type GlobalVariableValue = string | number | boolean | Date | DateLike | null | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Values the application injects into every form as read-only system inputs,
|
|
23
|
+
* keyed by control name. See `IStoreFunctions.getGlobalVariables` for the rules
|
|
24
|
+
* the keys and values follow and for how each entry becomes an input.
|
|
25
|
+
*/
|
|
26
|
+
export type GlobalVariables = Readonly<Record<string, GlobalVariableValue>>;
|
|
27
|
+
/**
|
|
28
|
+
* The financial-cycle variables the first consuming application injects.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated Since the `getGlobalVariables` contract the library no longer
|
|
31
|
+
* reads these keys by name: they are ordinary global variables like any other,
|
|
32
|
+
* and this shape is kept only so an application that still builds its
|
|
33
|
+
* financial-cycle bundle can type it. It is assignable to `GlobalVariables`
|
|
34
|
+
* (a `Moment` is a `DateLike`), so `getGlobalVariables` may return it as-is or
|
|
35
|
+
* spread it together with any other variables.
|
|
36
|
+
*/
|
|
4
37
|
export interface IFinancialCycles {
|
|
5
38
|
CURRENT_FINANCIAL_CYCLE: string;
|
|
6
39
|
CURRENT_FINANCIAL_CYCLE_START_DATE: Moment;
|
|
@@ -14,6 +47,94 @@ export interface IFinancialCycles {
|
|
|
14
47
|
PREVIOUS_FINANCIAL_CYCLE_START_DATE: Moment;
|
|
15
48
|
PREVIOUS_FINANCIAL_CYCLE_END_DATE: Moment;
|
|
16
49
|
}
|
|
50
|
+
/** Days a calendar week may start on, named the way the organisation schema names them. */
|
|
51
|
+
export declare const FORMS_WEEK_DAYS: readonly ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
|
|
52
|
+
/** One of {@link FORMS_WEEK_DAYS}. */
|
|
53
|
+
export type FormsWeekDay = (typeof FORMS_WEEK_DAYS)[number];
|
|
54
|
+
/**
|
|
55
|
+
* How a plain date is written wherever the library prints one — a table cell, a
|
|
56
|
+
* document-picker column, a printout, the calendar input. `locale` keeps each
|
|
57
|
+
* surface's own locale-appropriate default; the patterns are Angular date formats.
|
|
58
|
+
*/
|
|
59
|
+
export declare const FORMS_DATE_FORMATS: readonly ["locale", "dd/MM/yyyy", "MM/dd/yyyy", "yyyy-MM-dd", "d MMM yyyy"];
|
|
60
|
+
/** One of {@link FORMS_DATE_FORMATS}. */
|
|
61
|
+
export type FormsDateFormat = (typeof FORMS_DATE_FORMATS)[number];
|
|
62
|
+
/** The clock a time of day is written in. `locale` lets the locale decide. */
|
|
63
|
+
export declare const FORMS_TIME_FORMATS: readonly ["locale", "24h", "12h"];
|
|
64
|
+
/** One of {@link FORMS_TIME_FORMATS}. */
|
|
65
|
+
export type FormsTimeFormat = (typeof FORMS_TIME_FORMATS)[number];
|
|
66
|
+
/** How a currency is named next to an amount: its symbol (`R`), the narrow symbol, or the code (`ZAR`). */
|
|
67
|
+
export declare const FORMS_CURRENCY_DISPLAYS: readonly ["symbol", "narrowSymbol", "code"];
|
|
68
|
+
/** One of {@link FORMS_CURRENCY_DISPLAYS}. */
|
|
69
|
+
export type FormsCurrencyDisplay = (typeof FORMS_CURRENCY_DISPLAYS)[number];
|
|
70
|
+
/** Money, as the consuming application keeps it. See {@link NgxTFormsLocalization.currency}. */
|
|
71
|
+
export interface NgxTFormsCurrencyLocalization {
|
|
72
|
+
/**
|
|
73
|
+
* ISO 4217 code, upper case, e.g. `ZAR`. The builder writes it into `pipe.param`
|
|
74
|
+
* the moment an author sets a number's format to currency (the form schema
|
|
75
|
+
* requires a code), so the column is in the organisation's money without a
|
|
76
|
+
* further pick; the author can still choose another currency. It is also the
|
|
77
|
+
* code every amount is formatted in when a stored column names none. Default `ZAR`.
|
|
78
|
+
*/
|
|
79
|
+
code?: string;
|
|
80
|
+
/** How the currency is written next to the amount. Default `symbol`. */
|
|
81
|
+
display?: FormsCurrencyDisplay;
|
|
82
|
+
/**
|
|
83
|
+
* Fraction digits amounts in `code` are kept and shown at, 0–4. Unset → the
|
|
84
|
+
* currency's minor unit (`ZAR` 2, `JPY` 0, read from `Intl`). Applies to a column
|
|
85
|
+
* in this currency only; a column whose author picked another currency keeps that
|
|
86
|
+
* currency's minor unit. A column's own calculated-field precision still wins.
|
|
87
|
+
*/
|
|
88
|
+
decimals?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Rounding strategy for a currency column whose author chose none. Default
|
|
91
|
+
* `HALF_EVEN` (banker's). The organisation schema's `halfExpand` is `ROUND` here.
|
|
92
|
+
*/
|
|
93
|
+
rounding?: RoundingMode;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Regional rules the library presents and keeps values under. Codes are the
|
|
97
|
+
* platform standards (`Intl` accepts them as-is). Every member is optional and an
|
|
98
|
+
* unreadable value falls back to the library default, so a half-typed admin setting
|
|
99
|
+
* never breaks a form.
|
|
100
|
+
*/
|
|
101
|
+
export interface NgxTFormsLocalization {
|
|
102
|
+
/**
|
|
103
|
+
* BCP 47 tag, e.g. `en-ZA` — digit grouping, decimal mark, month names and the
|
|
104
|
+
* calendar input's own format. Default `en-ZA`. Angular ships only English data:
|
|
105
|
+
* register anything else with `registerLocaleData`, or amounts format as `en-US`.
|
|
106
|
+
*/
|
|
107
|
+
locale?: string;
|
|
108
|
+
/**
|
|
109
|
+
* IANA zone, e.g. `Africa/Johannesburg`, that times of day are displayed in.
|
|
110
|
+
* Unset → the browser's zone. Calendar days are never moved: a date-only value
|
|
111
|
+
* prints as the day it was captured whatever the zone.
|
|
112
|
+
*/
|
|
113
|
+
timeZone?: string;
|
|
114
|
+
/** The day the calendar grid starts on. Unset → the locale's own. */
|
|
115
|
+
firstDayOfWeek?: FormsWeekDay;
|
|
116
|
+
/** How plain dates are written. Default `locale`. */
|
|
117
|
+
dateFormat?: FormsDateFormat;
|
|
118
|
+
/** The clock times of day are written in. Default `locale`. */
|
|
119
|
+
timeFormat?: FormsTimeFormat;
|
|
120
|
+
/** Money. */
|
|
121
|
+
currency?: NgxTFormsCurrencyLocalization;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Either a fixed localization or a stream of it. An application whose organisation
|
|
125
|
+
* loads after bootstrap, or can be switched, hands the library the stream; the
|
|
126
|
+
* library follows every emission and uses its defaults until the first one.
|
|
127
|
+
*/
|
|
128
|
+
export type NgxTFormsLocalizationSource = NgxTFormsLocalization | Observable<NgxTFormsLocalization>;
|
|
129
|
+
/** Tuning for the spreadsheet import template — see `NgxTFormsConfig.importTemplate`. */
|
|
130
|
+
export interface ImportTemplateConfig {
|
|
131
|
+
/**
|
|
132
|
+
* The most options the template lists for one choice input — a select's options, a table's
|
|
133
|
+
* rows, a document picker's transactions (most recent first). A longer list is cut to this
|
|
134
|
+
* many and marked partial; the import still accepts anything the form offers. Default 500.
|
|
135
|
+
*/
|
|
136
|
+
maxOptionsPerInput?: number;
|
|
137
|
+
}
|
|
17
138
|
export interface NgxTFormsConfig {
|
|
18
139
|
base_url?: string;
|
|
19
140
|
formBuilder: IStoreFunctions;
|
|
@@ -49,5 +170,40 @@ export interface NgxTFormsConfig {
|
|
|
49
170
|
* })
|
|
50
171
|
*/
|
|
51
172
|
defaultSubmissionHandle?: FormSubmissionHandleInterface;
|
|
173
|
+
/**
|
|
174
|
+
* Tuning for the spreadsheet import template `TFormImportController.buildFormImportTemplate`
|
|
175
|
+
* builds. Omit it for the defaults.
|
|
176
|
+
*/
|
|
177
|
+
importTemplate?: ImportTemplateConfig;
|
|
178
|
+
/**
|
|
179
|
+
* Regional rules the library presents and keeps values under: the currency a
|
|
180
|
+
* money column defaults to (and is pre-selected with in the builder), the locale
|
|
181
|
+
* amounts and dates are written in, the zone times of day are shown in, the day the
|
|
182
|
+
* calendar starts on, and the date and time formats. Omit it for the library
|
|
183
|
+
* defaults — `en-ZA`, `ZAR`, the browser's zone — which are exactly what the
|
|
184
|
+
* library did before this member existed.
|
|
185
|
+
*
|
|
186
|
+
* Pass an `Observable` when the values come from the signed-in organisation: the
|
|
187
|
+
* token is bound once at bootstrap, long before the organisation is known.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* provideNgxTForms({
|
|
191
|
+
* formBuilder: myStoreFunctions,
|
|
192
|
+
* localization: orgSettings$.pipe(map(({ localization, currencyFormat }) => ({
|
|
193
|
+
* locale: localization.locale,
|
|
194
|
+
* timeZone: localization.timeZone,
|
|
195
|
+
* firstDayOfWeek: localization.firstDayOfWeek,
|
|
196
|
+
* dateFormat: localization.dateFormat,
|
|
197
|
+
* timeFormat: localization.timeFormat,
|
|
198
|
+
* currency: {
|
|
199
|
+
* code: currencyFormat.currencyCode,
|
|
200
|
+
* display: currencyFormat.display,
|
|
201
|
+
* decimals: currencyFormat.decimals,
|
|
202
|
+
* rounding: currencyFormat.rounding === 'halfExpand' ? 'ROUND' : 'HALF_EVEN',
|
|
203
|
+
* },
|
|
204
|
+
* }))),
|
|
205
|
+
* })
|
|
206
|
+
*/
|
|
207
|
+
localization?: NgxTFormsLocalizationSource;
|
|
52
208
|
[key: string]: string | Object | undefined;
|
|
53
209
|
}
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/** Days a calendar week may start on, named the way the organisation schema names them. */
|
|
2
|
+
export const FORMS_WEEK_DAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
|
|
3
|
+
/**
|
|
4
|
+
* How a plain date is written wherever the library prints one — a table cell, a
|
|
5
|
+
* document-picker column, a printout, the calendar input. `locale` keeps each
|
|
6
|
+
* surface's own locale-appropriate default; the patterns are Angular date formats.
|
|
7
|
+
*/
|
|
8
|
+
export const FORMS_DATE_FORMATS = ['locale', 'dd/MM/yyyy', 'MM/dd/yyyy', 'yyyy-MM-dd', 'd MMM yyyy'];
|
|
9
|
+
/** The clock a time of day is written in. `locale` lets the locale decide. */
|
|
10
|
+
export const FORMS_TIME_FORMATS = ['locale', '24h', '12h'];
|
|
11
|
+
/** How a currency is named next to an amount: its symbol (`R`), the narrow symbol, or the code (`ZAR`). */
|
|
12
|
+
export const FORMS_CURRENCY_DISPLAYS = ['symbol', 'narrowSymbol', 'code'];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ActionButton, BasisValidationError, DialogConfig, IStoreFunctions, MscoaValuetValidationErrors } from "./IStoreFunctions.js";
|
|
2
|
-
import { IFinancialCycles } from "./environment.js";
|
|
3
|
-
export { IStoreFunctions, ActionButton, DialogConfig, IFinancialCycles, MscoaValuetValidationErrors, BasisValidationError, };
|
|
2
|
+
import { DateLike, FORMS_CURRENCY_DISPLAYS, FORMS_DATE_FORMATS, FORMS_TIME_FORMATS, FORMS_WEEK_DAYS, FormsCurrencyDisplay, FormsDateFormat, FormsTimeFormat, FormsWeekDay, GlobalVariables, GlobalVariableValue, IFinancialCycles, NgxTFormsCurrencyLocalization, NgxTFormsLocalization, NgxTFormsLocalizationSource } from "./environment.js";
|
|
3
|
+
export { IStoreFunctions, FORMS_CURRENCY_DISPLAYS, FORMS_DATE_FORMATS, FORMS_TIME_FORMATS, FORMS_WEEK_DAYS, FormsCurrencyDisplay, FormsDateFormat, FormsTimeFormat, FormsWeekDay, NgxTFormsCurrencyLocalization, NgxTFormsLocalization, NgxTFormsLocalizationSource, ActionButton, DialogConfig, IFinancialCycles, DateLike, GlobalVariables, GlobalVariableValue, MscoaValuetValidationErrors, BasisValidationError, };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { FORMS_CURRENCY_DISPLAYS, FORMS_DATE_FORMATS, FORMS_TIME_FORMATS, FORMS_WEEK_DAYS, } from "./environment.js";
|
|
2
|
+
export { FORMS_CURRENCY_DISPLAYS, FORMS_DATE_FORMATS, FORMS_TIME_FORMATS, FORMS_WEEK_DAYS, };
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export type MatFormFieldAppearance = 'fill' | 'outline';
|
|
7
7
|
import { IFileUploadInput, IMatrixInput, IScoaInput, IMultiple, IToggleInput, IWorkflowAdjudicationInput } from ".";
|
|
8
8
|
import { ConditionalInputRule } from "./ConditionalInputRule.js";
|
|
9
|
+
import type { RoundingMode } from "./calculatedFieldRules.js";
|
|
9
10
|
import { IDateRangePickerInput } from "./DateRangePickerInput.js";
|
|
10
11
|
import { FormControlCustomValidatorsInterface } from "./FormControlCustomValidatorsInterface.js";
|
|
11
12
|
import { MatDataOptionsInterface } from "./MatDataOptionsInterface.js";
|
|
@@ -121,9 +122,23 @@ export interface IBasicFormInput extends IFormElementTemplate {
|
|
|
121
122
|
readonly?: boolean;
|
|
122
123
|
id: string;
|
|
123
124
|
sectionId: string;
|
|
125
|
+
/**
|
|
126
|
+
* Number / date presentation, and for the numeric formats the precision the
|
|
127
|
+
* value is kept at.
|
|
128
|
+
*
|
|
129
|
+
* `currency`, `decimal` and `integer` round the value itself — typed,
|
|
130
|
+
* imported, seeded or calculated — to their precision, so what is saved is
|
|
131
|
+
* what is shown: currency to the currency's minor unit (2 for ZAR) with
|
|
132
|
+
* `HALF_EVEN` unless `rounding` says otherwise; `decimal` to `param`
|
|
133
|
+
* places (a plain integer such as `"2"`); `integer` to none. Every other
|
|
134
|
+
* pipe type is presentation only and leaves the stored value unchanged.
|
|
135
|
+
*/
|
|
124
136
|
pipe?: {
|
|
125
137
|
pipeType: InputPipeTypes;
|
|
138
|
+
/** Currency code for `currency`, decimal places for `decimal`, date format for `date` / `time`. */
|
|
126
139
|
param: string;
|
|
140
|
+
/** Rounding strategy for the numeric formats. Unset → `HALF_EVEN` for `currency`, `ROUND` otherwise. */
|
|
141
|
+
rounding?: RoundingMode;
|
|
127
142
|
};
|
|
128
143
|
hintLabel?: string;
|
|
129
144
|
temporaryHint?: string;
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import { calculationVariableInterface } from "./calculationVariableInterface.js";
|
|
2
|
+
/**
|
|
3
|
+
* Every rounding strategy the library understands, in the order the editors
|
|
4
|
+
* list them.
|
|
5
|
+
*
|
|
6
|
+
* One list backs the {@link RoundingMode} type, the Joi schemas, the Skillet
|
|
7
|
+
* enumeration and both editors (the calculated-field rules editor and the
|
|
8
|
+
* number pipe), so a strategy added here reaches every surface at once.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ROUNDING_MODES: readonly ["ROUND", "FLOOR", "CEIL", "HALF_EVEN"];
|
|
11
|
+
/**
|
|
12
|
+
* How a numeric value is rounded at its precision.
|
|
13
|
+
*
|
|
14
|
+
* - `ROUND` — nearest; a tie (…5) rounds away from zero: 2.345 → 2.35, −2.345 → −2.35.
|
|
15
|
+
* - `FLOOR` — down, toward −∞: 2.349 → 2.34, −2.341 → −2.35.
|
|
16
|
+
* - `CEIL` — up, toward +∞: 2.341 → 2.35, −2.349 → −2.34.
|
|
17
|
+
* - `HALF_EVEN` — banker's rounding (IEEE 754 roundTiesToEven); a tie rounds to
|
|
18
|
+
* the even neighbour: 2.345 → 2.34, 2.355 → 2.36. The default for currency,
|
|
19
|
+
* because it does not drift a column of totals upward.
|
|
20
|
+
*/
|
|
21
|
+
export type RoundingMode = (typeof ROUNDING_MODES)[number];
|
|
22
|
+
/** Editor label for each {@link RoundingMode}. */
|
|
23
|
+
export declare const ROUNDING_MODE_LABELS: Record<RoundingMode, string>;
|
|
2
24
|
export interface CalculatedFieldRules {
|
|
3
25
|
formula: string;
|
|
4
26
|
variables: calculationVariableInterface[];
|
|
27
|
+
/**
|
|
28
|
+
* Decimal places the result is rounded to. Unset → the column's number format
|
|
29
|
+
* (`pipe`) decides; with neither, the result is not rounded.
|
|
30
|
+
*/
|
|
5
31
|
decimalPlaces?: number;
|
|
6
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Rounding strategy at `decimalPlaces`. Unset → `HALF_EVEN` for a column whose
|
|
34
|
+
* number format is currency, `ROUND` otherwise.
|
|
35
|
+
*/
|
|
36
|
+
roundingMode?: RoundingMode;
|
|
7
37
|
getFormulaFromAFormInput?: boolean;
|
|
8
38
|
formControlWithFormula?: string;
|
|
9
39
|
}
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Every rounding strategy the library understands, in the order the editors
|
|
3
|
+
* list them.
|
|
4
|
+
*
|
|
5
|
+
* One list backs the {@link RoundingMode} type, the Joi schemas, the Skillet
|
|
6
|
+
* enumeration and both editors (the calculated-field rules editor and the
|
|
7
|
+
* number pipe), so a strategy added here reaches every surface at once.
|
|
8
|
+
*/
|
|
9
|
+
export const ROUNDING_MODES = ['ROUND', 'FLOOR', 'CEIL', 'HALF_EVEN'];
|
|
10
|
+
/** Editor label for each {@link RoundingMode}. */
|
|
11
|
+
export const ROUNDING_MODE_LABELS = {
|
|
12
|
+
ROUND: 'Nearest',
|
|
13
|
+
FLOOR: 'Round down',
|
|
14
|
+
CEIL: 'Round up',
|
|
15
|
+
HALF_EVEN: "Banker's (half to even)",
|
|
16
|
+
};
|
|
@@ -21,9 +21,9 @@ import { ITextareaProperties } from "./TextAreaInput.js";
|
|
|
21
21
|
import { IToggleInput } from "./ToggleInputInterface.js";
|
|
22
22
|
import { AdjResponseReviewColumnMapping, AdjudicationSteps, IWorkflowAdjudicationInput, WorkflowAdjudicationMicroFlowReviewValue, WorkflowAdjudicationResponseElectedSupplierSelectionValue, WorkflowAdjudicationScoreSheetValue } from "./WorkflowAdjudication.js";
|
|
23
23
|
import { DOCUMENT_PICKER_FILTER_OPERATORS, DOCUMENT_PICKER_FILTER_VALUE_SOURCES, DOCUMENT_PICKER_FILTER_VALUE_TYPES, DocumentPickerFilterOperator, DocumentPickerFilterValueSource, DocumentPickerFilterValueType, IDocumentPage, IDocumentPickerFilter, IDocumentQueryRequest, IDocumentReference, IWorkflowDocumentPicker, IWorkflowDocumentPickerConfig, IWorkflowDocumentStepFilter, workflowStepStatus } from "./WorkflowDocumentPicker.js";
|
|
24
|
-
import { CalculatedFieldRules } from "./calculatedFieldRules.js";
|
|
24
|
+
import { CalculatedFieldRules, ROUNDING_MODES, ROUNDING_MODE_LABELS, RoundingMode } from "./calculatedFieldRules.js";
|
|
25
25
|
import { CalculationFunctions, calculationVariableInterface } from "./calculationVariableInterface.js";
|
|
26
26
|
import { IRichTextEditor, RichTextEditorType } from "./RichTextEditorInput.js";
|
|
27
27
|
import { ValidationError, ValidationOptions } from "./schema.js";
|
|
28
28
|
import { IUserSignature } from "./userSignature.js";
|
|
29
|
-
export { ElementTypes, InputTypes, InputPipeTypes, AutocapitalizeOptions, AutocompleteOptions, InputDataTypes, MinInputTypes, IFormElementTemplate, IBasicFormInput, IFileUploadInput, ConditionalInputRule, IDateRangePickerInput, ITextareaProperties, IToggleInput, IMatrixInput, IMultiple, IMultipleInputCal, IScoaInput, TableConfigurationsInterface, TableColumnConfigInterface, FormControlCustomValidatorsInterface, InputObservedForChange, DraftFormControlCustomValidator, IFormValidationOverride, MinimumInputRequiredInterface, MinInputMapInput, CalculatedFieldRules, calculationVariableInterface, APIDataFetchingConfigurationInterface, PayloadTemplate, PayloadTemplateValue, RequestBodyMode, HeaderTemplate, HeaderTemplateValue, QueryTemplate, QueryTemplateValue, IGetTreeResponse, CalculationFunctions, TreeNode, IPostmanCollection, IFolderItem, FileUploadInputValueInterface, AllDocumentFileExtensions, AllImageFileExtensions, UploadTypes, InputFileType, IScoaAccount, IScoaInputConfig, ITableScoaSelectionRow, ScoaSegmentValue, ScoaSegmentValueBag, IIncludedSegmentConfig, AccountingBasis, DualCashExclusionMatchMode, IDualCashExclusionConfig, IDualCashExclusionRule, ScoaAccountTree, IUserSignature, ValidationOptions, ValidationError, MatDataOptionsInterface, MongoDbPipeLineConfigInterface, InputAPIDataId, FormInputBasicOptionInterface, ScoaInterface, ScoaInnerInput, IAccountSegmentTreeKeys, IWorkflowDocumentPicker, IWorkflowDocumentPickerConfig, IWorkflowDocumentStepFilter, IDocumentPickerFilter, IDocumentPage, IDocumentQueryRequest, IDocumentReference, DocumentPickerFilterOperator, DocumentPickerFilterValueSource, DocumentPickerFilterValueType, DOCUMENT_PICKER_FILTER_OPERATORS, DOCUMENT_PICKER_FILTER_VALUE_SOURCES, DOCUMENT_PICKER_FILTER_VALUE_TYPES, workflowStepStatus, IWorkflowDocListCols, IWorkflowStepOption, JsDataTypes, AdjudicationSteps, IWorkflowAdjudicationInput, WorkflowAdjudicationScoreSheetValue, WorkflowAdjudicationMicroFlowReviewValue, WorkflowAdjudicationResponseElectedSupplierSelectionValue, ScoreSheetItem, AdjResponseReviewColumnMapping, OptionSelectTypes, ISelectInputInterface, MultipleInputAvailableOperations, RichTextEditorType, IRichTextEditor, };
|
|
29
|
+
export { ElementTypes, InputTypes, InputPipeTypes, AutocapitalizeOptions, AutocompleteOptions, InputDataTypes, MinInputTypes, IFormElementTemplate, IBasicFormInput, IFileUploadInput, ConditionalInputRule, IDateRangePickerInput, ITextareaProperties, IToggleInput, IMatrixInput, IMultiple, IMultipleInputCal, IScoaInput, TableConfigurationsInterface, TableColumnConfigInterface, FormControlCustomValidatorsInterface, InputObservedForChange, DraftFormControlCustomValidator, IFormValidationOverride, MinimumInputRequiredInterface, MinInputMapInput, CalculatedFieldRules, ROUNDING_MODES, ROUNDING_MODE_LABELS, RoundingMode, calculationVariableInterface, APIDataFetchingConfigurationInterface, PayloadTemplate, PayloadTemplateValue, RequestBodyMode, HeaderTemplate, HeaderTemplateValue, QueryTemplate, QueryTemplateValue, IGetTreeResponse, CalculationFunctions, TreeNode, IPostmanCollection, IFolderItem, FileUploadInputValueInterface, AllDocumentFileExtensions, AllImageFileExtensions, UploadTypes, InputFileType, IScoaAccount, IScoaInputConfig, ITableScoaSelectionRow, ScoaSegmentValue, ScoaSegmentValueBag, IIncludedSegmentConfig, AccountingBasis, DualCashExclusionMatchMode, IDualCashExclusionConfig, IDualCashExclusionRule, ScoaAccountTree, IUserSignature, ValidationOptions, ValidationError, MatDataOptionsInterface, MongoDbPipeLineConfigInterface, InputAPIDataId, FormInputBasicOptionInterface, ScoaInterface, ScoaInnerInput, IAccountSegmentTreeKeys, IWorkflowDocumentPicker, IWorkflowDocumentPickerConfig, IWorkflowDocumentStepFilter, IDocumentPickerFilter, IDocumentPage, IDocumentQueryRequest, IDocumentReference, DocumentPickerFilterOperator, DocumentPickerFilterValueSource, DocumentPickerFilterValueType, DOCUMENT_PICKER_FILTER_OPERATORS, DOCUMENT_PICKER_FILTER_VALUE_SOURCES, DOCUMENT_PICKER_FILTER_VALUE_TYPES, workflowStepStatus, IWorkflowDocListCols, IWorkflowStepOption, JsDataTypes, AdjudicationSteps, IWorkflowAdjudicationInput, WorkflowAdjudicationScoreSheetValue, WorkflowAdjudicationMicroFlowReviewValue, WorkflowAdjudicationResponseElectedSupplierSelectionValue, ScoreSheetItem, AdjResponseReviewColumnMapping, OptionSelectTypes, ISelectInputInterface, MultipleInputAvailableOperations, RichTextEditorType, IRichTextEditor, };
|
|
@@ -5,6 +5,7 @@ import { JsDataTypes, MinInputTypes } from "./MinimumInputRequiredInterface.js";
|
|
|
5
5
|
import { MultipleInputAvailableOperations } from "./MultipleInterface.js";
|
|
6
6
|
import { AdjudicationSteps } from "./WorkflowAdjudication.js";
|
|
7
7
|
import { DOCUMENT_PICKER_FILTER_OPERATORS, DOCUMENT_PICKER_FILTER_VALUE_SOURCES, DOCUMENT_PICKER_FILTER_VALUE_TYPES, workflowStepStatus, } from "./WorkflowDocumentPicker.js";
|
|
8
|
+
import { ROUNDING_MODES, ROUNDING_MODE_LABELS } from "./calculatedFieldRules.js";
|
|
8
9
|
import { CalculationFunctions } from "./calculationVariableInterface.js";
|
|
9
10
|
import { RichTextEditorType } from "./RichTextEditorInput.js";
|
|
10
11
|
// H-018b (Worker T-C): `OLD_FormInterface` and `FormInterfaceMigration` are
|
|
@@ -14,4 +15,4 @@ import { RichTextEditorType } from "./RichTextEditorInput.js";
|
|
|
14
15
|
// would otherwise trigger TS2300 "Duplicate identifier".
|
|
15
16
|
export {
|
|
16
17
|
///ENUMS
|
|
17
|
-
ElementTypes, InputTypes, InputPipeTypes, AutocapitalizeOptions, AutocompleteOptions, InputDataTypes, MinInputTypes, CalculationFunctions, AllDocumentFileExtensions, AllImageFileExtensions, UploadTypes, InputFileType, AccountingBasis, DOCUMENT_PICKER_FILTER_OPERATORS, DOCUMENT_PICKER_FILTER_VALUE_SOURCES, DOCUMENT_PICKER_FILTER_VALUE_TYPES, workflowStepStatus, JsDataTypes, AdjudicationSteps, OptionSelectTypes, MultipleInputAvailableOperations, RichTextEditorType, };
|
|
18
|
+
ElementTypes, InputTypes, InputPipeTypes, AutocapitalizeOptions, AutocompleteOptions, InputDataTypes, MinInputTypes, ROUNDING_MODES, ROUNDING_MODE_LABELS, CalculationFunctions, AllDocumentFileExtensions, AllImageFileExtensions, UploadTypes, InputFileType, AccountingBasis, DOCUMENT_PICKER_FILTER_OPERATORS, DOCUMENT_PICKER_FILTER_VALUE_SOURCES, DOCUMENT_PICKER_FILTER_VALUE_TYPES, workflowStepStatus, JsDataTypes, AdjudicationSteps, OptionSelectTypes, MultipleInputAvailableOperations, RichTextEditorType, };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Joi from 'joi';
|
|
2
|
+
import { ROUNDING_MODES } from '../interfaces/formInput/calculatedFieldRules.js';
|
|
2
3
|
const calculationVariableSchema = Joi.object({
|
|
3
4
|
formControlName: Joi.string().required(),
|
|
4
5
|
label: Joi.string().required(),
|
|
@@ -19,7 +20,7 @@ export const calculatedFieldRulesSchema = Joi.object({
|
|
|
19
20
|
variables: Joi.array().items(calculationVariableSchema).required(),
|
|
20
21
|
getFormulaFromAFormInput: Joi.boolean().optional(),
|
|
21
22
|
decimalPlaces: Joi.number().optional(),
|
|
22
|
-
roundingMode: Joi.string().valid(
|
|
23
|
+
roundingMode: Joi.string().valid(...ROUNDING_MODES).optional(),
|
|
23
24
|
formControlWithFormula: Joi.string().optional()
|
|
24
25
|
});
|
|
25
26
|
export function validateCalculatedFieldRules(value) {
|
|
@@ -7,6 +7,7 @@ import { AdjudicationSteps, AutocapitalizeOptions, AutocompleteOptions, ElementT
|
|
|
7
7
|
// import { calculatedFieldRulesSchema } from './CalculatedFieldRulesSchema.js';
|
|
8
8
|
// import { MatDataOptionsSchema } from './MatOptionsSchema.js';
|
|
9
9
|
import { formControlCustomValidatorSchema } from './customValidationSchema.js';
|
|
10
|
+
import { ROUNDING_MODES } from '../interfaces/formInput/calculatedFieldRules.js';
|
|
10
11
|
import { InputFileType } from '../interfaces/formInput/FileUploadInputInterface.js';
|
|
11
12
|
import { LabelPosition } from '../interfaces/formInput/ToggleInputInterface.js';
|
|
12
13
|
import { calculatedFieldRulesSchema } from './CalculatedFieldRulesSchema.js';
|
|
@@ -103,7 +104,8 @@ export const baseFormColumnInputsSchema = Joi.object({
|
|
|
103
104
|
[AllFormInputPrimaryKeys.Pipe]: Joi.object({
|
|
104
105
|
_id: Joi.string().optional(),
|
|
105
106
|
pipeType: Joi.string().valid(...Object.values(InputPipeTypes)).required(),
|
|
106
|
-
param: Joi.string().required()
|
|
107
|
+
param: Joi.string().required(),
|
|
108
|
+
rounding: Joi.string().valid(...ROUNDING_MODES).optional()
|
|
107
109
|
}).optional(),
|
|
108
110
|
[AllFormInputPrimaryKeys.Script]: Joi.object().optional(),
|
|
109
111
|
[AllFormInputPrimaryKeys.Validators]: Joi.array().items(Joi.alternatives().try(Joi.string(), formControlCustomValidatorSchema)).optional(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AllFormInputPrimaryKeys, } from '../../interfaces/FormBuilder/index.js';
|
|
2
2
|
import { ElementTypes, InputDataTypes, InputPipeTypes, InputTypes } from '../../interfaces/formInput/index.js';
|
|
3
|
+
import { validateCalculatedFieldRules } from '../CalculatedFieldRulesSchema.js';
|
|
3
4
|
import { formColumnInputsSchema } from '../FormInputSchema.js';
|
|
4
5
|
//ng test ngx-t-forms --include='projects/ngx-t-forms/src/lib/schemas/tests/FormInputValidator.spec.ts'
|
|
5
6
|
describe('FormInputValidator', () => {
|
|
@@ -60,4 +61,30 @@ describe('FormInputValidator', () => {
|
|
|
60
61
|
const result = formColumnInputsSchema.validate(invalidEnumInput);
|
|
61
62
|
expect(result.error).toBeDefined();
|
|
62
63
|
});
|
|
64
|
+
describe('number precision', () => {
|
|
65
|
+
const amount = (rounding) => ({
|
|
66
|
+
[AllFormInputPrimaryKeys.Element]: ElementTypes.Input,
|
|
67
|
+
[AllFormInputPrimaryKeys.ColSize]: 6,
|
|
68
|
+
[AllFormInputPrimaryKeys.Label]: 'Amount',
|
|
69
|
+
[AllFormInputPrimaryKeys.FormControlName]: 'amount',
|
|
70
|
+
[AllFormInputPrimaryKeys.Appearance]: 'outline',
|
|
71
|
+
[AllFormInputPrimaryKeys.Required]: false,
|
|
72
|
+
[AllFormInputPrimaryKeys.DataType]: InputDataTypes.Number,
|
|
73
|
+
[AllFormInputPrimaryKeys.Type]: InputTypes.Number,
|
|
74
|
+
[AllFormInputPrimaryKeys.Pipe]: { pipeType: InputPipeTypes.Currency, param: 'ZAR', rounding },
|
|
75
|
+
});
|
|
76
|
+
it('accepts every rounding strategy on the number pipe', () => {
|
|
77
|
+
for (const rounding of ['ROUND', 'FLOOR', 'CEIL', 'HALF_EVEN']) {
|
|
78
|
+
expect(formColumnInputsSchema.validate(amount(rounding)).error).toBeUndefined();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
it('rejects a rounding strategy the library does not know', () => {
|
|
82
|
+
expect(formColumnInputsSchema.validate(amount('HALF_DOWN')).error).toBeDefined();
|
|
83
|
+
});
|
|
84
|
+
it('accepts banker\'s rounding on calculated-field rules', () => {
|
|
85
|
+
const rules = { formula: '{a} * 2', variables: [], decimalPlaces: 2, roundingMode: 'HALF_EVEN' };
|
|
86
|
+
expect(validateCalculatedFieldRules(rules).error).toBeUndefined();
|
|
87
|
+
expect(validateCalculatedFieldRules({ ...rules, roundingMode: 'TRUNCATE' }).error).toBeDefined();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
63
90
|
});
|
|
@@ -90,7 +90,7 @@ export declare const extraDraftMemberSchemas: {
|
|
|
90
90
|
tableCell: boolean | null;
|
|
91
91
|
}>>;
|
|
92
92
|
decimalPlaces: import("@hashbrownai/core/src/schema/base").SchemaForUnion<number | null>;
|
|
93
|
-
roundingMode: import("@hashbrownai/core/src/schema/base").SchemaForUnion<"FLOOR" | "CEIL" | "
|
|
93
|
+
roundingMode: import("@hashbrownai/core/src/schema/base").SchemaForUnion<"ROUND" | "FLOOR" | "CEIL" | "HALF_EVEN" | null>;
|
|
94
94
|
getFormulaFromAFormInput: import("@hashbrownai/core/src/schema/base").SchemaForUnion<boolean | null>;
|
|
95
95
|
formControlWithFormula: import("@hashbrownai/core/src/schema/base").SchemaForUnion<string | null>;
|
|
96
96
|
}>;
|
|
@@ -191,7 +191,7 @@ export declare const draftMemberSchemas: {
|
|
|
191
191
|
tableCell: boolean | null;
|
|
192
192
|
}>>;
|
|
193
193
|
decimalPlaces: import("@hashbrownai/core/src/schema/base").SchemaForUnion<number | null>;
|
|
194
|
-
roundingMode: import("@hashbrownai/core/src/schema/base").SchemaForUnion<"FLOOR" | "CEIL" | "
|
|
194
|
+
roundingMode: import("@hashbrownai/core/src/schema/base").SchemaForUnion<"ROUND" | "FLOOR" | "CEIL" | "HALF_EVEN" | null>;
|
|
195
195
|
getFormulaFromAFormInput: import("@hashbrownai/core/src/schema/base").SchemaForUnion<boolean | null>;
|
|
196
196
|
formControlWithFormula: import("@hashbrownai/core/src/schema/base").SchemaForUnion<string | null>;
|
|
197
197
|
}>;
|
|
@@ -166,7 +166,7 @@ export const inputMemberSchemas = {
|
|
|
166
166
|
[AllFormInputPrimaryKeys.Accept]: s.string(describe('Accepted upload types as an HTML accept attribute, for example ".pdf,.docx" or "image/*". Match it to the documents actually expected, and name the accepted types in the hint as well.', AllFormInputPrimaryKeys.Accept)),
|
|
167
167
|
[AllFormInputPrimaryKeys.HandleLabel]: s.string(describe("The text of the button that adds a row to an item list. Name the action — 'Add item', 'Add attendee' — not the default 'Add to list'.", AllFormInputPrimaryKeys.HandleLabel)),
|
|
168
168
|
// --- display transform ----------------------------------------------------
|
|
169
|
-
[AllFormInputPrimaryKeys.Pipe]: s.object(describe(
|
|
169
|
+
[AllFormInputPrimaryKeys.Pipe]: s.object(describe("How the value is presented: currency for an amount, percent for a rate, date for a date. The numeric formats also fix the precision the value is kept at — currency rounds to the currency's minor unit with banker's rounding, decimal to the given places, integer to none — and that rounded value is what is saved; every other format is presentation only.", AllFormInputPrimaryKeys.Pipe), {
|
|
170
170
|
pipeType: inputPipeTypeSchema,
|
|
171
171
|
param: s.string('The pipe argument, such as a date format like "dd MMM yyyy" or a currency code like "ZAR".'),
|
|
172
172
|
}),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { s } from '@hashbrownai/core';
|
|
2
|
-
import type
|
|
2
|
+
import { type CalculatedFieldRules } from '../../interfaces/formInput/calculatedFieldRules.js';
|
|
3
3
|
import { CalculationFunctions } from '../../interfaces/formInput/calculationVariableInterface.js';
|
|
4
4
|
/**
|
|
5
5
|
* The `calculatedFieldRules` member: a value computed from other fields rather
|
|
@@ -43,8 +43,8 @@ import { CalculationFunctions } from '../../interfaces/formInput/calculationVari
|
|
|
43
43
|
* annotates the same `parentInputId` + `function` pair as "Multiple-input
|
|
44
44
|
* (list) bindings", which is the distinction drawn.
|
|
45
45
|
*/
|
|
46
|
-
/**
|
|
47
|
-
export declare const ROUNDING_MODE_VALUES: readonly ["FLOOR", "CEIL", "
|
|
46
|
+
/** The rounding strategies, from the one list `roundingMode` is typed by. */
|
|
47
|
+
export declare const ROUNDING_MODE_VALUES: readonly ["ROUND", "FLOOR", "CEIL", "HALF_EVEN"];
|
|
48
48
|
interface VariableCommonDraft {
|
|
49
49
|
/** The token this variable is referenced by inside `formula`. */
|
|
50
50
|
variable: string;
|
|
@@ -126,7 +126,7 @@ export declare const calculatedFieldRulesDraftSchema: s.ObjectType<{
|
|
|
126
126
|
tableCell: boolean | null;
|
|
127
127
|
}>>;
|
|
128
128
|
decimalPlaces: import("@hashbrownai/core/src/schema/base").SchemaForUnion<number | null>;
|
|
129
|
-
roundingMode: import("@hashbrownai/core/src/schema/base").SchemaForUnion<"FLOOR" | "CEIL" | "
|
|
129
|
+
roundingMode: import("@hashbrownai/core/src/schema/base").SchemaForUnion<"ROUND" | "FLOOR" | "CEIL" | "HALF_EVEN" | null>;
|
|
130
130
|
getFormulaFromAFormInput: import("@hashbrownai/core/src/schema/base").SchemaForUnion<boolean | null>;
|
|
131
131
|
formControlWithFormula: import("@hashbrownai/core/src/schema/base").SchemaForUnion<string | null>;
|
|
132
132
|
}>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { s } from '@hashbrownai/core';
|
|
2
|
+
import { ROUNDING_MODES } from '../../interfaces/formInput/calculatedFieldRules.js';
|
|
2
3
|
import { CalculationFunctions } from '../../interfaces/formInput/calculationVariableInterface.js';
|
|
3
|
-
import { enumValues,
|
|
4
|
+
import { enumValues, optional } from '../internal/coupling.js';
|
|
4
5
|
/**
|
|
5
6
|
* The `calculatedFieldRules` member: a value computed from other fields rather
|
|
6
7
|
* than typed by the user.
|
|
@@ -43,8 +44,8 @@ import { enumValues, exhaustive, optional } from '../internal/coupling.js';
|
|
|
43
44
|
* annotates the same `parentInputId` + `function` pair as "Multiple-input
|
|
44
45
|
* (list) bindings", which is the distinction drawn.
|
|
45
46
|
*/
|
|
46
|
-
/**
|
|
47
|
-
export const ROUNDING_MODE_VALUES =
|
|
47
|
+
/** The rounding strategies, from the one list `roundingMode` is typed by. */
|
|
48
|
+
export const ROUNDING_MODE_VALUES = ROUNDING_MODES;
|
|
48
49
|
// --- schema -----------------------------------------------------------------
|
|
49
50
|
const variableToken = s.string('The name this variable is referenced by inside the formula. Keep it short and lower case, and spell it identically in the formula.', { pattern: '^[a-zA-Z][a-zA-Z0-9_]*$' });
|
|
50
51
|
const variableLabel = s.string('A human-readable name for this variable, shown when the formula is explained back to an administrator.');
|
|
@@ -88,8 +89,8 @@ export const calculationVariableDraftSchema = s.anyOf([
|
|
|
88
89
|
export const calculatedFieldRulesDraftSchema = s.object('How this field computes its value from other fields on the form, so the user never types a figure the system can work out: a line total, VAT, an age. Whenever a total, average, minimum, maximum or count over an item list is used anywhere else — a decision gate, a validator, another formula, a list column, the next person — it must be a calculated field like this one on the form itself, aggregating the list; the roll-up shown beneath the list is for the user only.', {
|
|
89
90
|
formula: s.string('The arithmetic expression, written using the variable names declared below and nothing else. Every name in the formula must be declared as a variable, and every declared variable should appear in the formula.'),
|
|
90
91
|
variables: s.array('The fields the formula reads, one entry per variable name used in it.', calculationVariableDraftSchema, { minItems: 1 }),
|
|
91
|
-
decimalPlaces: optional(s.integer('How many decimal places the result is rounded to: 2 for money, 0 for a count.', { minimum: 0 })),
|
|
92
|
-
roundingMode: optional(s.enumeration("How the result is rounded at that precision
|
|
92
|
+
decimalPlaces: optional(s.integer('How many decimal places the result is rounded to: 2 for money, 0 for a count. The rounded result is what is saved and shown.', { minimum: 0 })),
|
|
93
|
+
roundingMode: optional(s.enumeration("How the result is rounded at that precision. 'HALF_EVEN' is banker's rounding (a tie goes to the even neighbour), the default for money and what a currency-formatted field uses when this is unset; 'ROUND' rounds a tie away from zero; 'FLOOR' or 'CEIL' only when the business rule says round down or up.", [...ROUNDING_MODE_VALUES])),
|
|
93
94
|
getFormulaFromAFormInput: optional(s.boolean('Whether the formula is read from another field on the form at runtime instead of being fixed here. Leave unset unless the form genuinely lets a user supply the formula.')),
|
|
94
95
|
formControlWithFormula: optional(s.string('The formControlName of the field supplying the formula. Only meaningful when the formula is read from a form input.')),
|
|
95
96
|
});
|
|
@@ -130,7 +130,7 @@ export declare const tableConfigSchema: s.ObjectType<{
|
|
|
130
130
|
tableCell: boolean | null;
|
|
131
131
|
}>>;
|
|
132
132
|
decimalPlaces: import("@hashbrownai/core/src/schema/base").SchemaForUnion<number | null>;
|
|
133
|
-
roundingMode: import("@hashbrownai/core/src/schema/base").SchemaForUnion<"FLOOR" | "CEIL" | "
|
|
133
|
+
roundingMode: import("@hashbrownai/core/src/schema/base").SchemaForUnion<"ROUND" | "FLOOR" | "CEIL" | "HALF_EVEN" | null>;
|
|
134
134
|
getFormulaFromAFormInput: import("@hashbrownai/core/src/schema/base").SchemaForUnion<boolean | null>;
|
|
135
135
|
formControlWithFormula: import("@hashbrownai/core/src/schema/base").SchemaForUnion<string | null>;
|
|
136
136
|
}>;
|
|
@@ -58,7 +58,7 @@ export const TEXTAREA_WRAP_VALUES = exhaustive()([
|
|
|
58
58
|
'soft',
|
|
59
59
|
]);
|
|
60
60
|
export const textareaWrapSchema = s.enumeration(describe("How a textarea wraps long lines when the form is submitted. 'soft' leaves the text unchanged; 'hard' inserts real newlines at the wrap points.", 'wrap'), [...TEXTAREA_WRAP_VALUES]);
|
|
61
|
-
export const inputPipeTypeSchema = s.enumeration(describe(
|
|
61
|
+
export const inputPipeTypeSchema = s.enumeration(describe("How the value is presented. 'currency', 'decimal' and 'integer' also round the stored value to their precision (currency with banker's rounding); the other transforms are presentation only.", 'pipe', 'pipeType'), enumValues(InputPipeTypes));
|
|
62
62
|
export const richTextEditorTypeSchema = s.enumeration(describe('Which rich-text editor library backs an editor element.', 'richTextEditorLibrary'), enumValues(RichTextEditorType));
|
|
63
63
|
export const inputFileTypeSchema = s.enumeration(describe("The kind of upload a file control accepts: 'file' for a document such as a quote, an invoice or a certificate; 'captureImage' for a photo taken on the phone camera; 'image' for a picture from disk.", 'fileType'), enumValues(InputFileType));
|
|
64
64
|
// --- Data sourcing ----------------------------------------------------------
|