Commit cdd9c867a0130789cae67a59ce521bb3c416c111
1 parent
d35f9d0e
Edge Downlinks: refactored, added missing EdgeEventType
Showing
3 changed files
with
58 additions
and
96 deletions
... | ... | @@ -21,7 +21,8 @@ import { |
21 | 21 | EntityTableConfig |
22 | 22 | } from '@home/models/entity/entities-table-config.models'; |
23 | 23 | import { |
24 | - EdgeEvent, edgeEventActionTypeTranslations, | |
24 | + EdgeEvent, | |
25 | + edgeEventActionTypeTranslations, | |
25 | 26 | EdgeEventStatus, |
26 | 27 | edgeEventStatusColor, |
27 | 28 | EdgeEventType, |
... | ... | @@ -42,17 +43,13 @@ import { |
42 | 43 | EventContentDialogComponent, |
43 | 44 | EventContentDialogData |
44 | 45 | } from '@home/components/event/event-content-dialog.component'; |
45 | -import { sortObjectKeys } from '@core/utils'; | |
46 | 46 | import { RuleChainService } from '@core/http/rule-chain.service'; |
47 | 47 | import { AttributeService } from '@core/http/attribute.service'; |
48 | 48 | import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; |
49 | 49 | import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component'; |
50 | 50 | import { EdgeService } from '@core/http/edge.service'; |
51 | 51 | import { map } from 'rxjs/operators'; |
52 | -import { AssetService } from '@core/http/asset.service'; | |
53 | -import { DeviceService } from '@core/http/device.service'; | |
54 | -import { EntityViewService } from '@core/http/entity-view.service'; | |
55 | -import { EventTableHeaderComponent } from '@home/components/event/event-table-header.component'; | |
52 | +import { EntityService } from "@core/http/entity.service"; | |
56 | 53 | |
57 | 54 | export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> { |
58 | 55 | |
... | ... | @@ -61,9 +58,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa |
61 | 58 | constructor(private edgeService: EdgeService, |
62 | 59 | private dialogService: DialogService, |
63 | 60 | private translate: TranslateService, |
64 | - private deviceService: DeviceService, | |
65 | - private assetService: AssetService, | |
66 | - private entityViewService: EntityViewService, | |
61 | + private entityService: EntityService, | |
67 | 62 | private ruleChainService: RuleChainService, |
68 | 63 | private attributeService: AttributeService, |
69 | 64 | private datePipe: DatePipe, |
... | ... | @@ -98,6 +93,24 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa |
98 | 93 | return this.edgeService.getEdgeEvents(this.entityId, pageLink); |
99 | 94 | } |
100 | 95 | |
96 | + loadEdgeInfo() { | |
97 | + this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']) | |
98 | + .subscribe( | |
99 | + attributes => this.onUpdate(attributes) | |
100 | + ); | |
101 | + } | |
102 | + | |
103 | + onUpdate(attributes) { | |
104 | + this.queueStartTs = 0; | |
105 | + let edge = attributes.reduce(function (map, attribute) { | |
106 | + map[attribute.key] = attribute; | |
107 | + return map; | |
108 | + }, {}); | |
109 | + if (edge.queueStartTs) { | |
110 | + this.queueStartTs = edge.queueStartTs.lastUpdateTs; | |
111 | + } | |
112 | + } | |
113 | + | |
101 | 114 | updateColumns(updateTableColumns: boolean = false): void { |
102 | 115 | this.columns = []; |
103 | 116 | this.columns.push( |
... | ... | @@ -132,31 +145,23 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa |
132 | 145 | } |
133 | 146 | } |
134 | 147 | |
135 | - showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null, sortKeys = false): void { | |
136 | - if ($event) { | |
137 | - $event.stopPropagation(); | |
138 | - } | |
139 | - if (contentType === ContentType.JSON && sortKeys) { | |
140 | - try { | |
141 | - content = JSON.stringify(sortObjectKeys(JSON.parse(content))); | |
142 | - } catch (e) { | |
143 | - } | |
148 | + updateEdgeEventStatus(createdTime) { | |
149 | + if (this.queueStartTs && createdTime < this.queueStartTs) { | |
150 | + return this.translate.instant('edge.deployed'); | |
151 | + } else { | |
152 | + return this.translate.instant('edge.pending'); | |
144 | 153 | } |
145 | - this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, { | |
146 | - disableClose: true, | |
147 | - panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], | |
148 | - data: { | |
149 | - content, | |
150 | - title, | |
151 | - contentType | |
152 | - } | |
153 | - }); | |
154 | + } | |
155 | + | |
156 | + isPending(createdTime) { | |
157 | + return createdTime > this.queueStartTs; | |
154 | 158 | } |
155 | 159 | |
156 | 160 | isEdgeEventHasData(edgeEventType: EdgeEventType) { |
157 | 161 | switch (edgeEventType) { |
158 | - case EdgeEventType.WIDGET_TYPE: | |
162 | + case EdgeEventType.DEVICE_PROFILE: | |
159 | 163 | case EdgeEventType.WIDGETS_BUNDLE: |
164 | + case EdgeEventType.WIDGET_TYPE: | |
160 | 165 | case EdgeEventType.ADMIN_SETTINGS: |
161 | 166 | return false; |
162 | 167 | default: |
... | ... | @@ -165,89 +170,50 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa |
165 | 170 | } |
166 | 171 | |
167 | 172 | prepareEdgeEventContent(entity) { |
168 | - // TODO: voba - extend this function with different cases based on action and entity type | |
169 | 173 | switch (entity.type) { |
170 | - case EdgeEventType.RELATION: | |
171 | - return of(JSON.stringify(entity.body)); | |
172 | - case EdgeEventType.ASSET: | |
173 | - return this.assetService.getAsset(entity.entityId, null).pipe( | |
174 | - map((asset) => { | |
175 | - return JSON.stringify(asset); | |
176 | - }) | |
177 | - ); | |
178 | 174 | case EdgeEventType.DEVICE: |
179 | - return this.deviceService.getDevice(entity.entityId, null).pipe( | |
180 | - map((device) => { | |
181 | - return JSON.stringify(device); | |
182 | - }) | |
183 | - ); | |
175 | + case EdgeEventType.ASSET: | |
176 | + case EdgeEventType.EDGE: | |
184 | 177 | case EdgeEventType.ENTITY_VIEW: |
185 | - return this.entityViewService.getEntityView(entity.entityId, null).pipe( | |
186 | - map((entityView) => { | |
187 | - return JSON.stringify(entityView); | |
178 | + case EdgeEventType.TENANT: | |
179 | + case EdgeEventType.CUSTOMER: | |
180 | + case EdgeEventType.DASHBOARD: | |
181 | + case EdgeEventType.USER: | |
182 | + case EdgeEventType.RULE_CHAIN: | |
183 | + case EdgeEventType.ALARM: | |
184 | + return this.entityService.getEntity(entity.type, entity.entityId, { ignoreLoading: true, ignoreErrors: true }).pipe( | |
185 | + map((entity) => { | |
186 | + return JSON.stringify(entity); | |
188 | 187 | }) |
189 | 188 | ); |
189 | + case EdgeEventType.RELATION: | |
190 | + return of(JSON.stringify(entity.body)); | |
190 | 191 | case EdgeEventType.RULE_CHAIN_METADATA: |
191 | 192 | return this.ruleChainService.getRuleChainMetadata(entity.entityId, null).pipe( |
192 | 193 | map((ruleChainMetaData) => { |
193 | 194 | return JSON.stringify(ruleChainMetaData.nodes); |
194 | 195 | }) |
195 | 196 | ); |
196 | - default: | |
197 | - return of(JSON.stringify(entity)); | |
197 | + case EdgeEventType.DEVICE_PROFILE: | |
198 | + case EdgeEventType.WIDGETS_BUNDLE: | |
199 | + case EdgeEventType.WIDGET_TYPE: | |
200 | + case EdgeEventType.ADMIN_SETTINGS: | |
201 | + return of(null); | |
198 | 202 | } |
199 | 203 | } |
200 | 204 | |
201 | - showEdgeEventContent($event: MouseEvent, content: string, title: string, sortKeys = false): void { | |
205 | + showEdgeEventContent($event: MouseEvent, content: string, title: string): void { | |
202 | 206 | if ($event) { |
203 | 207 | $event.stopPropagation(); |
204 | 208 | } |
205 | - var contentType = ContentType.JSON; | |
206 | - if (contentType === ContentType.JSON && sortKeys) { | |
207 | - try { | |
208 | - content = JSON.stringify(sortObjectKeys(JSON.parse(content))); | |
209 | - } catch (e) { | |
210 | - } | |
211 | - } | |
212 | 209 | this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, { |
213 | 210 | disableClose: true, |
214 | 211 | panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
215 | 212 | data: { |
216 | 213 | content, |
217 | 214 | title, |
218 | - contentType | |
215 | + contentType: ContentType.JSON | |
219 | 216 | } |
220 | 217 | }); |
221 | 218 | } |
222 | - | |
223 | - updateEdgeEventStatus(createdTime) { | |
224 | - if (this.queueStartTs && createdTime < this.queueStartTs) { | |
225 | - return this.translate.instant('edge.deployed'); | |
226 | - } else { | |
227 | - return this.translate.instant('edge.pending'); | |
228 | - } | |
229 | - } | |
230 | - | |
231 | - isPending(createdTime) { | |
232 | - return createdTime > this.queueStartTs; | |
233 | - } | |
234 | - | |
235 | - loadEdgeInfo() { | |
236 | - this.attributeService.getEntityAttributes(this.entityId, AttributeScope.SERVER_SCOPE, ['queueStartTs']) | |
237 | - .subscribe( | |
238 | - attributes => this.onUpdate(attributes) | |
239 | - ); | |
240 | - } | |
241 | - | |
242 | - onUpdate(attributes) { | |
243 | - this.queueStartTs = 0; | |
244 | - let edge = attributes.reduce(function (map, attribute) { | |
245 | - map[attribute.key] = attribute; | |
246 | - return map; | |
247 | - }, {}); | |
248 | - if (edge.queueStartTs) { | |
249 | - this.queueStartTs = edge.queueStartTs.lastUpdateTs; | |
250 | - } | |
251 | - } | |
252 | 219 | } |
253 | - | ... | ... |
... | ... | @@ -25,9 +25,7 @@ import { DialogService } from '@core/services/dialog.service'; |
25 | 25 | import { RuleChainService } from '@core/http/rule-chain.service'; |
26 | 26 | import { AttributeService } from '@core/http/attribute.service'; |
27 | 27 | import { EdgeService } from '@core/http/edge.service'; |
28 | -import { DeviceService } from '@core/http/device.service'; | |
29 | -import { AssetService } from '@core/http/asset.service'; | |
30 | -import { EntityViewService } from '@core/http/entity-view.service'; | |
28 | +import { EntityService } from "@core/http/entity.service"; | |
31 | 29 | |
32 | 30 | @Component({ |
33 | 31 | selector: 'tb-edge-downlink-table', |
... | ... | @@ -71,9 +69,7 @@ export class EdgeDownlinkTableComponent implements OnInit { |
71 | 69 | edgeDownlinkTableConfig: EdgeDownlinkTableConfig; |
72 | 70 | |
73 | 71 | constructor(private edgeService: EdgeService, |
74 | - private deviceService: DeviceService, | |
75 | - private assetService: AssetService, | |
76 | - private entityViewService: EntityViewService, | |
72 | + private entityService: EntityService, | |
77 | 73 | private dialogService: DialogService, |
78 | 74 | private translate: TranslateService, |
79 | 75 | private attributeService: AttributeService, |
... | ... | @@ -88,9 +84,7 @@ export class EdgeDownlinkTableComponent implements OnInit { |
88 | 84 | this.edgeService, |
89 | 85 | this.dialogService, |
90 | 86 | this.translate, |
91 | - this.deviceService, | |
92 | - this.assetService, | |
93 | - this.entityViewService, | |
87 | + this.entityService, | |
94 | 88 | this.ruleChainService, |
95 | 89 | this.attributeService, |
96 | 90 | this.datePipe, | ... | ... |
... | ... | @@ -59,6 +59,7 @@ export enum EdgeEventType { |
59 | 59 | USER = "USER", |
60 | 60 | CUSTOMER = "CUSTOMER", |
61 | 61 | RELATION = "RELATION", |
62 | + TENANT = "TENANT", | |
62 | 63 | WIDGETS_BUNDLE = "WIDGETS_BUNDLE", |
63 | 64 | WIDGET_TYPE = "WIDGET_TYPE", |
64 | 65 | ADMIN_SETTINGS = "ADMIN_SETTINGS" |
... | ... | @@ -105,6 +106,7 @@ export const edgeEventTypeTranslations = new Map<EdgeEventType, string>( |
105 | 106 | [EdgeEventType.USER, 'edge-event.type-user'], |
106 | 107 | [EdgeEventType.CUSTOMER, 'edge-event.type-customer'], |
107 | 108 | [EdgeEventType.RELATION, 'edge-event.type-relation'], |
109 | + [EdgeEventType.TENANT, 'edge-event.type-tenant'], | |
108 | 110 | [EdgeEventType.WIDGETS_BUNDLE, 'edge-event.type-widgets-bundle'], |
109 | 111 | [EdgeEventType.WIDGET_TYPE, 'edge-event.type-widgets-type'], |
110 | 112 | [EdgeEventType.ADMIN_SETTINGS, 'edge-event.type-admin-settings'] | ... | ... |