Merge pull request #3281 from vvlladd28/improvement/sort-meta-key
Add sort metadata key for rule chain
This commit is contained in:
commit
5833ac3521
@ -23,6 +23,7 @@ import {
|
||||
NodeScriptTestDialogComponent,
|
||||
NodeScriptTestDialogData
|
||||
} from '@shared/components/dialog/node-script-test-dialog.component';
|
||||
import { sortObjectKeys } from '@core/utils';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -71,10 +72,12 @@ export class NodeScriptTestService {
|
||||
}
|
||||
if (!metadata) {
|
||||
metadata = {
|
||||
deviceType: 'default',
|
||||
deviceName: 'Test Device',
|
||||
deviceType: 'default',
|
||||
ts: new Date().getTime() + ''
|
||||
};
|
||||
} else {
|
||||
metadata = sortObjectKeys(metadata);
|
||||
}
|
||||
if (!msgType) {
|
||||
msgType = 'POST_TELEMETRY_REQUEST';
|
||||
|
||||
@ -510,3 +510,10 @@ export function padValue(val: any, dec: number): string {
|
||||
strVal = (n ? '-' : '') + strVal;
|
||||
return strVal;
|
||||
}
|
||||
|
||||
export function sortObjectKeys<T>(obj: T): T {
|
||||
return Object.keys(obj).sort().reduce((acc, key) => {
|
||||
acc[key] = obj[key];
|
||||
return acc;
|
||||
}, {} as T);
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ import {
|
||||
EventContentDialogComponent,
|
||||
EventContentDialogData
|
||||
} from '@home/components/event/event-content-dialog.component';
|
||||
import { sortObjectKeys } from '@core/utils';
|
||||
|
||||
export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
|
||||
|
||||
@ -209,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',
|
||||
@ -229,10 +230,15 @@ 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();
|
||||
}
|
||||
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'],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user