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) {
metadata = {
deviceType: 'default',
deviceName: 'Test Device',
deviceType: 'default',
ts: new Date().getTime() + ''
};
} else {
metadata = sortObjectKeys(metadata) as {[key: string]: string};
metadata = sortObjectKeys(metadata);
}
if (!msgType) {
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;
}
export function sortObjectKeys(obj: object): object{
return Object.keys(obj).sort().reduce((acc,key)=>{
acc[key]=obj[key];
export function sortObjectKeys<T>(obj: T): T {
return Object.keys(obj).sort().reduce((acc, key) => {
acc[key] = obj[key];
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',
isEnabled: (entity) => entity.body.metadata ? entity.body.metadata.length > 0 : false,
onAction: ($event, entity) => this.showContent($event, entity.body.metadata,
'event.metadata', ContentType.JSON)
'event.metadata', ContentType.JSON, true)
},
'40px'),
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) {
$event.stopPropagation();
}
let sortedContent: string;
try {
sortedContent = JSON.stringify(sortObjectKeys(JSON.parse(content)));
} catch() {
sortedContent = content;
if (contentType === ContentType.JSON && sortKeys) {
try {
content = JSON.stringify(sortObjectKeys(JSON.parse(content)));
} catch (e) {}
}
this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, {
disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
constent: sortedContent,
content,
title,
contentType
}

Loading…
Cancel
Save