plmt-constructor-sdk 0.13.4 → 0.13.6

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.
@@ -1,112 +1,112 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.provideDataTo = void 0;
4
- const config_1 = require("./config");
5
- const widget_1 = require("./widget");
6
- const defaultDataSettingsMethods = {
7
- setFilter() { },
8
- removeFilterAt() { },
9
- setSort() { },
10
- removeSortAt() { },
11
- interact() { },
12
- };
13
- function provideDataTo(widget, { dataOptionsMap, viewOptions }, dataSettingsMethods = defaultDataSettingsMethods) {
14
- const widgetMultiData = {};
15
- const widgetDataSettingsMap = {};
16
- const formatters = window.parent['format']?.[widget.uid] || {};
17
- widget.viewSettings = {};
18
- Object.values(dataOptionsMap).forEach(({ data_option, rows, total }) => {
19
- widgetMultiData[data_option.key] = rows;
20
- const columns = data_option.dataset.columns_id.map((source) => ({
21
- type: source.base_type,
22
- id: source.id,
23
- path: source.path,
24
- format: formatters[source.path] || ((value) => value),
25
- name: source.name,
26
- }));
27
- const columnsByBlock = {};
28
- const filters = [];
29
- const sort = [];
30
- const colorize = [];
31
- data_option.blocks.forEach((block) => {
32
- if (block.block_type === config_1.ConfigDataBlockType_Server.Drilldown)
33
- return;
34
- switch (block.key) {
35
- case config_1.blockFilterKey:
36
- block.columns.forEach(({ column_id, action, value }) => {
37
- const column = columns.find(({ id }) => column_id === id);
38
- filters.push({
39
- column,
40
- method: action,
41
- value,
42
- });
43
- });
44
- break;
45
- case config_1.blockSortKey:
46
- block.columns.forEach(({ column_id, value: direction }) => {
47
- const column = columns.find(({ id }) => column_id === id);
48
- sort.push({
49
- column,
50
- direction,
51
- });
52
- });
53
- break;
54
- case config_1.blockColorizeKey:
55
- block.columns.forEach(({ value }) => {
56
- const source = value;
57
- const column = columns.find(({ id }) => source.columnId === id);
58
- colorize.push((0, widget_1.createColorizeItem)(widget, column, source));
59
- });
60
- break;
61
- default:
62
- columnsByBlock[block.key] = block.columns.map(({ column_id }) => {
63
- return columns.find((item) => item.id === column_id);
64
- });
65
- }
66
- });
67
- const dataSettingsItem = {
68
- columns,
69
- columnsByBlock,
70
- filters,
71
- sort,
72
- colorize,
73
- total,
74
- limit: data_option.limit_rows,
75
- offset: data_option.offset,
76
- ...{
77
- ...dataSettingsMethods,
78
- interact: dataSettingsMethods.interact.bind(data_option),
79
- },
80
- ...getDataSettingsEvents(widget, data_option.key),
81
- };
82
- widgetDataSettingsMap[data_option.key] = dataSettingsItem;
83
- });
84
- if (widget_1.widgetDefaultKey in widgetDataSettingsMap) {
85
- Object.assign(widget, {
86
- data: widgetMultiData[widget_1.widgetDefaultKey],
87
- dataSettings: widgetDataSettingsMap[widget_1.widgetDefaultKey],
88
- });
89
- }
90
- else {
91
- Object.assign(widget, {
92
- data: widgetMultiData,
93
- dataSettings: widgetDataSettingsMap,
94
- });
95
- }
96
- widget.viewSettings = {};
97
- viewOptions.forEach(({ key, value }) => (widget.viewSettings[key] = value));
98
- }
99
- exports.provideDataTo = provideDataTo;
100
- function getDataSettingsEvents(widget, key) {
101
- const dataSettings = key === widget_1.widgetDefaultKey
102
- ? widget.dataSettings
103
- : widget.dataSettings[key];
104
- if (dataSettings)
105
- return {
106
- events: dataSettings.events,
107
- };
108
- else
109
- return {
110
- events: {},
111
- };
112
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.provideDataTo = void 0;
4
+ const config_1 = require("./config");
5
+ const widget_1 = require("./widget");
6
+ const defaultDataSettingsMethods = {
7
+ setFilter() { },
8
+ removeFilterAt() { },
9
+ setSort() { },
10
+ removeSortAt() { },
11
+ interact() { },
12
+ };
13
+ function provideDataTo(widget, { dataOptionsMap, viewOptions }, dataSettingsMethods = defaultDataSettingsMethods) {
14
+ const widgetMultiData = {};
15
+ const widgetDataSettingsMap = {};
16
+ const formatters = window.parent['format']?.[widget.uid] || {};
17
+ widget.viewSettings = {};
18
+ Object.values(dataOptionsMap).forEach(({ data_option, rows, total }) => {
19
+ widgetMultiData[data_option.key] = rows;
20
+ const columns = data_option.dataset.columns_id.map((source) => ({
21
+ type: source.base_type,
22
+ id: source.id,
23
+ path: source.path,
24
+ format: formatters[source.path] || ((value) => value),
25
+ name: source.name,
26
+ }));
27
+ const columnsByBlock = {};
28
+ const filters = [];
29
+ const sort = [];
30
+ const colorize = [];
31
+ data_option.blocks.forEach((block) => {
32
+ if (block.block_type === config_1.ConfigDataBlockType_Server.Drilldown)
33
+ return;
34
+ switch (block.key) {
35
+ case config_1.blockFilterKey:
36
+ block.columns.forEach(({ column_id, action, value }) => {
37
+ const column = columns.find(({ id }) => column_id === id);
38
+ filters.push({
39
+ column,
40
+ method: action,
41
+ value,
42
+ });
43
+ });
44
+ break;
45
+ case config_1.blockSortKey:
46
+ block.columns.forEach(({ column_id, value: direction }) => {
47
+ const column = columns.find(({ id }) => column_id === id);
48
+ sort.push({
49
+ column,
50
+ direction,
51
+ });
52
+ });
53
+ break;
54
+ case config_1.blockColorizeKey:
55
+ block.columns.forEach(({ value }) => {
56
+ const source = value;
57
+ const column = columns.find(({ id }) => source.columnId === id);
58
+ colorize.push((0, widget_1.createColorizeItem)(widget, column, source));
59
+ });
60
+ break;
61
+ default:
62
+ columnsByBlock[block.key] = block.columns.map(({ column_id }) => {
63
+ return columns.find((item) => item.id === column_id);
64
+ });
65
+ }
66
+ });
67
+ const dataSettingsItem = {
68
+ columns,
69
+ columnsByBlock,
70
+ filters,
71
+ sort,
72
+ colorize,
73
+ total,
74
+ limit: data_option.limit_rows,
75
+ offset: data_option.offset,
76
+ ...{
77
+ ...dataSettingsMethods,
78
+ interact: dataSettingsMethods.interact.bind(data_option),
79
+ },
80
+ ...getDataSettingsEvents(widget, data_option.key),
81
+ };
82
+ widgetDataSettingsMap[data_option.key] = dataSettingsItem;
83
+ });
84
+ if (widget_1.widgetDefaultKey in widgetDataSettingsMap) {
85
+ Object.assign(widget, {
86
+ data: widgetMultiData[widget_1.widgetDefaultKey],
87
+ dataSettings: widgetDataSettingsMap[widget_1.widgetDefaultKey],
88
+ });
89
+ }
90
+ else {
91
+ Object.assign(widget, {
92
+ data: widgetMultiData,
93
+ dataSettings: widgetDataSettingsMap,
94
+ });
95
+ }
96
+ widget.viewSettings = {};
97
+ viewOptions.forEach(({ key, value }) => (widget.viewSettings[key] = value));
98
+ }
99
+ exports.provideDataTo = provideDataTo;
100
+ function getDataSettingsEvents(widget, key) {
101
+ const dataSettings = key === widget_1.widgetDefaultKey
102
+ ? widget.dataSettings
103
+ : widget.dataSettings[key];
104
+ if (dataSettings)
105
+ return {
106
+ events: dataSettings.events,
107
+ };
108
+ else
109
+ return {
110
+ events: {},
111
+ };
112
+ }
@@ -1,64 +1,64 @@
1
- import { DataQueryMethod, DataQueryFunction } from '../config';
2
- import { Dataset_Server } from './dataset';
3
- import { ConfigDataBlockType_Server } from './config';
4
- import { ColorizeItem, Widget } from '../widget';
5
- import { Column, DataItem } from '../data';
6
- export declare const widgetDefaultKey = "ffed0a4d-4a9d-417f-b502-eb50142c6956";
7
- export interface Widget_Server {
8
- data_options: WidgetDataOption_Server[];
9
- view_options: WidgetViewOption_Server[];
10
- }
11
- export interface WidgetRepresent {
12
- dataOptionsMap: DatasetMultiData_Server;
13
- viewOptions: WidgetViewOption_Server[];
14
- }
15
- export interface DatasetMultiData_Server {
16
- [key: string]: {
17
- data_option: WidgetDataOption_Server;
18
- rows: DataItem[];
19
- total: number;
20
- };
21
- }
22
- export interface WidgetDataOption_Server {
23
- key: string;
24
- id: number;
25
- dataset: Dataset_Server;
26
- method: DataQueryMethod;
27
- limit_rows: number;
28
- offset: number;
29
- blocks: WidgetDataOptionBlock_Server[];
30
- }
31
- export interface WidgetDataOptionParams_Server {
32
- id?: number;
33
- dataset_id: number;
34
- method: DataQueryMethod;
35
- limit_rows?: number;
36
- offset?: number;
37
- key?: string;
38
- blocks: WidgetDataOptionBlock_Server[];
39
- }
40
- export interface WidgetDataOptionColumn_Server {
41
- column_id: number;
42
- value?: any;
43
- action?: string;
44
- }
45
- export interface WidgetDataOptionBlock_Server {
46
- key: string;
47
- block_type: ConfigDataBlockType_Server;
48
- function: DataQueryFunction;
49
- columns: WidgetDataOptionColumn_Server[];
50
- }
51
- export interface WidgetViewOption_Server {
52
- key: string;
53
- value: any;
54
- }
55
- export interface ColorizeSettings_Server {
56
- columnId: number;
57
- max?: number;
58
- min?: number;
59
- threshold?: number;
60
- colorAbove?: number;
61
- colorBelow?: number;
62
- }
63
- export declare function createColorizeItem(widget: Widget, column: Column, source: ColorizeSettings_Server): ColorizeItem;
64
- export declare function dispatchChangeOtherFilters(widget: any, source: WidgetDataOptionColumn_Server[]): void;
1
+ import { DataQueryMethod, DataQueryFunction } from '../config';
2
+ import { Dataset_Server } from './dataset';
3
+ import { ConfigDataBlockType_Server } from './config';
4
+ import { ColorizeItem, Widget } from '../widget';
5
+ import { Column, DataItem } from '../data';
6
+ export declare const widgetDefaultKey = "ffed0a4d-4a9d-417f-b502-eb50142c6956";
7
+ export interface Widget_Server {
8
+ data_options: WidgetDataOption_Server[];
9
+ view_options: WidgetViewOption_Server[];
10
+ }
11
+ export interface WidgetRepresent {
12
+ dataOptionsMap: DatasetMultiData_Server;
13
+ viewOptions: WidgetViewOption_Server[];
14
+ }
15
+ export interface DatasetMultiData_Server {
16
+ [key: string]: {
17
+ data_option: WidgetDataOption_Server;
18
+ rows: DataItem[];
19
+ total: number;
20
+ };
21
+ }
22
+ export interface WidgetDataOption_Server {
23
+ key: string;
24
+ id: number;
25
+ dataset: Dataset_Server;
26
+ method: DataQueryMethod;
27
+ limit_rows: number;
28
+ offset: number;
29
+ blocks: WidgetDataOptionBlock_Server[];
30
+ }
31
+ export interface WidgetDataOptionParams_Server {
32
+ id?: number;
33
+ dataset_id: number;
34
+ method: DataQueryMethod;
35
+ limit_rows?: number;
36
+ offset?: number;
37
+ key?: string;
38
+ blocks: WidgetDataOptionBlock_Server[];
39
+ }
40
+ export interface WidgetDataOptionColumn_Server {
41
+ column_id: number;
42
+ value?: any;
43
+ action?: string;
44
+ }
45
+ export interface WidgetDataOptionBlock_Server {
46
+ key: string;
47
+ block_type: ConfigDataBlockType_Server;
48
+ function: DataQueryFunction;
49
+ columns: WidgetDataOptionColumn_Server[];
50
+ }
51
+ export interface WidgetViewOption_Server {
52
+ key: string;
53
+ value: any;
54
+ }
55
+ export interface ColorizeSettings_Server {
56
+ columnId: number;
57
+ max?: number;
58
+ min?: number;
59
+ threshold?: number;
60
+ colorAbove?: number;
61
+ colorBelow?: number;
62
+ }
63
+ export declare function createColorizeItem(widget: Widget, column: Column, source: ColorizeSettings_Server): ColorizeItem;
64
+ export declare function dispatchChangeOtherFilters(widget: any, source: WidgetDataOptionColumn_Server[]): void;
@@ -1,64 +1,64 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dispatchChangeOtherFilters = exports.createColorizeItem = exports.widgetDefaultKey = void 0;
4
- const data_1 = require("../data");
5
- exports.widgetDefaultKey = 'ffed0a4d-4a9d-417f-b502-eb50142c6956';
6
- function createColorizeItem(widget, column, source) {
7
- const max = +source.max || 0;
8
- const min = +source.min || 0;
9
- const threshold = +source.threshold || 0;
10
- const colorAbove = source.colorAbove;
11
- const colorBelow = source.colorBelow;
12
- const deltaAbove = max - threshold;
13
- const deltaBelow = threshold - min;
14
- return {
15
- column,
16
- getColor(value) {
17
- value = +value || 0;
18
- if (value > max || value < min)
19
- return color();
20
- if (value >= threshold) {
21
- const colors = widget.theme.colorize[colorAbove] || [];
22
- if (value === max)
23
- return color(colors[colors.length - 1]);
24
- const i = Math.floor(((value - threshold) / deltaAbove) * colors.length);
25
- return color(colors[i]);
26
- }
27
- else {
28
- const colors = widget.theme.colorize[colorBelow] || [];
29
- if (value === min)
30
- return color(colors[colors.length - 1]);
31
- const i = Math.floor(((threshold - value) / deltaBelow) * colors.length);
32
- return color(colors[i]);
33
- }
34
- },
35
- };
36
- }
37
- exports.createColorizeItem = createColorizeItem;
38
- function color(source) {
39
- return source || 'transparent';
40
- }
41
- function dispatchChangeOtherFilters(widget, source) {
42
- source.forEach(({ column_id, value }) => {
43
- const dataSettings = getDataSettingsByColumnId(widget, column_id);
44
- if (dataSettings &&
45
- typeof dataSettings.events.onOtherFilterChange === 'function') {
46
- const column = dataSettings.columns.find(({ id }) => id === column_id);
47
- if (column)
48
- dataSettings.events.onOtherFilterChange({
49
- column,
50
- method: data_1.FilterMethod.InList,
51
- value,
52
- });
53
- }
54
- });
55
- }
56
- exports.dispatchChangeOtherFilters = dispatchChangeOtherFilters;
57
- function getDataSettingsByColumnId(widget, columnId) {
58
- if (Array.isArray(widget.data))
59
- return widget.dataSettings;
60
- for (let dataSettings of Object.values(widget.dataSettings))
61
- if (dataSettings.columns.find(({ id }) => id === columnId))
62
- return dataSettings;
63
- return null;
64
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dispatchChangeOtherFilters = exports.createColorizeItem = exports.widgetDefaultKey = void 0;
4
+ const data_1 = require("../data");
5
+ exports.widgetDefaultKey = 'ffed0a4d-4a9d-417f-b502-eb50142c6956';
6
+ function createColorizeItem(widget, column, source) {
7
+ const max = +source.max || 0;
8
+ const min = +source.min || 0;
9
+ const threshold = +source.threshold || 0;
10
+ const colorAbove = source.colorAbove;
11
+ const colorBelow = source.colorBelow;
12
+ const deltaAbove = max - threshold;
13
+ const deltaBelow = threshold - min;
14
+ return {
15
+ column,
16
+ getColor(value) {
17
+ value = +value || 0;
18
+ if (value > max || value < min)
19
+ return color();
20
+ if (value >= threshold) {
21
+ const colors = widget.theme.colorize[colorAbove] || [];
22
+ if (value === max)
23
+ return color(colors[colors.length - 1]);
24
+ const i = Math.floor(((value - threshold) / deltaAbove) * colors.length);
25
+ return color(colors[i]);
26
+ }
27
+ else {
28
+ const colors = widget.theme.colorize[colorBelow] || [];
29
+ if (value === min)
30
+ return color(colors[colors.length - 1]);
31
+ const i = Math.floor(((threshold - value) / deltaBelow) * colors.length);
32
+ return color(colors[i]);
33
+ }
34
+ },
35
+ };
36
+ }
37
+ exports.createColorizeItem = createColorizeItem;
38
+ function color(source) {
39
+ return source || 'transparent';
40
+ }
41
+ function dispatchChangeOtherFilters(widget, source) {
42
+ source.forEach(({ column_id, value }) => {
43
+ const dataSettings = getDataSettingsByColumnId(widget, column_id);
44
+ if (dataSettings &&
45
+ typeof dataSettings.events.onOtherFilterChange === 'function') {
46
+ const column = dataSettings.columns.find(({ id }) => id === column_id);
47
+ if (column)
48
+ dataSettings.events.onOtherFilterChange({
49
+ column,
50
+ method: data_1.FilterMethod.InList,
51
+ value,
52
+ });
53
+ }
54
+ });
55
+ }
56
+ exports.dispatchChangeOtherFilters = dispatchChangeOtherFilters;
57
+ function getDataSettingsByColumnId(widget, columnId) {
58
+ if (Array.isArray(widget.data))
59
+ return widget.dataSettings;
60
+ for (let dataSettings of Object.values(widget.dataSettings))
61
+ if (dataSettings.columns.find(({ id }) => id === columnId))
62
+ return dataSettings;
63
+ return null;
64
+ }