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: {}, macroArgs: {},
selectedCells: MacroSelectedCell[], selectedCells: MacroSelectedCell[],
changeSet: ChangeSet, changeSet: ChangeSet,
display: GridDisplay display: GridDisplay,
useRowIndexInsteaOfCondition: boolean
): ChangeSet { ): ChangeSet {
const errors = []; const errors = [];
const compiledMacroFunc = compileMacroFunction(macro, errors); const compiledMacroFunc = compileMacroFunction(macro, errors);
@@ -222,7 +223,13 @@ export function runMacroOnChangeSet(
let res = changeSet; let res = changeSet;
for (const cell of selectedCells) { 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( const macroResult = runMacroOnValue(
compiledMacroFunc, compiledMacroFunc,
macroArgs, macroArgs,

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <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 { generateTablePairingId, processJsonDataUpdateCommands } from 'dbgate-tools';
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import JslFormView from '../formview/JslFormView.svelte'; import JslFormView from '../formview/JslFormView.svelte';
@@ -33,6 +33,13 @@
infoCounter += 1; 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)); $: effect = useEffect(() => onJslId(jslid));
function onJslId(jslidVal) { function onJslId(jslidVal) {
if (jslidVal && listenInitializeFile) { if (jslidVal && listenInitializeFile) {
@@ -77,6 +84,10 @@
bind:loadedRows bind:loadedRows
isDynamicStructure={!!infoUsed?.__isDynamicStructure} isDynamicStructure={!!infoUsed?.__isDynamicStructure}
useEvalFilters useEvalFilters
showMacros={!!dispatchChangeSet}
expandMacros={!!dispatchChangeSet}
onRunMacro={handleRunMacro}
macroCondition={infoUsed?.__isDynamicStructure ? null : macro => macro.type == 'transformValue'}
{changeSetState} {changeSetState}
{changeSetStore} {changeSetStore}
{dispatchChangeSet} {dispatchChangeSet}

View File

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

View File

@@ -140,7 +140,7 @@
}; };
function handleRunMacro(macro, params, cells) { 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) { if (newChangeSet) {
dispatchChangeSet({ type: 'set', value: newChangeSet }); dispatchChangeSet({ type: 'set', value: newChangeSet });
} }

View File

@@ -154,7 +154,7 @@
} }
function handleRunMacro(macro, params, cells) { 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) { if (newChangeSet) {
dispatchChangeSet({ type: 'set', value: newChangeSet }); dispatchChangeSet({ type: 'set', value: newChangeSet });
} }

View File

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