mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 21:56:00 +00:00
perspective refactor
This commit is contained in:
@@ -47,8 +47,8 @@ export class PerspectiveDisplayColumn {
|
|||||||
return this.parentNodes[level]?.title;
|
return this.parentNodes[level]?.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
getParentDataAttributes(level) {
|
getParentTableUniqueName(level) {
|
||||||
return this.parentNodes[level]?.headerDataAttributes;
|
return this.parentNodes[level]?.headerTableAttributes ? this.parentNodes[level]?.uniqueName : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasParentNode(node: PerspectiveTreeNode) {
|
// hasParentNode(node: PerspectiveTreeNode) {
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ export abstract class PerspectiveTreeNode {
|
|||||||
get fieldName() {
|
get fieldName() {
|
||||||
return this.codeName;
|
return this.codeName;
|
||||||
}
|
}
|
||||||
get headerDataAttributes() {
|
get headerTableAttributes() {
|
||||||
return {};
|
return null;
|
||||||
}
|
}
|
||||||
get dataField() {
|
get dataField() {
|
||||||
return this.codeName;
|
return this.codeName;
|
||||||
@@ -92,7 +92,7 @@ export abstract class PerspectiveTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get uniqueName() {
|
get uniqueName() {
|
||||||
if (this.parentNode) return `${this.parentNode.uniqueName}.${this.codeName}`;
|
if (this.parentNode) return `${this.parentNode.uniqueName}::${this.codeName}`;
|
||||||
return this.codeName;
|
return this.codeName;
|
||||||
}
|
}
|
||||||
get level() {
|
get level() {
|
||||||
@@ -252,6 +252,21 @@ export abstract class PerspectiveTreeNode {
|
|||||||
get filterInfo(): PerspectiveFilterColumnInfo {
|
get filterInfo(): PerspectiveFilterColumnInfo {
|
||||||
return null;
|
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 {
|
export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
||||||
@@ -398,7 +413,7 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
get headerDataAttributes() {
|
get headerTableAttributes() {
|
||||||
if (this.foreignKey) {
|
if (this.foreignKey) {
|
||||||
return {
|
return {
|
||||||
schemaName: this.foreignKey.refSchemaName,
|
schemaName: this.foreignKey.refSchemaName,
|
||||||
@@ -474,7 +489,7 @@ export class PerspectiveTableNode extends PerspectiveTreeNode {
|
|||||||
return this.table;
|
return this.table;
|
||||||
}
|
}
|
||||||
|
|
||||||
get headerDataAttributes() {
|
get headerTableAttributes() {
|
||||||
return {
|
return {
|
||||||
schemaName: this.table.schemaName,
|
schemaName: this.table.schemaName,
|
||||||
pureName: this.table.pureName,
|
pureName: this.table.pureName,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ChangePerspectiveConfigFunc, PerspectiveConfig } from 'dbgate-datalib';
|
import { ChangePerspectiveConfigFunc, PerspectiveConfig, PerspectiveTreeNode } from 'dbgate-datalib';
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
export let managerSize;
|
export let managerSize;
|
||||||
export let config: PerspectiveConfig;
|
export let config: PerspectiveConfig;
|
||||||
export let setConfig: ChangePerspectiveConfigFunc;
|
export let setConfig: ChangePerspectiveConfigFunc;
|
||||||
|
export let root: PerspectiveTreeNode;
|
||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
|
|||||||
@@ -49,8 +49,7 @@
|
|||||||
<th
|
<th
|
||||||
colspan={column.getColSpan(columnLevel)}
|
colspan={column.getColSpan(columnLevel)}
|
||||||
class="tableHeader"
|
class="tableHeader"
|
||||||
{..._.mapKeys(column.getParentDataAttributes(columnLevel), (v, k) => `data-${k}`)}
|
data-tableNodeUniqueName={column.getParentTableUniqueName(columnLevel)}>{column.getParentName(columnLevel)}</th
|
||||||
>{column.getParentName(columnLevel)}</th
|
|
||||||
>
|
>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -188,11 +188,11 @@
|
|||||||
td.classList.remove('highlight');
|
td.classList.remove('highlight');
|
||||||
});
|
});
|
||||||
|
|
||||||
const pureName = td.getAttribute('data-pureName');
|
const tableNodeUniqueName = td.getAttribute('data-tableNodeUniqueName');
|
||||||
const schemaName = td.getAttribute('data-schemaName');
|
const tableNode = root?.findNodeByUniqueName(tableNodeUniqueName);
|
||||||
const dataConid = td.getAttribute('data-conid');
|
|
||||||
const dataDatabase = td.getAttribute('data-database');
|
if (tableNode?.headerTableAttributes) {
|
||||||
if (pureName) {
|
const { pureName, schemaName, conid, database } = tableNode?.headerTableAttributes;
|
||||||
res.push({
|
res.push({
|
||||||
text: `Open table ${pureName}`,
|
text: `Open table ${pureName}`,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
@@ -203,8 +203,8 @@
|
|||||||
props: {
|
props: {
|
||||||
schemaName,
|
schemaName,
|
||||||
pureName,
|
pureName,
|
||||||
conid: dataConid || conid,
|
conid: conid,
|
||||||
database: dataDatabase || database,
|
database: database,
|
||||||
objectTypeField: 'tables',
|
objectTypeField: 'tables',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -131,7 +131,7 @@
|
|||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
|
|
||||||
<WidgetColumnBarItem title="Filters" name="tableFilters">
|
<WidgetColumnBarItem title="Filters" name="tableFilters">
|
||||||
<PerspectiveFilters {managerSize} {config} {setConfig} {conid} {database} {driver} />
|
<PerspectiveFilters {managerSize} {config} {setConfig} {conid} {database} {driver} {root} />
|
||||||
</WidgetColumnBarItem>
|
</WidgetColumnBarItem>
|
||||||
</WidgetColumnBar>
|
</WidgetColumnBar>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user