@qrvey/utils 1.4.5 → 1.5.0-2
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/README.md +1 -1
- package/dist/cjs/column_format/constants/DURATION_PARTS_LIST.d.ts +1 -0
- package/dist/cjs/column_format/constants/DURATION_PARTS_LIST.js +12 -0
- package/dist/cjs/column_format/constants/index.d.ts +1 -0
- package/dist/cjs/column_format/constants/index.js +1 -0
- package/dist/cjs/column_format/helpers/defineXYChartFormat.js +4 -1
- package/dist/cjs/filters/constants/common/FILTER_TOKENS_STRUCTURE_TYPE.d.ts +8 -0
- package/dist/cjs/filters/constants/common/FILTER_TOKENS_STRUCTURE_TYPE.js +12 -0
- package/dist/cjs/filters/constants/common/index.d.ts +1 -0
- package/dist/cjs/filters/constants/common/index.js +1 -0
- package/dist/cjs/filters/helpers/filtersTokensToString.d.ts +7 -0
- package/dist/cjs/filters/helpers/filtersTokensToString.js +20 -0
- package/dist/cjs/filters/helpers/getTokensFromFilters.d.ts +10 -0
- package/dist/cjs/filters/helpers/getTokensFromFilters.js +116 -0
- package/dist/cjs/filters/helpers/getVerboseFilter.d.ts +9 -0
- package/dist/cjs/filters/helpers/getVerboseFilter.js +16 -0
- package/dist/cjs/filters/helpers/index.d.ts +3 -0
- package/dist/cjs/filters/helpers/index.js +3 -0
- package/dist/cjs/filters/interfaces/IFFilterTokens.d.ts +5 -0
- package/dist/cjs/filters/interfaces/IFFilterTokens.js +2 -0
- package/dist/cjs/filters/interfaces/IFTokensFromFiltersSettings.d.ts +7 -0
- package/dist/cjs/filters/interfaces/IFTokensFromFiltersSettings.js +2 -0
- package/dist/cjs/filters/interfaces/index.d.ts +2 -0
- package/dist/cjs/filters/interfaces/index.js +2 -0
- package/dist/cjs/format/definition.d.ts +2 -1
- package/dist/cjs/format/format.js +4 -1
- package/dist/cjs/format/localization.js +18 -2
- package/dist/cjs/globalization/interfaces/II18nResource.d.ts +2 -0
- package/dist/cjs/globalization/interfaces/chart_builder/II18nChartBuilderFormatValues.d.ts +1 -0
- package/dist/cjs/globalization/interfaces/chart_builder/II18nChartBuilderTableStyleOptions.d.ts +4 -0
- package/dist/cjs/globalization/interfaces/common/II18nCommon.d.ts +1 -0
- package/dist/cjs/globalization/interfaces/tabular_view/II18nTabularView.d.ts +4 -0
- package/dist/cjs/globalization/interfaces/tabular_view/II18nTabularView.js +2 -0
- package/dist/cjs/globalization/labels/I18N_DEFAULT.js +2 -0
- package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER.js +1 -0
- package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_COMPARISION_OPTIONS.js +1 -1
- package/dist/cjs/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +5 -1
- package/dist/cjs/globalization/labels/common/I18N_COMMON.js +1 -0
- package/dist/cjs/globalization/labels/tabular_view/I18N_TABULAR_VIEW.d.ts +2 -0
- package/dist/cjs/globalization/labels/tabular_view/I18N_TABULAR_VIEW.js +7 -0
- package/dist/cjs/globalization/service/i18nextBuilder.d.ts +7 -0
- package/dist/cjs/globalization/service/i18nextBuilder.js +25 -14
- package/dist/cjs/interfaces/format/IFormatOutputFormat.Interface.d.ts +1 -0
- package/dist/column_format/constants/DURATION_PARTS_LIST.d.ts +1 -0
- package/dist/column_format/constants/DURATION_PARTS_LIST.js +9 -0
- package/dist/column_format/constants/index.d.ts +1 -0
- package/dist/column_format/constants/index.js +1 -0
- package/dist/column_format/helpers/defineXYChartFormat.js +4 -1
- package/dist/filters/constants/common/FILTER_TOKENS_STRUCTURE_TYPE.d.ts +8 -0
- package/dist/filters/constants/common/FILTER_TOKENS_STRUCTURE_TYPE.js +9 -0
- package/dist/filters/constants/common/index.d.ts +1 -0
- package/dist/filters/constants/common/index.js +1 -0
- package/dist/filters/helpers/filtersTokensToString.d.ts +7 -0
- package/dist/filters/helpers/filtersTokensToString.js +16 -0
- package/dist/filters/helpers/getTokensFromFilters.d.ts +10 -0
- package/dist/filters/helpers/getTokensFromFilters.js +112 -0
- package/dist/filters/helpers/getVerboseFilter.d.ts +9 -0
- package/dist/filters/helpers/getVerboseFilter.js +12 -0
- package/dist/filters/helpers/index.d.ts +3 -0
- package/dist/filters/helpers/index.js +3 -0
- package/dist/filters/interfaces/IFFilterTokens.d.ts +5 -0
- package/dist/filters/interfaces/IFFilterTokens.js +1 -0
- package/dist/filters/interfaces/IFTokensFromFiltersSettings.d.ts +7 -0
- package/dist/filters/interfaces/IFTokensFromFiltersSettings.js +1 -0
- package/dist/filters/interfaces/index.d.ts +2 -0
- package/dist/filters/interfaces/index.js +2 -0
- package/dist/format/definition.d.ts +2 -1
- package/dist/format/format.js +4 -1
- package/dist/format/localization.js +18 -2
- package/dist/globalization/interfaces/II18nResource.d.ts +2 -0
- package/dist/globalization/interfaces/chart_builder/II18nChartBuilderFormatValues.d.ts +1 -0
- package/dist/globalization/interfaces/chart_builder/II18nChartBuilderTableStyleOptions.d.ts +4 -0
- package/dist/globalization/interfaces/common/II18nCommon.d.ts +1 -0
- package/dist/globalization/interfaces/tabular_view/II18nTabularView.d.ts +4 -0
- package/dist/globalization/interfaces/tabular_view/II18nTabularView.js +1 -0
- package/dist/globalization/labels/I18N_DEFAULT.js +2 -0
- package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER.js +1 -0
- package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_COMPARISION_OPTIONS.js +1 -1
- package/dist/globalization/labels/chart_builder/I18N_CHART_BUILDER_STYLE_OPTIONS.js +5 -1
- package/dist/globalization/labels/common/I18N_COMMON.js +1 -0
- package/dist/globalization/labels/tabular_view/I18N_TABULAR_VIEW.d.ts +2 -0
- package/dist/globalization/labels/tabular_view/I18N_TABULAR_VIEW.js +4 -0
- package/dist/globalization/service/i18nextBuilder.d.ts +7 -0
- package/dist/globalization/service/i18nextBuilder.js +24 -14
- package/dist/interfaces/format/IFormatOutputFormat.Interface.d.ts +1 -0
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { isEmpty } from "../../general/mix/isEmpty";
|
|
|
4
4
|
import { CALCULATION_LABEL } from "../../qrvey/constants/CALCULATION_LABEL";
|
|
5
5
|
import { CHART_GROUPS } from "../constants/CHART_GROUP";
|
|
6
6
|
import { DATEGROUP_UNSUPPORT_FORMAT } from "../constants/DATEGROUP_UNSUPPORT_FORMAT";
|
|
7
|
+
import { DURATION_PARTS_LIST } from "../constants/DURATION_PARTS_LIST";
|
|
7
8
|
import { STRING_FORMAT } from "../constants/STRING_FORMAT";
|
|
8
9
|
import { columnTypeByChart } from "./columnTypeByChart";
|
|
9
10
|
/**
|
|
@@ -34,6 +35,8 @@ export const defineXYChartFormat = (column, settings) => {
|
|
|
34
35
|
const hasDefaultFormat = isEmpty(selectedFormat) ||
|
|
35
36
|
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === defaultText ||
|
|
36
37
|
(selectedFormat === null || selectedFormat === void 0 ? void 0 : selectedFormat.format) === defaultText;
|
|
38
|
+
const newOutputFormat = DURATION_PARTS_LIST.includes(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format)
|
|
39
|
+
? Object.assign(Object.assign({}, outputFormat), { template: outputFormat.format, format: "Duration" }) : outputFormat;
|
|
37
40
|
switch (columnType) {
|
|
38
41
|
case COLUMN.YES_NO:
|
|
39
42
|
case COLUMN.PHONE:
|
|
@@ -79,7 +82,7 @@ export const defineXYChartFormat = (column, settings) => {
|
|
|
79
82
|
return columnDefaultFormat;
|
|
80
83
|
}
|
|
81
84
|
else if (hasDefaultFormat) {
|
|
82
|
-
return Object.assign({},
|
|
85
|
+
return Object.assign({}, newOutputFormat);
|
|
83
86
|
}
|
|
84
87
|
else
|
|
85
88
|
return selectedFormat;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var FILTER_TOKENS_STRUCTURE_TYPE;
|
|
2
|
+
(function (FILTER_TOKENS_STRUCTURE_TYPE) {
|
|
3
|
+
FILTER_TOKENS_STRUCTURE_TYPE["SCOPE"] = "SCOPE";
|
|
4
|
+
FILTER_TOKENS_STRUCTURE_TYPE["DATABASE_NAME"] = "DATABASE_NAME";
|
|
5
|
+
FILTER_TOKENS_STRUCTURE_TYPE["COLUMN_NAME"] = "COLUMN_NAME";
|
|
6
|
+
FILTER_TOKENS_STRUCTURE_TYPE["VALIDATOR"] = "VALIDATOR";
|
|
7
|
+
FILTER_TOKENS_STRUCTURE_TYPE["VALUE"] = "VALUE";
|
|
8
|
+
FILTER_TOKENS_STRUCTURE_TYPE["LOGICAL_OPERATOR"] = "LOGICAL_OPERATOR";
|
|
9
|
+
})(FILTER_TOKENS_STRUCTURE_TYPE || (FILTER_TOKENS_STRUCTURE_TYPE = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IFFilterTokens } from "../interfaces/IFFilterTokens";
|
|
2
|
+
/**
|
|
3
|
+
* It takes an array of tokens and returns a string
|
|
4
|
+
* @param {IFFilterTokens[]} tokens - IFFilterTokens[] - the tokens to convert to a string
|
|
5
|
+
* @returns A string
|
|
6
|
+
*/
|
|
7
|
+
export declare function filtersTokensToString(tokens: IFFilterTokens[]): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FILTER_TOKENS_STRUCTURE_TYPE } from "../constants/common/FILTER_TOKENS_STRUCTURE_TYPE";
|
|
2
|
+
/**
|
|
3
|
+
* It takes an array of tokens and returns a string
|
|
4
|
+
* @param {IFFilterTokens[]} tokens - IFFilterTokens[] - the tokens to convert to a string
|
|
5
|
+
* @returns A string
|
|
6
|
+
*/
|
|
7
|
+
export function filtersTokensToString(tokens) {
|
|
8
|
+
let str = "";
|
|
9
|
+
for (const token of tokens) {
|
|
10
|
+
if (token.type === FILTER_TOKENS_STRUCTURE_TYPE.SCOPE) {
|
|
11
|
+
str += `\n`;
|
|
12
|
+
}
|
|
13
|
+
str += `${token.token} `;
|
|
14
|
+
}
|
|
15
|
+
return str.trim();
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IFUData } from "../interfaces/ui/IFUData";
|
|
2
|
+
import { IFTokensFromFiltersSettings } from "../interfaces/IFTokensFromFiltersSettings";
|
|
3
|
+
import { IFFilterTokens } from "../interfaces/IFFilterTokens";
|
|
4
|
+
/**
|
|
5
|
+
* It takes a filter object and returns an array of tokens that represent the filter
|
|
6
|
+
* @param {IFUData} filters - The filters object.
|
|
7
|
+
* @param {IFTokensFromFiltersSettings} options - IFTokensFromFiltersSettings
|
|
8
|
+
* @returns {IFFilterTokens[]} An array of tokens that represents the filters object
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTokensFromFilters(filters: IFUData, options: IFTokensFromFiltersSettings): IFFilterTokens[];
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { getUIValues } from "./ui/getUIValues";
|
|
2
|
+
import { getFilterPropertyLabel } from "./ui/getFilterPropertyLabel";
|
|
3
|
+
import { FILTER_TOKENS_STRUCTURE_TYPE } from "../constants/common/FILTER_TOKENS_STRUCTURE_TYPE";
|
|
4
|
+
import { isEmpty } from "../../general/mix/isEmpty";
|
|
5
|
+
/**
|
|
6
|
+
* It takes a filter object and returns an array of tokens that represent the filter
|
|
7
|
+
* @param {IFUData} filters - The filters object.
|
|
8
|
+
* @param {IFTokensFromFiltersSettings} options - IFTokensFromFiltersSettings
|
|
9
|
+
* @returns {IFFilterTokens[]} An array of tokens that represents the filters object
|
|
10
|
+
*/
|
|
11
|
+
export function getTokensFromFilters(filters, options) {
|
|
12
|
+
var _a, _b, _c;
|
|
13
|
+
const tokens = [];
|
|
14
|
+
const i18nService = options.i18nService;
|
|
15
|
+
const settings = {
|
|
16
|
+
translate: i18nService.translate.bind(i18nService),
|
|
17
|
+
};
|
|
18
|
+
const getValue = (valueItem) => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (valueItem.value) {
|
|
21
|
+
return ((_a = valueItem.displayed) !== null && _a !== void 0 ? _a : true) ? valueItem.value : "";
|
|
22
|
+
}
|
|
23
|
+
else if (valueItem.imageUrl) {
|
|
24
|
+
return `(${i18nService.translate("filter.value_container.no_label")})`;
|
|
25
|
+
}
|
|
26
|
+
return "";
|
|
27
|
+
};
|
|
28
|
+
for (const scope of filters.scopes) {
|
|
29
|
+
if (scope.datasets.length === 0)
|
|
30
|
+
continue;
|
|
31
|
+
if (options.showScope) {
|
|
32
|
+
tokens.push({
|
|
33
|
+
token: i18nService.translate(`filter.scope_title.${scope.scope.toLowerCase()}`) + ":",
|
|
34
|
+
type: FILTER_TOKENS_STRUCTURE_TYPE.SCOPE,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
let thereIsFiltersWithValues = false;
|
|
38
|
+
for (const database of scope.datasets) {
|
|
39
|
+
if (database.filters.length === 0)
|
|
40
|
+
continue;
|
|
41
|
+
if (options.showDatabaseName) {
|
|
42
|
+
tokens.push({
|
|
43
|
+
token: database.label + ":",
|
|
44
|
+
type: FILTER_TOKENS_STRUCTURE_TYPE.DATABASE_NAME,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
for (const [index, filter] of Object.entries(database.filters)) {
|
|
48
|
+
if (!(filter === null || filter === void 0 ? void 0 : filter.enabled)) {
|
|
49
|
+
if (((_a = tokens[tokens.length - 1]) === null || _a === void 0 ? void 0 : _a.type) ===
|
|
50
|
+
FILTER_TOKENS_STRUCTURE_TYPE.LOGICAL_OPERATOR) {
|
|
51
|
+
tokens.pop();
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const values = getUIValues(filter, settings);
|
|
56
|
+
if (!thereIsFiltersWithValues)
|
|
57
|
+
thereIsFiltersWithValues = true;
|
|
58
|
+
let columnLabel = filter.column.label;
|
|
59
|
+
if ((_b = filter === null || filter === void 0 ? void 0 : filter.column) === null || _b === void 0 ? void 0 : _b.aggregate) {
|
|
60
|
+
columnLabel +=
|
|
61
|
+
" (" +
|
|
62
|
+
i18nService.translate(`common.aggregate_labels.${(_c = filter === null || filter === void 0 ? void 0 : filter.column) === null || _c === void 0 ? void 0 : _c.aggregate.toLowerCase()}`) +
|
|
63
|
+
")";
|
|
64
|
+
}
|
|
65
|
+
tokens.push({
|
|
66
|
+
token: columnLabel + ":",
|
|
67
|
+
type: FILTER_TOKENS_STRUCTURE_TYPE.COLUMN_NAME,
|
|
68
|
+
});
|
|
69
|
+
const property = getFilterPropertyLabel(filter, settings.translate);
|
|
70
|
+
tokens.push({
|
|
71
|
+
token: i18nService.translate(`filter.validators.${filter.validator.toLowerCase()}_label`) + (property ? ` (${property})` : ""),
|
|
72
|
+
type: FILTER_TOKENS_STRUCTURE_TYPE.VALIDATOR,
|
|
73
|
+
});
|
|
74
|
+
let uiValue = values
|
|
75
|
+
.map(getValue)
|
|
76
|
+
.filter((value) => !isEmpty(value))
|
|
77
|
+
.join(", ");
|
|
78
|
+
if (filter.selectAll) {
|
|
79
|
+
if (isEmpty(uiValue)) {
|
|
80
|
+
uiValue = i18nService.translate("filter_panel.card_all_selected");
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
uiValue = `${i18nService.translate("filter_panel.card_all_except")} ${uiValue}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (isEmpty(uiValue)) {
|
|
88
|
+
uiValue = i18nService.translate("filter_panel.card_none_selected");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
tokens.push({
|
|
92
|
+
token: uiValue,
|
|
93
|
+
type: FILTER_TOKENS_STRUCTURE_TYPE.VALUE,
|
|
94
|
+
});
|
|
95
|
+
if (index === (database.filters.length - 1).toString(10)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
tokens.push({
|
|
99
|
+
token: i18nService.translate(`filter.operators.${filter.operator.toLowerCase()}`),
|
|
100
|
+
type: FILTER_TOKENS_STRUCTURE_TYPE.LOGICAL_OPERATOR,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (!thereIsFiltersWithValues && options.showDatabaseName) {
|
|
104
|
+
tokens.pop();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!thereIsFiltersWithValues && options.showScope) {
|
|
108
|
+
tokens.pop();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return tokens;
|
|
112
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IFUData } from "../interfaces/ui/IFUData";
|
|
2
|
+
import { IFTokensFromFiltersSettings } from "../interfaces/IFTokensFromFiltersSettings";
|
|
3
|
+
/**
|
|
4
|
+
* It takes a set of filters and returns a string that describes the filters
|
|
5
|
+
* @param {IFUData} filters - The filters object that you want to convert to a string.
|
|
6
|
+
* @param {IFTokensFromFiltersSettings} options - IFTokensFromFiltersSettings
|
|
7
|
+
* @returns A string
|
|
8
|
+
*/
|
|
9
|
+
export declare function getVerboseFilter(filters: IFUData, options: IFTokensFromFiltersSettings): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getTokensFromFilters } from "./getTokensFromFilters";
|
|
2
|
+
import { filtersTokensToString } from "./filtersTokensToString";
|
|
3
|
+
/**
|
|
4
|
+
* It takes a set of filters and returns a string that describes the filters
|
|
5
|
+
* @param {IFUData} filters - The filters object that you want to convert to a string.
|
|
6
|
+
* @param {IFTokensFromFiltersSettings} options - IFTokensFromFiltersSettings
|
|
7
|
+
* @returns A string
|
|
8
|
+
*/
|
|
9
|
+
export function getVerboseFilter(filters, options) {
|
|
10
|
+
const tokensFromFilters = getTokensFromFilters(filters, options);
|
|
11
|
+
return filtersTokensToString(tokensFromFilters);
|
|
12
|
+
}
|
|
@@ -6,4 +6,7 @@ export * from "./applyHierarchyForAggFilters";
|
|
|
6
6
|
export * from "./getAvailableScopes";
|
|
7
7
|
export * from "./getAvailableScopesIDsByConfig";
|
|
8
8
|
export * from "./getScopesByHierarchy";
|
|
9
|
+
export * from "./getTokensFromFilters";
|
|
10
|
+
export * from "./filtersTokensToString";
|
|
11
|
+
export * from "./getVerboseFilter";
|
|
9
12
|
export * from "./OLD_getAggFilters";
|
|
@@ -6,4 +6,7 @@ export * from "./applyHierarchyForAggFilters";
|
|
|
6
6
|
export * from "./getAvailableScopes";
|
|
7
7
|
export * from "./getAvailableScopesIDsByConfig";
|
|
8
8
|
export * from "./getScopesByHierarchy";
|
|
9
|
+
export * from "./getTokensFromFilters";
|
|
10
|
+
export * from "./filtersTokensToString";
|
|
11
|
+
export * from "./getVerboseFilter";
|
|
9
12
|
export * from "./OLD_getAggFilters";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -30,6 +30,8 @@ export * from "./IFStructureType";
|
|
|
30
30
|
export * from "./IFValidator";
|
|
31
31
|
export * from "./IFValidatorInfo";
|
|
32
32
|
export * from "./IFValue";
|
|
33
|
+
export * from "./IFTokensFromFiltersSettings";
|
|
34
|
+
export * from "./IFFilterTokens";
|
|
33
35
|
export * from "./OLD_IFilterData";
|
|
34
36
|
export * from "./OLD_IFilterDetail";
|
|
35
37
|
export * from "./OLD_IFilterExpression";
|
|
@@ -30,6 +30,8 @@ export * from "./IFStructureType";
|
|
|
30
30
|
export * from "./IFValidator";
|
|
31
31
|
export * from "./IFValidatorInfo";
|
|
32
32
|
export * from "./IFValue";
|
|
33
|
+
export * from "./IFTokensFromFiltersSettings";
|
|
34
|
+
export * from "./IFFilterTokens";
|
|
33
35
|
export * from "./OLD_IFilterData";
|
|
34
36
|
export * from "./OLD_IFilterDetail";
|
|
35
37
|
export * from "./OLD_IFilterExpression";
|
|
@@ -18,7 +18,8 @@ export declare const enum LOCALE_FORMATS {
|
|
|
18
18
|
CURRENCY = "Currency",
|
|
19
19
|
PERCENTAGE = "Percentage",
|
|
20
20
|
SCIENTIFIC = "Scientific",
|
|
21
|
-
ABBREVIATED = "Abbreviated"
|
|
21
|
+
ABBREVIATED = "Abbreviated",
|
|
22
|
+
DURATION = "Duration"
|
|
22
23
|
}
|
|
23
24
|
export declare const enum LOCALE_STYLES {
|
|
24
25
|
DECIMAL = "decimal",
|
package/dist/format/format.js
CHANGED
|
@@ -8,6 +8,7 @@ import { COLUMN } from "../columns/constants/COLUMN";
|
|
|
8
8
|
import { FORMULA } from "../formulas/constants/FORMULA";
|
|
9
9
|
import { formatWithLocale } from "./localization";
|
|
10
10
|
import { isObject } from "../general/object/isObject";
|
|
11
|
+
import { DURATION_PARTS_LIST } from "../column_format/constants/DURATION_PARTS_LIST";
|
|
11
12
|
dayjs.extend(advancedFormat); // Add support to advanced formats https://day.js.org/docs/en/plugin/advanced-format
|
|
12
13
|
/**
|
|
13
14
|
* Apply to the given date format to a date value
|
|
@@ -105,7 +106,9 @@ export const addFormat = (value, outputFormat = "None", config) => {
|
|
|
105
106
|
: outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format);
|
|
106
107
|
case "NUMERIC": {
|
|
107
108
|
const parse = parseFloat(value);
|
|
108
|
-
const withLocale = outputFormat !== "None" && (config === null || config === void 0 ? void 0 : config.lang)
|
|
109
|
+
const withLocale = (outputFormat !== "None" && (config === null || config === void 0 ? void 0 : config.lang)) ||
|
|
110
|
+
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Duration" ||
|
|
111
|
+
DURATION_PARTS_LIST.includes[outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format];
|
|
109
112
|
return isNaN(parse)
|
|
110
113
|
? value
|
|
111
114
|
: withLocale
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DATETIME_COLUMN_FORMAT } from "../dates/constants/DATETIME_COLUMN_FORMAT";
|
|
2
2
|
import { isEmpty } from "../general/mix/isEmpty";
|
|
3
3
|
import { currencyISO, LANG_DEFAULT, CURRENCY_DEFAULT, DATETIME_OPTIONS, } from "./definition";
|
|
4
|
+
import { DurationFormatter } from "./duration/durationFormatter";
|
|
4
5
|
export const getLang = (locale) => {
|
|
5
6
|
if (!locale)
|
|
6
7
|
return;
|
|
@@ -55,10 +56,20 @@ function formatLocaleNumber(value, outputFormat, config) {
|
|
|
55
56
|
const langOpts = options || getLocaleOptions(outputFormat);
|
|
56
57
|
const valueToFormat = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Percentage" /* LOCALE_FORMATS.PERCENTAGE */ ? value / 100 : value;
|
|
57
58
|
try {
|
|
58
|
-
const key =
|
|
59
|
+
const key = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) +
|
|
60
|
+
lang +
|
|
61
|
+
JSON.stringify(langOpts) +
|
|
62
|
+
((outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.template) ? outputFormat.template : "");
|
|
59
63
|
let formatter = NUMBER_FORMAT_CACHE[key];
|
|
60
64
|
if (!formatter) {
|
|
61
|
-
|
|
65
|
+
const intlNumberFormat = new Intl.NumberFormat([lang, LANG_DEFAULT], langOpts);
|
|
66
|
+
formatter =
|
|
67
|
+
(outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Duration" /* LOCALE_FORMATS.DURATION */
|
|
68
|
+
? new DurationFormatter({
|
|
69
|
+
template: outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.template,
|
|
70
|
+
intlNumberFormat,
|
|
71
|
+
})
|
|
72
|
+
: intlNumberFormat;
|
|
62
73
|
NUMBER_FORMAT_CACHE[key] = formatter;
|
|
63
74
|
}
|
|
64
75
|
return formatter.format(valueToFormat);
|
|
@@ -107,6 +118,11 @@ function getLocaleOptions(outputFormat) {
|
|
|
107
118
|
maximumFractionDigits: decimals,
|
|
108
119
|
minimumFractionDigits: decimals,
|
|
109
120
|
};
|
|
121
|
+
case "Duration" /* LOCALE_FORMATS.DURATION */:
|
|
122
|
+
return {
|
|
123
|
+
maximumFractionDigits: 0,
|
|
124
|
+
minimumFractionDigits: 0,
|
|
125
|
+
};
|
|
110
126
|
default:
|
|
111
127
|
return {
|
|
112
128
|
style: "decimal" /* LOCALE_STYLES.DECIMAL */,
|
|
@@ -11,6 +11,7 @@ import { II18nBucketBuilder } from "./bucket_builder/II18nBucketBuilder";
|
|
|
11
11
|
import { II18nCrossTabs } from "./cross_tabs";
|
|
12
12
|
import { II18nChartBuilder } from ".";
|
|
13
13
|
import { II18nStyleThemes } from "./style_themes/II18nStyleThemes";
|
|
14
|
+
import { II18nTabularView } from './tabular_view/II18nTabularView';
|
|
14
15
|
export interface II18nResource {
|
|
15
16
|
bucket_builder?: II18nBucketBuilder;
|
|
16
17
|
chart_builder?: II18nChartBuilder;
|
|
@@ -25,4 +26,5 @@ export interface II18nResource {
|
|
|
25
26
|
panel?: II18nPanel;
|
|
26
27
|
style_themes?: II18nStyleThemes;
|
|
27
28
|
table_charts?: II18nTableCharts;
|
|
29
|
+
tabular_view?: II18nTabularView;
|
|
28
30
|
}
|
|
@@ -8,7 +8,11 @@ export interface II18nChartBuilderTableStyleOptions {
|
|
|
8
8
|
typeface: string;
|
|
9
9
|
weight: string;
|
|
10
10
|
weight_bold: string;
|
|
11
|
+
weight_black: string;
|
|
12
|
+
weight_light: string;
|
|
13
|
+
weight_medium: string;
|
|
11
14
|
weight_normal: string;
|
|
15
|
+
weight_thin: string;
|
|
12
16
|
size: string;
|
|
13
17
|
font_color: string;
|
|
14
18
|
bg_color: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -8,6 +8,7 @@ import { I18N_FORMULA_BUILDER } from "./formula_builder";
|
|
|
8
8
|
import { I18N_FILTER_PANEL } from "./filters/I18N_FILTER_PANEL";
|
|
9
9
|
import { I18N_FILTER_DISPLAY } from "./filters/I18N_FILTER_DISPLAY";
|
|
10
10
|
import { I18N_BUCKET_BUILDER } from "./bucket_builder/I18N_BUCKET_BUILDER";
|
|
11
|
+
import { I18N_TABULAR_VIEW } from './tabular_view/I18N_TABULAR_VIEW';
|
|
11
12
|
import { I18N_CROSS_TABS } from "./cross_tabs";
|
|
12
13
|
import { I18N_CHART_BUILDER } from "./chart_builder";
|
|
13
14
|
import { I18N_STYLE_THEMES } from "./style_themes";
|
|
@@ -25,4 +26,5 @@ export const I18N_DEFAULT = {
|
|
|
25
26
|
panel: I18N_PANEL,
|
|
26
27
|
style_themes: I18N_STYLE_THEMES,
|
|
27
28
|
table_charts: I18N_TABLE_CHARTS,
|
|
29
|
+
tabular_view: I18N_TABULAR_VIEW
|
|
28
30
|
};
|
|
@@ -200,7 +200,11 @@ export const I18N_CHART_BUILDER_STYLE_OPTIONS = {
|
|
|
200
200
|
typeface: "Typeface",
|
|
201
201
|
weight: "Weight",
|
|
202
202
|
weight_bold: "Bold",
|
|
203
|
-
|
|
203
|
+
weight_black: "Black",
|
|
204
|
+
weight_light: "Light",
|
|
205
|
+
weight_medium: "Medium",
|
|
206
|
+
weight_normal: "Normal",
|
|
207
|
+
weight_thin: "Thin",
|
|
204
208
|
size: "Size",
|
|
205
209
|
font_color: "Font Color",
|
|
206
210
|
bg_color: "BG Color",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { i18n } from "i18next";
|
|
1
2
|
import { II18nResource } from "../interfaces/II18nResource";
|
|
2
3
|
import { II18nServiceTranslateOption } from "../interfaces/II18nServiceTranslateOption";
|
|
3
4
|
export declare class I18nServiceBuilder {
|
|
4
5
|
static buildI18n(i18nDefault: II18nResource, i18nResource: II18nResource): Promise<I18nService>;
|
|
5
6
|
private static _initI18n;
|
|
7
|
+
static getI18nInstance(i18nDefault: II18nResource, i18nResource: II18nResource, _i18next?: i18n): Promise<i18n>;
|
|
6
8
|
static setTranslations(i18nDefault: any, i18nResource: II18nResource): II18nResource;
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
@@ -17,3 +19,8 @@ export declare abstract class I18nService {
|
|
|
17
19
|
*/
|
|
18
20
|
abstract translate(key: string, options?: II18nServiceTranslateOption): string;
|
|
19
21
|
}
|
|
22
|
+
export declare class I18nServiceConcrete extends I18nService {
|
|
23
|
+
_i18next: any;
|
|
24
|
+
constructor(i18nInstance: any);
|
|
25
|
+
translate(key: string, options?: II18nServiceTranslateOption): any;
|
|
26
|
+
}
|
|
@@ -16,23 +16,33 @@ export class I18nServiceBuilder {
|
|
|
16
16
|
static _initI18n(i18nDefault, i18nResource) {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
18
|
if (!i18next.isInitialized) {
|
|
19
|
-
yield
|
|
20
|
-
lng: "en",
|
|
21
|
-
debug: false,
|
|
22
|
-
nsSeparator: false,
|
|
23
|
-
keySeparator: ".",
|
|
24
|
-
fallbackLng: false,
|
|
25
|
-
defaultNS: "translation",
|
|
26
|
-
resources: {
|
|
27
|
-
en: {
|
|
28
|
-
translation: this.setTranslations(i18nDefault, i18nResource),
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
});
|
|
19
|
+
yield this.getI18nInstance(i18nDefault, i18nResource, i18next);
|
|
32
20
|
}
|
|
33
21
|
return new I18nServiceConcrete(i18next);
|
|
34
22
|
});
|
|
35
23
|
}
|
|
24
|
+
static getI18nInstance(i18nDefault, i18nResource, _i18next) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
let __i18next = _i18next;
|
|
27
|
+
if (!__i18next) {
|
|
28
|
+
__i18next = i18next.createInstance();
|
|
29
|
+
}
|
|
30
|
+
yield __i18next.init({
|
|
31
|
+
lng: "en",
|
|
32
|
+
debug: false,
|
|
33
|
+
nsSeparator: false,
|
|
34
|
+
keySeparator: ".",
|
|
35
|
+
fallbackLng: false,
|
|
36
|
+
defaultNS: "translation",
|
|
37
|
+
resources: {
|
|
38
|
+
en: {
|
|
39
|
+
translation: this.setTranslations(i18nDefault, i18nResource),
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return __i18next;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
36
46
|
static setTranslations(i18nDefault, i18nResource) {
|
|
37
47
|
return mergeDeep(i18nResource, i18nDefault, { mergeExistingValues: false });
|
|
38
48
|
}
|
|
@@ -42,7 +52,7 @@ export class I18nServiceBuilder {
|
|
|
42
52
|
*/
|
|
43
53
|
export class I18nService {
|
|
44
54
|
}
|
|
45
|
-
class I18nServiceConcrete extends I18nService {
|
|
55
|
+
export class I18nServiceConcrete extends I18nService {
|
|
46
56
|
constructor(i18nInstance) {
|
|
47
57
|
super();
|
|
48
58
|
this._i18next = i18nInstance;
|