Browse Source

Add sort metadata key

pull/3281/head
Vladyslav_Prykhodko 6 years ago
parent
commit
ce649822e2
  1. 4
      ui-ngx/src/app/core/services/script/node-script-test.service.ts
  2. 8
      ui-ngx/src/app/core/utils.ts
  3. 15
      ui-ngx/src/app/modules/home/components/event/event-table-config.ts

4
ui-ngx/src/app/core/services/script/node-script-test.service.ts

@ -72,12 +72,12 @@ export class NodeScriptTestService {
} }
if (!metadata) { if (!metadata) {
metadata = { metadata = {
deviceType: 'default',
deviceName: 'Test Device', deviceName: 'Test Device',
deviceType: 'default',
ts: new Date().getTime() + '' ts: new Date().getTime() + ''
}; };
} else { } else {
metadata = sortObjectKeys(metadata) as {[key: string]: string}; metadata = sortObjectKeys(metadata);
} }
if (!msgType) { if (!msgType) {
msgType = 'POST_TELEMETRY_REQUEST'; msgType = 'POST_TELEMETRY_REQUEST';

8
ui-ngx/src/app/core/utils.ts

@ -511,9 +511,9 @@ export function padValue(val: any, dec: number): string {
return strVal; return strVal;
} }
export function sortObjectKeys(obj: object): object{ export function sortObjectKeys<T>(obj: T): T {
return Object.keys(obj).sort().reduce((acc,key)=>{ return Object.keys(obj).sort().reduce((acc, key) => {
acc[key]=obj[key]; acc[key] = obj[key];
return acc; return acc;
},{}); }, {} as T);
} }

15
ui-ngx/src/app/modules/home/components/event/event-table-config.ts

@ -210,7 +210,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
icon: 'more_horiz', icon: 'more_horiz',
isEnabled: (entity) => entity.body.metadata ? entity.body.metadata.length > 0 : false, isEnabled: (entity) => entity.body.metadata ? entity.body.metadata.length > 0 : false,
onAction: ($event, entity) => this.showContent($event, entity.body.metadata, onAction: ($event, entity) => this.showContent($event, entity.body.metadata,
'event.metadata', ContentType.JSON) 'event.metadata', ContentType.JSON, true)
}, },
'40px'), '40px'),
new EntityActionTableColumn<Event>('error', 'event.error', new EntityActionTableColumn<Event>('error', 'event.error',
@ -230,21 +230,20 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
} }
} }
showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null): void { showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null, sortKeys = false): void {
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
let sortedContent: string; if (contentType === ContentType.JSON && sortKeys) {
try { try {
sortedContent = JSON.stringify(sortObjectKeys(JSON.parse(content))); content = JSON.stringify(sortObjectKeys(JSON.parse(content)));
} catch() { } catch (e) {}
sortedContent = content;
} }
this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, { this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, {
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: { data: {
constent: sortedContent, content,
title, title,
contentType contentType
} }

Loading…
Cancel
Save