mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 17:53:59 +00:00
mongo changeset WIP
This commit is contained in:
@@ -6,6 +6,7 @@ export interface ChangeSetItem {
|
|||||||
pureName: string;
|
pureName: string;
|
||||||
schemaName?: string;
|
schemaName?: string;
|
||||||
insertedRowIndex?: number;
|
insertedRowIndex?: number;
|
||||||
|
document?: any;
|
||||||
condition?: { [column: string]: string };
|
condition?: { [column: string]: string };
|
||||||
fields?: { [column: string]: string };
|
fields?: { [column: string]: string };
|
||||||
}
|
}
|
||||||
@@ -77,6 +78,7 @@ export function setChangeSetValue(
|
|||||||
definition: ChangeSetFieldDefinition,
|
definition: ChangeSetFieldDefinition,
|
||||||
value: string
|
value: string
|
||||||
): ChangeSet {
|
): ChangeSet {
|
||||||
|
console.log('SET', changeSet, definition, value);
|
||||||
if (!changeSet || !definition) return changeSet;
|
if (!changeSet || !definition) return changeSet;
|
||||||
let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
||||||
if (fieldName == 'deletes') {
|
if (fieldName == 'deletes') {
|
||||||
@@ -332,6 +334,7 @@ export function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjec
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectInfo): ChangeSet {
|
export function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectInfo): ChangeSet {
|
||||||
|
console.log('INSERT', name);
|
||||||
const insertedRows = getChangeSetInsertedRows(changeSet, name);
|
const insertedRows = getChangeSetInsertedRows(changeSet, name);
|
||||||
return {
|
return {
|
||||||
...changeSet,
|
...changeSet,
|
||||||
|
|||||||
@@ -39,9 +39,11 @@ export class CollectionGridDisplay extends GridDisplay {
|
|||||||
this.columns = this.getDisplayColumns(loadedRows || []);
|
this.columns = this.getDisplayColumns(loadedRows || []);
|
||||||
this.filterable = true;
|
this.filterable = true;
|
||||||
this.sortable = true;
|
this.sortable = true;
|
||||||
this.editable = false;
|
this.editable = true;
|
||||||
this.supportsReload = true;
|
this.supportsReload = true;
|
||||||
this.isDynamicStructure = true;
|
this.isDynamicStructure = true;
|
||||||
|
this.changeSetKeyFields = ['_id'];
|
||||||
|
this.baseCollection = collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDisplayColumns(rows) {
|
getDisplayColumns(rows) {
|
||||||
@@ -95,6 +97,8 @@ export class CollectionGridDisplay extends GridDisplay {
|
|||||||
isStructured: true,
|
isStructured: true,
|
||||||
parentHeaderText: createHeaderText(basePath),
|
parentHeaderText: createHeaderText(basePath),
|
||||||
filterType: 'mongo',
|
filterType: 'mongo',
|
||||||
|
pureName: this.collection.pureName,
|
||||||
|
schemaName: this.collection.schemaName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { GridConfig, GridCache, GridConfigColumns, createGridCache, GroupFunc } from './GridConfig';
|
import { GridConfig, GridCache, GridConfigColumns, createGridCache, GroupFunc } from './GridConfig';
|
||||||
import { ForeignKeyInfo, TableInfo, ColumnInfo, EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
|
import {
|
||||||
|
ForeignKeyInfo,
|
||||||
|
TableInfo,
|
||||||
|
ColumnInfo,
|
||||||
|
EngineDriver,
|
||||||
|
NamedObjectInfo,
|
||||||
|
DatabaseInfo,
|
||||||
|
CollectionInfo,
|
||||||
|
} from 'dbgate-types';
|
||||||
import { parseFilter, getFilterType } from 'dbgate-filterparser';
|
import { parseFilter, getFilterType } from 'dbgate-filterparser';
|
||||||
import { filterName } from './filterName';
|
import { filterName } from './filterName';
|
||||||
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
|
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
|
||||||
@@ -56,6 +64,10 @@ export abstract class GridDisplay {
|
|||||||
) {}
|
) {}
|
||||||
columns: DisplayColumn[];
|
columns: DisplayColumn[];
|
||||||
baseTable?: TableInfo;
|
baseTable?: TableInfo;
|
||||||
|
baseCollection?: CollectionInfo;
|
||||||
|
get baseTableOrCollection(): NamedObjectInfo {
|
||||||
|
return this.baseTable || this.baseCollection;
|
||||||
|
}
|
||||||
changeSetKeyFields: string[] = null;
|
changeSetKeyFields: string[] = null;
|
||||||
sortable = false;
|
sortable = false;
|
||||||
filterable = false;
|
filterable = false;
|
||||||
@@ -391,8 +403,12 @@ export abstract class GridDisplay {
|
|||||||
getChangeSetField(row, uniqueName, insertedRowIndex): ChangeSetFieldDefinition {
|
getChangeSetField(row, uniqueName, insertedRowIndex): ChangeSetFieldDefinition {
|
||||||
const col = this.columns.find(x => x.uniqueName == uniqueName);
|
const col = this.columns.find(x => x.uniqueName == uniqueName);
|
||||||
if (!col) return null;
|
if (!col) return null;
|
||||||
if (!this.baseTable) return null;
|
const baseTableOrCollection = this.baseTableOrCollection;
|
||||||
if (this.baseTable.pureName != col.pureName || this.baseTable.schemaName != col.schemaName) return null;
|
if (!baseTableOrCollection) return null;
|
||||||
|
if (baseTableOrCollection.pureName != col.pureName || baseTableOrCollection.schemaName != col.schemaName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...this.getChangeSetRow(row, insertedRowIndex),
|
...this.getChangeSetRow(row, insertedRowIndex),
|
||||||
uniqueName: uniqueName,
|
uniqueName: uniqueName,
|
||||||
@@ -401,10 +417,11 @@ export abstract class GridDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getChangeSetRow(row, insertedRowIndex): ChangeSetRowDefinition {
|
getChangeSetRow(row, insertedRowIndex): ChangeSetRowDefinition {
|
||||||
if (!this.baseTable) return null;
|
const baseTableOrCollection = this.baseTableOrCollection;
|
||||||
|
if (!baseTableOrCollection) return null;
|
||||||
return {
|
return {
|
||||||
pureName: this.baseTable.pureName,
|
pureName: baseTableOrCollection.pureName,
|
||||||
schemaName: this.baseTable.schemaName,
|
schemaName: baseTableOrCollection.schemaName,
|
||||||
insertedRowIndex,
|
insertedRowIndex,
|
||||||
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
|
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.changeSet = changeSetState && changeSetState.value;
|
this.changeSet = changeSetState && changeSetState.value;
|
||||||
this.insertedRows = getChangeSetInsertedRows(this.changeSet, display?.baseTable);
|
this.insertedRows = getChangeSetInsertedRows(this.changeSet, display?.baseTableOrCollection);
|
||||||
this.setChangeSet = value => dispatchChangeSet({ type: 'set', value });
|
this.setChangeSet = value => dispatchChangeSet({ type: 'set', value });
|
||||||
this.rowCacheIndexes = new Set();
|
this.rowCacheIndexes = new Set();
|
||||||
this.rowDataCache = {};
|
this.rowDataCache = {};
|
||||||
@@ -47,6 +47,8 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
this.rowDefinitionsCache = {};
|
this.rowDefinitionsCache = {};
|
||||||
this.batchChangeSet = null;
|
this.batchChangeSet = null;
|
||||||
this.compiledMacroFunc = compileMacroFunction(macro, this._errors);
|
this.compiledMacroFunc = compileMacroFunction(macro, this._errors);
|
||||||
|
|
||||||
|
console.log('changeSet', this.changeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
get errors() {
|
get errors() {
|
||||||
@@ -110,7 +112,7 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get canInsert() {
|
get canInsert() {
|
||||||
return !!this.display.baseTable;
|
return !!this.display.baseTableOrCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
getRowData(index: number) {
|
getRowData(index: number) {
|
||||||
@@ -157,7 +159,7 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
|
|
||||||
insertRow(): number {
|
insertRow(): number {
|
||||||
const res = this.rowCountInUpdate;
|
const res = this.rowCountInUpdate;
|
||||||
this.applyModification(chs => changeSetInsertNewRow(chs, this.display.baseTable));
|
this.applyModification(chs => changeSetInsertNewRow(chs, this.display.baseTableOrCollection));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,9 +98,10 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
.toolbar {
|
.toolbar {
|
||||||
background: var(--theme-bg-3);
|
background: var(--theme-bg-1);
|
||||||
display: flex;
|
display: flex;
|
||||||
border-bottom: 1px solid var(--theme-border);
|
border-bottom: 1px solid var(--theme-border);
|
||||||
|
border-top: 2px solid var(--theme-border);
|
||||||
margin-bottom: 3px;
|
margin-bottom: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user