From bd3a10bad8b3d95fa2d64f05e12ec44fab41119e Mon Sep 17 00:00:00 2001 From: Max Ehrlicher-Schmidt Date: Thu, 12 Nov 2020 19:36:47 +0100 Subject: [PATCH] Remove addColumnsFromObject function --- src/app/helperFunctions/flattenObject.ts | 2 +- src/app/pages/tables/bikes/bikes.component.ts | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/app/helperFunctions/flattenObject.ts b/src/app/helperFunctions/flattenObject.ts index abb715f..1edae54 100644 --- a/src/app/helperFunctions/flattenObject.ts +++ b/src/app/helperFunctions/flattenObject.ts @@ -8,7 +8,7 @@ export function flatten(object: Object, prefix: string = ''): any { newObject[flattenedProperty] = flattenedObject[flattenedProperty]; } - } else if(!prop.includes('_', 0)) { + } else { newObject[propName] = object[prop]; } } diff --git a/src/app/pages/tables/bikes/bikes.component.ts b/src/app/pages/tables/bikes/bikes.component.ts index ee1afa4..1e0f4d3 100644 --- a/src/app/pages/tables/bikes/bikes.component.ts +++ b/src/app/pages/tables/bikes/bikes.component.ts @@ -69,13 +69,17 @@ export class BikesComponent { if (this.data[0]) { this.displayedColumns = []; this.dataColumns = []; - - this.addColumnsFromObject('', this.data[0]); for (let index in this.data) { this.data[index] = flatten(this.data[index]); } + for (const prop in this.data[0]) { + if (!this.blacklistedColumns.includes(prop) && !prop.includes("__")) { + this.dataColumns.push(prop); + } + } + //sort, so the displayedColumns array is in the same order as the columnInfo this.dataColumns.sort((columnA, columnB) => { const indexA = this.columnInfo.findIndex((c) => c.name == columnA); @@ -110,17 +114,6 @@ export class BikesComponent { clearInterval(this.relockingInterval); } - addColumnsFromObject(prefix: string, object: Object) { - for (const prop in object) { - let propName = prefix + prop; - if (typeof object[prop] === 'object') { - this.addColumnsFromObject(prefix + prop + '.', object[prop]); - } else if (!this.blacklistedColumns.includes(propName)) { - this.dataColumns.push(propName); - } - } - } - getHeader(propertyName: string) { return ( this.columnInfo.find((column) => column.name === propertyName)?.header ||