@c8y/ngx-components 1018.0.211 → 1018.0.213

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,34 +1,16 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Directive, Injectable, EventEmitter, Component, Optional, Inject, ViewChild, ContentChild, Input, Output, SimpleChange, NgModule } from '@angular/core';
2
+ import { InjectionToken, Injectable, Directive, EventEmitter, Component, Optional, Inject, ViewChild, ContentChild, Input, Output, SimpleChange, NgModule } from '@angular/core';
3
3
  import * as i1$1 from '@c8y/ngx-components';
4
4
  import { gettext, sortByPriority, ManagedObjectRealtimeService, CommonModule as CommonModule$1, FormsModule as FormsModule$1, RealtimeModule } from '@c8y/ngx-components';
5
5
  import * as i3 from '@ngx-translate/core';
6
6
  import { Subject, fromEvent, BehaviorSubject, NEVER, interval, of, merge, from } from 'rxjs';
7
7
  import { takeUntil, map, switchMap, tap, filter, first, debounceTime, mergeMap } from 'rxjs/operators';
8
- import { flatten, cloneDeep } from 'lodash-es';
9
8
  import * as i1 from '@c8y/client';
9
+ import { flatten, cloneDeep } from 'lodash-es';
10
10
  import * as i1$2 from '@angular/common';
11
11
  import { CommonModule } from '@angular/common';
12
12
  import { FormsModule } from '@angular/forms';
13
13
 
14
- function getStatus(device) {
15
- if (!device.c8y_ActiveAlarmsStatus) {
16
- return 'text-muted';
17
- }
18
- if (device.c8y_ActiveAlarmsStatus.critical) {
19
- return 'status critical';
20
- }
21
- if (device.c8y_ActiveAlarmsStatus.major) {
22
- return 'status major';
23
- }
24
- if (device.c8y_ActiveAlarmsStatus.warning) {
25
- return 'status warning';
26
- }
27
- if (device.c8y_ActiveAlarmsStatus.minor) {
28
- return 'status minor';
29
- }
30
- return 'text-muted';
31
- }
32
14
  function getC8yMarker(marker, asset) {
33
15
  marker.asset = asset;
34
16
  return marker;
@@ -57,109 +39,6 @@ const defaultMapConfig = {
57
39
  zoomLevel: 2
58
40
  };
59
41
 
60
- class ClusterMap {
61
- constructor(iterable, addAssetCallback, translateService) {
62
- this.iterable = iterable;
63
- this.addAssetCallback = addAssetCallback;
64
- this.translateService = translateService;
65
- this.markers = [];
66
- this.positions = [];
67
- this.iterableDiffer = this.iterable.find(this.positions).create(this.trackBy);
68
- }
69
- set clusterMarker(item) {
70
- this.removeClusterToBigMarker();
71
- this._clusterMarker = item;
72
- }
73
- get clusterMarker() {
74
- return this._clusterMarker;
75
- }
76
- set rect(item) {
77
- if (this._rect) {
78
- this._rect.remove();
79
- }
80
- this._rect = item;
81
- }
82
- get rect() {
83
- return this._rect;
84
- }
85
- render(map) {
86
- if (this._rect) {
87
- this._rect.addTo(map);
88
- }
89
- this.updateChanges(map);
90
- if (this._clusterMarker) {
91
- this._clusterMarker.addTo(map);
92
- }
93
- }
94
- clear(map) {
95
- this.removeClusterToBigMarker();
96
- this._rect.remove();
97
- this.positions = [];
98
- this.updateChanges(map);
99
- }
100
- removeClusterToBigMarker() {
101
- if (this._clusterMarker) {
102
- this._clusterMarker.remove();
103
- this._clusterMarker = null;
104
- }
105
- }
106
- addMarkerToMap(device, map) {
107
- const marker = this.addAssetCallback(device);
108
- this.markers.push(marker);
109
- marker.addTo(map);
110
- }
111
- setClusterToBigMarker(map, count, leaflet) {
112
- const bound = this.rect.getBounds();
113
- const text = this.translateService.instant(gettext('Zoom in'));
114
- const divMarker = leaflet.divIcon({
115
- html: `<div class="c8y-map-marker-count" data-count="${count}" title="${text}"></div>`
116
- });
117
- const labelIcon = leaflet.marker(bound.getCenter(), {
118
- icon: divMarker
119
- });
120
- labelIcon.addTo(map);
121
- labelIcon.on('click', () => {
122
- map.fitBounds(bound);
123
- });
124
- this.clusterMarker = labelIcon;
125
- }
126
- updateChanges(map) {
127
- const changes = this.iterableDiffer.diff(this.positions);
128
- if (changes) {
129
- changes.forEachRemovedItem((record) => {
130
- this.removeMarkerFromMap(record.item);
131
- });
132
- changes.forEachAddedItem((record) => {
133
- this.addMarkerToMap(record.item, map);
134
- });
135
- }
136
- }
137
- trackBy(index, item) {
138
- const trackItems = [item.id, item.c8y_Position.lat, item.c8y_Position.lng, getStatus(item)];
139
- return trackItems.join('');
140
- }
141
- removeMarkerFromMap(device) {
142
- const markers = this.markers.filter((marker) => marker.asset?.id === device.id);
143
- markers.forEach(marker => marker.remove());
144
- }
145
- }
146
-
147
- class MapPopupDirective {
148
- constructor(template, elementRef, viewContainer) {
149
- this.template = template;
150
- this.elementRef = elementRef;
151
- this.viewContainer = viewContainer;
152
- }
153
- }
154
- MapPopupDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.6", ngImport: i0, type: MapPopupDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ElementRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
155
- MapPopupDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.6", type: MapPopupDirective, selector: "[c8yMapPopup]", ngImport: i0 });
156
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.6", ngImport: i0, type: MapPopupDirective, decorators: [{
157
- type: Directive,
158
- args: [{
159
- selector: '[c8yMapPopup]'
160
- }]
161
- }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ElementRef }, { type: i0.ViewContainerRef }]; } });
162
-
163
42
  class MapService {
164
43
  constructor(inventory) {
165
44
  this.inventory = inventory;
@@ -173,6 +52,29 @@ class MapService {
173
52
  */
174
53
  this.CLUSTER_LEVEL_THRESHOLD = 500;
175
54
  }
55
+ /**
56
+ * Returns asset icon status for highest alarm severity found in device object.
57
+ * @param device Device that contains alarms information.
58
+ * @returns Status string according to alarm severity
59
+ */
60
+ static getStatus(device) {
61
+ if (!device.c8y_ActiveAlarmsStatus) {
62
+ return 'text-muted';
63
+ }
64
+ if (device.c8y_ActiveAlarmsStatus.critical) {
65
+ return 'status critical';
66
+ }
67
+ if (device.c8y_ActiveAlarmsStatus.major) {
68
+ return 'status major';
69
+ }
70
+ if (device.c8y_ActiveAlarmsStatus.minor) {
71
+ return 'status minor';
72
+ }
73
+ if (device.c8y_ActiveAlarmsStatus.warning) {
74
+ return 'status warning';
75
+ }
76
+ return 'text-muted';
77
+ }
176
78
  /**
177
79
  * Returns the leaflet instance used by the cumulocity core.
178
80
  */
@@ -265,6 +167,114 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.6", ngImpor
265
167
  }]
266
168
  }], ctorParameters: function () { return [{ type: i1.InventoryService }]; } });
267
169
 
170
+ class ClusterMap {
171
+ constructor(iterable, addAssetCallback, translateService) {
172
+ this.iterable = iterable;
173
+ this.addAssetCallback = addAssetCallback;
174
+ this.translateService = translateService;
175
+ this.markers = [];
176
+ this.positions = [];
177
+ this.iterableDiffer = this.iterable.find(this.positions).create(this.trackBy);
178
+ }
179
+ set clusterMarker(item) {
180
+ this.removeClusterToBigMarker();
181
+ this._clusterMarker = item;
182
+ }
183
+ get clusterMarker() {
184
+ return this._clusterMarker;
185
+ }
186
+ set rect(item) {
187
+ if (this._rect) {
188
+ this._rect.remove();
189
+ }
190
+ this._rect = item;
191
+ }
192
+ get rect() {
193
+ return this._rect;
194
+ }
195
+ render(map) {
196
+ if (this._rect) {
197
+ this._rect.addTo(map);
198
+ }
199
+ this.updateChanges(map);
200
+ if (this._clusterMarker) {
201
+ this._clusterMarker.addTo(map);
202
+ }
203
+ }
204
+ clear(map) {
205
+ this.removeClusterToBigMarker();
206
+ this._rect.remove();
207
+ this.positions = [];
208
+ this.updateChanges(map);
209
+ }
210
+ removeClusterToBigMarker() {
211
+ if (this._clusterMarker) {
212
+ this._clusterMarker.remove();
213
+ this._clusterMarker = null;
214
+ }
215
+ }
216
+ addMarkerToMap(device, map) {
217
+ const marker = this.addAssetCallback(device);
218
+ this.markers.push(marker);
219
+ marker.addTo(map);
220
+ }
221
+ setClusterToBigMarker(map, count, leaflet) {
222
+ const bound = this.rect.getBounds();
223
+ const text = this.translateService.instant(gettext('Zoom in'));
224
+ const divMarker = leaflet.divIcon({
225
+ html: `<div class="c8y-map-marker-count" data-count="${count}" title="${text}"></div>`
226
+ });
227
+ const labelIcon = leaflet.marker(bound.getCenter(), {
228
+ icon: divMarker
229
+ });
230
+ labelIcon.addTo(map);
231
+ labelIcon.on('click', () => {
232
+ map.fitBounds(bound);
233
+ });
234
+ this.clusterMarker = labelIcon;
235
+ }
236
+ updateChanges(map) {
237
+ const changes = this.iterableDiffer.diff(this.positions);
238
+ if (changes) {
239
+ changes.forEachRemovedItem((record) => {
240
+ this.removeMarkerFromMap(record.item);
241
+ });
242
+ changes.forEachAddedItem((record) => {
243
+ this.addMarkerToMap(record.item, map);
244
+ });
245
+ }
246
+ }
247
+ trackBy(index, item) {
248
+ const trackItems = [
249
+ item.id,
250
+ item.c8y_Position.lat,
251
+ item.c8y_Position.lng,
252
+ MapService.getStatus(item)
253
+ ];
254
+ return trackItems.join('');
255
+ }
256
+ removeMarkerFromMap(device) {
257
+ const markers = this.markers.filter((marker) => marker.asset?.id === device.id);
258
+ markers.forEach(marker => marker.remove());
259
+ }
260
+ }
261
+
262
+ class MapPopupDirective {
263
+ constructor(template, elementRef, viewContainer) {
264
+ this.template = template;
265
+ this.elementRef = elementRef;
266
+ this.viewContainer = viewContainer;
267
+ }
268
+ }
269
+ MapPopupDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.6", ngImport: i0, type: MapPopupDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ElementRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
270
+ MapPopupDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.6", type: MapPopupDirective, selector: "[c8yMapPopup]", ngImport: i0 });
271
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.6", ngImport: i0, type: MapPopupDirective, decorators: [{
272
+ type: Directive,
273
+ args: [{
274
+ selector: '[c8yMapPopup]'
275
+ }]
276
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }, { type: i0.ElementRef }, { type: i0.ViewContainerRef }]; } });
277
+
268
278
  class MapComponent {
269
279
  constructor(moRealtimeService, mapService, layers, defaultConfig, translateService) {
270
280
  this.moRealtimeService = moRealtimeService;
@@ -354,7 +364,7 @@ class MapComponent {
354
364
  }
355
365
  getAssetIcon(asset) {
356
366
  const assetTypeIcon = this.config.icon || asset.icon?.name;
357
- const status = getStatus(asset);
367
+ const status = MapService.getStatus(asset);
358
368
  const color = this.config.color ? `style='color: ${this.config.color};'` : '';
359
369
  const icon = this.leaflet.divIcon({
360
370
  html: `<div class="dlt-c8y-icon-marker icon-3x ${status}" ${color}><i class="dlt-c8y-icon-${assetTypeIcon || 'data-transfer'}" /></div>`,
@@ -925,5 +935,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.6", ngImpor
925
935
  * Generated bundle index. Do not edit.
926
936
  */
927
937
 
928
- export { ClusterMap, ClusterMapComponent, ClusterSize, MAP_DEFAULT_CONFIG, MAP_TILE_LAYER, MapComponent, MapModule, MapPopupDirective, MapService, MapStatusComponent, defaultLayer, defaultMapConfig, getC8yMarker, getStatus };
938
+ export { ClusterMap, ClusterMapComponent, ClusterSize, MAP_DEFAULT_CONFIG, MAP_TILE_LAYER, MapComponent, MapModule, MapPopupDirective, MapService, MapStatusComponent, defaultLayer, defaultMapConfig, getC8yMarker };
929
939
  //# sourceMappingURL=c8y-ngx-components-map.mjs.map