mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 01:33:59 +00:00
perspective: filter this value, open filtered table
This commit is contained in:
@@ -257,6 +257,8 @@ export abstract class PerspectiveTreeNode {
|
|||||||
export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
||||||
foreignKey: ForeignKeyInfo;
|
foreignKey: ForeignKeyInfo;
|
||||||
refTable: TableInfo;
|
refTable: TableInfo;
|
||||||
|
isView: boolean;
|
||||||
|
isTable: boolean;
|
||||||
constructor(
|
constructor(
|
||||||
public column: ColumnInfo,
|
public column: ColumnInfo,
|
||||||
public table: TableInfo | ViewInfo,
|
public table: TableInfo | ViewInfo,
|
||||||
@@ -269,6 +271,9 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
|||||||
) {
|
) {
|
||||||
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
|
super(dbs, config, setConfig, parentNode, dataProvider, databaseConfig);
|
||||||
|
|
||||||
|
this.isTable = !!this.db?.tables?.find(x => x.schemaName == table.schemaName && x.pureName == table.pureName);
|
||||||
|
this.isView = !!this.db?.views?.find(x => x.schemaName == table.schemaName && x.pureName == table.pureName);
|
||||||
|
|
||||||
this.foreignKey = (table as TableInfo)?.foreignKeys?.find(
|
this.foreignKey = (table as TableInfo)?.foreignKeys?.find(
|
||||||
fk => fk.columns.length == 1 && fk.columns[0].columnName == column.columnName
|
fk => fk.columns.length == 1 && fk.columns[0].columnName == column.columnName
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,14 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { PerspectiveDisplay, PerspectiveTreeNode, PERSPECTIVE_PAGE_SIZE } from 'dbgate-datalib';
|
import {
|
||||||
|
ChangePerspectiveConfigFunc,
|
||||||
|
PerspectiveConfig,
|
||||||
|
PerspectiveDisplay,
|
||||||
|
PerspectiveTableColumnNode,
|
||||||
|
PerspectiveTreeNode,
|
||||||
|
PERSPECTIVE_PAGE_SIZE,
|
||||||
|
} from 'dbgate-datalib';
|
||||||
import _, { values } from 'lodash';
|
import _, { values } from 'lodash';
|
||||||
import { onMount, tick } from 'svelte';
|
import { onMount, tick } from 'svelte';
|
||||||
import resizeObserver from '../utility/resizeObserver';
|
import resizeObserver from '../utility/resizeObserver';
|
||||||
@@ -31,14 +38,15 @@
|
|||||||
import createRef from '../utility/createRef';
|
import createRef from '../utility/createRef';
|
||||||
import { getPerspectiveNodeMenu } from './perspectiveMenu';
|
import { getPerspectiveNodeMenu } from './perspectiveMenu';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
|
import { getFilterValueExpression } from 'dbgate-filterparser';
|
||||||
|
|
||||||
const dbg = debug('dbgate:PerspectivaTable');
|
const dbg = debug('dbgate:PerspectivaTable');
|
||||||
export const activator = createActivator('PerspectiveTable', true);
|
export const activator = createActivator('PerspectiveTable', true);
|
||||||
|
|
||||||
export let root: PerspectiveTreeNode;
|
export let root: PerspectiveTreeNode;
|
||||||
export let loadedCounts;
|
export let loadedCounts;
|
||||||
export let config;
|
export let config: PerspectiveConfig;
|
||||||
export let setConfig;
|
export let setConfig: ChangePerspectiveConfigFunc;
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
|
|
||||||
@@ -160,6 +168,8 @@
|
|||||||
const td = targetElement.closest('td') || targetElement.closest('th');
|
const td = targetElement.closest('td') || targetElement.closest('th');
|
||||||
|
|
||||||
if (td) {
|
if (td) {
|
||||||
|
const tr = td.closest('tr');
|
||||||
|
|
||||||
const columnIndex = td.getAttribute('data-column');
|
const columnIndex = td.getAttribute('data-column');
|
||||||
const column = display?.columns?.[columnIndex];
|
const column = display?.columns?.[columnIndex];
|
||||||
if (column)
|
if (column)
|
||||||
@@ -201,6 +211,78 @@
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rowIndex = tr?.getAttribute('data-rowIndex');
|
||||||
|
if (rowIndex != null) {
|
||||||
|
const value = display.rows[rowIndex].rowData[columnIndex];
|
||||||
|
const { dataNode } = column;
|
||||||
|
|
||||||
|
if (dataNode instanceof PerspectiveTableColumnNode) {
|
||||||
|
const { table } = dataNode;
|
||||||
|
let tabComponent = null;
|
||||||
|
let icon = null;
|
||||||
|
let objectTypeField = null;
|
||||||
|
if (dataNode.isTable) {
|
||||||
|
tabComponent = 'TableDataTab';
|
||||||
|
icon = 'img table';
|
||||||
|
objectTypeField = 'tables';
|
||||||
|
}
|
||||||
|
if (dataNode.isView) {
|
||||||
|
tabComponent = 'ViewDataTab';
|
||||||
|
icon = 'img view';
|
||||||
|
objectTypeField = 'views';
|
||||||
|
}
|
||||||
|
if (tabComponent) {
|
||||||
|
res.push({
|
||||||
|
text: 'Open filtered table',
|
||||||
|
onClick: () => {
|
||||||
|
openNewTab(
|
||||||
|
{
|
||||||
|
title: table.pureName,
|
||||||
|
icon,
|
||||||
|
tabComponent,
|
||||||
|
props: {
|
||||||
|
schemaName: table.schemaName,
|
||||||
|
pureName: table.pureName,
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
objectTypeField,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
grid: {
|
||||||
|
filters: {
|
||||||
|
[dataNode.columnName]: getFilterValueExpression(value, dataNode.column.dataType),
|
||||||
|
},
|
||||||
|
isFormView: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
forceNewTab: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
res.push({
|
||||||
|
text: 'Filter this value',
|
||||||
|
onClick: () => {
|
||||||
|
setConfig(cfg => ({
|
||||||
|
...cfg,
|
||||||
|
filters: {
|
||||||
|
...cfg.filters,
|
||||||
|
[dataNode.uniqueName]: getFilterValueExpression(value, dataNode.column.dataType),
|
||||||
|
},
|
||||||
|
filterInfos: {
|
||||||
|
...cfg.filterInfos,
|
||||||
|
[dataNode.uniqueName]: dataNode.filterInfo,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.push([
|
res.push([
|
||||||
@@ -344,8 +426,8 @@
|
|||||||
</tr> -->
|
</tr> -->
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each display.rows as row}
|
{#each display.rows as row, rowIndex}
|
||||||
<tr>
|
<tr data-rowIndex={rowIndex}>
|
||||||
{#each display.columns as column}
|
{#each display.columns as column}
|
||||||
{#if !row.rowCellSkips[column.columnIndex]}
|
{#if !row.rowCellSkips[column.columnIndex]}
|
||||||
<PerspectiveCell
|
<PerspectiveCell
|
||||||
|
|||||||
Reference in New Issue
Block a user