|
|
@ -23,11 +23,11 @@ const extractNestedData: any = (obj: any, path: any) => path.reduce((val: any, k |
|
|
|
export default class JSONTemplateAdapter extends TemplateGenerator { |
|
|
|
export default class JSONTemplateAdapter extends TemplateGenerator { |
|
|
|
config: Record<string, any> |
|
|
|
config: Record<string, any> |
|
|
|
name: string |
|
|
|
name: string |
|
|
|
_jsonData: string | object |
|
|
|
|
|
|
|
project: Record<string, any> |
|
|
|
|
|
|
|
data: Record<string, any> |
|
|
|
data: Record<string, any> |
|
|
|
|
|
|
|
_jsonData: string | Record<string, any> |
|
|
|
|
|
|
|
jsonData: Record<string, any> |
|
|
|
|
|
|
|
project: Record<string, any> |
|
|
|
columns: object |
|
|
|
columns: object |
|
|
|
csv: Record<string, any> |
|
|
|
|
|
|
|
constructor(name = 'test', data: object, parserConfig = {}) { |
|
|
|
constructor(name = 'test', data: object, parserConfig = {}) { |
|
|
|
super() |
|
|
|
super() |
|
|
|
this.config = { |
|
|
|
this.config = { |
|
|
@ -40,16 +40,13 @@ export default class JSONTemplateAdapter extends TemplateGenerator { |
|
|
|
title: this.name, |
|
|
|
title: this.name, |
|
|
|
tables: [], |
|
|
|
tables: [], |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.jsonData = [] |
|
|
|
|
|
|
|
this.data = [] |
|
|
|
this.columns = {} |
|
|
|
this.columns = {} |
|
|
|
this.data = {} |
|
|
|
|
|
|
|
this.csv = {} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async init() {} |
|
|
|
async init() { |
|
|
|
|
|
|
|
this.jsonData = JSON.parse(new TextDecoder().decode(this._jsonData as BufferSource)) |
|
|
|
parseData(): any { |
|
|
|
|
|
|
|
this.columns = this.csv.meta.fields |
|
|
|
|
|
|
|
this.data = this.csv.data |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getColumns(): any { |
|
|
|
getColumns(): any { |
|
|
@ -60,10 +57,6 @@ export default class JSONTemplateAdapter extends TemplateGenerator { |
|
|
|
return this.data |
|
|
|
return this.data |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get jsonData(): any { |
|
|
|
|
|
|
|
return Array.isArray(this._jsonData) ? this._jsonData : [this._jsonData] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parse(): any { |
|
|
|
parse(): any { |
|
|
|
const jsonData = this.jsonData |
|
|
|
const jsonData = this.jsonData |
|
|
|
const tn = 'table' |
|
|
|
const tn = 'table' |
|
|
@ -148,7 +141,7 @@ export default class JSONTemplateAdapter extends TemplateGenerator { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_parseTableData(tableMeta: any) { |
|
|
|
_parseTableData(tableMeta: any) { |
|
|
|
for (const row of this.jsonData) { |
|
|
|
for (const row of this.jsonData as any) { |
|
|
|
const rowData: any = {} |
|
|
|
const rowData: any = {} |
|
|
|
for (let i = 0; i < tableMeta.columns.length; i++) { |
|
|
|
for (let i = 0; i < tableMeta.columns.length; i++) { |
|
|
|
const value = extractNestedData(row, tableMeta.columns[i].path || []) |
|
|
|
const value = extractNestedData(row, tableMeta.columns[i].path || []) |
|
|
|