mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 14:06:00 +00:00
perspective sorting
This commit is contained in:
@@ -6,6 +6,10 @@ export interface PerspectiveConfigColumns {
|
||||
|
||||
export interface PerspectiveConfig extends PerspectiveConfigColumns {
|
||||
filters: { [uniqueName: string]: string };
|
||||
sort: {
|
||||
uniqueName: string;
|
||||
order: 'ASC' | 'DESC';
|
||||
}[];
|
||||
}
|
||||
|
||||
export function createPerspectiveConfig(): PerspectiveConfig {
|
||||
@@ -14,6 +18,7 @@ export function createPerspectiveConfig(): PerspectiveConfig {
|
||||
checkedColumns: [],
|
||||
uncheckedColumns: [],
|
||||
filters: {},
|
||||
sort: [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -109,10 +109,10 @@ export class PerspectiveDataLoader {
|
||||
},
|
||||
})),
|
||||
selectAll: !dataColumns,
|
||||
orderBy: orderBy?.map(columnName => ({
|
||||
orderBy: orderBy?.map(({ columnName, order }) => ({
|
||||
exprType: 'column',
|
||||
columnName,
|
||||
direction: 'ASC',
|
||||
direction: order,
|
||||
source: {
|
||||
name: { schemaName, pureName },
|
||||
},
|
||||
|
||||
@@ -16,7 +16,10 @@ export interface PerspectiveDataLoadProps {
|
||||
schemaName: string;
|
||||
pureName: string;
|
||||
dataColumns: string[];
|
||||
orderBy: string[];
|
||||
orderBy: {
|
||||
columnName: string;
|
||||
order: 'ASC' | 'DESC';
|
||||
}[];
|
||||
bindingColumns?: string[];
|
||||
bindingValues?: any[][];
|
||||
range?: RangeDefinition;
|
||||
|
||||
@@ -95,6 +95,9 @@ export abstract class PerspectiveTreeNode {
|
||||
get filterType(): FilterType {
|
||||
return 'string';
|
||||
}
|
||||
get columnName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
getChildMatchColumns() {
|
||||
return [];
|
||||
@@ -181,6 +184,25 @@ export abstract class PerspectiveTreeNode {
|
||||
conditions,
|
||||
};
|
||||
}
|
||||
|
||||
getOrderBy(table: TableInfo): PerspectiveDataLoadProps['orderBy'] {
|
||||
const res = _compact(
|
||||
this.childNodes.map(node => {
|
||||
const sort = this.config?.sort?.find(x => x.uniqueName == node.uniqueName);
|
||||
if (sort) {
|
||||
return {
|
||||
columnName: node.columnName,
|
||||
order: sort.order,
|
||||
};
|
||||
}
|
||||
})
|
||||
);
|
||||
return res.length > 0
|
||||
? res
|
||||
: table?.primaryKey?.columns.map(x => ({ columnName: x.columnName, order: 'ASC' })) || [
|
||||
{ columnName: table?.columns[0].columnName, order: 'ASC' },
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
||||
@@ -237,7 +259,7 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
||||
),
|
||||
dataColumns: this.getDataLoadColumns(),
|
||||
databaseConfig: this.databaseConfig,
|
||||
orderBy: this.refTable?.primaryKey?.columns.map(x => x.columnName) || [this.refTable.columns[0].columnName],
|
||||
orderBy: this.getOrderBy(this.refTable),
|
||||
condition: this.getChildrenCondition(),
|
||||
};
|
||||
}
|
||||
@@ -252,6 +274,10 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
|
||||
return this.column.columnName;
|
||||
}
|
||||
|
||||
get columnName() {
|
||||
return this.column.columnName;
|
||||
}
|
||||
|
||||
get fieldName() {
|
||||
return this.codeName + 'Ref';
|
||||
}
|
||||
@@ -322,7 +348,7 @@ export class PerspectiveTableNode extends PerspectiveTreeNode {
|
||||
pureName: this.table.pureName,
|
||||
dataColumns: this.getDataLoadColumns(),
|
||||
databaseConfig: this.databaseConfig,
|
||||
orderBy: this.table.primaryKey?.columns.map(x => x.columnName) || [this.table.columns[0].columnName],
|
||||
orderBy: this.getOrderBy(this.table),
|
||||
condition: this.getChildrenCondition(),
|
||||
};
|
||||
}
|
||||
@@ -397,7 +423,7 @@ export class PerspectiveTableReferenceNode extends PerspectiveTableNode {
|
||||
),
|
||||
dataColumns: this.getDataLoadColumns(),
|
||||
databaseConfig: this.databaseConfig,
|
||||
orderBy: this.table.primaryKey?.columns.map(x => x.columnName) || [this.table.columns[0].columnName],
|
||||
orderBy: this.getOrderBy(this.table),
|
||||
condition: this.getChildrenCondition(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user