mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
menu.placeTag
This commit is contained in:
parent
bcc1f91352
commit
2db17f9eca
@ -31,13 +31,19 @@ export interface GlobalCommand {
|
|||||||
|
|
||||||
export default function registerCommand(command: GlobalCommand) {
|
export default function registerCommand(command: GlobalCommand) {
|
||||||
const { testEnabled } = command;
|
const { testEnabled } = command;
|
||||||
commands.update(x => ({
|
commands.update(x => {
|
||||||
...x,
|
if (x[command.id]) {
|
||||||
[command.id]: {
|
console.error(`Command ${command.id} already registered`);
|
||||||
text: `${command.category}: ${command.name}`,
|
return x;
|
||||||
...command,
|
}
|
||||||
enabled: !testEnabled,
|
return {
|
||||||
},
|
...x,
|
||||||
}));
|
[command.id]: {
|
||||||
|
text: `${command.category}: ${command.name}`,
|
||||||
|
...command,
|
||||||
|
enabled: !testEnabled,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
invalidateCommandDefinitions();
|
invalidateCommandDefinitions();
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@
|
|||||||
import DataGridRow from './DataGridRow.svelte';
|
import DataGridRow from './DataGridRow.svelte';
|
||||||
import { getFilterType, getFilterValueExpression } from 'dbgate-filterparser';
|
import { getFilterType, getFilterValueExpression } from 'dbgate-filterparser';
|
||||||
import stableStringify from 'json-stable-stringify';
|
import stableStringify from 'json-stable-stringify';
|
||||||
import contextMenu from '../utility/contextMenu';
|
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
||||||
import { tick } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
import {
|
import {
|
||||||
cellIsSelected,
|
cellIsSelected,
|
||||||
@ -303,10 +303,6 @@
|
|||||||
display.reload();
|
display.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTabId() {
|
|
||||||
return tabid;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function save() {
|
export function save() {
|
||||||
if (onSave) onSave();
|
if (onSave) onSave();
|
||||||
}
|
}
|
||||||
@ -1015,33 +1011,33 @@
|
|||||||
return ['filter', columnRealIndex];
|
return ['filter', columnRealIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMenu() {
|
registerMenu(
|
||||||
return [
|
{ command: 'dataGrid.refresh' },
|
||||||
{ command: 'dataGrid.refresh' },
|
{ command: 'dataGrid.copyToClipboard' },
|
||||||
{ command: 'dataGrid.copyToClipboard' },
|
{ command: 'dataGrid.export' },
|
||||||
{ command: 'dataGrid.export' },
|
{ command: 'dataGrid.switchToForm', hideDisabled: true },
|
||||||
{ command: 'dataGrid.switchToForm', hideDisabled: true },
|
{ command: 'dataGrid.switchToJson', hideDisabled: true },
|
||||||
{ command: 'dataGrid.switchToJson', hideDisabled: true },
|
{ command: 'dataGrid.editJsonDocument', hideDisabled: true },
|
||||||
{ command: 'dataGrid.editJsonDocument', hideDisabled: true },
|
{ divider: true },
|
||||||
{ divider: true },
|
{ command: 'dataGrid.save' },
|
||||||
{ command: 'dataGrid.save' },
|
{ command: 'dataGrid.revertRowChanges' },
|
||||||
{ command: 'dataGrid.revertRowChanges' },
|
{ command: 'dataGrid.revertAllChanges' },
|
||||||
{ command: 'dataGrid.revertAllChanges' },
|
{ command: 'dataGrid.deleteSelectedRows' },
|
||||||
{ command: 'dataGrid.deleteSelectedRows' },
|
{ command: 'dataGrid.insertNewRow' },
|
||||||
{ command: 'dataGrid.insertNewRow' },
|
{ command: 'dataGrid.setNull' },
|
||||||
{ command: 'dataGrid.setNull' },
|
{ divider: true },
|
||||||
{ divider: true },
|
{ command: 'dataGrid.filterSelected' },
|
||||||
{ command: 'dataGrid.filterSelected' },
|
{ command: 'dataGrid.clearFilter' },
|
||||||
{ command: 'dataGrid.clearFilter' },
|
{ command: 'dataGrid.undo' },
|
||||||
{ command: 'dataGrid.undo' },
|
{ command: 'dataGrid.redo' },
|
||||||
{ command: 'dataGrid.redo' },
|
{ divider: true },
|
||||||
{ divider: true },
|
{ command: 'dataGrid.openQuery' },
|
||||||
{ command: 'dataGrid.openQuery' },
|
{ command: 'dataGrid.openFreeTable' },
|
||||||
{ command: 'dataGrid.openFreeTable' },
|
{ command: 'dataGrid.openChartFromSelection' },
|
||||||
{ command: 'dataGrid.openChartFromSelection' },
|
{ placeTag: 'chart' }
|
||||||
{ command: 'dataGrid.openActiveChart', hideDisabled: true },
|
);
|
||||||
];
|
|
||||||
}
|
const menu = getContextMenu();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if !display || (!isDynamicStructure && (!columns || columns.length == 0))}
|
{#if !display || (!isDynamicStructure && (!columns || columns.length == 0))}
|
||||||
@ -1062,12 +1058,7 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div
|
<div class="container" bind:clientWidth={containerWidth} bind:clientHeight={containerHeight} use:contextMenu={menu}>
|
||||||
class="container"
|
|
||||||
bind:clientWidth={containerWidth}
|
|
||||||
bind:clientHeight={containerHeight}
|
|
||||||
use:contextMenu={createMenu}
|
|
||||||
>
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
class="focus-field"
|
class="focus-field"
|
||||||
|
@ -63,6 +63,7 @@
|
|||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
|
|
||||||
import axiosInstance from '../utility/axiosInstance';
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
|
import { registerMenu } from '../utility/contextMenu';
|
||||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
import ChangeSetGrider from './ChangeSetGrider';
|
import ChangeSetGrider from './ChangeSetGrider';
|
||||||
@ -180,6 +181,8 @@
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerMenu({ command: 'dataGrid.openActiveChart', tag: 'chart' });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<LoadingDataGridCore
|
<LoadingDataGridCore
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { getContext, setContext } from 'svelte';
|
import { getContext, setContext } from 'svelte';
|
||||||
import { currentDropDownMenu } from '../stores';
|
import { currentDropDownMenu } from '../stores';
|
||||||
|
import getAsArray from './getAsArray';
|
||||||
|
|
||||||
export function registerMenu(items) {
|
export function registerMenu(...items) {
|
||||||
const parentMenu = getContext('componentContextMenu');
|
const parentMenu = getContext('componentContextMenu');
|
||||||
setContext('componentContextMenu', [parentMenu, items]);
|
setContext('componentContextMenu', [parentMenu, ...items]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function contextMenu(node, items = []) {
|
export default function contextMenu(node, items = []) {
|
||||||
@ -30,21 +31,43 @@ export default function contextMenu(node, items = []) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function doExtractMenuItems(menu, res) {
|
function doExtractMenuItems(menu, res, tagged) {
|
||||||
if (_.isFunction(menu)) {
|
if (_.isFunction(menu)) {
|
||||||
doExtractMenuItems(menu(), res);
|
doExtractMenuItems(menu(), res, tagged);
|
||||||
} else if (_.isArray(menu)) {
|
} else if (_.isArray(menu)) {
|
||||||
for (const item of menu) {
|
for (const item of menu) {
|
||||||
doExtractMenuItems(item, res);
|
doExtractMenuItems(item, res, tagged);
|
||||||
}
|
}
|
||||||
} else if (_.isPlainObject(menu)) {
|
} else if (_.isPlainObject(menu)) {
|
||||||
res.push(menu);
|
if (menu.tag) {
|
||||||
|
tagged.push({
|
||||||
|
...menu,
|
||||||
|
tags: getAsArray(menu.tag),
|
||||||
|
});
|
||||||
|
} else if (menu.placeTag) {
|
||||||
|
const placeTags = getAsArray(menu.placeTag);
|
||||||
|
for (let index = 0; index < tagged.length; ) {
|
||||||
|
const current = tagged[index];
|
||||||
|
if (_.intersection(placeTags, current.tags).length > 0) {
|
||||||
|
tagged.splice(index, 1);
|
||||||
|
res.push(current);
|
||||||
|
} else {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.push(menu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractMenuItems(menu) {
|
export function extractMenuItems(menu) {
|
||||||
const res = [];
|
const res = [];
|
||||||
doExtractMenuItems(menu, res);
|
const tagged = [];
|
||||||
|
doExtractMenuItems(menu, res, tagged);
|
||||||
|
|
||||||
|
// append tagged, which were not appended by placeTag
|
||||||
|
res.push(...tagged);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user