mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 16:53:58 +00:00
perspective nosql test
This commit is contained in:
@@ -17,7 +17,7 @@ export interface PerspectiveDataPatternColumn {
|
|||||||
export interface PerspectiveDataPattern {
|
export interface PerspectiveDataPattern {
|
||||||
conid: string;
|
conid: string;
|
||||||
database: string;
|
database: string;
|
||||||
schemaName: string;
|
schemaName?: string;
|
||||||
pureName: string;
|
pureName: string;
|
||||||
columns: PerspectiveDataPatternColumn[];
|
columns: PerspectiveDataPatternColumn[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,14 +126,14 @@ export class PerspectiveDisplay {
|
|||||||
|
|
||||||
fillColumns(children: PerspectiveTreeNode[], parentNodes: PerspectiveTreeNode[]) {
|
fillColumns(children: PerspectiveTreeNode[], parentNodes: PerspectiveTreeNode[]) {
|
||||||
for (const child of children) {
|
for (const child of children) {
|
||||||
if (child.isCheckedColumn || child.isCheckedNode) {
|
if (child.generatesHiearchicGridColumn || child.generatesDataGridColumn) {
|
||||||
this.processColumn(child, parentNodes);
|
this.processColumn(child, parentNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processColumn(node: PerspectiveTreeNode, parentNodes: PerspectiveTreeNode[]) {
|
processColumn(node: PerspectiveTreeNode, parentNodes: PerspectiveTreeNode[]) {
|
||||||
if (node.isCheckedColumn) {
|
if (node.generatesDataGridColumn) {
|
||||||
const column = new PerspectiveDisplayColumn(this);
|
const column = new PerspectiveDisplayColumn(this);
|
||||||
column.title = node.columnTitle;
|
column.title = node.columnTitle;
|
||||||
column.dataField = node.dataField;
|
column.dataField = node.dataField;
|
||||||
@@ -145,7 +145,7 @@ export class PerspectiveDisplay {
|
|||||||
this.columns.push(column);
|
this.columns.push(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.isExpandable && node.isCheckedNode) {
|
if (node.generatesHiearchicGridColumn) {
|
||||||
const countBefore = this.columns.length;
|
const countBefore = this.columns.length;
|
||||||
this.fillColumns(node.childNodes, [...parentNodes, node]);
|
this.fillColumns(node.childNodes, [...parentNodes, node]);
|
||||||
|
|
||||||
@@ -185,6 +185,7 @@ export class PerspectiveDisplay {
|
|||||||
const subRowCollections = [];
|
const subRowCollections = [];
|
||||||
|
|
||||||
for (const node of treeNodes) {
|
for (const node of treeNodes) {
|
||||||
|
// console.log('sourceRow[node.fieldName]', node.fieldName, sourceRow[node.fieldName]);
|
||||||
if (sourceRow[node.fieldName]) {
|
if (sourceRow[node.fieldName]) {
|
||||||
const subrows = {
|
const subrows = {
|
||||||
rows: this.collectRows(sourceRow[node.fieldName], node.childNodes),
|
rows: this.collectRows(sourceRow[node.fieldName], node.childNodes),
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export abstract class PerspectiveTreeNode {
|
|||||||
this.parentNodeConfig = parentNode?.nodeConfig;
|
this.parentNodeConfig = parentNode?.nodeConfig;
|
||||||
}
|
}
|
||||||
readonly nodeConfig: PerspectiveNodeConfig;
|
readonly nodeConfig: PerspectiveNodeConfig;
|
||||||
readonly parentNodeConfig: PerspectiveNodeConfig;
|
parentNodeConfig: PerspectiveNodeConfig;
|
||||||
// defaultChecked: boolean;
|
// defaultChecked: boolean;
|
||||||
abstract get title();
|
abstract get title();
|
||||||
abstract get codeName();
|
abstract get codeName();
|
||||||
@@ -110,6 +110,15 @@ export abstract class PerspectiveTreeNode {
|
|||||||
get namedObject(): NamedObjectInfo {
|
get namedObject(): NamedObjectInfo {
|
||||||
return null;
|
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;
|
abstract getNodeLoadProps(parentRows: any[]): PerspectiveDataLoadProps;
|
||||||
get isRoot() {
|
get isRoot() {
|
||||||
return this.parentNode == null;
|
return this.parentNode == null;
|
||||||
@@ -121,6 +130,12 @@ export abstract class PerspectiveTreeNode {
|
|||||||
get isSortable() {
|
get isSortable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
get generatesHiearchicGridColumn() {
|
||||||
|
return this.isExpandable && this.isCheckedNode;
|
||||||
|
}
|
||||||
|
get generatesDataGridColumn() {
|
||||||
|
return this.isCheckedColumn;
|
||||||
|
}
|
||||||
matchChildRow(parentRow: any, childRow: any): boolean {
|
matchChildRow(parentRow: any, childRow: any): boolean {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -273,12 +288,12 @@ export abstract class PerspectiveTreeNode {
|
|||||||
[field]: isIncluded ? [...(n[field] || []), this.codeName] : (n[field] || []).filter(x => x != this.codeName),
|
[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 {
|
return {
|
||||||
...cfgChanged,
|
...cfgChanged,
|
||||||
nodes: cfgChanged.nodes.map(n =>
|
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
|
designerId: string
|
||||||
) {
|
) {
|
||||||
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
|
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig, designerId);
|
||||||
|
this.parentNodeConfig = this.parentTableNode?.nodeConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isChildColumn() {
|
get isChildColumn() {
|
||||||
@@ -780,11 +796,22 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get generatesHiearchicGridColumn() {
|
||||||
|
return !!this.parentTableNode?.nodeConfig?.checkedColumns?.find(x => x.startsWith(this.codeName + '::'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// get generatesHiearchicGridColumn() {
|
||||||
|
// // return this.config &&;
|
||||||
|
// }
|
||||||
|
|
||||||
get icon() {
|
get icon() {
|
||||||
return 'img column';
|
return 'img column';
|
||||||
}
|
}
|
||||||
|
|
||||||
get codeName() {
|
get codeName() {
|
||||||
|
if (this.parentNode instanceof PerspectivePatternColumnNode) {
|
||||||
|
return `${this.parentNode.codeName}::${this.column.name}`;
|
||||||
|
}
|
||||||
return this.column.name;
|
return this.column.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,7 +820,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get fieldName() {
|
get fieldName() {
|
||||||
return this.codeName + 'Ref';
|
return this.column.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
get title() {
|
get title() {
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import artistDataFlat from './artistDataFlat';
|
|||||||
import artistDataAlbum from './artistDataAlbum';
|
import artistDataAlbum from './artistDataAlbum';
|
||||||
import artistDataAlbumTrack from './artistDataAlbumTrack';
|
import artistDataAlbumTrack from './artistDataAlbumTrack';
|
||||||
import { processPerspectiveDefaultColunns } from '../processPerspectiveDefaultColunns';
|
import { processPerspectiveDefaultColunns } from '../processPerspectiveDefaultColunns';
|
||||||
|
import { DatabaseAnalyser, isCollectionInfo } from 'dbgate-tools';
|
||||||
|
import { analyseDataPattern } from '../PerspectiveDataPattern';
|
||||||
|
import { PerspectiveDataProvider } from '../PerspectiveDataProvider';
|
||||||
|
|
||||||
test('test flat view', () => {
|
test('test flat view', () => {
|
||||||
const artistTable = chinookDbInfo.tables.find(x => x.pureName == 'Artist');
|
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].rowSpans).toEqual([1, 2, 1]);
|
||||||
expect(display.rows[2].rowCellSkips).toEqual([true, false, false]);
|
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']);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user