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