mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 11:03:57 +00:00
view data improvements
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
DatabaseInfo,
|
||||
CollectionInfo,
|
||||
SqlDialect,
|
||||
ViewInfo,
|
||||
} from 'dbgate-types';
|
||||
import { parseFilter, getFilterType } from 'dbgate-filterparser';
|
||||
import { filterName } from 'dbgate-tools';
|
||||
@@ -69,10 +70,17 @@ export abstract class GridDisplay {
|
||||
dialect: SqlDialect;
|
||||
columns: DisplayColumn[];
|
||||
baseTable?: TableInfo;
|
||||
baseView?: ViewInfo;
|
||||
baseCollection?: CollectionInfo;
|
||||
get baseTableOrSimilar(): NamedObjectInfo {
|
||||
return this.baseTable || this.baseCollection || this.baseView;
|
||||
}
|
||||
get baseTableOrCollection(): NamedObjectInfo {
|
||||
return this.baseTable || this.baseCollection;
|
||||
}
|
||||
get baseTableOrView(): TableInfo | ViewInfo {
|
||||
return this.baseTable || this.baseView;
|
||||
}
|
||||
changeSetKeyFields: string[] = null;
|
||||
sortable = false;
|
||||
groupable = false;
|
||||
@@ -373,7 +381,7 @@ export abstract class GridDisplay {
|
||||
getGrouping(uniqueName): GroupFunc {
|
||||
if (this.isGrouped) {
|
||||
if (this.config.grouping[uniqueName]) return this.config.grouping[uniqueName];
|
||||
const column = this.baseTable.columns.find(x => x.columnName == uniqueName);
|
||||
const column = (this.baseTable || this.baseView)?.columns?.find(x => x.columnName == uniqueName);
|
||||
if (isTypeLogical(column?.dataType)) return 'COUNT DISTINCT';
|
||||
if (column?.autoIncrement) return 'COUNT';
|
||||
return 'MAX';
|
||||
@@ -413,9 +421,9 @@ export abstract class GridDisplay {
|
||||
getChangeSetField(row, uniqueName, insertedRowIndex): ChangeSetFieldDefinition {
|
||||
const col = this.columns.find(x => x.uniqueName == uniqueName);
|
||||
if (!col) return null;
|
||||
const baseTableOrCollection = this.baseTableOrCollection;
|
||||
if (!baseTableOrCollection) return null;
|
||||
if (baseTableOrCollection.pureName != col.pureName || baseTableOrCollection.schemaName != col.schemaName) {
|
||||
const baseObj = this.baseTableOrSimilar;
|
||||
if (!baseObj) return null;
|
||||
if (baseObj.pureName != col.pureName || baseObj.schemaName != col.schemaName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -427,11 +435,11 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
getChangeSetRow(row, insertedRowIndex): ChangeSetRowDefinition {
|
||||
const baseTableOrCollection = this.baseTableOrCollection;
|
||||
if (!baseTableOrCollection) return null;
|
||||
const baseObj = this.baseTableOrSimilar;
|
||||
if (!baseObj) return null;
|
||||
return {
|
||||
pureName: baseTableOrCollection.pureName,
|
||||
schemaName: baseTableOrCollection.schemaName,
|
||||
pureName: baseObj.pureName,
|
||||
schemaName: baseObj.schemaName,
|
||||
insertedRowIndex,
|
||||
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ export class ViewGridDisplay extends GridDisplay {
|
||||
this.groupable = true;
|
||||
this.editable = false;
|
||||
this.supportsReload = true;
|
||||
this.baseView = view;
|
||||
}
|
||||
|
||||
getDisplayColumns(view: ViewInfo) {
|
||||
|
||||
@@ -52,7 +52,7 @@ export default class ChangeSetGrider extends Grider {
|
||||
) {
|
||||
super();
|
||||
this.changeSet = changeSetState && changeSetState.value;
|
||||
this.insertedRows = getChangeSetInsertedRows(this.changeSet, display?.baseTableOrCollection);
|
||||
this.insertedRows = getChangeSetInsertedRows(this.changeSet, display?.baseTableOrSimilar);
|
||||
this.setChangeSet = value => dispatchChangeSet({ type: 'set', value });
|
||||
this.rowCacheIndexes = new Set();
|
||||
this.rowDataCache = {};
|
||||
@@ -169,7 +169,7 @@ export default class ChangeSetGrider extends Grider {
|
||||
|
||||
get rowCountInUpdate() {
|
||||
if (this.batchChangeSet) {
|
||||
const newRows = getChangeSetInsertedRows(this.batchChangeSet, this.display.baseTable);
|
||||
const newRows = getChangeSetInsertedRows(this.batchChangeSet, this.display.baseTableOrSimilar);
|
||||
return this.sourceRows.length + newRows.length;
|
||||
} else {
|
||||
return this.rowCount;
|
||||
@@ -178,13 +178,13 @@ export default class ChangeSetGrider extends Grider {
|
||||
|
||||
insertRow(): number {
|
||||
const res = this.rowCountInUpdate;
|
||||
this.applyModification(chs => changeSetInsertNewRow(chs, this.display.baseTableOrCollection));
|
||||
this.applyModification(chs => changeSetInsertNewRow(chs, this.display.baseTableOrSimilar));
|
||||
return res;
|
||||
}
|
||||
|
||||
insertDocuments(documents: any[]): number {
|
||||
const res = this.rowCountInUpdate;
|
||||
this.applyModification(chs => changeSetInsertDocuments(chs, documents, this.display.baseTableOrCollection));
|
||||
this.applyModification(chs => changeSetInsertDocuments(chs, documents, this.display.baseTableOrSimilar));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -758,15 +758,18 @@
|
||||
|
||||
// $: console.log('DISPLAY.config', display.config);
|
||||
$: {
|
||||
if (display?.groupColumns && display?.baseTable) {
|
||||
if (display?.groupColumns && display?.baseTableOrSimilar && onReferenceClick) {
|
||||
onReferenceClick({
|
||||
referenceId: stableStringify(display && display.groupColumns),
|
||||
schemaName: display.baseTable.schemaName,
|
||||
pureName: display.baseTable.pureName,
|
||||
schemaName: display.baseTableOrSimilar?.schemaName,
|
||||
pureName: display.baseTableOrSimilar?.pureName,
|
||||
columns: display.groupColumns.map(col => ({
|
||||
baseName: col,
|
||||
refName: col,
|
||||
dataType: _.get(display.baseTable && display.baseTable.columns.find(x => x.columnName == col), 'dataType'),
|
||||
dataType: _.get(
|
||||
display.baseTableOrView?.columns?.find(x => x.columnName == col),
|
||||
'dataType'
|
||||
),
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@
|
||||
|
||||
return parseInt(response.data.rows[0].count);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -128,7 +127,7 @@
|
||||
initialValues.sourceConnectionId = conid;
|
||||
initialValues.sourceDatabaseName = database;
|
||||
initialValues.sourceSql = display.getExportQuery();
|
||||
initialValues.sourceList = display.baseTable ? [display.baseTable.pureName] : [];
|
||||
initialValues.sourceList = display.baseTableOrSimilar ? [display.baseTableOrSimilar.pureName] : [];
|
||||
showModal(ImportExportModal, { initialValues });
|
||||
}
|
||||
|
||||
@@ -139,8 +138,8 @@
|
||||
icon: 'img sql-file',
|
||||
tabComponent: 'QueryTab',
|
||||
props: {
|
||||
schemaName: display.baseTable.schemaName,
|
||||
pureName: display.baseTable.pureName,
|
||||
schemaName: display.baseTableOrSimilar?.schemaName,
|
||||
pureName: display.baseTableOrSimilar?.pureName,
|
||||
conid,
|
||||
database,
|
||||
},
|
||||
@@ -198,7 +197,6 @@
|
||||
},
|
||||
{ command: 'sqlDataGrid.export', tag: 'export' }
|
||||
);
|
||||
|
||||
</script>
|
||||
|
||||
<LoadingDataGridCore
|
||||
|
||||
Reference in New Issue
Block a user