expand all, collapse all commands

This commit is contained in:
SPRINX0\prochazka
2025-01-24 14:27:05 +01:00
parent c09c5e588a
commit 4944bc4bca
4 changed files with 66 additions and 10 deletions

View File

@@ -31,6 +31,9 @@
export let rowIndex; export let rowIndex;
export let grider; export let grider;
export let expandAll = false;
let expandKey = 0;
$: rowData = grider.getRowData(rowIndex); $: rowData = grider.getRowData(rowIndex);
$: rowStatus = grider.getRowStatus(rowIndex); $: rowStatus = grider.getRowStatus(rowIndex);
@@ -43,18 +46,27 @@
copyTextToClipboard(JSON.stringify(rowData, undefined, 2)); copyTextToClipboard(JSON.stringify(rowData, undefined, 2));
} }
function handleExpandDocument() {
expandAll = true;
expandKey += 1;
}
registerMenu([ registerMenu([
{ text: 'Copy JSON document', onClick: handleCopyJsonDocument }, { text: 'Copy JSON document', onClick: handleCopyJsonDocument },
{ text: 'Edit document', onClick: handleEditDocument }, { text: 'Edit document', onClick: handleEditDocument },
{ text: 'Delete document', onClick: () => grider.deleteRow(rowIndex) }, { text: 'Delete document', onClick: () => grider.deleteRow(rowIndex) },
{ text: 'Revert row changes', onClick: () => grider.revertRowChanges(rowIndex) }, { text: 'Revert row changes', onClick: () => grider.revertRowChanges(rowIndex) },
{ text: 'Expand document', onClick: handleExpandDocument },
]); ]);
</script> </script>
<JSONTree {#key expandKey}
<JSONTree
value={rowData} value={rowData}
labelOverride="({rowIndex + 1}) " labelOverride="({rowIndex + 1}) "
isModified={rowStatus.status == 'updated'} isModified={rowStatus.status == 'updated'}
isInserted={rowStatus.status == 'inserted'} isInserted={rowStatus.status == 'inserted'}
isDeleted={rowStatus.status == 'deleted'} isDeleted={rowStatus.status == 'deleted'}
/> {expandAll}
/>
{/key}

View File

@@ -1,5 +1,24 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
const getCurrentEditor = () => getActiveComponent('CollectionJsonView'); const getCurrentEditor = () => getActiveComponent('CollectionJsonView');
registerCommand({
id: 'collectionJsonView.expandAll',
category: 'Collection data',
name: 'Expand all',
isRelatedToTab: true,
icon: 'icon expand-all',
onClick: () => getCurrentEditor().handleExpandAll(),
testEnabled: () => getCurrentEditor() != null && !getCurrentEditor()?.isExpandedAll(),
});
registerCommand({
id: 'collectionJsonView.collapseAll',
category: 'Collection data',
name: 'Collapse all',
isRelatedToTab: true,
icon: 'icon collapse-all',
onClick: () => getCurrentEditor().handleCollapseAll(),
testEnabled: () => getCurrentEditor() != null && getCurrentEditor()?.isExpandedAll(),
});
</script> </script>
<script lang="ts"> <script lang="ts">
@@ -17,6 +36,7 @@
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu'; import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
import CollectionJsonRow from './CollectionJsonRow.svelte'; import CollectionJsonRow from './CollectionJsonRow.svelte';
import { getIntSettingsValue } from '../settings/settingsTools'; import { getIntSettingsValue } from '../settings/settingsTools';
import invalidateCommands from '../commands/invalidateCommands';
export let conid; export let conid;
export let database; export let database;
@@ -32,6 +52,8 @@
let isLoading = false; let isLoading = false;
let loadedTime = null; let loadedTime = null;
let expandAll = false;
let expandKey = 0;
let loadedRows = []; let loadedRows = [];
let skip = 0; let skip = 0;
@@ -61,6 +83,22 @@
$: grider = new ChangeSetGrider(loadedRows, changeSetState, dispatchChangeSet, display); $: grider = new ChangeSetGrider(loadedRows, changeSetState, dispatchChangeSet, display);
// $: console.log('GRIDER', grider); // $: console.log('GRIDER', grider);
export function handleExpandAll() {
expandAll = true;
expandKey += 1;
invalidateCommands();
}
export function handleCollapseAll() {
expandAll = false;
expandKey += 1;
invalidateCommands();
}
export function isExpandedAll() {
return expandAll;
}
</script> </script>
<div class="wrapper" use:contextMenu={menu}> <div class="wrapper" use:contextMenu={menu}>
@@ -68,9 +106,11 @@
<Pager bind:skip bind:limit on:load={() => display.reload()} /> <Pager bind:skip bind:limit on:load={() => display.reload()} />
</div> </div>
<div class="json"> <div class="json">
{#key expandKey}
{#each _.range(0, grider.rowCount) as rowIndex} {#each _.range(0, grider.rowCount) as rowIndex}
<CollectionJsonRow {grider} {rowIndex} /> <CollectionJsonRow {grider} {rowIndex} {expandAll} />
{/each} {/each}
{/key}
</div> </div>
</div> </div>

View File

@@ -204,6 +204,8 @@
'icon type-unknown': 'mdi mdi-help-box', 'icon type-unknown': 'mdi mdi-help-box',
'icon at': 'mdi mdi-at', 'icon at': 'mdi mdi-at',
'icon expand-all': 'mdi mdi-expand-all',
'icon collapse-all': 'mdi mdi-collapse-all',
'img ok': 'mdi mdi-check-circle color-icon-green', 'img ok': 'mdi mdi-check-circle color-icon-green',
'img ok-inv': 'mdi mdi-check-circle color-icon-inv-green', 'img ok-inv': 'mdi mdi-check-circle color-icon-inv-green',

View File

@@ -216,5 +216,7 @@
<ToolStripCommandButton command="dataGrid.switchToJson" hideDisabled /> <ToolStripCommandButton command="dataGrid.switchToJson" hideDisabled />
<ToolStripCommandButton command="dataGrid.switchToTable" hideDisabled /> <ToolStripCommandButton command="dataGrid.switchToTable" hideDisabled />
<ToolStripExportButton {quickExportHandlerRef} command="collectionDataGrid.export" /> <ToolStripExportButton {quickExportHandlerRef} command="collectionDataGrid.export" />
<ToolStripCommandButton command="collectionJsonView.expandAll" hideDisabled />
<ToolStripCommandButton command="collectionJsonView.collapseAll" hideDisabled />
</svelte:fragment> </svelte:fragment>
</ToolStripContainer> </ToolStripContainer>