widget-common-container 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.angular/cache/19.2.26/ng-packagr/0997d7866dbb7999756bcd6dce071e827244865f4ff149c26d049d1515686b01 +1 -0
- package/.angular/cache/19.2.26/ng-packagr/882519e10fb587011272af89a34932495c0e2cc97d0c030536d1033ee55ce561 +1 -0
- package/.angular/cache/19.2.26/ng-packagr/8b15b546ec32b4e82b20945f62d23ba911050bdc6a4a60d34875eea6fe236635 +1 -0
- package/.angular/cache/19.2.26/ng-packagr/9711df1afdc00e2ac901d2b22d9559a220e74d16c0bf6d3917e410c565aed496 +1 -0
- package/.angular/cache/19.2.26/ng-packagr/tsbuildinfo/inspark-widget-common.tsbuildinfo +1 -0
- package/.editorconfig +13 -0
- package/.eslintrc.json +28 -0
- package/README.md +27 -0
- package/angular.json +46 -0
- package/e2e/protractor.conf.js +28 -0
- package/e2e/src/app.e2e-spec.ts +14 -0
- package/e2e/src/app.po.ts +11 -0
- package/e2e/tsconfig.e2e.json +13 -0
- package/package.json +75 -0
- package/projects/widget-common/copy.json +8 -0
- package/projects/widget-common/karma.conf.js +31 -0
- package/projects/widget-common/ng-package.json +7 -0
- package/projects/widget-common/package-lock.json +78 -0
- package/projects/widget-common/package.json +23 -0
- package/projects/widget-common/src/assets/error.svg +6 -0
- package/projects/widget-common/src/assets/falsevalue.svg +6 -0
- package/projects/widget-common/src/assets/icon.svg +6 -0
- package/projects/widget-common/src/assets/none.svg +6 -0
- package/projects/widget-common/src/assets/success.svg +6 -0
- package/projects/widget-common/src/assets/warning.svg +6 -0
- package/projects/widget-common/src/lib/common.ts +23 -0
- package/projects/widget-common/src/lib/communication.service.ts +59 -0
- package/projects/widget-common/src/lib/echart/echart.component.html +2 -0
- package/projects/widget-common/src/lib/echart/echart.component.scss +40 -0
- package/projects/widget-common/src/lib/echart/echart.component.ts +703 -0
- package/projects/widget-common/src/lib/echart/en.ts +156 -0
- package/projects/widget-common/src/lib/echart/ru.ts +156 -0
- package/projects/widget-common/src/lib/forge/ParamAssign.ts +187 -0
- package/projects/widget-common/src/lib/forge/Script.service.ts +86 -0
- package/projects/widget-common/src/lib/forge/extenstion.ts +263 -0
- package/projects/widget-common/src/lib/forge/forge.component.html +2 -0
- package/projects/widget-common/src/lib/forge/forge.component.scss +6 -0
- package/projects/widget-common/src/lib/forge/forge.component.ts +184 -0
- package/projects/widget-common/src/lib/forge/forge.interface.ts +4 -0
- package/projects/widget-common/src/lib/loader.ts +19 -0
- package/projects/widget-common/src/lib/pie-chart/pie-chart.component.html +1 -0
- package/projects/widget-common/src/lib/pie-chart/pie-chart.component.scss +3 -0
- package/projects/widget-common/src/lib/pie-chart/pie-chart.component.ts +252 -0
- package/projects/widget-common/src/lib/shared.module.ts +40 -0
- package/projects/widget-common/src/lib/sprintf.ts +212 -0
- package/projects/widget-common/src/lib/widget-container/widget-container.component.ts +53 -0
- package/projects/widget-common/src/lib/widget.api.ts +24 -0
- package/projects/widget-common/src/lib/widget.component.ts +87 -0
- package/projects/widget-common/src/lib/widget.dialog.ts +14 -0
- package/projects/widget-common/src/lib/widget.generator.ts +1532 -0
- package/projects/widget-common/src/lib/widget.interface.ts +871 -0
- package/projects/widget-common/src/lib/widget.utils.ts +634 -0
- package/projects/widget-common/src/public_api.ts +9 -0
- package/projects/widget-common/src/scss/main.scss +24 -0
- package/projects/widget-common/src/test.ts +22 -0
- package/projects/widget-common/tsconfig.lib.json +38 -0
- package/projects/widget-common/tsconfig.lib.prod.json +6 -0
- package/projects/widget-common/tsconfig.spec.json +17 -0
- package/projects/widget-common/tslint.json +17 -0
- package/projects/widget-common/versions/full/copy.json +15 -0
- package/projects/widget-common/versions/full/package.json +7 -0
- package/projects/widget-common/versions/full/public_api.ts +19 -0
- package/projects/widget-common/versions/interfaces/copy.json +15 -0
- package/projects/widget-common/versions/interfaces/package.json +7 -0
- package/projects/widget-common/versions/interfaces/public_api.ts +9 -0
- package/src/app/app.component.html +20 -0
- package/src/app/app.component.scss +0 -0
- package/src/app/app.component.spec.ts +31 -0
- package/src/app/app.component.ts +10 -0
- package/src/app/app.module.ts +16 -0
- package/src/assets/.gitkeep +0 -0
- package/src/browserslist +11 -0
- package/src/environments/environment.prod.ts +3 -0
- package/src/environments/environment.ts +16 -0
- package/src/favicon.ico +0 -0
- package/src/index.html +14 -0
- package/src/karma.conf.js +31 -0
- package/src/main.ts +12 -0
- package/src/polyfills.ts +80 -0
- package/src/styles.scss +1 -0
- package/src/test.ts +20 -0
- package/src/tsconfig.app.json +11 -0
- package/src/tsconfig.spec.json +18 -0
- package/src/tslint.json +17 -0
- package/tsconfig.json +34 -0
- package/tslint.json +131 -0
- package/update_full.js +27 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChartTypes,
|
|
3
|
+
GenerateConfigItem,
|
|
4
|
+
ITEM_TYPE,
|
|
5
|
+
ItemParent,
|
|
6
|
+
ItemTable,
|
|
7
|
+
IWidgetDeviceParamData,
|
|
8
|
+
IWidgetParam,
|
|
9
|
+
IWidgetParamConfig,
|
|
10
|
+
PARAM_TYPE,
|
|
11
|
+
ParamConfigCustom,
|
|
12
|
+
ParamConfigurator,
|
|
13
|
+
SeriesDuration,
|
|
14
|
+
TableValues,
|
|
15
|
+
WidgetArrayParam,
|
|
16
|
+
WidgetItem,
|
|
17
|
+
WidgetItems,
|
|
18
|
+
WidgetParamChildren,
|
|
19
|
+
WidgetParamsChildren,
|
|
20
|
+
} from './widget.interface';
|
|
21
|
+
import {_} from './widget.component';
|
|
22
|
+
import {Pipe, PipeTransform} from '@angular/core';
|
|
23
|
+
import {common} from './common';
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@Pipe({name: 'filterIndexOf'})
|
|
27
|
+
export class FilterIndexOfPipe implements PipeTransform {
|
|
28
|
+
transform(array: any[], field: string, search: any) {
|
|
29
|
+
return array.filter(val => {
|
|
30
|
+
return val[field].indexOf(search) !== -1;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@Pipe({name: 'periodFromDate'})
|
|
37
|
+
export class PeriodFromDatePipe implements PipeTransform {
|
|
38
|
+
transform(count: number, period: string): string {
|
|
39
|
+
|
|
40
|
+
switch (period) {
|
|
41
|
+
case 'now':
|
|
42
|
+
return Utils.getDate();
|
|
43
|
+
|
|
44
|
+
case 'day':
|
|
45
|
+
return Utils.getDay(count);
|
|
46
|
+
|
|
47
|
+
case 'week':
|
|
48
|
+
return Utils.getWeek(count);
|
|
49
|
+
|
|
50
|
+
case 'month':
|
|
51
|
+
return Utils.getMonth(count);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@Pipe({name: 'arrayNumber'})
|
|
59
|
+
export class ArrayNumberPipe implements PipeTransform {
|
|
60
|
+
transform(value, args: string[] = []): any {
|
|
61
|
+
return Array(value).fill(1).map((x, i) => i + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Pipe({name: 'makePictureUrl'})
|
|
66
|
+
export class MakePictureUrl implements PipeTransform {
|
|
67
|
+
transform(id: number): string {
|
|
68
|
+
if (id === -1) {
|
|
69
|
+
return 'data:image/gif;base64,R0lGODlhZABkAIAAAP///ztXpyH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4zLWMwMTEgNjYuMTQ1NjYxLCAyMDEyLzAyLzA2LTE0OjU2OjI3ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M2IChNYWNpbnRvc2gpIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkNCMTBEMjc5NDJCMjExRTlCOTY0Q0MxNURGQkREMDc0IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkNCMTBEMjdBNDJCMjExRTlCOTY0Q0MxNURGQkREMDc0Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6Q0IxMEQyNzc0MkIyMTFFOUI5NjRDQzE1REZCREQwNzQiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6Q0IxMEQyNzg0MkIyMTFFOUI5NjRDQzE1REZCREQwNzQiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4B//79/Pv6+fj39vX08/Lx8O/u7ezr6uno5+bl5OPi4eDf3t3c29rZ2NfW1dTT0tHQz87NzMvKycjHxsXEw8LBwL++vby7urm4t7a1tLOysbCvrq2sq6qpqKempaSjoqGgn56dnJuamZiXlpWUk5KRkI+OjYyLiomIh4aFhIOCgYB/fn18e3p5eHd2dXRzcnFwb25tbGtqaWhnZmVkY2JhYF9eXVxbWllYV1ZVVFNSUVBPTk1MS0pJSEdGRURDQkFAPz49PDs6OTg3NjU0MzIxMC8uLSwrKikoJyYlJCMiISAfHh0cGxoZGBcWFRQTEhEQDw4NDAsKCQgHBgUEAwIBAAAh+QQAAAAAACwAAAAAZABkAAAC/4SPqcvtD6MLtNqLs968+58Z4EiWpime6sqOaQvH8CvXNkjf+m7l/G/zAYctIfGIAiCXKyPzuXFCpz0l9aqRYqHaLbPrRYLDxDEZaD7z0modux20wrny+bduF+Pz5T0f7fe3FijoRlgYh9inOPTGSOL4iHMoyRJZ2XGJGUW5meSZCCqjKVpVGkN6GpB6ylrqKgoLKutJu2mLiVupK8n76MsIrCiMSFxoLIj8p8zHnOdsBz0nDUfdZq2GfaZNxh3m7QW+JY5FfmVOhT6lTqda1OnOwf40fxffBH8fkq9/Ub/0T0+/TwMh8Su46mDBgEcYLkI4CWJEiR4cNlI40CIgig0VMfaTADKkyJEkDRQAADs=';
|
|
70
|
+
} else {
|
|
71
|
+
return common.serviceUrl + `/db/icon/${id}/img`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Pipe({name: 'makeIconUrl'})
|
|
77
|
+
export class MakeIconUrl implements PipeTransform {
|
|
78
|
+
transform(id: number): string {
|
|
79
|
+
if (id === -1) {
|
|
80
|
+
return '/assets/icon.svg';
|
|
81
|
+
} else {
|
|
82
|
+
return common.serviceUrl + `/db/icon/${id}/img`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated
|
|
89
|
+
*/
|
|
90
|
+
@Pipe({name: 'makeChartUrl'})
|
|
91
|
+
export class MakeChartUrl implements PipeTransform {
|
|
92
|
+
transform(id: number, isCalc, isSignal = false): string {
|
|
93
|
+
return common.transformChartUrlConfig(id, isCalc, isSignal);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Pipe({name: 'chartUrl'})
|
|
98
|
+
export class ChartUrl implements PipeTransform {
|
|
99
|
+
transform(param: IWidgetDeviceParamData): string {
|
|
100
|
+
return common.transformChartUrlConfig(param);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// Добавляем значения для
|
|
106
|
+
export function assignValues(inputValues: WidgetParamsChildren, params: IWidgetParam[], viewConfig: {
|
|
107
|
+
[k: string]: IWidgetParamConfig
|
|
108
|
+
}, path = []): ItemParent {
|
|
109
|
+
|
|
110
|
+
const result: WidgetItems = {};
|
|
111
|
+
for (const key in inputValues) {
|
|
112
|
+
if (inputValues.hasOwnProperty(key)) {
|
|
113
|
+
const item = inputValues[key];
|
|
114
|
+
const itemPath = [...path, key];
|
|
115
|
+
const refName = itemPath.join('.');
|
|
116
|
+
if (item.items) {
|
|
117
|
+
const param = params.find(val => val.refName === itemPath.join('.'));
|
|
118
|
+
const cfg = getConfig(viewConfig, refName);
|
|
119
|
+
if (item.items instanceof Array) {
|
|
120
|
+
result[key] = {
|
|
121
|
+
items: assignValuesArray(item.items as WidgetArrayParam[], params, viewConfig, itemPath, item.param_type),
|
|
122
|
+
viewConfig: cfg,
|
|
123
|
+
files: cfg.files ? cfg.files : null,
|
|
124
|
+
custom_data: item.custom_data
|
|
125
|
+
} as ItemParent;
|
|
126
|
+
} else {
|
|
127
|
+
result[key] = {
|
|
128
|
+
...assignValues(item.items as WidgetParamsChildren, params, viewConfig, itemPath),
|
|
129
|
+
refName,
|
|
130
|
+
viewConfig: cfg,
|
|
131
|
+
files: cfg.files ? cfg.files : null,
|
|
132
|
+
custom_data: item.custom_data
|
|
133
|
+
} as ItemParent;
|
|
134
|
+
}
|
|
135
|
+
if (param && param.config && (result[key] as ItemParent)) {
|
|
136
|
+
(result[key] as ItemParent).config = param.config;
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
result[key] = assignValue(item, itemPath, params, viewConfig);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function validateArcherParams(variables) {
|
|
147
|
+
const errors = [];
|
|
148
|
+
const forbiddenNames = ['viewConfig', 'title', 'config', 'files'];
|
|
149
|
+
|
|
150
|
+
forbiddenNames.forEach(name => {
|
|
151
|
+
if (variables.find(item => item.name === name)) {
|
|
152
|
+
errors.push(name);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return errors;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
function getConfig(viewConfig, refName): IWidgetParamConfig {
|
|
160
|
+
return viewConfig[refName] ? viewConfig[refName] : {};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function assignValuesArray(inputValues: WidgetArrayParam[], params: IWidgetParam[], viewConfigs: { [k: string]: IWidgetParamConfig },
|
|
164
|
+
path = [], paramType: PARAM_TYPE = PARAM_TYPE.value): WidgetItem[] {
|
|
165
|
+
let result: WidgetItem[] = [];
|
|
166
|
+
const sPath = path.join('.');
|
|
167
|
+
const inputValue = inputValues[0];
|
|
168
|
+
params.forEach(val => {
|
|
169
|
+
const valPath = val.refName.split('.');
|
|
170
|
+
const ind: any = valPath.splice(valPath.length - 1, 1);
|
|
171
|
+
const pType = inputValue.param_type ?? paramType;
|
|
172
|
+
if (valPath.join('.') === sPath) {
|
|
173
|
+
const viewConfig = getConfig(viewConfigs, val.refName);
|
|
174
|
+
if (val.itemType === ITEM_TYPE.custom) {
|
|
175
|
+
let value: any;
|
|
176
|
+
if (pType === PARAM_TYPE.custom_json) {
|
|
177
|
+
try {
|
|
178
|
+
value = JSON.parse((val.config as ParamConfigCustom).value);
|
|
179
|
+
} catch (e) {
|
|
180
|
+
value = {};
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
value = (val.config as ParamConfigCustom).value;
|
|
184
|
+
}
|
|
185
|
+
if (pType === PARAM_TYPE.virtual_object) {
|
|
186
|
+
result[ind] = assignValues(inputValue as any, params, viewConfigs, [...path, ...ind]);
|
|
187
|
+
} else {
|
|
188
|
+
result[ind] = {...val, data: null, value, viewConfig};
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
const value = (val.itemType === ITEM_TYPE.single && val?.device?.param?.value) ? val.device.param.value : null;
|
|
192
|
+
result[ind] = {...val, data: value, value, viewConfig};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
result = result.filter(val => val);
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
function assignValue(item: WidgetParamChildren, itemPath, params: IWidgetParam[],
|
|
202
|
+
viewConfigs: { [k: string]: IWidgetParamConfig }): WidgetItem {
|
|
203
|
+
const path = itemPath.join('.');
|
|
204
|
+
|
|
205
|
+
if (item.item_type === ITEM_TYPE.table) {
|
|
206
|
+
const itemValues: TableValues = [];
|
|
207
|
+
let rows = 0, cols = 0;
|
|
208
|
+
const itemTable: IWidgetParam = params.find(param => param.refName === path);
|
|
209
|
+
params.forEach((param: IWidgetParam) => {
|
|
210
|
+
if (param.refName.indexOf(path) === 0) {
|
|
211
|
+
|
|
212
|
+
const path = param.refName.split('.');
|
|
213
|
+
const i = parseInt(path[path.length - 2]) - 1;
|
|
214
|
+
const j = parseInt(path[path.length - 1]) - 1;
|
|
215
|
+
if (!itemValues[i]) {
|
|
216
|
+
itemValues[i] = [];
|
|
217
|
+
}
|
|
218
|
+
itemValues[i][j] = {
|
|
219
|
+
...param,
|
|
220
|
+
data: null,
|
|
221
|
+
value: null,
|
|
222
|
+
custom: {},
|
|
223
|
+
config: {},
|
|
224
|
+
viewConfig: getConfig(viewConfigs, path.join('.')),
|
|
225
|
+
custom_data: item.custom_data,
|
|
226
|
+
};
|
|
227
|
+
if (i > rows) {
|
|
228
|
+
rows = i;
|
|
229
|
+
}
|
|
230
|
+
if (j > cols) {
|
|
231
|
+
cols = j;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const res: ItemTable = {
|
|
237
|
+
...itemTable,
|
|
238
|
+
values: itemValues,
|
|
239
|
+
viewConfig: getConfig(viewConfigs, path),
|
|
240
|
+
custom_data: item.custom_data,
|
|
241
|
+
};
|
|
242
|
+
return res;
|
|
243
|
+
} else {
|
|
244
|
+
const param = params.find(val => val.refName === path);
|
|
245
|
+
if (param && param.config) {
|
|
246
|
+
const viewConfig = getConfig(viewConfigs, path);
|
|
247
|
+
if (item.item_type === ITEM_TYPE.custom) {
|
|
248
|
+
let value: any;
|
|
249
|
+
if (item.param_type === PARAM_TYPE.custom_json) {
|
|
250
|
+
try {
|
|
251
|
+
value = JSON.parse((param.config as ParamConfigCustom).value);
|
|
252
|
+
} catch (e) {
|
|
253
|
+
value = {};
|
|
254
|
+
}
|
|
255
|
+
} else if (item.param_type === PARAM_TYPE.custom_fuxa) {
|
|
256
|
+
value = (param as any).value;
|
|
257
|
+
} else {
|
|
258
|
+
value = (param.config as ParamConfigCustom).value;
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
...param,
|
|
262
|
+
data: null,
|
|
263
|
+
value,
|
|
264
|
+
custom_data: item.custom_data,
|
|
265
|
+
viewConfig,
|
|
266
|
+
custom: {}
|
|
267
|
+
};
|
|
268
|
+
} else {
|
|
269
|
+
const value = (param.itemType === ITEM_TYPE.single && param?.device?.param?.value) ? param.device.param.value : null;
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
...param,
|
|
273
|
+
data: value,
|
|
274
|
+
value,
|
|
275
|
+
custom_data: item.custom_data,
|
|
276
|
+
viewConfig,
|
|
277
|
+
custom: {}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
return {data: null};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function clearParams(params: ParamConfigurator[]) {
|
|
287
|
+
for (let i = 0; i < params.length; i++) {
|
|
288
|
+
params[i].value = null;
|
|
289
|
+
if (params[i].items) {
|
|
290
|
+
clearParams(params[i].items);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function findParam(params: ParamConfigurator[], refname: string): ParamConfigurator {
|
|
296
|
+
for (let i = 0; i < params.length; i++) {
|
|
297
|
+
if (params[i].name === refname) {
|
|
298
|
+
return params[i];
|
|
299
|
+
}
|
|
300
|
+
if (params[i].items) {
|
|
301
|
+
const param = findParam(params[i].items, refname);
|
|
302
|
+
if (param) {
|
|
303
|
+
return param;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
// Преобразует структуру параметров виджета в структуру для конфигуратора
|
|
312
|
+
export function createParamList(params: WidgetParamsChildren | WidgetParamsChildren[] | WidgetParamChildren[], itemType = ITEM_TYPE.single,
|
|
313
|
+
paramType: PARAM_TYPE = PARAM_TYPE.value, path = [], parent = null): ParamConfigurator[] {
|
|
314
|
+
const result: ParamConfigurator[] = [];
|
|
315
|
+
if (params instanceof Array) {
|
|
316
|
+
// Элемент масссива
|
|
317
|
+
const item: any = params[0];
|
|
318
|
+
// if (!item.title) {
|
|
319
|
+
// item.title = 'Item 1';
|
|
320
|
+
// }
|
|
321
|
+
|
|
322
|
+
const pItemType = item.item_type || itemType;
|
|
323
|
+
const pParamType = item.param_type || paramType;
|
|
324
|
+
|
|
325
|
+
if (pParamType === PARAM_TYPE.virtual_object) {
|
|
326
|
+
const itemPath = [...path, 1];
|
|
327
|
+
result.push(createParam(item, itemPath, pItemType, pParamType, item));
|
|
328
|
+
|
|
329
|
+
} else {
|
|
330
|
+
const itemPath = [...path, 1];
|
|
331
|
+
result.push({
|
|
332
|
+
name: itemPath.join('.'),
|
|
333
|
+
title: 'Item 1',
|
|
334
|
+
views: item.views,
|
|
335
|
+
itemType: pItemType,
|
|
336
|
+
paramType: pParamType,
|
|
337
|
+
parent,
|
|
338
|
+
config: null,
|
|
339
|
+
generateConfig: {count: 3, param: true, data: true},
|
|
340
|
+
param: item,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
} else {
|
|
344
|
+
for (const key in params) {
|
|
345
|
+
if (params.hasOwnProperty(key)) {
|
|
346
|
+
const item = params[key];
|
|
347
|
+
|
|
348
|
+
const pItemType = item.item_type || itemType;
|
|
349
|
+
const pParamType = item.param_type || paramType;
|
|
350
|
+
const itemPath = [...path, key];
|
|
351
|
+
|
|
352
|
+
if (params[key].items) {
|
|
353
|
+
// Массив
|
|
354
|
+
result.push(createParam(item, itemPath, pItemType, pParamType, parent));
|
|
355
|
+
} else {
|
|
356
|
+
// Таблица
|
|
357
|
+
if (pItemType === ITEM_TYPE.table) {
|
|
358
|
+
result.push({
|
|
359
|
+
name: itemPath.join('.'),
|
|
360
|
+
views: item.views,
|
|
361
|
+
title: item.title,
|
|
362
|
+
itemType: pItemType,
|
|
363
|
+
paramType: pParamType,
|
|
364
|
+
parent,
|
|
365
|
+
param: params[key],
|
|
366
|
+
viewConfig: {
|
|
367
|
+
rows: 1,
|
|
368
|
+
cols: 1,
|
|
369
|
+
colsName: ['Col 1'],
|
|
370
|
+
rowsName: ['Row 1'],
|
|
371
|
+
visibleRow: true,
|
|
372
|
+
visibleCol: true,
|
|
373
|
+
table: {
|
|
374
|
+
visibleRow: true,
|
|
375
|
+
visibleCol: true,
|
|
376
|
+
colConfig: [{name: ''}, {name: 'Col 1'}],
|
|
377
|
+
rowConfig: [{name: 'Row 1'}],
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
config: {},
|
|
381
|
+
generateConfig: {
|
|
382
|
+
data: true,
|
|
383
|
+
param: true,
|
|
384
|
+
rows: 2,
|
|
385
|
+
columns: 2,
|
|
386
|
+
visibleCol: true,
|
|
387
|
+
visibleRow: true,
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
} else {
|
|
391
|
+
// Простой элемент
|
|
392
|
+
|
|
393
|
+
let config: any = {};
|
|
394
|
+
if (ITEM_TYPE.series === pItemType) {
|
|
395
|
+
config = {count: 0, charttype: ChartTypes.lineChart, duration: SeriesDuration.day};
|
|
396
|
+
}
|
|
397
|
+
result.push({
|
|
398
|
+
name: itemPath.join('.'),
|
|
399
|
+
title: item.title,
|
|
400
|
+
views: item.views,
|
|
401
|
+
itemType: pItemType,
|
|
402
|
+
paramType: pParamType,
|
|
403
|
+
parent,
|
|
404
|
+
config,
|
|
405
|
+
param: params[key],
|
|
406
|
+
generateConfig: {data: true, param: true}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return result;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
function createParam(item, itemPath, itemType, paramType, parent) {
|
|
418
|
+
let config: any = {};
|
|
419
|
+
if (ITEM_TYPE.series === itemType) {
|
|
420
|
+
config = {count: 0, charttype: ChartTypes.lineChart, duration: SeriesDuration.day};
|
|
421
|
+
}
|
|
422
|
+
const res: ParamConfigurator = {
|
|
423
|
+
name: itemPath.join('.'),
|
|
424
|
+
title: _(item.title),
|
|
425
|
+
itemType,
|
|
426
|
+
paramType,
|
|
427
|
+
parent,
|
|
428
|
+
views: item.views,
|
|
429
|
+
config,
|
|
430
|
+
generateConfig: {count: 3, param: true, data: true},
|
|
431
|
+
param: item,
|
|
432
|
+
};
|
|
433
|
+
if (item.items) {
|
|
434
|
+
res.items = createParamList(item.items, itemType, paramType, itemPath, res);
|
|
435
|
+
if (item.items instanceof Array) {
|
|
436
|
+
res.isArray = true;
|
|
437
|
+
if (item.items[0].max) {
|
|
438
|
+
res.maxItems = item.items[0].max;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
} else if (paramType === PARAM_TYPE.virtual_object) {
|
|
442
|
+
// Массив объектов
|
|
443
|
+
res.items = createParamList(item, itemType, paramType, itemPath, res);
|
|
444
|
+
}
|
|
445
|
+
return res;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
export function createGenerateItemConfig(): GenerateConfigItem {
|
|
450
|
+
return {
|
|
451
|
+
pageLink: false,
|
|
452
|
+
isOnline: true,
|
|
453
|
+
data: true,
|
|
454
|
+
param: true,
|
|
455
|
+
borders: false,
|
|
456
|
+
editable: false,
|
|
457
|
+
paragraphCount: 1,
|
|
458
|
+
isWorkingDevice: true,
|
|
459
|
+
title: 'Title param',
|
|
460
|
+
ctrability: true,
|
|
461
|
+
archer: {}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export function addArrayItem(parent: ParamConfigurator) {
|
|
466
|
+
if (parent.paramType === PARAM_TYPE.virtual_object) {
|
|
467
|
+
parent.items.push({
|
|
468
|
+
...updateIndex(clearValue(deepClone(parent.items[0])), parent.items[0].name, [parent.name, parent.items.length + 1].join('.')),
|
|
469
|
+
name: [parent.name, parent.items.length + 1].join('.'),
|
|
470
|
+
title: `Item ${parent.items.length + 1}`,
|
|
471
|
+
parent: parent,
|
|
472
|
+
});
|
|
473
|
+
} else {
|
|
474
|
+
parent.items.push({
|
|
475
|
+
name: [parent.name, parent.items.length + 1].join('.'),
|
|
476
|
+
title: `Item ${parent.items.length + 1}`,
|
|
477
|
+
itemType: parent.itemType,
|
|
478
|
+
paramType: parent.paramType,
|
|
479
|
+
parent: parent,
|
|
480
|
+
config: {}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function deepClone(obj, map = new WeakMap()) {
|
|
486
|
+
if (obj === null || typeof obj !== 'object') {
|
|
487
|
+
return obj; // Если obj не объект или null, просто возвращаем его
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
if (obj instanceof Date) {
|
|
491
|
+
return new Date(obj.getTime()); // Клонируем даты
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (obj instanceof RegExp) {
|
|
495
|
+
return new RegExp(obj); // Клонируем регулярные выражения
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (map.has(obj)) {
|
|
499
|
+
return map.get(obj); // Обработка циклических ссылок
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const result = Array.isArray(obj) ? [] : {}; // Создаем пустой объект или массив в зависимости от типа
|
|
503
|
+
|
|
504
|
+
map.set(obj, result); // Сохраняем объект в WeakMap для отслеживания циклических ссылок
|
|
505
|
+
|
|
506
|
+
for (const key of Object.keys(obj)) {
|
|
507
|
+
result[key] = deepClone(obj[key], map); // Рекурсивно клонируем все свойства
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return result;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
export function clearValue(param: ParamConfigurator) {
|
|
515
|
+
param.value = undefined;
|
|
516
|
+
if (param.items) {
|
|
517
|
+
param.items = param.items.map((p) => clearValue(p));
|
|
518
|
+
if (param.isArray && param.paramType !== PARAM_TYPE.virtual_object) {
|
|
519
|
+
param.items = param.items.slice(0, 1);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return param;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export function updateIndex(param: ParamConfigurator, oldName, newName) {
|
|
526
|
+
param.name = param.name.replace(oldName, newName);
|
|
527
|
+
if (param.items) {
|
|
528
|
+
param.items = param.items.map((p) => updateIndex(p, oldName, newName));
|
|
529
|
+
if (param.isArray && param.paramType !== PARAM_TYPE.virtual_object) {
|
|
530
|
+
param.items = param.items.slice(0, 1);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return param;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
export function convertArcherToItem(item, param): ParamConfigurator {
|
|
537
|
+
return {
|
|
538
|
+
name: (param.name || param.refName) + '.' + item.name,
|
|
539
|
+
title: item.title ? item.title : item.name,
|
|
540
|
+
itemType: ITEM_TYPE.single,
|
|
541
|
+
paramType: PARAM_TYPE.value,
|
|
542
|
+
parent: param,
|
|
543
|
+
config: {},
|
|
544
|
+
generateConfig: {
|
|
545
|
+
count: 3, param: true, data: true
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
export function prepareExternalJSON(json) {
|
|
552
|
+
for (const k in json) {
|
|
553
|
+
if (json.hasOwnProperty(k)) {
|
|
554
|
+
if (json[k].item_type && typeof json[k].item_type === 'string') {
|
|
555
|
+
json[k].item_type = ITEM_TYPE[json[k].item_type];
|
|
556
|
+
}
|
|
557
|
+
if (json[k].param_type && typeof json[k].param_type === 'string') {
|
|
558
|
+
json[k].param_type = PARAM_TYPE[json[k].param_type];
|
|
559
|
+
}
|
|
560
|
+
if (json[k].items) {
|
|
561
|
+
json[k].items = prepareExternalJSON(json[k].items);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return json;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
export class Utils {
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
public static getDate(ts: number = Date.now()) {
|
|
573
|
+
const d = new Date(ts);
|
|
574
|
+
const dd = d.getDate();
|
|
575
|
+
const mm = d.getMonth() + 1;
|
|
576
|
+
const yyyy = d.getFullYear();
|
|
577
|
+
return ('0' + dd).slice(-2) + '/' + ('0' + mm).slice(-2) + '/' + yyyy;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
public static getDay(num: number) {
|
|
581
|
+
const d = new Date();
|
|
582
|
+
d.setDate(d.getDate() - num);
|
|
583
|
+
const dd = d.getDate();
|
|
584
|
+
const mm = d.getMonth() + 1;
|
|
585
|
+
const yyyy = d.getFullYear();
|
|
586
|
+
return ('0' + dd).slice(-2) + '/' + ('0' + mm).slice(-2) + '/' + yyyy;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
public static getWeek(num: number) {
|
|
590
|
+
const d = new Date();
|
|
591
|
+
const day = d.getDay();
|
|
592
|
+
if (day === 0) {
|
|
593
|
+
num++;
|
|
594
|
+
}
|
|
595
|
+
const firstDay: any = new Date();
|
|
596
|
+
firstDay.setDate(d.getDate() - day - num * 7 + 1);
|
|
597
|
+
const lastDay: any = new Date();
|
|
598
|
+
if (num > 0) {
|
|
599
|
+
lastDay.setDate(d.getDate() - day - (num - 1) * 7);
|
|
600
|
+
}
|
|
601
|
+
return ('0' + firstDay.getDate()).slice(-2) + '/' + ('0' + (firstDay.getMonth() + 1)).slice(-2) + '/' + firstDay.getFullYear() + ' - ' +
|
|
602
|
+
('0' + lastDay.getDate()).slice(-2) + '/' + ('0' + (lastDay.getMonth() + 1)).slice(-2) + '/' + lastDay.getFullYear();
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
public static getMonth(num: number) {
|
|
607
|
+
const d: any = new Date();
|
|
608
|
+
d.setMonth(d.getMonth() - num);
|
|
609
|
+
const dd: any = d.getDate();
|
|
610
|
+
const mm: any = d.getMonth();
|
|
611
|
+
const yyyy: any = d.getFullYear();
|
|
612
|
+
|
|
613
|
+
const firstDay: any = new Date(yyyy, mm, 1);
|
|
614
|
+
const lastDay: any = new Date(yyyy, mm + 1, 0);
|
|
615
|
+
return ('0' + firstDay.getDate()).slice(-2) + '/' + ('0' + (firstDay.getMonth() + 1)).slice(-2) + '/' + firstDay.getFullYear() + ' - ' +
|
|
616
|
+
('0' + lastDay.getDate()).slice(-2) + '/' + ('0' + (lastDay.getMonth() + 1)).slice(-2) + '/' + lastDay.getFullYear();
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
public static getTime(ts: number) {
|
|
621
|
+
let d;
|
|
622
|
+
if (typeof ts === 'undefined') {
|
|
623
|
+
d = new Date();
|
|
624
|
+
} else {
|
|
625
|
+
d = new Date(ts);
|
|
626
|
+
}
|
|
627
|
+
const hh = d.getHours();
|
|
628
|
+
const mm = d.getMinutes();
|
|
629
|
+
const ss = d.getSeconds();
|
|
630
|
+
return ('0' + hh).slice(-2) + ':' + ('0' + mm).slice(-2);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
.label-formatter {
|
|
3
|
+
background: #f00;
|
|
4
|
+
.title {
|
|
5
|
+
padding-bottom: 8px;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
table {
|
|
9
|
+
color: #333;
|
|
10
|
+
|
|
11
|
+
.label {
|
|
12
|
+
padding-right: 8px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.value {
|
|
16
|
+
text-align: right;
|
|
17
|
+
font-weight: bold;
|
|
18
|
+
color: #555;
|
|
19
|
+
min-width: 100px;
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'core-js/es7/reflect';
|
|
4
|
+
import 'zone.js/dist/zone';
|
|
5
|
+
import 'zone.js/dist/zone-testing';
|
|
6
|
+
import { getTestBed } from '@angular/core/testing';
|
|
7
|
+
import {
|
|
8
|
+
BrowserDynamicTestingModule,
|
|
9
|
+
platformBrowserDynamicTesting
|
|
10
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
11
|
+
|
|
12
|
+
declare const require: any;
|
|
13
|
+
|
|
14
|
+
// First, initialize the Angular testing environment.
|
|
15
|
+
getTestBed().initTestEnvironment(
|
|
16
|
+
BrowserDynamicTestingModule,
|
|
17
|
+
platformBrowserDynamicTesting()
|
|
18
|
+
);
|
|
19
|
+
// Then we find all the tests.
|
|
20
|
+
const context = require.context('./', true, /\.spec\.ts$/);
|
|
21
|
+
// And load the modules.
|
|
22
|
+
context.keys().map(context);
|