@c8y/ngx-components 1023.58.3 → 1023.59.1
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/assets-navigator/index.d.ts.map +1 -1
- package/computed-asset-properties/index.d.ts.map +1 -1
- package/fesm2022/c8y-ngx-components-assets-navigator.mjs +4 -2
- package/fesm2022/c8y-ngx-components-assets-navigator.mjs.map +1 -1
- package/fesm2022/c8y-ngx-components-computed-asset-properties-c8y-ngx-components-computed-asset-properties-C5oS4Be-.mjs +790 -0
- package/fesm2022/c8y-ngx-components-computed-asset-properties-c8y-ngx-components-computed-asset-properties-C5oS4Be-.mjs.map +1 -0
- package/fesm2022/c8y-ngx-components-computed-asset-properties-fieldbus-item-status-config.component-Bg9mbBkF.mjs +120 -0
- package/fesm2022/c8y-ngx-components-computed-asset-properties-fieldbus-item-status-config.component-Bg9mbBkF.mjs.map +1 -0
- package/fesm2022/c8y-ngx-components-computed-asset-properties.mjs +1 -642
- package/fesm2022/c8y-ngx-components-computed-asset-properties.mjs.map +1 -1
- package/locales/locales.pot +15 -0
- package/package.json +1 -1
|
@@ -1,643 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { inject, Injector } from '@angular/core';
|
|
3
|
-
import { MeasurementService, InventoryService, AlarmService, EventService, OperationService } from '@c8y/client';
|
|
4
|
-
import { MeasurementRealtimeService, DatePipe, ManagedObjectRealtimeService, AlarmRealtimeService, EventRealtimeService, OperationRealtimeService } from '@c8y/ngx-components';
|
|
5
|
-
import { from, map, filter, startWith, take, switchMap, distinctUntilChanged, pairwise, share, NEVER, scan, tap, of, catchError, combineLatest, merge } from 'rxjs';
|
|
6
|
-
import { gettext } from '@c8y/ngx-components/gettext';
|
|
7
|
-
|
|
8
|
-
class LastMeasurementStrategy {
|
|
9
|
-
constructor(config, injector) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
this.measurementService = injector.get(MeasurementService);
|
|
12
|
-
this.measurementRealtime = injector.get(MeasurementRealtimeService);
|
|
13
|
-
this.datePipe = injector.get(DatePipe);
|
|
14
|
-
this.datapoint = config.dp.filter(dp => dp.__active)[0];
|
|
15
|
-
}
|
|
16
|
-
fetchCurrentValue() {
|
|
17
|
-
const measurementFilter = {
|
|
18
|
-
valueFragmentSeries: this.datapoint.series,
|
|
19
|
-
valueFragmentType: this.datapoint.fragment,
|
|
20
|
-
pageSize: 1,
|
|
21
|
-
revert: true,
|
|
22
|
-
dateFrom: '1970-01-01',
|
|
23
|
-
source: this.datapoint.__target.id
|
|
24
|
-
};
|
|
25
|
-
return from(this.measurementService.list(measurementFilter)).pipe(map(({ data }) => data[0]), filter(measurement => !!measurement), map(measurement => this.formatMeasurement(measurement)));
|
|
26
|
-
}
|
|
27
|
-
createRealtimeStream(initialValue) {
|
|
28
|
-
return this.measurementRealtime
|
|
29
|
-
.onCreateOfSpecificMeasurement$(this.datapoint.fragment, this.datapoint.series, this.datapoint.__target)
|
|
30
|
-
.pipe(map(measurement => this.formatMeasurement(measurement)), startWith(initialValue));
|
|
31
|
-
}
|
|
32
|
-
formatMeasurement(measurement) {
|
|
33
|
-
const resultType = this.config?.resultType;
|
|
34
|
-
const fragment = this.datapoint.fragment;
|
|
35
|
-
const series = this.datapoint.series;
|
|
36
|
-
if (resultType === 1) {
|
|
37
|
-
return measurement[fragment][series].value;
|
|
38
|
-
}
|
|
39
|
-
else if (resultType === 2) {
|
|
40
|
-
return measurement[fragment][series].value + ' ' + measurement[fragment][series].unit;
|
|
41
|
-
}
|
|
42
|
-
else if (resultType === 3) {
|
|
43
|
-
const date = this.datePipe.transform(new Date(measurement.time), 'short');
|
|
44
|
-
return `${date} | ${measurement[fragment][series].value} ${measurement[fragment][series].unit}`;
|
|
45
|
-
}
|
|
46
|
-
else if (resultType === 4) {
|
|
47
|
-
return measurement[fragment][series];
|
|
48
|
-
}
|
|
49
|
-
return '';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Generic handler for realtime values following the three modes pattern
|
|
55
|
-
* Closed for modification but open for extension through strategies
|
|
56
|
-
*/
|
|
57
|
-
class RealtimeValueHandler {
|
|
58
|
-
constructor(strategy, config) {
|
|
59
|
-
this.strategy = strategy;
|
|
60
|
-
this.config = {
|
|
61
|
-
refetchOnResume: true,
|
|
62
|
-
preserveValueOnPause: true
|
|
63
|
-
};
|
|
64
|
-
if (config) {
|
|
65
|
-
this.config = { ...this.config, ...config };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Creates an Observable based on the metadata mode
|
|
70
|
-
*/
|
|
71
|
-
getValue(metadata = { mode: 'realtime' }) {
|
|
72
|
-
if (metadata.mode === 'singleValue') {
|
|
73
|
-
return this.strategy.fetchCurrentValue().pipe(take(1));
|
|
74
|
-
}
|
|
75
|
-
if (metadata.mode === 'realtime' && !metadata.realtimeControl$) {
|
|
76
|
-
return this.handleUncontrolledRealtime();
|
|
77
|
-
}
|
|
78
|
-
if (metadata.mode === 'realtime' && metadata.realtimeControl$) {
|
|
79
|
-
return this.handleControlledRealtime(metadata.realtimeControl$);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
handleUncontrolledRealtime() {
|
|
83
|
-
return this.strategy
|
|
84
|
-
.fetchCurrentValue()
|
|
85
|
-
.pipe(switchMap(initialValue => this.strategy.createRealtimeStream(initialValue)));
|
|
86
|
-
}
|
|
87
|
-
handleControlledRealtime(control$) {
|
|
88
|
-
const controlWithPrevious$ = control$.pipe(distinctUntilChanged(), startWith(null), pairwise(), share());
|
|
89
|
-
return controlWithPrevious$.pipe(switchMap(([previous, current]) => {
|
|
90
|
-
if (!current) {
|
|
91
|
-
// Realtime is disabled
|
|
92
|
-
if (previous === null) {
|
|
93
|
-
// Initial emission while disabled
|
|
94
|
-
return this.strategy.fetchCurrentValue().pipe(take(1));
|
|
95
|
-
}
|
|
96
|
-
else if (this.config.preserveValueOnPause) {
|
|
97
|
-
// Was previously enabled - preserve last value
|
|
98
|
-
return NEVER;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
// Don't preserve value - fetch current
|
|
102
|
-
return this.strategy.fetchCurrentValue().pipe(take(1));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// Realtime is enabled
|
|
107
|
-
if (this.config.refetchOnResume || previous === null) {
|
|
108
|
-
// Re-fetch current value and start streaming
|
|
109
|
-
return this.strategy
|
|
110
|
-
.fetchCurrentValue()
|
|
111
|
-
.pipe(switchMap(currentValue => this.strategy.createRealtimeStream(currentValue)));
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
// Continue with realtime stream without re-fetching
|
|
115
|
-
return this.strategy.createRealtimeStream(null);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Creates an Observable that tracks the latest measurement value for a specific datapoint.
|
|
124
|
-
* Combines initial server fetch with real-time measurement updates.
|
|
125
|
-
*
|
|
126
|
-
* @param config - Measurement configuration (datapoint, result type, etc.)
|
|
127
|
-
* @param metadata - Configuration controlling the behavior of the function
|
|
128
|
-
* @returns Observable<string> - Stream of measurement string values
|
|
129
|
-
*/
|
|
130
|
-
function lastMeasurementValue(config, metadata = { mode: 'realtime' }) {
|
|
131
|
-
const injector = inject(Injector);
|
|
132
|
-
const strategy = new LastMeasurementStrategy(config, injector);
|
|
133
|
-
const handler = new RealtimeValueHandler(strategy);
|
|
134
|
-
return handler.getValue(metadata);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const lastMeasurement = {
|
|
138
|
-
name: 'lastMeasurement',
|
|
139
|
-
contextType: ['device', 'asset', 'group'],
|
|
140
|
-
prop: {
|
|
141
|
-
c8y_JsonSchema: {
|
|
142
|
-
properties: {
|
|
143
|
-
lastMeasurement: {
|
|
144
|
-
label: 'Last measurement',
|
|
145
|
-
type: 'string'
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
name: 'lastMeasurement',
|
|
150
|
-
label: gettext('Last measurement'),
|
|
151
|
-
type: 'string',
|
|
152
|
-
config: { dp: [], resultType: 1 },
|
|
153
|
-
computed: true,
|
|
154
|
-
isEditable: false,
|
|
155
|
-
isStandardProperty: true
|
|
156
|
-
},
|
|
157
|
-
loadConfigComponent: () => import('./c8y-ngx-components-computed-asset-properties-last-measurement-config.component-DkrSvf9F.mjs').then(m => m.ComputedPropertyLastMeasurementConfigComponent),
|
|
158
|
-
value: ({ config }) => {
|
|
159
|
-
return lastMeasurementValue(config);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
class ChildCountStrategy {
|
|
164
|
-
constructor(asset, childType, injector) {
|
|
165
|
-
this.asset = asset;
|
|
166
|
-
this.childType = childType;
|
|
167
|
-
this.inventoryService = injector.get(InventoryService);
|
|
168
|
-
this.moRealtimeService = injector.get(ManagedObjectRealtimeService);
|
|
169
|
-
}
|
|
170
|
-
fetchCurrentValue() {
|
|
171
|
-
return from(this.inventoryService.detail(this.asset.id, { withChildren: true })).pipe(map(resp => resp?.data?.[this.childType]?.references?.length || 0));
|
|
172
|
-
}
|
|
173
|
-
createRealtimeStream(initialValue) {
|
|
174
|
-
return this.moRealtimeService.onAll$(this.asset.id).pipe(map(resp => resp?.data?.[this.childType]?.references?.length || 0), startWith(initialValue));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Shared function that tracks the count of child items (devices or assets) for a specific managed object.
|
|
180
|
-
* Supports real-time updates when child items are added or removed.
|
|
181
|
-
*
|
|
182
|
-
* @param asset - The managed object to track child items for
|
|
183
|
-
* @param childType - Type of child items ('childDevices' or 'childAssets')
|
|
184
|
-
* @param metadata - Configuration controlling the behavior of the function
|
|
185
|
-
* @returns Observable<number> - Stream of child items count values
|
|
186
|
-
*/
|
|
187
|
-
function childCountValue(asset, metadata = { mode: 'realtime' }, childType) {
|
|
188
|
-
const injector = inject(Injector);
|
|
189
|
-
const strategy = new ChildCountStrategy(asset, childType, injector);
|
|
190
|
-
const handler = new RealtimeValueHandler(strategy);
|
|
191
|
-
return handler.getValue(metadata);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const childAssetsCount = {
|
|
195
|
-
name: 'childAssetsCount',
|
|
196
|
-
contextType: ['group', 'asset'],
|
|
197
|
-
prop: {
|
|
198
|
-
c8y_JsonSchema: {
|
|
199
|
-
properties: {
|
|
200
|
-
childAssetsCount: {
|
|
201
|
-
label: 'Number of child assets',
|
|
202
|
-
type: 'number'
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
name: 'childAssetsCount',
|
|
207
|
-
label: gettext('Number of child assets'),
|
|
208
|
-
type: 'number',
|
|
209
|
-
computed: true,
|
|
210
|
-
isEditable: false,
|
|
211
|
-
isStandardProperty: true
|
|
212
|
-
},
|
|
213
|
-
value: ({ context, metadata }) => childAssetsCountValue(context, metadata)
|
|
214
|
-
};
|
|
215
|
-
/**
|
|
216
|
-
* Creates an Observable that tracks the count of child assets for a specific asset.
|
|
217
|
-
* Supports real-time updates when child assets are added or removed.
|
|
218
|
-
*
|
|
219
|
-
* @param asset - The managed object (asset) to track child assets for
|
|
220
|
-
* @param metadata - Configuration controlling the behavior of the function
|
|
221
|
-
* @returns Observable<number> - Stream of child assets count values
|
|
222
|
-
*/
|
|
223
|
-
function childAssetsCountValue(asset, metadata = { mode: 'realtime' }) {
|
|
224
|
-
return childCountValue(asset, metadata, 'childAssets');
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Base class for count-based strategies
|
|
229
|
-
* Provides common accumulation logic
|
|
230
|
-
*/
|
|
231
|
-
class CountStrategyBase {
|
|
232
|
-
createRealtimeStream(initialValue) {
|
|
233
|
-
return this.getRealtimeIncrement$().pipe(scan((count, increment) => count + increment, initialValue), startWith(initialValue));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
class AlarmCountStrategy extends CountStrategyBase {
|
|
238
|
-
constructor(config, asset, dateFrom, injector) {
|
|
239
|
-
super();
|
|
240
|
-
this.config = config;
|
|
241
|
-
this.asset = asset;
|
|
242
|
-
this.dateFrom = dateFrom;
|
|
243
|
-
this.alarmService = injector.get(AlarmService);
|
|
244
|
-
this.alarmRealtimeService = injector.get(AlarmRealtimeService);
|
|
245
|
-
this.startTime = new Date();
|
|
246
|
-
}
|
|
247
|
-
fetchCurrentValue() {
|
|
248
|
-
const severities = Object.keys(this.config.severities || {}).filter(key => this.config.severities[key]);
|
|
249
|
-
const filters = {
|
|
250
|
-
source: this.asset.id,
|
|
251
|
-
dateFrom: this.dateFrom.toISOString(),
|
|
252
|
-
type: this.config.type,
|
|
253
|
-
pageSize: 1,
|
|
254
|
-
withTotalElements: true,
|
|
255
|
-
...(severities.length && { severity: severities.join(',') })
|
|
256
|
-
};
|
|
257
|
-
return from(this.alarmService.list(filters)).pipe(map(resp => resp?.paging?.totalElements || 0), tap(() => (this.startTime = new Date())) // Update start time after fetch
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
getRealtimeIncrement$() {
|
|
261
|
-
return this.alarmRealtimeService.onAll$(this.asset.id).pipe(map(({ data }) => data), filter(alarm => alarm.type === this.config.type &&
|
|
262
|
-
this.config.severities[alarm.severity] &&
|
|
263
|
-
new Date(alarm.creationTime) > this.startTime), tap(() => (this.startTime = new Date())), map(() => 1) // Each matching alarm increments by 1
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Creates an Observable that tracks alarm count for a specific asset.
|
|
270
|
-
* When real-time is paused and resumed, it re-fetches the current count from server
|
|
271
|
-
* to account for alarms that occurred during the pause.
|
|
272
|
-
*
|
|
273
|
-
* @param config - Alarm filtering configuration (type, severities, etc.)
|
|
274
|
-
* @param asset - The managed object (device/asset) to track alarms for
|
|
275
|
-
* @param dateFrom - Start date for counting alarms
|
|
276
|
-
* @param metadata - Configuration controlling the behavior of the function
|
|
277
|
-
* @returns Observable<number> - Stream of alarm count values
|
|
278
|
-
*/
|
|
279
|
-
function alarmCountValue(config, asset, dateFrom, metadata = { mode: 'realtime' }) {
|
|
280
|
-
const injector = inject(Injector);
|
|
281
|
-
const strategy = new AlarmCountStrategy(config, asset, dateFrom, injector);
|
|
282
|
-
const handler = new RealtimeValueHandler(strategy);
|
|
283
|
-
return handler.getValue(metadata);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const alarmCount3Months = {
|
|
287
|
-
name: 'alarmCount3Months',
|
|
288
|
-
contextType: ['device', 'group', 'asset'],
|
|
289
|
-
prop: {
|
|
290
|
-
c8y_JsonSchema: {
|
|
291
|
-
properties: {
|
|
292
|
-
alarmCount3Months: {
|
|
293
|
-
label: 'Alarm count 3 months',
|
|
294
|
-
type: 'number'
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
name: 'alarmCount3Months',
|
|
299
|
-
label: gettext('Alarm count 3 months'),
|
|
300
|
-
type: 'number',
|
|
301
|
-
config: { type: '' },
|
|
302
|
-
computed: true,
|
|
303
|
-
isEditable: false,
|
|
304
|
-
isStandardProperty: true
|
|
305
|
-
},
|
|
306
|
-
loadConfigComponent: () => import('./c8y-ngx-components-computed-asset-properties-alarm-count-config.component-SA0syLy7.mjs').then(m => m.ComputedPropertyAlarmCountConfigComponent),
|
|
307
|
-
value: ({ config, context, metadata }) => alarmCount3MonthsValue(config, context, metadata)
|
|
308
|
-
};
|
|
309
|
-
function alarmCount3MonthsValue(config, asset, metadata) {
|
|
310
|
-
const threeMonthsAgo = new Date();
|
|
311
|
-
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
|
|
312
|
-
return alarmCountValue(config, asset, threeMonthsAgo, metadata);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const alarmCountToday = {
|
|
316
|
-
name: 'alarmCountToday',
|
|
317
|
-
contextType: ['device', 'group', 'asset'],
|
|
318
|
-
prop: {
|
|
319
|
-
c8y_JsonSchema: {
|
|
320
|
-
properties: {
|
|
321
|
-
alarmCountToday: {
|
|
322
|
-
label: 'Alarm count today',
|
|
323
|
-
type: 'number'
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
name: 'alarmCountToday',
|
|
328
|
-
label: gettext('Alarm count today'),
|
|
329
|
-
type: 'number',
|
|
330
|
-
config: { type: '' },
|
|
331
|
-
computed: true,
|
|
332
|
-
isEditable: false,
|
|
333
|
-
isStandardProperty: true
|
|
334
|
-
},
|
|
335
|
-
loadConfigComponent: () => import('./c8y-ngx-components-computed-asset-properties-alarm-count-config.component-SA0syLy7.mjs').then(m => m.ComputedPropertyAlarmCountConfigComponent),
|
|
336
|
-
value: ({ config, context, metadata }) => alarmCountTodayValue(config, context, metadata)
|
|
337
|
-
};
|
|
338
|
-
function alarmCountTodayValue(config, asset, metadata) {
|
|
339
|
-
const oneDayAgo = new Date();
|
|
340
|
-
oneDayAgo.setDate(oneDayAgo.getDate() - 1);
|
|
341
|
-
return alarmCountValue(config, asset, oneDayAgo, metadata);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
class EventCountStrategy extends CountStrategyBase {
|
|
345
|
-
constructor(config, asset, dateFrom, injector) {
|
|
346
|
-
super();
|
|
347
|
-
this.config = config;
|
|
348
|
-
this.asset = asset;
|
|
349
|
-
this.dateFrom = dateFrom;
|
|
350
|
-
this.eventService = injector.get(EventService);
|
|
351
|
-
this.eventRealtimeService = injector.get(EventRealtimeService);
|
|
352
|
-
}
|
|
353
|
-
fetchCurrentValue() {
|
|
354
|
-
const filters = {
|
|
355
|
-
source: this.asset.id,
|
|
356
|
-
dateFrom: this.dateFrom.toISOString(),
|
|
357
|
-
type: this.config.type,
|
|
358
|
-
pageSize: 1,
|
|
359
|
-
withTotalElements: true
|
|
360
|
-
};
|
|
361
|
-
return from(this.eventService.list(filters)).pipe(map(resp => resp?.paging?.totalElements || 0));
|
|
362
|
-
}
|
|
363
|
-
getRealtimeIncrement$() {
|
|
364
|
-
return this.eventRealtimeService.onAll$(this.asset.id).pipe(map(({ data }) => data), filter(event => event.type === this.config.type && new Date(event.time) >= this.dateFrom), map(() => 1));
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Creates an Observable that tracks event count for a specific asset.
|
|
370
|
-
* When real-time is paused and resumed, it re-fetches the current count from server
|
|
371
|
-
* to account for events that occurred during the pause.
|
|
372
|
-
*
|
|
373
|
-
* @param config - Event filtering configuration (type, etc.)
|
|
374
|
-
* @param asset - The managed object (device/asset) to track events for
|
|
375
|
-
* @param dateFrom - Start date for counting events
|
|
376
|
-
* @param metadata - Configuration controlling the behavior of the function
|
|
377
|
-
* @returns Observable<number> - Stream of event count values
|
|
378
|
-
*/
|
|
379
|
-
function eventCountValue(config, asset, dateFrom, metadata = { mode: 'realtime' }) {
|
|
380
|
-
const injector = inject(Injector);
|
|
381
|
-
const strategy = new EventCountStrategy(config, asset, dateFrom, injector);
|
|
382
|
-
const handler = new RealtimeValueHandler(strategy);
|
|
383
|
-
return handler.getValue(metadata);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const eventCountToday = {
|
|
387
|
-
name: 'eventCountToday',
|
|
388
|
-
contextType: ['device', 'group', 'asset'],
|
|
389
|
-
prop: {
|
|
390
|
-
c8y_JsonSchema: {
|
|
391
|
-
properties: {
|
|
392
|
-
eventCountToday: {
|
|
393
|
-
label: 'Event count today',
|
|
394
|
-
type: 'number'
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
},
|
|
398
|
-
name: 'eventCountToday',
|
|
399
|
-
label: gettext('Event count today'),
|
|
400
|
-
type: 'number',
|
|
401
|
-
config: { type: '' },
|
|
402
|
-
computed: true,
|
|
403
|
-
isEditable: false,
|
|
404
|
-
isStandardProperty: true
|
|
405
|
-
},
|
|
406
|
-
loadConfigComponent: () => import('./c8y-ngx-components-computed-asset-properties-event-count-config.component-CaTb9cph.mjs').then(m => m.ComputedPropertyEventCountConfigComponent),
|
|
407
|
-
value: ({ config, context, metadata }) => eventCountTodayValue(config, context, metadata)
|
|
408
|
-
};
|
|
409
|
-
function eventCountTodayValue(config, asset, metadata) {
|
|
410
|
-
const today = new Date();
|
|
411
|
-
today.setHours(0, 0, 0, 0);
|
|
412
|
-
return eventCountValue(config, asset, today, metadata);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const eventCount3Months = {
|
|
416
|
-
name: 'eventCount3Months',
|
|
417
|
-
contextType: ['device', 'group', 'asset'],
|
|
418
|
-
prop: {
|
|
419
|
-
c8y_JsonSchema: {
|
|
420
|
-
properties: {
|
|
421
|
-
eventCount3Months: {
|
|
422
|
-
label: 'Event count 3 months',
|
|
423
|
-
type: 'number'
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
},
|
|
427
|
-
name: 'eventCount3Months',
|
|
428
|
-
label: gettext('Event count 3 months'),
|
|
429
|
-
type: 'number',
|
|
430
|
-
config: { type: '' },
|
|
431
|
-
computed: true,
|
|
432
|
-
isEditable: false,
|
|
433
|
-
isStandardProperty: true
|
|
434
|
-
},
|
|
435
|
-
loadConfigComponent: () => import('./c8y-ngx-components-computed-asset-properties-event-count-config.component-CaTb9cph.mjs').then(m => m.ComputedPropertyEventCountConfigComponent),
|
|
436
|
-
value: ({ config, context, metadata }) => eventCount3MonthsValue(config, context, metadata)
|
|
437
|
-
};
|
|
438
|
-
function eventCount3MonthsValue(config, asset, metadata) {
|
|
439
|
-
const threeMonthsAgo = new Date();
|
|
440
|
-
threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
|
|
441
|
-
return eventCountValue(config, asset, threeMonthsAgo, metadata);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
const configurationSnapshot = {
|
|
445
|
-
name: 'configurationSnapshot',
|
|
446
|
-
contextType: ['device', 'asset'],
|
|
447
|
-
prop: {
|
|
448
|
-
c8y_JsonSchema: {
|
|
449
|
-
properties: {
|
|
450
|
-
configurationSnapshot: {
|
|
451
|
-
label: 'Configuration snapshot',
|
|
452
|
-
type: 'string'
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
},
|
|
456
|
-
contextType: ['device', 'asset'],
|
|
457
|
-
name: 'configurationSnapshot',
|
|
458
|
-
label: gettext('Configuration snapshot'),
|
|
459
|
-
type: 'string',
|
|
460
|
-
config: { legacy: true },
|
|
461
|
-
computed: true,
|
|
462
|
-
isEditable: false,
|
|
463
|
-
isStandardProperty: true
|
|
464
|
-
},
|
|
465
|
-
loadConfigComponent: () => import('./c8y-ngx-components-computed-asset-properties-configuration-snapshot-config.component-BOmgJI14.mjs').then(m => m.ConfigurationSnapshotConfigComponent),
|
|
466
|
-
value: ({ config, context }) => configurationSnapshotValue(config, context)
|
|
467
|
-
};
|
|
468
|
-
function configurationSnapshotValue(config, asset) {
|
|
469
|
-
if (config.legacy) {
|
|
470
|
-
const configId = asset.c8y_ConfigurationDump?.id;
|
|
471
|
-
if (!configId) {
|
|
472
|
-
return of(null);
|
|
473
|
-
}
|
|
474
|
-
const injector = inject(Injector);
|
|
475
|
-
const inventoryService = injector.get(InventoryService);
|
|
476
|
-
return from(inventoryService.detail(configId)).pipe(switchMap(({ data }) => {
|
|
477
|
-
return of(data?.name);
|
|
478
|
-
}));
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
const fragment = `c8y_Configuration_${config.type}`;
|
|
482
|
-
return of(asset[fragment]?.name);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
const childDevicesCount = {
|
|
487
|
-
name: 'childDevicesCount',
|
|
488
|
-
contextType: ['group', 'device', 'asset'],
|
|
489
|
-
prop: {
|
|
490
|
-
c8y_JsonSchema: {
|
|
491
|
-
properties: {
|
|
492
|
-
childDevicesCount: {
|
|
493
|
-
label: 'Number of child devices',
|
|
494
|
-
type: 'number'
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
},
|
|
498
|
-
name: 'childDevicesCount',
|
|
499
|
-
label: gettext('Number of child devices'),
|
|
500
|
-
type: 'number',
|
|
501
|
-
computed: true,
|
|
502
|
-
isEditable: false,
|
|
503
|
-
isStandardProperty: true
|
|
504
|
-
},
|
|
505
|
-
value: ({ context, metadata }) => childDevicesCountValue(context, metadata)
|
|
506
|
-
};
|
|
507
|
-
/**
|
|
508
|
-
* Creates an Observable that tracks the count of child devices for a specific asset.
|
|
509
|
-
* Supports real-time updates when child devices are added or removed.
|
|
510
|
-
*
|
|
511
|
-
* @param asset - The managed object (asset) to track child devices for
|
|
512
|
-
* @param metadata - Configuration controlling the behavior of the function
|
|
513
|
-
* @returns Observable<number> - Stream of child devices count values
|
|
514
|
-
*/
|
|
515
|
-
function childDevicesCountValue(asset, metadata = { mode: 'realtime' }) {
|
|
516
|
-
return childCountValue(asset, metadata, 'childDevices');
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
class LastDeviceMessageStrategy {
|
|
520
|
-
constructor(asset, injector) {
|
|
521
|
-
this.asset = asset;
|
|
522
|
-
this.measurementService = injector.get(MeasurementService);
|
|
523
|
-
this.measurementRealtime = injector.get(MeasurementRealtimeService);
|
|
524
|
-
this.eventService = injector.get(EventService);
|
|
525
|
-
this.eventRealtimeService = injector.get(EventRealtimeService);
|
|
526
|
-
this.alarmService = injector.get(AlarmService);
|
|
527
|
-
this.alarmRealtimeService = injector.get(AlarmRealtimeService);
|
|
528
|
-
this.operationService = injector.get(OperationService);
|
|
529
|
-
this.operationRealtimeService = injector.get(OperationRealtimeService);
|
|
530
|
-
this.startTime = new Date();
|
|
531
|
-
}
|
|
532
|
-
fetchCurrentValue() {
|
|
533
|
-
const fetchFilter = {
|
|
534
|
-
source: this.asset.id,
|
|
535
|
-
pageSize: 1,
|
|
536
|
-
revert: true
|
|
537
|
-
};
|
|
538
|
-
const fetchLatestMeasurement = () => {
|
|
539
|
-
return from(this.measurementService.list(fetchFilter)).pipe(map(resp => resp.data?.[0]?.time || null), catchError(() => of(null)));
|
|
540
|
-
};
|
|
541
|
-
const fetchLatestEvent = () => {
|
|
542
|
-
return from(this.eventService.list(fetchFilter)).pipe(map(resp => resp.data?.[0]?.time || null), catchError(() => of(null)));
|
|
543
|
-
};
|
|
544
|
-
const fetchLatestAlarm = () => {
|
|
545
|
-
return from(this.alarmService.list(fetchFilter)).pipe(map(resp => resp.data?.[0]?.time || null), catchError(() => of(null)));
|
|
546
|
-
};
|
|
547
|
-
const fetchLatestOperation = () => {
|
|
548
|
-
return from(this.operationService.list(fetchFilter)).pipe(map(resp => resp.data?.[0]?.creationTime || null), catchError(() => of(null)));
|
|
549
|
-
};
|
|
550
|
-
return combineLatest([
|
|
551
|
-
fetchLatestMeasurement(),
|
|
552
|
-
fetchLatestEvent(),
|
|
553
|
-
fetchLatestAlarm(),
|
|
554
|
-
fetchLatestOperation()
|
|
555
|
-
]).pipe(map(timestamps => {
|
|
556
|
-
const validTimestamps = timestamps.filter(Boolean);
|
|
557
|
-
if (validTimestamps.length === 0) {
|
|
558
|
-
return null;
|
|
559
|
-
}
|
|
560
|
-
const latest = validTimestamps.reduce((latest, current) => {
|
|
561
|
-
return new Date(current) > new Date(latest) ? current : latest;
|
|
562
|
-
});
|
|
563
|
-
// Update start time for realtime filtering
|
|
564
|
-
this.startTime = new Date();
|
|
565
|
-
return latest;
|
|
566
|
-
}));
|
|
567
|
-
}
|
|
568
|
-
createRealtimeStream(initialValue) {
|
|
569
|
-
const measurementStream$ = this.measurementRealtime.onAll$(this.asset.id).pipe(map(({ data }) => data.time), filter(time => new Date(time) > this.startTime));
|
|
570
|
-
const eventStream$ = this.eventRealtimeService.onAll$(this.asset.id).pipe(map(({ data }) => data.time), filter(time => new Date(time) > this.startTime));
|
|
571
|
-
const alarmStream$ = this.alarmRealtimeService.onAll$(this.asset.id).pipe(map(({ data }) => data.time), filter(time => time && new Date(time) > this.startTime));
|
|
572
|
-
const operationStream$ = this.operationRealtimeService.onAll$(this.asset.id).pipe(map(({ data }) => data.creationTime), filter(time => time && new Date(time) > this.startTime));
|
|
573
|
-
return merge(measurementStream$, eventStream$, alarmStream$, operationStream$).pipe(scan((latestTimestamp, newTimestamp) => {
|
|
574
|
-
return new Date(newTimestamp) > new Date(latestTimestamp) ? newTimestamp : latestTimestamp;
|
|
575
|
-
}, initialValue), startWith(initialValue));
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Gets the latest timestamp from events, alarms, measurements, and operations for a device.
|
|
581
|
-
* Returns the most recent timestamp across all these sources.
|
|
582
|
-
*
|
|
583
|
-
* @param asset - The managed object (device/asset) to track
|
|
584
|
-
* @param metadata - Configuration controlling the behavior of the function
|
|
585
|
-
* @returns Observable<string> - Stream of latest timestamp values
|
|
586
|
-
*/
|
|
587
|
-
function getLastDeviceMessage(asset, metadata = { mode: 'realtime' }) {
|
|
588
|
-
const injector = inject(Injector);
|
|
589
|
-
const strategy = new LastDeviceMessageStrategy(asset, injector);
|
|
590
|
-
const handler = new RealtimeValueHandler(strategy);
|
|
591
|
-
return handler.getValue(metadata);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
const lastDeviceMessage = {
|
|
595
|
-
name: 'lastDeviceMessage',
|
|
596
|
-
contextType: ['device'],
|
|
597
|
-
prop: {
|
|
598
|
-
c8y_JsonSchema: {
|
|
599
|
-
properties: {
|
|
600
|
-
lastDeviceMessage: {
|
|
601
|
-
label: 'Last device message',
|
|
602
|
-
type: 'string'
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
},
|
|
606
|
-
name: 'lastDeviceMessage',
|
|
607
|
-
label: gettext('Last device message'),
|
|
608
|
-
printFormat: 'datetime',
|
|
609
|
-
type: 'string',
|
|
610
|
-
computed: true,
|
|
611
|
-
isEditable: false,
|
|
612
|
-
isStandardProperty: true
|
|
613
|
-
},
|
|
614
|
-
value: ({ context }) => {
|
|
615
|
-
return getLastDeviceMessage(context);
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
const computedAssetPropertiesProviders = [
|
|
620
|
-
AlarmRealtimeService,
|
|
621
|
-
EventRealtimeService,
|
|
622
|
-
MeasurementRealtimeService,
|
|
623
|
-
OperationRealtimeService,
|
|
624
|
-
ManagedObjectRealtimeService,
|
|
625
|
-
hookComputedProperty([
|
|
626
|
-
lastMeasurement,
|
|
627
|
-
lastDeviceMessage,
|
|
628
|
-
childAssetsCount,
|
|
629
|
-
childDevicesCount,
|
|
630
|
-
alarmCount3Months,
|
|
631
|
-
alarmCountToday,
|
|
632
|
-
eventCountToday,
|
|
633
|
-
eventCount3Months,
|
|
634
|
-
configurationSnapshot
|
|
635
|
-
])
|
|
636
|
-
];
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* Generated bundle index. Do not edit.
|
|
640
|
-
*/
|
|
641
|
-
|
|
642
|
-
export { computedAssetPropertiesProviders };
|
|
1
|
+
export { c as computedAssetPropertiesProviders } from './c8y-ngx-components-computed-asset-properties-c8y-ngx-components-computed-asset-properties-C5oS4Be-.mjs';
|
|
643
2
|
//# sourceMappingURL=c8y-ngx-components-computed-asset-properties.mjs.map
|