Browse Source

feat: template import(in progress)

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/743/head
Pranav C 3 years ago
parent
commit
fa677ffc22
  1. 6
      packages/nocodb/src/lib/sqlUi/UITypes.ts
  2. 51
      packages/nocodb/src/lib/templateParser/NcTemplateParser.ts

6
packages/nocodb/src/lib/sqlUi/UITypes.ts

@ -0,0 +1,6 @@
enum UITypes {
LinkToAnotherRecord = 'LinkToAnotherRecord',
ForeignKey = 'ForeignKey'
}
export default UITypes;

51
packages/nocodb/src/lib/templateParser/NcTemplateParser.ts

@ -6,6 +6,7 @@ import {
SqliteUi, SqliteUi,
SqlUiFactory SqlUiFactory
} from '../sqlUi'; } from '../sqlUi';
import UITypes from '../sqlUi/UITypes';
export default class NcTemplateParser { export default class NcTemplateParser {
sqlUi: sqlUi:
@ -15,18 +16,24 @@ export default class NcTemplateParser {
| typeof OracleUi | typeof OracleUi
| typeof SqliteUi; | typeof SqliteUi;
constructor(client) { private _tables: any[];
private _relations: any[];
private template: any;
constructor({ client, template }) {
this.sqlUi = SqlUiFactory.create({ client }); this.sqlUi = SqlUiFactory.create({ client });
this.template = template;
} }
public parse(template: any): any { public parse(template?: any): any {
const tables = []; const tables = [];
for (const tableTemplate of template.tables) { this.template = template || this.template;
for (const tableTemplate of this.template._tables) {
const table = this.extractTable(tableTemplate); const table = this.extractTable(tableTemplate);
tables.push(table); tables.push(table);
} }
return { tables }; this._tables = tables;
} }
private extractTable(tableTemplate) { private extractTable(tableTemplate) {
@ -58,17 +65,35 @@ export default class NcTemplateParser {
if (!tableColumn?.cn) { if (!tableColumn?.cn) {
throw Error('Missing column name in template'); throw Error('Missing column name in template');
} }
const column = {
...this.sqlUi.getNewColumn(''), if (
cn: tableColumn.cn, tableColumn.uidt === UITypes.LinkToAnotherRecord ||
_cn: tableColumn.cn, tableColumn.uidt === UITypes.ForeignKey
uidt: tableColumn.uidt, ) {
...this.sqlUi.getDataTypeForUiType(tableColumn) // todo :
}; } else {
columns.push(column); const column = {
...this.sqlUi.getNewColumn(''),
cn: tableColumn.cn,
_cn: tableColumn.cn,
uidt: tableColumn.uidt,
...this.sqlUi.getDataTypeForUiType(tableColumn)
};
columns.push(column);
}
} }
return columns; return columns;
} }
private ex; protected extractRelations(_columnTemplate) {
if (!this._relations) this._relations = [];
}
get tables(): any[] {
return this._tables;
}
get relations(): any[] {
return this._relations;
}
} }

Loading…
Cancel
Save