mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
multi column condition in perspectives
This commit is contained in:
parent
7c03d31b84
commit
a2043b237f
@ -80,6 +80,8 @@ export interface PerspectiveNodeConfig {
|
|||||||
isAutoGenerated?: true | undefined;
|
isAutoGenerated?: true | undefined;
|
||||||
isNodeChecked?: boolean;
|
isNodeChecked?: boolean;
|
||||||
|
|
||||||
|
multiColumnFilter?: string;
|
||||||
|
|
||||||
position?: {
|
position?: {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
@ -35,7 +35,7 @@ import { PerspectiveDataLoadProps, PerspectiveDataProvider } from './Perspective
|
|||||||
import stableStringify from 'json-stable-stringify';
|
import stableStringify from 'json-stable-stringify';
|
||||||
import { getFilterType, parseFilter } from 'dbgate-filterparser';
|
import { getFilterType, parseFilter } from 'dbgate-filterparser';
|
||||||
import { FilterType } from 'dbgate-filterparser/lib/types';
|
import { FilterType } from 'dbgate-filterparser/lib/types';
|
||||||
import { Condition, Expression, Select } from 'dbgate-sqltree';
|
import { CompoudCondition, Condition, Expression, Select } from 'dbgate-sqltree';
|
||||||
// import { getPerspectiveDefaultColumns } from './getPerspectiveDefaultColumns';
|
// import { getPerspectiveDefaultColumns } from './getPerspectiveDefaultColumns';
|
||||||
import uuidv1 from 'uuid/v1';
|
import uuidv1 from 'uuid/v1';
|
||||||
import { PerspectiveDataPatternColumn } from './PerspectiveDataPattern';
|
import { PerspectiveDataPatternColumn } from './PerspectiveDataPattern';
|
||||||
@ -341,10 +341,66 @@ export abstract class PerspectiveTreeNode {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMutliColumnSqlCondition(source): Condition {
|
||||||
|
if (!this.nodeConfig?.multiColumnFilter) return null;
|
||||||
|
const base = this.getBaseTableFromThis() as TableInfo | ViewInfo;
|
||||||
|
if (!base) return null;
|
||||||
|
try {
|
||||||
|
const condition = parseFilter(this.nodeConfig?.multiColumnFilter, 'string');
|
||||||
|
if (condition) {
|
||||||
|
const orCondition: CompoudCondition = {
|
||||||
|
conditionType: 'or',
|
||||||
|
conditions: [],
|
||||||
|
};
|
||||||
|
for (const column of base.columns || []) {
|
||||||
|
orCondition.conditions.push(
|
||||||
|
_cloneDeepWith(condition, (expr: Expression) => {
|
||||||
|
if (expr.exprType == 'placeholder') {
|
||||||
|
return {
|
||||||
|
exprType: 'column',
|
||||||
|
alias: source,
|
||||||
|
columnName: column.columnName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (orCondition.conditions.length > 0) {
|
||||||
|
return orCondition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(err.message);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getMutliColumnMongoCondition(): {} {
|
||||||
|
if (!this.nodeConfig?.multiColumnFilter) return null;
|
||||||
|
const pattern = this.dataProvider?.dataPatterns?.[this.designerId];
|
||||||
|
if (!pattern) return null;
|
||||||
|
|
||||||
|
const condition = parseFilter(this.nodeConfig?.multiColumnFilter, 'mongo');
|
||||||
|
if (!condition) return null;
|
||||||
|
const res = pattern.columns.map(col => {
|
||||||
|
return _cloneDeepWith(condition, expr => {
|
||||||
|
if (expr.__placeholder__) {
|
||||||
|
return {
|
||||||
|
[col.name]: expr.__placeholder__,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
$or: res,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
getChildrenSqlCondition(source = null): Condition {
|
getChildrenSqlCondition(source = null): Condition {
|
||||||
const conditions = _compact([
|
const conditions = _compact([
|
||||||
...this.childNodes.map(x => x.parseFilterCondition(source)),
|
...this.childNodes.map(x => x.parseFilterCondition(source)),
|
||||||
...this.buildParentFilterConditions(),
|
...this.buildParentFilterConditions(),
|
||||||
|
this.getMutliColumnSqlCondition(source),
|
||||||
]);
|
]);
|
||||||
if (conditions.length == 0) {
|
if (conditions.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
@ -359,7 +415,10 @@ export abstract class PerspectiveTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getChildrenMongoCondition(source = null): {} {
|
getChildrenMongoCondition(source = null): {} {
|
||||||
const conditions = _compact([...this.childNodes.map(x => x.parseFilterCondition(source))]);
|
const conditions = _compact([
|
||||||
|
...this.childNodes.map(x => x.parseFilterCondition(source)),
|
||||||
|
this.getMutliColumnMongoCondition(),
|
||||||
|
]);
|
||||||
if (conditions.length == 0) {
|
if (conditions.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -402,7 +461,7 @@ export abstract class PerspectiveTreeNode {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
getBaseTableFromThis() {
|
getBaseTableFromThis(): TableInfo | ViewInfo | CollectionInfo {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@
|
|||||||
export let columnName = null;
|
export let columnName = null;
|
||||||
export let uniqueName = null;
|
export let uniqueName = null;
|
||||||
|
|
||||||
|
export let placeholder = 'Filter';
|
||||||
|
|
||||||
let value;
|
let value;
|
||||||
let isError;
|
let isError;
|
||||||
let isOk;
|
let isOk;
|
||||||
@ -318,7 +320,7 @@
|
|||||||
on:paste={handlePaste}
|
on:paste={handlePaste}
|
||||||
class:isError
|
class:isError
|
||||||
class:isOk
|
class:isOk
|
||||||
placeholder="Filter"
|
{placeholder}
|
||||||
/>
|
/>
|
||||||
{#if customCommandIcon && onCustomCommand}
|
{#if customCommandIcon && onCustomCommand}
|
||||||
<InlineButton on:click={onCustomCommand} title={customCommandTooltip} narrow square>
|
<InlineButton on:click={onCustomCommand} title={customCommandTooltip} narrow square>
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import { tick } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
import { createDatabaseObjectMenu } from '../appobj/DatabaseObjectAppObject.svelte';
|
import { createDatabaseObjectMenu } from '../appobj/DatabaseObjectAppObject.svelte';
|
||||||
|
import DataFilterControl from '../datagrid/DataFilterControl.svelte';
|
||||||
import CheckboxField from '../forms/CheckboxField.svelte';
|
import CheckboxField from '../forms/CheckboxField.svelte';
|
||||||
|
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
@ -300,6 +301,15 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{#if settings?.getMutliColumnFilter && settings?.setMutliColumnFilter}
|
||||||
|
<DataFilterControl
|
||||||
|
filterType="string"
|
||||||
|
filter={settings?.getMutliColumnFilter(designerId)}
|
||||||
|
setFilter={value => settings?.setMutliColumnFilter(designerId, value)}
|
||||||
|
placeholder="Data filter"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="columns" on:scroll={() => tick().then(onMoveReferences)} class:scroll={settings?.allowScrollColumns}>
|
<div class="columns" on:scroll={() => tick().then(onMoveReferences)} class:scroll={settings?.allowScrollColumns}>
|
||||||
{#each flatColumns || [] as column (column.columnName)}
|
{#each flatColumns || [] as column (column.columnName)}
|
||||||
<ColumnLine
|
<ColumnLine
|
||||||
|
@ -334,6 +334,20 @@
|
|||||||
toggleExpandedColumn: (column, value) => column.toggleExpanded(value),
|
toggleExpandedColumn: (column, value) => column.toggleExpanded(value),
|
||||||
getColumnDisplayName: column => column.shortName || column.columnName,
|
getColumnDisplayName: column => column.shortName || column.columnName,
|
||||||
getParentColumnName: getPerspectiveParentColumnName,
|
getParentColumnName: getPerspectiveParentColumnName,
|
||||||
|
getMutliColumnFilter: designerId => config.nodes.find(x => x.designerId == designerId).multiColumnFilter,
|
||||||
|
setMutliColumnFilter: (designerId, multiColumnFilter) => {
|
||||||
|
setConfig(cfg => ({
|
||||||
|
...cfg,
|
||||||
|
nodes: cfg.nodes.map(node =>
|
||||||
|
node.designerId == designerId
|
||||||
|
? {
|
||||||
|
...node,
|
||||||
|
multiColumnFilter,
|
||||||
|
}
|
||||||
|
: node
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
referenceComponent={QueryDesignerReference}
|
referenceComponent={QueryDesignerReference}
|
||||||
value={createDesignerModel(config, dbInfos, dataPatterns)}
|
value={createDesignerModel(config, dbInfos, dataPatterns)}
|
||||||
|
Loading…
Reference in New Issue
Block a user