mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
perspective nosql test
This commit is contained in:
parent
8b511a0532
commit
d647d30258
@ -17,7 +17,7 @@ export interface PerspectiveDataPatternColumn {
|
||||
export interface PerspectiveDataPattern {
|
||||
conid: string;
|
||||
database: string;
|
||||
schemaName: string;
|
||||
schemaName?: string;
|
||||
pureName: string;
|
||||
columns: PerspectiveDataPatternColumn[];
|
||||
}
|
||||
|
@ -126,14 +126,14 @@ export class PerspectiveDisplay {
|
||||
|
||||
fillColumns(children: PerspectiveTreeNode[], parentNodes: PerspectiveTreeNode[]) {
|
||||
for (const child of children) {
|
||||
if (child.isCheckedColumn || child.isCheckedNode) {
|
||||
if (child.generatesHiearchicGridColumn || child.generatesDataGridColumn) {
|
||||
this.processColumn(child, parentNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processColumn(node: PerspectiveTreeNode, parentNodes: PerspectiveTreeNode[]) {
|
||||
if (node.isCheckedColumn) {
|
||||
if (node.generatesDataGridColumn) {
|
||||
const column = new PerspectiveDisplayColumn(this);
|
||||
column.title = node.columnTitle;
|
||||
column.dataField = node.dataField;
|
||||
@ -145,7 +145,7 @@ export class PerspectiveDisplay {
|
||||
this.columns.push(column);
|
||||
}
|
||||
|
||||
if (node.isExpandable && node.isCheckedNode) {
|
||||
if (node.generatesHiearchicGridColumn) {
|
||||
const countBefore = this.columns.length;
|
||||
this.fillColumns(node.childNodes, [...parentNodes, node]);
|
||||
|
||||
@ -185,6 +185,7 @@ export class PerspectiveDisplay {
|
||||
const subRowCollections = [];
|
||||
|
||||
for (const node of treeNodes) {
|
||||
// console.log('sourceRow[node.fieldName]', node.fieldName, sourceRow[node.fieldName]);
|
||||
if (sourceRow[node.fieldName]) {
|
||||
const subrows = {
|
||||
rows: this.collectRows(sourceRow[node.fieldName], node.childNodes),
|
||||
|
@ -81,7 +81,7 @@ export abstract class PerspectiveTreeNode {
|
||||
this.parentNodeConfig = parentNode?.nodeConfig;
|
||||
}
|
||||
readonly nodeConfig: PerspectiveNodeConfig;
|
||||
readonly parentNodeConfig: PerspectiveNodeConfig;
|
||||
parentNodeConfig: PerspectiveNodeConfig;
|
||||
// defaultChecked: boolean;
|
||||
abstract get title();
|
||||
abstract get codeName();
|
||||
@ -110,6 +110,15 @@ export abstract class PerspectiveTreeNode {
|
||||
get namedObject(): NamedObjectInfo {
|
||||
return null;
|
||||
}
|
||||
get parentTableNode(): PerspectiveTableNode {
|
||||
if (this instanceof PerspectiveTableNode) {
|
||||
return this;
|
||||
}
|
||||
if (this.parentNode == null) {
|
||||
return null;
|
||||
}
|
||||
return this.parentNode.parentTableNode;
|
||||
}
|
||||
abstract getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
|
||||
get isRoot() {
|
||||
return this.parentNode == null;
|
||||
@ -121,6 +130,12 @@ export abstract class PerspectiveTreeNode {
|
||||
get isSortable() {
|
||||
return false;
|
||||
}
|
||||
get generatesHiearchicGridColumn() {
|
||||
return this.isExpandable && this.isCheckedNode;
|
||||
}
|
||||
get generatesDataGridColumn() {
|
||||
return this.isCheckedColumn;
|
||||
}
|
||||
matchChildRow(parentRow: any, childRow: any): boolean {
|
||||
return true;
|
||||
}
|
||||
@ -273,12 +288,12 @@ export abstract class PerspectiveTreeNode {
|
||||
[field]: isIncluded ? [...(n[field] || []), this.codeName] : (n[field] || []).filter(x => x != this.codeName),
|
||||
});
|
||||
|
||||
const [cfgChanged, nodeCfg] = this.parentNode?.ensureNodeConfig(cfg);
|
||||
const [cfgChanged, nodeCfg] = this.parentTableNode?.ensureNodeConfig(cfg);
|
||||
|
||||
return {
|
||||
...cfgChanged,
|
||||
nodes: cfgChanged.nodes.map(n =>
|
||||
n.designerId == (this.parentNode?.designerId || nodeCfg?.designerId) ? changedFields(n) : n
|
||||
n.designerId == (this.parentTableNode?.designerId || nodeCfg?.designerId) ? changedFields(n) : n
|
||||
),
|
||||
};
|
||||
});
|
||||
@ -727,6 +742,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
||||
designerId: string
|
||||
) {
|
||||
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
|
||||
this.parentNodeConfig = this.parentTableNode?.nodeConfig;
|
||||
}
|
||||
|
||||
get isChildColumn() {
|
||||
@ -780,11 +796,22 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
||||
return null;
|
||||
}
|
||||
|
||||
get generatesHiearchicGridColumn() {
|
||||
return !!this.parentTableNode?.nodeConfig?.checkedColumns?.find(x => x.startsWith(this.codeName + '::'));
|
||||
}
|
||||
|
||||
// get generatesHiearchicGridColumn() {
|
||||
// // return this.config &&;
|
||||
// }
|
||||
|
||||
get icon() {
|
||||
return 'img column';
|
||||
}
|
||||
|
||||
get codeName() {
|
||||
if (this.parentNode instanceof PerspectivePatternColumnNode) {
|
||||
return `${this.parentNode.codeName}::${this.column.name}`;
|
||||
}
|
||||
return this.column.name;
|
||||
}
|
||||
|
||||
@ -793,7 +820,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
||||
}
|
||||
|
||||
get fieldName() {
|
||||
return this.codeName + 'Ref';
|
||||
return this.column.name;
|
||||
}
|
||||
|
||||
get title() {
|
||||
|
@ -7,6 +7,9 @@ import artistDataFlat from './artistDataFlat';
|
||||
import artistDataAlbum from './artistDataAlbum';
|
||||
import artistDataAlbumTrack from './artistDataAlbumTrack';
|
||||
import { processPerspectiveDefaultColunns } from '../processPerspectiveDefaultColunns';
|
||||
import { DatabaseAnalyser, isCollectionInfo } from 'dbgate-tools';
|
||||
import { analyseDataPattern } from '../PerspectiveDataPattern';
|
||||
import { PerspectiveDataProvider } from '../PerspectiveDataProvider';
|
||||
|
||||
test('test flat view', () => {
|
||||
const artistTable = chinookDbInfo.tables.find(x => x.pureName == 'Artist');
|
||||
@ -141,3 +144,52 @@ test('test two level nesting', () => {
|
||||
expect(display.rows[2].rowSpans).toEqual([1, 2, 1]);
|
||||
expect(display.rows[2].rowCellSkips).toEqual([true, false, false]);
|
||||
});
|
||||
|
||||
test('test nosql display', () => {
|
||||
const collectionInfo = {
|
||||
objectTypeField: 'collections',
|
||||
pureName: 'Account',
|
||||
};
|
||||
const dbInfo = {
|
||||
...DatabaseAnalyser.createEmptyStructure(),
|
||||
collections: [collectionInfo],
|
||||
};
|
||||
const accountData = [
|
||||
{ name: 'jan', email: 'jan@foo.co', follows: [{ name: 'lucie' }, { name: 'petr' }] },
|
||||
{ name: 'romeo', email: 'romeo@foo.co', follows: [{ name: 'julie' }, { name: 'wiliam' }] },
|
||||
];
|
||||
const config = createPerspectiveConfig({ pureName: 'Account' });
|
||||
const dataPatterns = {
|
||||
[config.rootDesignerId]: analyseDataPattern(
|
||||
{
|
||||
conid: 'conid',
|
||||
database: 'db',
|
||||
pureName: 'Account',
|
||||
},
|
||||
accountData
|
||||
),
|
||||
};
|
||||
|
||||
const configColumns = processPerspectiveDefaultColunns(
|
||||
config,
|
||||
{ conid: { db: dbInfo } },
|
||||
dataPatterns,
|
||||
'conid',
|
||||
'db'
|
||||
);
|
||||
const root = new PerspectiveTableNode(
|
||||
collectionInfo,
|
||||
{ conid: { db: dbInfo } },
|
||||
configColumns,
|
||||
null,
|
||||
new PerspectiveDataProvider(null, null, dataPatterns),
|
||||
{ conid: 'conid', database: 'db' },
|
||||
null,
|
||||
configColumns.rootDesignerId
|
||||
);
|
||||
const display = new PerspectiveDisplay(root, accountData);
|
||||
|
||||
expect(display.rows.length).toEqual(2);
|
||||
expect(display.rows[0].rowData).toEqual(['jan']);
|
||||
expect(display.rows[1].rowData).toEqual(['romeo']);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user