mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
filters
This commit is contained in:
parent
ed11b9e5a1
commit
290acdb68a
@ -9,7 +9,9 @@ import {
|
||||
referenceIsConnecting,
|
||||
mergeSelectsFromDesigner,
|
||||
findQuerySource,
|
||||
findDesignerFilterType,
|
||||
} from './designerTools';
|
||||
import { parseFilter } from 'dbgate-filterparser';
|
||||
|
||||
export class DesignerQueryDumper {
|
||||
constructor(public designer: DesignerInfo, public components: DesignerComponent[]) {}
|
||||
@ -61,11 +63,35 @@ export class DesignerQueryDumper {
|
||||
});
|
||||
}
|
||||
}
|
||||
this.addConditions(select, component.tables);
|
||||
}
|
||||
|
||||
return select;
|
||||
}
|
||||
|
||||
addConditions(select: Select, tables: DesignerTableInfo[]) {
|
||||
for (const column of this.designer.columns) {
|
||||
if (!column.filter) continue;
|
||||
const table = this.designer.tables.find((x) => x.designerId == column.designerId);
|
||||
if (!tables.find((x) => x.designerId == table.designerId)) continue;
|
||||
|
||||
const condition = parseFilter(column.filter, findDesignerFilterType(column, this.designer));
|
||||
if (condition) {
|
||||
select.where = mergeConditions(
|
||||
select.where,
|
||||
_.cloneDeepWith(condition, (expr) => {
|
||||
if (expr.exprType == 'placeholder')
|
||||
return {
|
||||
exprType: 'column',
|
||||
columnName: column.columnName,
|
||||
source: findQuerySource(this.designer, column.designerId),
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run() {
|
||||
let res: Select = null;
|
||||
for (const component of this.components) {
|
||||
@ -148,6 +174,8 @@ export class DesignerQueryDumper {
|
||||
}));
|
||||
}
|
||||
|
||||
this.addConditions(res, topLevelTables);
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import React from 'react';
|
||||
import DataFilterControl from '../datagrid/DataFilterControl';
|
||||
import { CheckboxField, SelectField, TextField } from '../utility/inputs';
|
||||
import TableControl, { TableColumn } from '../utility/TableControl';
|
||||
import { findDesignerFilterType } from './designerTools';
|
||||
|
||||
function getTableDisplayName(column, tables) {
|
||||
const table = tables.find((x) => x.designerId == column.designerId);
|
||||
@ -115,7 +116,7 @@ export default function QueryDesignColumns({ value, onChange }) {
|
||||
header="Filter"
|
||||
formatter={(row) => (
|
||||
<DataFilterControl
|
||||
filterType="string"
|
||||
filterType={findDesignerFilterType(row, value)}
|
||||
filter={row.filter}
|
||||
setFilter={(filter) => {
|
||||
changeColumn({ ...row, filter });
|
||||
|
@ -4,6 +4,7 @@ import { EngineDriver } from 'dbgate-types';
|
||||
import { DesignerInfo, DesignerTableInfo, DesignerReferenceInfo, DesignerJoinType } from './types';
|
||||
import { DesignerComponentCreator } from './DesignerComponentCreator';
|
||||
import { DesignerQueryDumper } from './DesignerQueryDumper';
|
||||
import { getFilterType } from 'dbgate-filterparser';
|
||||
|
||||
export function referenceIsConnecting(
|
||||
reference: DesignerReferenceInfo,
|
||||
@ -129,3 +130,15 @@ export function isConnectedByReference(
|
||||
const array2 = arrays.find((a) => a.find((x) => x.designerId == table2.designerId));
|
||||
return array1 == array2;
|
||||
}
|
||||
|
||||
export function findDesignerFilterType({ designerId, columnName }, designer) {
|
||||
const table = (designer.tables || []).find((x) => x.designerId == designerId);
|
||||
if (table) {
|
||||
const column = (table.columns || []).find((x) => x.columnName == columnName);
|
||||
if (column) {
|
||||
const { dataType } = column;
|
||||
return getFilterType(dataType);
|
||||
}
|
||||
}
|
||||
return 'string';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user