Commit 5833ac3521a0b01bfdbb9ce1fc9f850be056411f
Committed by
GitHub
Merge pull request #3281 from vvlladd28/improvement/sort-meta-key
Add sort metadata key for rule chain
Showing
3 changed files
with
19 additions
and
3 deletions
... | ... | @@ -23,6 +23,7 @@ import { |
23 | 23 | NodeScriptTestDialogComponent, |
24 | 24 | NodeScriptTestDialogData |
25 | 25 | } from '@shared/components/dialog/node-script-test-dialog.component'; |
26 | +import { sortObjectKeys } from '@core/utils'; | |
26 | 27 | |
27 | 28 | @Injectable({ |
28 | 29 | providedIn: 'root' |
... | ... | @@ -71,10 +72,12 @@ export class NodeScriptTestService { |
71 | 72 | } |
72 | 73 | if (!metadata) { |
73 | 74 | metadata = { |
74 | - deviceType: 'default', | |
75 | 75 | deviceName: 'Test Device', |
76 | + deviceType: 'default', | |
76 | 77 | ts: new Date().getTime() + '' |
77 | 78 | }; |
79 | + } else { | |
80 | + metadata = sortObjectKeys(metadata); | |
78 | 81 | } |
79 | 82 | if (!msgType) { |
80 | 83 | msgType = 'POST_TELEMETRY_REQUEST'; | ... | ... |
... | ... | @@ -510,3 +510,10 @@ export function padValue(val: any, dec: number): string { |
510 | 510 | strVal = (n ? '-' : '') + strVal; |
511 | 511 | return strVal; |
512 | 512 | } |
513 | + | |
514 | +export function sortObjectKeys<T>(obj: T): T { | |
515 | + return Object.keys(obj).sort().reduce((acc, key) => { | |
516 | + acc[key] = obj[key]; | |
517 | + return acc; | |
518 | + }, {} as T); | |
519 | +} | ... | ... |
... | ... | @@ -38,6 +38,7 @@ import { |
38 | 38 | EventContentDialogComponent, |
39 | 39 | EventContentDialogData |
40 | 40 | } from '@home/components/event/event-content-dialog.component'; |
41 | +import { sortObjectKeys } from '@core/utils'; | |
41 | 42 | |
42 | 43 | export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> { |
43 | 44 | |
... | ... | @@ -209,7 +210,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> { |
209 | 210 | icon: 'more_horiz', |
210 | 211 | isEnabled: (entity) => entity.body.metadata ? entity.body.metadata.length > 0 : false, |
211 | 212 | onAction: ($event, entity) => this.showContent($event, entity.body.metadata, |
212 | - 'event.metadata', ContentType.JSON) | |
213 | + 'event.metadata', ContentType.JSON, true) | |
213 | 214 | }, |
214 | 215 | '40px'), |
215 | 216 | new EntityActionTableColumn<Event>('error', 'event.error', |
... | ... | @@ -229,10 +230,15 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> { |
229 | 230 | } |
230 | 231 | } |
231 | 232 | |
232 | - showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null): void { | |
233 | + showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null, sortKeys = false): void { | |
233 | 234 | if ($event) { |
234 | 235 | $event.stopPropagation(); |
235 | 236 | } |
237 | + if (contentType === ContentType.JSON && sortKeys) { | |
238 | + try { | |
239 | + content = JSON.stringify(sortObjectKeys(JSON.parse(content))); | |
240 | + } catch (e) {} | |
241 | + } | |
236 | 242 | this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, { |
237 | 243 | disableClose: true, |
238 | 244 | panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], | ... | ... |