|
|
|
@ -23,7 +23,8 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
private _selectFormulasObj: any; |
|
|
|
|
private _defaultNestedQueryParams: any; |
|
|
|
|
private _nestedProps: { [prop: string]: any }; |
|
|
|
|
private readonly _primaryCol: any; |
|
|
|
|
private _nestedPropsModels: { [prop: string]: BaseModelSql } = {}; |
|
|
|
|
private readonly _primaryColRef: any; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
@ -68,7 +69,7 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
this.columns = columns; |
|
|
|
|
|
|
|
|
|
this.pks = columns.filter(c => c.pk === true); |
|
|
|
|
this.primaryCol = columns.find(c => c.pv)?._cn; |
|
|
|
|
this._primaryColRef = columns.find(c => c.pv); |
|
|
|
|
this.hasManyRelations = hasMany; |
|
|
|
|
this.belongsToRelations = belongsTo; |
|
|
|
|
this.manyToManyRelations = manyToMany; |
|
|
|
@ -2344,11 +2345,17 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
if (!this._nestedProps) { |
|
|
|
|
this._nestedProps = (this.virtualColumns || [])?.reduce((obj, v) => { |
|
|
|
|
if (v.bt) { |
|
|
|
|
obj[`${this.dbModels[v.bt.rtn]._tn}Read`] = v; |
|
|
|
|
const prop = `${this.dbModels[v.bt.rtn]._tn}Read`; |
|
|
|
|
obj[prop] = v; |
|
|
|
|
this._nestedPropsModels[v] = this.dbModels[v.bt?.rtn]; |
|
|
|
|
} else if (v.hm) { |
|
|
|
|
obj[`${this.dbModels[v.hm.tn]._tn}List`] = v; |
|
|
|
|
const prop = `${this.dbModels[v.hm.tn]._tn}List`; |
|
|
|
|
obj[prop] = v; |
|
|
|
|
this._nestedPropsModels[v] = this.dbModels[v.hm?.tn]; |
|
|
|
|
} else if (v.mm) { |
|
|
|
|
obj[`${this.dbModels[v.mm.rtn]._tn}MMList`] = v; |
|
|
|
|
const prop = `${this.dbModels[v.mm.rtn]._tn}MMList`; |
|
|
|
|
obj[prop] = v; |
|
|
|
|
this._nestedPropsModels[v] = this.dbModels[v.bt?.rtn]; |
|
|
|
|
} |
|
|
|
|
return obj; |
|
|
|
|
}, {}); |
|
|
|
@ -2433,9 +2440,23 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (const [prop, vColumn] of Object.entries(this.nestedProps)) { |
|
|
|
|
for (const prop of Object.keys(this.nestedProps)) { |
|
|
|
|
const refModel = this._nestedPropsModels[prop]; |
|
|
|
|
|
|
|
|
|
if (prop in row) { |
|
|
|
|
if (Array.is) csvRow[prop] = row.map; |
|
|
|
|
if (Array.isArray(row[prop])) { |
|
|
|
|
csvRow[prop] = row.map(r => |
|
|
|
|
refModel.serializeCellValue({ |
|
|
|
|
value: r[refModel.primaryColAlias], |
|
|
|
|
columnName: refModel.primaryColAlias |
|
|
|
|
}) |
|
|
|
|
); |
|
|
|
|
} else if (row[prop]) { |
|
|
|
|
csvRow[prop] = refModel.serializeCellValue({ |
|
|
|
|
value: row[refModel.primaryColAlias], |
|
|
|
|
columnName: refModel.primaryColAlias |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2443,87 +2464,9 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Papaparse.unparse(csvRows); |
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// return Promise.all(this.data.map(async (r) => {
|
|
|
|
|
// const row = {}
|
|
|
|
|
// for (const col of this.availableColumns) {
|
|
|
|
|
// if (col.virtual) {
|
|
|
|
|
// let prop, cn
|
|
|
|
|
// if (col.mm || (col.lk && col.lk.type === 'mm')) {
|
|
|
|
|
// const tn = col.mm ? col.mm.rtn : col.lk.ltn
|
|
|
|
|
// const _tn = col.mm ? col.mm._rtn : col.lk._ltn
|
|
|
|
|
// await this.$store.dispatch('meta/ActLoadMeta', {
|
|
|
|
|
// env: this.nodes.env,
|
|
|
|
|
// dbAlias: this.nodes.dbAlias,
|
|
|
|
|
// tn
|
|
|
|
|
// })
|
|
|
|
|
//
|
|
|
|
|
// prop = `${_tn}MMList`
|
|
|
|
|
// cn = col.lk
|
|
|
|
|
// ? col.lk._lcn
|
|
|
|
|
// : (this.$store.state.meta.metas[tn].columns.find(c => c.pv) || this.$store.state.meta.metas[tn].columns.find(c => c.pk) || {})._cn
|
|
|
|
|
//
|
|
|
|
|
// row[col._cn] = r.row[prop] && r.row[prop].map(r => cn && r[cn])
|
|
|
|
|
// } else if (col.hm || (col.lk && col.lk.type === 'hm')) {
|
|
|
|
|
// const tn = col.hm ? col.hm.tn : col.lk.ltn
|
|
|
|
|
// const _tn = col.hm ? col.hm._tn : col.lk._ltn
|
|
|
|
|
//
|
|
|
|
|
// await this.$store.dispatch('meta/ActLoadMeta', {
|
|
|
|
|
// env: this.nodes.env,
|
|
|
|
|
// dbAlias: this.nodes.dbAlias,
|
|
|
|
|
// tn
|
|
|
|
|
// })
|
|
|
|
|
//
|
|
|
|
|
// prop = `${_tn}List`
|
|
|
|
|
// cn = col.lk
|
|
|
|
|
// ? col.lk._lcn
|
|
|
|
|
// : (this.$store.state.meta.metas[tn].columns.find(c => c.pv) ||
|
|
|
|
|
// this.$store.state.meta.metas[tn].columns.find(c => c.pk))._cn
|
|
|
|
|
// row[col._cn] = r.row[prop] && r.row[prop].map(r => cn && r[cn])
|
|
|
|
|
// } else if (col.bt || (col.lk && col.lk.type === 'bt')) {
|
|
|
|
|
// const tn = col.bt ? col.bt.rtn : col.lk.ltn
|
|
|
|
|
// const _tn = col.bt ? col.bt._rtn : col.lk._ltn
|
|
|
|
|
// await this.$store.dispatch('meta/ActLoadMeta', {
|
|
|
|
|
// env: this.nodes.env,
|
|
|
|
|
// dbAlias: this.nodes.dbAlias,
|
|
|
|
|
// tn
|
|
|
|
|
// })
|
|
|
|
|
//
|
|
|
|
|
// prop = `${_tn}Read`
|
|
|
|
|
// cn = col.lk
|
|
|
|
|
// ? col.lk._lcn
|
|
|
|
|
// : (this.$store.state.meta.metas[tn].columns.find(c => c.pv) ||
|
|
|
|
|
// this.$store.state.meta.metas[tn].columns.find(c => c.pk) || {})._cn
|
|
|
|
|
// row[col._cn] = r.row[prop] &&
|
|
|
|
|
// r.row[prop] && cn && r.row[prop][cn]
|
|
|
|
|
// } else {
|
|
|
|
|
// row[col._cn] = r.row[col._cn]
|
|
|
|
|
// }
|
|
|
|
|
// } else if (col.uidt === 'Attachment') {
|
|
|
|
|
// let data = []
|
|
|
|
|
// try {
|
|
|
|
|
// if (typeof r.row[col._cn] === 'string') {
|
|
|
|
|
// data = JSON.parse(r.row[col._cn])
|
|
|
|
|
// } else if (r.row[col._cn]) {
|
|
|
|
|
// data = r.row[col._cn]
|
|
|
|
|
// }
|
|
|
|
|
// } catch {
|
|
|
|
|
// }
|
|
|
|
|
// row[col._cn] = (data || []).map(a => `${a.title}(${a.url})`)
|
|
|
|
|
// } else {
|
|
|
|
|
// row[col._cn] = r.row[col._cn]
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return row
|
|
|
|
|
// }))
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// async exportCsv() {
|
|
|
|
|
// const blob = new Blob([Papaparse.unparse(await this.extractCsvData())], {type: 'text/plain;charset=utf-8'})
|
|
|
|
|
// FileSaver.saveAs(blob, `${this.meta._tn}_exported.csv`)
|
|
|
|
|
// }
|
|
|
|
|
private serializeCellValue({ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public serializeCellValue({ |
|
|
|
|
value, |
|
|
|
|
...args |
|
|
|
|
}: { |
|
|
|
@ -2555,11 +2498,12 @@ class BaseModelSql extends BaseModel {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public get primaryCol(): string { |
|
|
|
|
return this._primaryCol?.cn; |
|
|
|
|
public get primaryColRef(): string { |
|
|
|
|
return this._primaryColRef?.cn; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public get primaryColAlias(): string { |
|
|
|
|
return this._primaryCol?._cn; |
|
|
|
|
return this._primaryColRef?._cn; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|