run macro on jsl data

This commit is contained in:
Jan Prochazka 2023-02-24 16:48:37 +01:00
parent 6ff4acc50d
commit d024b6f25c
6 changed files with 59 additions and 16 deletions

View File

@ -214,7 +214,8 @@ export function runMacroOnChangeSet(
macroArgs: {},
selectedCells: MacroSelectedCell[],
changeSet: ChangeSet,
display: GridDisplay
display: GridDisplay,
useRowIndexInsteaOfCondition: boolean
): ChangeSet {
const errors = [];
const compiledMacroFunc = compileMacroFunction(macro, errors);
@ -222,7 +223,13 @@ export function runMacroOnChangeSet(
let res = changeSet;
for (const cell of selectedCells) {
const definition = display.getChangeSetField(cell.rowData, cell.column, undefined);
const definition = display.getChangeSetField(
cell.rowData,
cell.column,
undefined,
useRowIndexInsteaOfCondition ? cell.row : undefined,
useRowIndexInsteaOfCondition
);
const macroResult = runMacroOnValue(
compiledMacroFunc,
macroArgs,

View File

@ -1,5 +1,5 @@
<script lang="ts">
import { createGridCache, createGridConfig, JslGridDisplay } from 'dbgate-datalib';
import { createGridCache, createGridConfig, JslGridDisplay, runMacro, runMacroOnChangeSet } from 'dbgate-datalib';
import { generateTablePairingId, processJsonDataUpdateCommands } from 'dbgate-tools';
import { writable } from 'svelte/store';
import JslFormView from '../formview/JslFormView.svelte';
@ -33,6 +33,13 @@
infoCounter += 1;
}
function handleRunMacro(macro, params, cells) {
const newChangeSet = runMacroOnChangeSet(macro, params, cells, changeSetState?.value, display, true);
if (newChangeSet) {
dispatchChangeSet({ type: 'set', value: newChangeSet });
}
}
$: effect = useEffect(() => onJslId(jslid));
function onJslId(jslidVal) {
if (jslidVal && listenInitializeFile) {
@ -77,6 +84,10 @@
bind:loadedRows
isDynamicStructure={!!infoUsed?.__isDynamicStructure}
useEvalFilters
showMacros={!!dispatchChangeSet}
expandMacros={!!dispatchChangeSet}
onRunMacro={handleRunMacro}
macroCondition={infoUsed?.__isDynamicStructure ? null : macro => macro.type == 'transformValue'}
{changeSetState}
{changeSetStore}
{dispatchChangeSet}

View File

@ -67,6 +67,9 @@
export let changeSetState;
export let dispatchChangeSet;
export let macroPreview;
export let macroValues;
export let selectedCellsPublished = () => [];
export const activator = createActivator('JslDataGridCore', false);
export let loadedRows = [];
@ -97,16 +100,37 @@
}
$: $effect;
$: grider = new ChangeSetGrider(
loadedRows,
changeSetState,
dispatchChangeSet,
display,
undefined,
undefined,
undefined,
true
);
let grider;
$: {
if (macroPreview) {
grider = new ChangeSetGrider(
loadedRows,
changeSetState,
dispatchChangeSet,
display,
macroPreview,
macroValues,
selectedCellsPublished(),
true
);
}
}
$: {
if (!macroPreview) {
grider = new ChangeSetGrider(
loadedRows,
changeSetState,
dispatchChangeSet,
display,
undefined,
undefined,
undefined,
true
);
}
}
// $: grider = new RowsArrayGrider(loadedRows);
@ -168,6 +192,7 @@
bind:this={domGrid}
{...$$props}
bind:loadedRows
bind:selectedCellsPublished
{loadDataPage}
{dataPageAvailable}
{loadRowCount}

View File

@ -140,7 +140,7 @@
};
function handleRunMacro(macro, params, cells) {
const newChangeSet = runMacroOnChangeSet(macro, params, cells, changeSetState?.value, display);
const newChangeSet = runMacroOnChangeSet(macro, params, cells, changeSetState?.value, display, false);
if (newChangeSet) {
dispatchChangeSet({ type: 'set', value: newChangeSet });
}

View File

@ -154,7 +154,7 @@
}
function handleRunMacro(macro, params, cells) {
const newChangeSet = runMacroOnChangeSet(macro, params, cells, $changeSetStore?.value, display);
const newChangeSet = runMacroOnChangeSet(macro, params, cells, $changeSetStore?.value, display, false);
if (newChangeSet) {
dispatchChangeSet({ type: 'set', value: newChangeSet });
}

View File

@ -155,7 +155,7 @@
$selectedWidget = 'archive';
}}
>
<FontIcon icon="icon archive" />
<FontIcon icon="icon archive" padRight />
{$currentArchive}
</div>
{/if}