mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 21:25:59 +00:00
editing changeset on archive file
This commit is contained in:
@@ -15,6 +15,7 @@ export interface ChangeSetItem {
|
|||||||
pureName: string;
|
pureName: string;
|
||||||
schemaName?: string;
|
schemaName?: string;
|
||||||
insertedRowIndex?: number;
|
insertedRowIndex?: number;
|
||||||
|
existingRowIndex?: number;
|
||||||
document?: any;
|
document?: any;
|
||||||
condition?: { [column: string]: string };
|
condition?: { [column: string]: string };
|
||||||
fields?: { [column: string]: string };
|
fields?: { [column: string]: string };
|
||||||
@@ -38,6 +39,7 @@ export interface ChangeSetRowDefinition {
|
|||||||
pureName: string;
|
pureName: string;
|
||||||
schemaName: string;
|
schemaName: string;
|
||||||
insertedRowIndex?: number;
|
insertedRowIndex?: number;
|
||||||
|
existingRowIndex?: number;
|
||||||
condition?: { [column: string]: string };
|
condition?: { [column: string]: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +68,8 @@ export function findExistingChangeSetItem(
|
|||||||
x =>
|
x =>
|
||||||
x.pureName == definition.pureName &&
|
x.pureName == definition.pureName &&
|
||||||
x.schemaName == definition.schemaName &&
|
x.schemaName == definition.schemaName &&
|
||||||
_.isEqual(x.condition, definition.condition)
|
((definition.existingRowIndex != null && x.existingRowIndex == definition.existingRowIndex) ||
|
||||||
|
(definition.existingRowIndex == null && _.isEqual(x.condition, definition.condition)))
|
||||||
);
|
);
|
||||||
if (inUpdates) return ['updates', inUpdates];
|
if (inUpdates) return ['updates', inUpdates];
|
||||||
|
|
||||||
@@ -74,7 +77,8 @@ export function findExistingChangeSetItem(
|
|||||||
x =>
|
x =>
|
||||||
x.pureName == definition.pureName &&
|
x.pureName == definition.pureName &&
|
||||||
x.schemaName == definition.schemaName &&
|
x.schemaName == definition.schemaName &&
|
||||||
_.isEqual(x.condition, definition.condition)
|
((definition.existingRowIndex != null && x.existingRowIndex == definition.existingRowIndex) ||
|
||||||
|
(definition.existingRowIndex == null && _.isEqual(x.condition, definition.condition)))
|
||||||
);
|
);
|
||||||
if (inDeletes) return ['deletes', inDeletes];
|
if (inDeletes) return ['deletes', inDeletes];
|
||||||
|
|
||||||
@@ -119,6 +123,7 @@ export function setChangeSetValue(
|
|||||||
schemaName: definition.schemaName,
|
schemaName: definition.schemaName,
|
||||||
condition: definition.condition,
|
condition: definition.condition,
|
||||||
insertedRowIndex: definition.insertedRowIndex,
|
insertedRowIndex: definition.insertedRowIndex,
|
||||||
|
existingRowIndex: definition.existingRowIndex,
|
||||||
fields: {
|
fields: {
|
||||||
[definition.uniqueName]: value,
|
[definition.uniqueName]: value,
|
||||||
},
|
},
|
||||||
@@ -162,6 +167,7 @@ export function setChangeSetRowData(
|
|||||||
schemaName: definition.schemaName,
|
schemaName: definition.schemaName,
|
||||||
condition: definition.condition,
|
condition: definition.condition,
|
||||||
insertedRowIndex: definition.insertedRowIndex,
|
insertedRowIndex: definition.insertedRowIndex,
|
||||||
|
existingRowIndex: definition.existingRowIndex,
|
||||||
document,
|
document,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -395,6 +401,7 @@ export function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetR
|
|||||||
pureName: definition.pureName,
|
pureName: definition.pureName,
|
||||||
schemaName: definition.schemaName,
|
schemaName: definition.schemaName,
|
||||||
condition: definition.condition,
|
condition: definition.condition,
|
||||||
|
existingRowIndex: definition.existingRowIndex,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -402,9 +409,11 @@ export function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetR
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjectInfo) {
|
export function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjectInfo) {
|
||||||
if (!name) return [];
|
// if (!name) return [];
|
||||||
if (!changeSet) return [];
|
if (!changeSet) return [];
|
||||||
const rows = changeSet.inserts.filter(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
|
const rows = changeSet.inserts.filter(
|
||||||
|
x => name == null || (x.pureName == name.pureName && x.schemaName == name.schemaName)
|
||||||
|
);
|
||||||
const maxIndex = _.maxBy(rows, x => x.insertedRowIndex)?.insertedRowIndex;
|
const maxIndex = _.maxBy(rows, x => x.insertedRowIndex)?.insertedRowIndex;
|
||||||
if (maxIndex == null) return [];
|
if (maxIndex == null) return [];
|
||||||
const res = Array(maxIndex + 1).fill({});
|
const res = Array(maxIndex + 1).fill({});
|
||||||
|
|||||||
@@ -460,30 +460,39 @@ export abstract class GridDisplay {
|
|||||||
return _.pick(row, this.changeSetKeyFields);
|
return _.pick(row, this.changeSetKeyFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
getChangeSetField(row, uniqueName, insertedRowIndex): ChangeSetFieldDefinition {
|
getChangeSetField(
|
||||||
|
row,
|
||||||
|
uniqueName,
|
||||||
|
insertedRowIndex,
|
||||||
|
existingRowIndex = null,
|
||||||
|
baseNameOmitable = false
|
||||||
|
): 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;
|
||||||
const baseObj = this.baseTableOrSimilar;
|
const baseObj = this.baseTableOrSimilar;
|
||||||
if (!baseObj) return null;
|
if (!baseNameOmitable) {
|
||||||
if (baseObj.pureName != col.pureName || baseObj.schemaName != col.schemaName) {
|
if (!baseObj) return null;
|
||||||
return null;
|
if (baseObj.pureName != col.pureName || baseObj.schemaName != col.schemaName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...this.getChangeSetRow(row, insertedRowIndex),
|
...this.getChangeSetRow(row, insertedRowIndex, existingRowIndex, baseNameOmitable),
|
||||||
uniqueName: uniqueName,
|
uniqueName: uniqueName,
|
||||||
columnName: col.columnName,
|
columnName: col.columnName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getChangeSetRow(row, insertedRowIndex): ChangeSetRowDefinition {
|
getChangeSetRow(row, insertedRowIndex, existingRowIndex, baseNameOmitable = false): ChangeSetRowDefinition {
|
||||||
const baseObj = this.baseTableOrSimilar;
|
const baseObj = this.baseTableOrSimilar;
|
||||||
if (!baseObj) return null;
|
if (!baseNameOmitable && !baseObj) return null;
|
||||||
return {
|
return {
|
||||||
pureName: baseObj.pureName,
|
pureName: baseObj?.pureName,
|
||||||
schemaName: baseObj.schemaName,
|
schemaName: baseObj?.schemaName,
|
||||||
insertedRowIndex,
|
insertedRowIndex,
|
||||||
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
|
existingRowIndex,
|
||||||
|
condition: insertedRowIndex == null && existingRowIndex == null ? this.getChangeSetCondition(row) : null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ export class JslGridDisplay extends GridDisplay {
|
|||||||
setCache: ChangeCacheFunc,
|
setCache: ChangeCacheFunc,
|
||||||
rows: any,
|
rows: any,
|
||||||
isDynamicStructure: boolean,
|
isDynamicStructure: boolean,
|
||||||
supportsReload: boolean
|
supportsReload: boolean,
|
||||||
|
editable: boolean = false
|
||||||
) {
|
) {
|
||||||
super(config, setConfig, cache, setCache, null);
|
super(config, setConfig, cache, setCache, null);
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ export class JslGridDisplay extends GridDisplay {
|
|||||||
this.supportsReload = supportsReload;
|
this.supportsReload = supportsReload;
|
||||||
this.isDynamicStructure = isDynamicStructure;
|
this.isDynamicStructure = isDynamicStructure;
|
||||||
this.filterTypeOverride = 'eval';
|
this.filterTypeOverride = 'eval';
|
||||||
|
this.editable = editable;
|
||||||
|
|
||||||
if (structure?.columns) {
|
if (structure?.columns) {
|
||||||
this.columns = _.uniqBy(
|
this.columns = _.uniqBy(
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
public display: GridDisplay,
|
public display: GridDisplay,
|
||||||
public macro: MacroDefinition = null,
|
public macro: MacroDefinition = null,
|
||||||
public macroArgs: {} = {},
|
public macroArgs: {} = {},
|
||||||
public selectedCells: MacroSelectedCell[] = []
|
public selectedCells: MacroSelectedCell[] = [],
|
||||||
|
public useRowIndexInsteaOfCondition: boolean = false
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.changeSet = changeSetState && changeSetState.value;
|
this.changeSet = changeSetState && changeSetState.value;
|
||||||
@@ -81,7 +82,12 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
if (this.rowCacheIndexes.has(index)) return;
|
if (this.rowCacheIndexes.has(index)) return;
|
||||||
const row = this.getRowSource(index);
|
const row = this.getRowSource(index);
|
||||||
const insertedRowIndex = this.getInsertedRowIndex(index);
|
const insertedRowIndex = this.getInsertedRowIndex(index);
|
||||||
const rowDefinition = this.display?.getChangeSetRow(row, insertedRowIndex);
|
const rowDefinition = this.display?.getChangeSetRow(
|
||||||
|
row,
|
||||||
|
insertedRowIndex,
|
||||||
|
this.useRowIndexInsteaOfCondition && index < this.sourceRows.length ? index : null,
|
||||||
|
this.useRowIndexInsteaOfCondition
|
||||||
|
);
|
||||||
const [matchedField, matchedChangeSetItem] = findExistingChangeSetItem(this.changeSet, rowDefinition);
|
const [matchedField, matchedChangeSetItem] = findExistingChangeSetItem(this.changeSet, rowDefinition);
|
||||||
const rowUpdated = matchedChangeSetItem
|
const rowUpdated = matchedChangeSetItem
|
||||||
? getRowFromItem(row, matchedChangeSetItem)
|
? getRowFromItem(row, matchedChangeSetItem)
|
||||||
@@ -125,7 +131,7 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get canInsert() {
|
get canInsert() {
|
||||||
return !!this.display.baseTableOrCollection;
|
return this.useRowIndexInsteaOfCondition || !!this.display.baseTableOrCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
getRowData(index: number) {
|
getRowData(index: number) {
|
||||||
@@ -152,13 +158,23 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
|
|
||||||
setCellValue(index: number, uniqueName: string, value: any) {
|
setCellValue(index: number, uniqueName: string, value: any) {
|
||||||
const row = this.getRowSource(index);
|
const row = this.getRowSource(index);
|
||||||
const definition = this.display.getChangeSetField(row, uniqueName, this.getInsertedRowIndex(index));
|
const definition = this.display.getChangeSetField(
|
||||||
|
row,
|
||||||
|
uniqueName,
|
||||||
|
this.getInsertedRowIndex(index),
|
||||||
|
this.useRowIndexInsteaOfCondition && index < this.sourceRows.length ? index : null,
|
||||||
|
this.useRowIndexInsteaOfCondition
|
||||||
|
);
|
||||||
this.applyModification(chs => setChangeSetValue(chs, definition, value));
|
this.applyModification(chs => setChangeSetValue(chs, definition, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
setRowData(index: number, document: any) {
|
setRowData(index: number, document: any) {
|
||||||
const row = this.getRowSource(index);
|
const row = this.getRowSource(index);
|
||||||
const definition = this.display.getChangeSetRow(row, this.getInsertedRowIndex(index));
|
const definition = this.display.getChangeSetRow(
|
||||||
|
row,
|
||||||
|
this.getInsertedRowIndex(index),
|
||||||
|
this.useRowIndexInsteaOfCondition && index < this.sourceRows.length ? index : null
|
||||||
|
);
|
||||||
this.applyModification(chs => setChangeSetRowData(chs, definition, document));
|
this.applyModification(chs => setChangeSetRowData(chs, definition, document));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,10 @@
|
|||||||
export let supportsReload = false;
|
export let supportsReload = false;
|
||||||
export let listenInitializeFile = false;
|
export let listenInitializeFile = false;
|
||||||
|
|
||||||
|
export let changeSetState = null;
|
||||||
|
export let changeSetStore = null;
|
||||||
|
export let dispatchChangeSet = null;
|
||||||
|
|
||||||
let loadedRows;
|
let loadedRows;
|
||||||
let infoCounter = 0;
|
let infoCounter = 0;
|
||||||
|
|
||||||
@@ -47,7 +51,8 @@
|
|||||||
cache.update,
|
cache.update,
|
||||||
loadedRows,
|
loadedRows,
|
||||||
$info?.__isDynamicStructure,
|
$info?.__isDynamicStructure,
|
||||||
supportsReload
|
supportsReload,
|
||||||
|
!!changeSetState
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -63,5 +68,8 @@
|
|||||||
bind:loadedRows
|
bind:loadedRows
|
||||||
isDynamicStructure={$info?.__isDynamicStructure}
|
isDynamicStructure={$info?.__isDynamicStructure}
|
||||||
useEvalFilters
|
useEvalFilters
|
||||||
|
{changeSetState}
|
||||||
|
{changeSetStore}
|
||||||
|
{dispatchChangeSet}
|
||||||
/>
|
/>
|
||||||
{/key}
|
{/key}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@
|
|||||||
import createQuickExportMenu from '../utility/createQuickExportMenu';
|
import createQuickExportMenu from '../utility/createQuickExportMenu';
|
||||||
import { exportQuickExportFile } from '../utility/exportFileTools';
|
import { exportQuickExportFile } from '../utility/exportFileTools';
|
||||||
import useEffect from '../utility/useEffect';
|
import useEffect from '../utility/useEffect';
|
||||||
|
import ChangeSetGrider from './ChangeSetGrider';
|
||||||
|
|
||||||
import LoadingDataGridCore from './LoadingDataGridCore.svelte';
|
import LoadingDataGridCore from './LoadingDataGridCore.svelte';
|
||||||
import RowsArrayGrider from './RowsArrayGrider';
|
import RowsArrayGrider from './RowsArrayGrider';
|
||||||
@@ -63,6 +64,9 @@
|
|||||||
export let display;
|
export let display;
|
||||||
export let formatterFunction;
|
export let formatterFunction;
|
||||||
|
|
||||||
|
export let changeSetState;
|
||||||
|
export let dispatchChangeSet;
|
||||||
|
|
||||||
export const activator = createActivator('JslDataGridCore', false);
|
export const activator = createActivator('JslDataGridCore', false);
|
||||||
|
|
||||||
export let loadedRows = [];
|
export let loadedRows = [];
|
||||||
@@ -93,7 +97,18 @@
|
|||||||
}
|
}
|
||||||
$: $effect;
|
$: $effect;
|
||||||
|
|
||||||
$: grider = new RowsArrayGrider(loadedRows);
|
$: grider = new ChangeSetGrider(
|
||||||
|
loadedRows,
|
||||||
|
changeSetState,
|
||||||
|
dispatchChangeSet,
|
||||||
|
display,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
// $: grider = new RowsArrayGrider(loadedRows);
|
||||||
|
|
||||||
export function exportGrid() {
|
export function exportGrid() {
|
||||||
const initialValues = {} as any;
|
const initialValues = {} as any;
|
||||||
|
|||||||
@@ -3,22 +3,58 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { changeSetContainsChanges, createChangeSet } from 'dbgate-datalib';
|
||||||
|
|
||||||
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
|
||||||
|
|
||||||
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
|
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
|
||||||
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
|
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
|
||||||
|
import invalidateCommands from '../commands/invalidateCommands';
|
||||||
|
|
||||||
import JslDataGrid from '../datagrid/JslDataGrid.svelte';
|
import JslDataGrid from '../datagrid/JslDataGrid.svelte';
|
||||||
|
import useEditorData from '../query/useEditorData';
|
||||||
|
import { markTabSaved, markTabUnsaved } from '../utility/common';
|
||||||
|
import createUndoReducer from '../utility/createUndoReducer';
|
||||||
|
|
||||||
export let archiveFolder = undefined;
|
export let archiveFolder = undefined;
|
||||||
export let archiveFile = undefined;
|
export let archiveFile = undefined;
|
||||||
export let jslid = undefined;
|
export let jslid = undefined;
|
||||||
|
|
||||||
|
export let tabid;
|
||||||
|
|
||||||
const quickExportHandlerRef = createQuickExportHandlerRef();
|
const quickExportHandlerRef = createQuickExportHandlerRef();
|
||||||
|
|
||||||
|
const { editorState, editorValue, setEditorData } = useEditorData({
|
||||||
|
tabid,
|
||||||
|
onInitialData: value => {
|
||||||
|
dispatchChangeSet({ type: 'reset', value });
|
||||||
|
invalidateCommands();
|
||||||
|
if (changeSetContainsChanges(value)) {
|
||||||
|
markTabUnsaved(tabid);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [changeSetStore, dispatchChangeSet] = createUndoReducer(createChangeSet());
|
||||||
|
|
||||||
|
$: {
|
||||||
|
setEditorData($changeSetStore.value);
|
||||||
|
if (changeSetContainsChanges($changeSetStore?.value)) {
|
||||||
|
markTabUnsaved(tabid);
|
||||||
|
} else {
|
||||||
|
markTabSaved(tabid);
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ToolStripContainer>
|
<ToolStripContainer>
|
||||||
<JslDataGrid jslid={jslid || `archive://${archiveFolder}/${archiveFile}`} supportsReload />
|
<JslDataGrid
|
||||||
|
jslid={jslid || `archive://${archiveFolder}/${archiveFile}`}
|
||||||
|
supportsReload
|
||||||
|
changeSetState={$changeSetStore}
|
||||||
|
{changeSetStore}
|
||||||
|
{dispatchChangeSet}
|
||||||
|
/>
|
||||||
<svelte:fragment slot="toolstrip">
|
<svelte:fragment slot="toolstrip">
|
||||||
<ToolStripCommandButton command="dataGrid.refresh" />
|
<ToolStripCommandButton command="dataGrid.refresh" />
|
||||||
<ToolStripExportButton command="jslTableGrid.export" {quickExportHandlerRef} />
|
<ToolStripExportButton command="jslTableGrid.export" {quickExportHandlerRef} />
|
||||||
|
|||||||
Reference in New Issue
Block a user