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,7 +21,8 @@ import { | ||
21 | EntityTableConfig | 21 | EntityTableConfig |
22 | } from '@home/models/entity/entities-table-config.models'; | 22 | } from '@home/models/entity/entities-table-config.models'; |
23 | import { | 23 | import { |
24 | - EdgeEvent, edgeEventActionTypeTranslations, | 24 | + EdgeEvent, |
25 | + edgeEventActionTypeTranslations, | ||
25 | EdgeEventStatus, | 26 | EdgeEventStatus, |
26 | edgeEventStatusColor, | 27 | edgeEventStatusColor, |
27 | EdgeEventType, | 28 | EdgeEventType, |
@@ -42,17 +43,13 @@ import { | @@ -42,17 +43,13 @@ import { | ||
42 | EventContentDialogComponent, | 43 | EventContentDialogComponent, |
43 | EventContentDialogData | 44 | EventContentDialogData |
44 | } from '@home/components/event/event-content-dialog.component'; | 45 | } from '@home/components/event/event-content-dialog.component'; |
45 | -import { sortObjectKeys } from '@core/utils'; | ||
46 | import { RuleChainService } from '@core/http/rule-chain.service'; | 46 | import { RuleChainService } from '@core/http/rule-chain.service'; |
47 | import { AttributeService } from '@core/http/attribute.service'; | 47 | import { AttributeService } from '@core/http/attribute.service'; |
48 | import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; | 48 | import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; |
49 | import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component'; | 49 | import { EdgeDownlinkTableHeaderComponent } from '@home/components/edge/edge-downlink-table-header.component'; |
50 | import { EdgeService } from '@core/http/edge.service'; | 50 | import { EdgeService } from '@core/http/edge.service'; |
51 | import { map } from 'rxjs/operators'; | 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 | export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> { | 54 | export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePageLink> { |
58 | 55 | ||
@@ -61,9 +58,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa | @@ -61,9 +58,7 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa | ||
61 | constructor(private edgeService: EdgeService, | 58 | constructor(private edgeService: EdgeService, |
62 | private dialogService: DialogService, | 59 | private dialogService: DialogService, |
63 | private translate: TranslateService, | 60 | private translate: TranslateService, |
64 | - private deviceService: DeviceService, | ||
65 | - private assetService: AssetService, | ||
66 | - private entityViewService: EntityViewService, | 61 | + private entityService: EntityService, |
67 | private ruleChainService: RuleChainService, | 62 | private ruleChainService: RuleChainService, |
68 | private attributeService: AttributeService, | 63 | private attributeService: AttributeService, |
69 | private datePipe: DatePipe, | 64 | private datePipe: DatePipe, |
@@ -98,6 +93,24 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa | @@ -98,6 +93,24 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa | ||
98 | return this.edgeService.getEdgeEvents(this.entityId, pageLink); | 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 | updateColumns(updateTableColumns: boolean = false): void { | 114 | updateColumns(updateTableColumns: boolean = false): void { |
102 | this.columns = []; | 115 | this.columns = []; |
103 | this.columns.push( | 116 | this.columns.push( |
@@ -132,31 +145,23 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa | @@ -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 | isEdgeEventHasData(edgeEventType: EdgeEventType) { | 160 | isEdgeEventHasData(edgeEventType: EdgeEventType) { |
157 | switch (edgeEventType) { | 161 | switch (edgeEventType) { |
158 | - case EdgeEventType.WIDGET_TYPE: | 162 | + case EdgeEventType.DEVICE_PROFILE: |
159 | case EdgeEventType.WIDGETS_BUNDLE: | 163 | case EdgeEventType.WIDGETS_BUNDLE: |
164 | + case EdgeEventType.WIDGET_TYPE: | ||
160 | case EdgeEventType.ADMIN_SETTINGS: | 165 | case EdgeEventType.ADMIN_SETTINGS: |
161 | return false; | 166 | return false; |
162 | default: | 167 | default: |
@@ -165,89 +170,50 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa | @@ -165,89 +170,50 @@ export class EdgeDownlinkTableConfig extends EntityTableConfig<EdgeEvent, TimePa | ||
165 | } | 170 | } |
166 | 171 | ||
167 | prepareEdgeEventContent(entity) { | 172 | prepareEdgeEventContent(entity) { |
168 | - // TODO: voba - extend this function with different cases based on action and entity type | ||
169 | switch (entity.type) { | 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 | case EdgeEventType.DEVICE: | 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 | case EdgeEventType.ENTITY_VIEW: | 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 | case EdgeEventType.RULE_CHAIN_METADATA: | 191 | case EdgeEventType.RULE_CHAIN_METADATA: |
191 | return this.ruleChainService.getRuleChainMetadata(entity.entityId, null).pipe( | 192 | return this.ruleChainService.getRuleChainMetadata(entity.entityId, null).pipe( |
192 | map((ruleChainMetaData) => { | 193 | map((ruleChainMetaData) => { |
193 | return JSON.stringify(ruleChainMetaData.nodes); | 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 | if ($event) { | 206 | if ($event) { |
203 | $event.stopPropagation(); | 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 | this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, { | 209 | this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, { |
213 | disableClose: true, | 210 | disableClose: true, |
214 | panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], | 211 | panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], |
215 | data: { | 212 | data: { |
216 | content, | 213 | content, |
217 | title, | 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,9 +25,7 @@ import { DialogService } from '@core/services/dialog.service'; | ||
25 | import { RuleChainService } from '@core/http/rule-chain.service'; | 25 | import { RuleChainService } from '@core/http/rule-chain.service'; |
26 | import { AttributeService } from '@core/http/attribute.service'; | 26 | import { AttributeService } from '@core/http/attribute.service'; |
27 | import { EdgeService } from '@core/http/edge.service'; | 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 | @Component({ | 30 | @Component({ |
33 | selector: 'tb-edge-downlink-table', | 31 | selector: 'tb-edge-downlink-table', |
@@ -71,9 +69,7 @@ export class EdgeDownlinkTableComponent implements OnInit { | @@ -71,9 +69,7 @@ export class EdgeDownlinkTableComponent implements OnInit { | ||
71 | edgeDownlinkTableConfig: EdgeDownlinkTableConfig; | 69 | edgeDownlinkTableConfig: EdgeDownlinkTableConfig; |
72 | 70 | ||
73 | constructor(private edgeService: EdgeService, | 71 | constructor(private edgeService: EdgeService, |
74 | - private deviceService: DeviceService, | ||
75 | - private assetService: AssetService, | ||
76 | - private entityViewService: EntityViewService, | 72 | + private entityService: EntityService, |
77 | private dialogService: DialogService, | 73 | private dialogService: DialogService, |
78 | private translate: TranslateService, | 74 | private translate: TranslateService, |
79 | private attributeService: AttributeService, | 75 | private attributeService: AttributeService, |
@@ -88,9 +84,7 @@ export class EdgeDownlinkTableComponent implements OnInit { | @@ -88,9 +84,7 @@ export class EdgeDownlinkTableComponent implements OnInit { | ||
88 | this.edgeService, | 84 | this.edgeService, |
89 | this.dialogService, | 85 | this.dialogService, |
90 | this.translate, | 86 | this.translate, |
91 | - this.deviceService, | ||
92 | - this.assetService, | ||
93 | - this.entityViewService, | 87 | + this.entityService, |
94 | this.ruleChainService, | 88 | this.ruleChainService, |
95 | this.attributeService, | 89 | this.attributeService, |
96 | this.datePipe, | 90 | this.datePipe, |
@@ -59,6 +59,7 @@ export enum EdgeEventType { | @@ -59,6 +59,7 @@ export enum EdgeEventType { | ||
59 | USER = "USER", | 59 | USER = "USER", |
60 | CUSTOMER = "CUSTOMER", | 60 | CUSTOMER = "CUSTOMER", |
61 | RELATION = "RELATION", | 61 | RELATION = "RELATION", |
62 | + TENANT = "TENANT", | ||
62 | WIDGETS_BUNDLE = "WIDGETS_BUNDLE", | 63 | WIDGETS_BUNDLE = "WIDGETS_BUNDLE", |
63 | WIDGET_TYPE = "WIDGET_TYPE", | 64 | WIDGET_TYPE = "WIDGET_TYPE", |
64 | ADMIN_SETTINGS = "ADMIN_SETTINGS" | 65 | ADMIN_SETTINGS = "ADMIN_SETTINGS" |
@@ -105,6 +106,7 @@ export const edgeEventTypeTranslations = new Map<EdgeEventType, string>( | @@ -105,6 +106,7 @@ export const edgeEventTypeTranslations = new Map<EdgeEventType, string>( | ||
105 | [EdgeEventType.USER, 'edge-event.type-user'], | 106 | [EdgeEventType.USER, 'edge-event.type-user'], |
106 | [EdgeEventType.CUSTOMER, 'edge-event.type-customer'], | 107 | [EdgeEventType.CUSTOMER, 'edge-event.type-customer'], |
107 | [EdgeEventType.RELATION, 'edge-event.type-relation'], | 108 | [EdgeEventType.RELATION, 'edge-event.type-relation'], |
109 | + [EdgeEventType.TENANT, 'edge-event.type-tenant'], | ||
108 | [EdgeEventType.WIDGETS_BUNDLE, 'edge-event.type-widgets-bundle'], | 110 | [EdgeEventType.WIDGETS_BUNDLE, 'edge-event.type-widgets-bundle'], |
109 | [EdgeEventType.WIDGET_TYPE, 'edge-event.type-widgets-type'], | 111 | [EdgeEventType.WIDGET_TYPE, 'edge-event.type-widgets-type'], |
110 | [EdgeEventType.ADMIN_SETTINGS, 'edge-event.type-admin-settings'] | 112 | [EdgeEventType.ADMIN_SETTINGS, 'edge-event.type-admin-settings'] |