editing changeset on archive file

This commit is contained in:
Jan Prochazka
2023-02-10 10:22:38 +01:00
parent a3db8e2903
commit be0f68fb7f
7 changed files with 118 additions and 23 deletions

View File

@@ -48,7 +48,8 @@ export default class ChangeSetGrider extends Grider {
public display: GridDisplay,
public macro: MacroDefinition = null,
public macroArgs: {} = {},
public selectedCells: MacroSelectedCell[] = []
public selectedCells: MacroSelectedCell[] = [],
public useRowIndexInsteaOfCondition: boolean = false
) {
super();
this.changeSet = changeSetState && changeSetState.value;
@@ -81,7 +82,12 @@ export default class ChangeSetGrider extends Grider {
if (this.rowCacheIndexes.has(index)) return;
const row = this.getRowSource(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 rowUpdated = matchedChangeSetItem
? getRowFromItem(row, matchedChangeSetItem)
@@ -125,7 +131,7 @@ export default class ChangeSetGrider extends Grider {
}
get canInsert() {
return !!this.display.baseTableOrCollection;
return this.useRowIndexInsteaOfCondition || !!this.display.baseTableOrCollection;
}
getRowData(index: number) {
@@ -152,13 +158,23 @@ export default class ChangeSetGrider extends Grider {
setCellValue(index: number, uniqueName: string, value: any) {
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));
}
setRowData(index: number, document: any) {
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));
}

View File

@@ -12,6 +12,10 @@
export let supportsReload = false;
export let listenInitializeFile = false;
export let changeSetState = null;
export let changeSetStore = null;
export let dispatchChangeSet = null;
let loadedRows;
let infoCounter = 0;
@@ -47,7 +51,8 @@
cache.update,
loadedRows,
$info?.__isDynamicStructure,
supportsReload
supportsReload,
!!changeSetState
);
</script>
@@ -63,5 +68,8 @@
bind:loadedRows
isDynamicStructure={$info?.__isDynamicStructure}
useEvalFilters
{changeSetState}
{changeSetStore}
{dispatchChangeSet}
/>
{/key}

View File

@@ -55,6 +55,7 @@
import createQuickExportMenu from '../utility/createQuickExportMenu';
import { exportQuickExportFile } from '../utility/exportFileTools';
import useEffect from '../utility/useEffect';
import ChangeSetGrider from './ChangeSetGrider';
import LoadingDataGridCore from './LoadingDataGridCore.svelte';
import RowsArrayGrider from './RowsArrayGrider';
@@ -63,6 +64,9 @@
export let display;
export let formatterFunction;
export let changeSetState;
export let dispatchChangeSet;
export const activator = createActivator('JslDataGridCore', false);
export let loadedRows = [];
@@ -93,7 +97,18 @@
}
$: $effect;
$: grider = new RowsArrayGrider(loadedRows);
$: grider = new ChangeSetGrider(
loadedRows,
changeSetState,
dispatchChangeSet,
display,
undefined,
undefined,
undefined,
true
);
// $: grider = new RowsArrayGrider(loadedRows);
export function exportGrid() {
const initialValues = {} as any;

View File

@@ -3,22 +3,58 @@
</script>
<script lang="ts">
import { changeSetContainsChanges, createChangeSet } from 'dbgate-datalib';
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
import ToolStripContainer from '../buttons/ToolStripContainer.svelte';
import ToolStripExportButton, { createQuickExportHandlerRef } from '../buttons/ToolStripExportButton.svelte';
import invalidateCommands from '../commands/invalidateCommands';
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 archiveFile = undefined;
export let jslid = undefined;
export let tabid;
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>
<ToolStripContainer>
<JslDataGrid jslid={jslid || `archive://${archiveFolder}/${archiveFile}`} supportsReload />
<JslDataGrid
jslid={jslid || `archive://${archiveFolder}/${archiveFile}`}
supportsReload
changeSetState={$changeSetStore}
{changeSetStore}
{dispatchChangeSet}
/>
<svelte:fragment slot="toolstrip">
<ToolStripCommandButton command="dataGrid.refresh" />
<ToolStripExportButton command="jslTableGrid.export" {quickExportHandlerRef} />