perspective refactor

This commit is contained in:
Jan Prochazka
2022-08-07 16:40:37 +02:00
parent b5c6ddce59
commit 3f9bd100e1
6 changed files with 33 additions and 18 deletions

View File

@@ -47,8 +47,8 @@ export class PerspectiveDisplayColumn {
return this.parentNodes[level]?.title;
}
getParentDataAttributes(level) {
return this.parentNodes[level]?.headerDataAttributes;
getParentTableUniqueName(level) {
return this.parentNodes[level]?.headerTableAttributes ? this.parentNodes[level]?.uniqueName : '';
}
// hasParentNode(node: PerspectiveTreeNode) {

View File

@@ -70,8 +70,8 @@ export abstract class PerspectiveTreeNode {
get fieldName() {
return this.codeName;
}
get headerDataAttributes() {
return {};
get headerTableAttributes() {
return null;
}
get dataField() {
return this.codeName;
@@ -92,7 +92,7 @@ export abstract class PerspectiveTreeNode {
}
get uniqueName() {
if (this.parentNode) return `${this.parentNode.uniqueName}.${this.codeName}`;
if (this.parentNode) return `${this.parentNode.uniqueName}::${this.codeName}`;
return this.codeName;
}
get level() {
@@ -252,6 +252,21 @@ export abstract class PerspectiveTreeNode {
get filterInfo(): PerspectiveFilterColumnInfo {
return null;
}
findChildNodeByUniquePath(uniquePath: string[]) {
if (uniquePath.length == 0) {
return this;
}
const child = this.childNodes.find(x => x.codeName == uniquePath[0]);
return child?.findChildNodeByUniquePath(uniquePath.slice(1));
}
findNodeByUniqueName(uniqueName: string): PerspectiveTreeNode {
if (!uniqueName) return null;
const uniquePath = uniqueName.split('::');
if (uniquePath[0] != this.codeName) return null;
return this.findChildNodeByUniquePath(uniquePath.slice(1));
}
}
export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
@@ -398,7 +413,7 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
return condition;
}
get headerDataAttributes() {
get headerTableAttributes() {
if (this.foreignKey) {
return {
schemaName: this.foreignKey.refSchemaName,
@@ -474,7 +489,7 @@ export class PerspectiveTableNode extends PerspectiveTreeNode {
return this.table;
}
get headerDataAttributes() {
get headerTableAttributes() {
return {
schemaName: this.table.schemaName,
pureName: this.table.pureName,

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { ChangePerspectiveConfigFunc, PerspectiveConfig } from 'dbgate-datalib';
import { ChangePerspectiveConfigFunc, PerspectiveConfig, PerspectiveTreeNode } from 'dbgate-datalib';
import _ from 'lodash';
@@ -10,6 +10,7 @@
export let managerSize;
export let config: PerspectiveConfig;
export let setConfig: ChangePerspectiveConfigFunc;
export let root: PerspectiveTreeNode;
export let conid;
export let database;

View File

@@ -49,8 +49,7 @@
<th
colspan={column.getColSpan(columnLevel)}
class="tableHeader"
{..._.mapKeys(column.getParentDataAttributes(columnLevel), (v, k) => `data-${k}`)}
>{column.getParentName(columnLevel)}</th
data-tableNodeUniqueName={column.getParentTableUniqueName(columnLevel)}>{column.getParentName(columnLevel)}</th
>
{/if}

View File

@@ -188,11 +188,11 @@
td.classList.remove('highlight');
});
const pureName = td.getAttribute('data-pureName');
const schemaName = td.getAttribute('data-schemaName');
const dataConid = td.getAttribute('data-conid');
const dataDatabase = td.getAttribute('data-database');
if (pureName) {
const tableNodeUniqueName = td.getAttribute('data-tableNodeUniqueName');
const tableNode = root?.findNodeByUniqueName(tableNodeUniqueName);
if (tableNode?.headerTableAttributes) {
const { pureName, schemaName, conid, database } = tableNode?.headerTableAttributes;
res.push({
text: `Open table ${pureName}`,
onClick: () => {
@@ -203,8 +203,8 @@
props: {
schemaName,
pureName,
conid: dataConid || conid,
database: dataDatabase || database,
conid: conid,
database: database,
objectTypeField: 'tables',
},
});

View File

@@ -131,7 +131,7 @@
</WidgetColumnBarItem>
<WidgetColumnBarItem title="Filters" name="tableFilters">
<PerspectiveFilters {managerSize} {config} {setConfig} {conid} {database} {driver} />
<PerspectiveFilters {managerSize} {config} {setConfig} {conid} {database} {driver} {root} />
</WidgetColumnBarItem>
</WidgetColumnBar>
</div>