Commit ce649822e2d677a16678605e919f57cc93321ef7

Authored by Vladyslav_Prykhodko
1 parent e3b8c28b

Add sort metadata key

... ... @@ -72,12 +72,12 @@ export class NodeScriptTestService {
72 72 }
73 73 if (!metadata) {
74 74 metadata = {
75   - deviceType: 'default',
76 75 deviceName: 'Test Device',
  76 + deviceType: 'default',
77 77 ts: new Date().getTime() + ''
78 78 };
79 79 } else {
80   - metadata = sortObjectKeys(metadata) as {[key: string]: string};
  80 + metadata = sortObjectKeys(metadata);
81 81 }
82 82 if (!msgType) {
83 83 msgType = 'POST_TELEMETRY_REQUEST';
... ...
... ... @@ -511,9 +511,9 @@ export function padValue(val: any, dec: number): string {
511 511 return strVal;
512 512 }
513 513
514   -export function sortObjectKeys(obj: object): object{
515   - return Object.keys(obj).sort().reduce((acc,key)=>{
516   - acc[key]=obj[key];
  514 +export function sortObjectKeys<T>(obj: T): T {
  515 + return Object.keys(obj).sort().reduce((acc, key) => {
  516 + acc[key] = obj[key];
517 517 return acc;
518   - },{});
  518 + }, {} as T);
519 519 }
... ...
... ... @@ -210,7 +210,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
210 210 icon: 'more_horiz',
211 211 isEnabled: (entity) => entity.body.metadata ? entity.body.metadata.length > 0 : false,
212 212 onAction: ($event, entity) => this.showContent($event, entity.body.metadata,
213   - 'event.metadata', ContentType.JSON)
  213 + 'event.metadata', ContentType.JSON, true)
214 214 },
215 215 '40px'),
216 216 new EntityActionTableColumn<Event>('error', 'event.error',
... ... @@ -230,21 +230,20 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
230 230 }
231 231 }
232 232
233   - 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 {
234 234 if ($event) {
235 235 $event.stopPropagation();
236 236 }
237   - let sortedContent: string;
238   - try {
239   - sortedContent = JSON.stringify(sortObjectKeys(JSON.parse(content)));
240   - } catch() {
241   - sortedContent = content;
  237 + if (contentType === ContentType.JSON && sortKeys) {
  238 + try {
  239 + content = JSON.stringify(sortObjectKeys(JSON.parse(content)));
  240 + } catch (e) {}
242 241 }
243 242 this.dialog.open<EventContentDialogComponent, EventContentDialogData>(EventContentDialogComponent, {
244 243 disableClose: true,
245 244 panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
246 245 data: {
247   - constent: sortedContent,
  246 + content,
248 247 title,
249 248 contentType
250 249 }
... ...