mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 20:13:57 +00:00
export mongo grid, generate query
This commit is contained in:
@@ -1,4 +1,23 @@
|
|||||||
<script context="module" lang="ts">
|
<script context="module" lang="ts">
|
||||||
|
const getCurrentEditor = () => getActiveComponent('CollectionDataGridCore');
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'collectionDataGrid.openQuery',
|
||||||
|
category: 'Data grid',
|
||||||
|
name: 'Open query',
|
||||||
|
testEnabled: () => getCurrentEditor() != null,
|
||||||
|
onClick: () => getCurrentEditor().openQuery(),
|
||||||
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'collectionDataGrid.export',
|
||||||
|
category: 'Data grid',
|
||||||
|
name: 'Export',
|
||||||
|
keyText: 'Ctrl+E',
|
||||||
|
testEnabled: () => getCurrentEditor() != null,
|
||||||
|
onClick: () => getCurrentEditor().exportGrid(),
|
||||||
|
});
|
||||||
|
|
||||||
function buildGridMongoCondition(props) {
|
function buildGridMongoCondition(props) {
|
||||||
const filters = props?.display?.config?.filters;
|
const filters = props?.display?.config?.filters;
|
||||||
|
|
||||||
@@ -100,6 +119,7 @@
|
|||||||
import { parseFilter } from 'dbgate-filterparser';
|
import { parseFilter } from 'dbgate-filterparser';
|
||||||
import { scriptToSql } from 'dbgate-sqltree';
|
import { scriptToSql } from 'dbgate-sqltree';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import registerCommand from '../commands/registerCommand';
|
||||||
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
||||||
import ConfirmNoSqlModal from '../modals/ConfirmNoSqlModal.svelte';
|
import ConfirmNoSqlModal from '../modals/ConfirmNoSqlModal.svelte';
|
||||||
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
|
||||||
@@ -107,6 +127,8 @@
|
|||||||
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 openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
import ChangeSetGrider from './ChangeSetGrider';
|
import ChangeSetGrider from './ChangeSetGrider';
|
||||||
|
|
||||||
@@ -129,6 +151,8 @@
|
|||||||
|
|
||||||
export let loadedRows = [];
|
export let loadedRows = [];
|
||||||
|
|
||||||
|
export const activator = createActivator('CollectionDataGridCore', false);
|
||||||
|
|
||||||
// $: console.log('loadedRows BIND', loadedRows);
|
// $: console.log('loadedRows BIND', loadedRows);
|
||||||
$: grider = new ChangeSetGrider(
|
$: grider = new ChangeSetGrider(
|
||||||
loadedRows,
|
loadedRows,
|
||||||
@@ -141,6 +165,44 @@
|
|||||||
);
|
);
|
||||||
// $: console.log('GRIDER', grider);
|
// $: console.log('GRIDER', grider);
|
||||||
// $: if (onChangeGrider) onChangeGrider(grider);
|
// $: if (onChangeGrider) onChangeGrider(grider);
|
||||||
|
|
||||||
|
function getExportQuery() {
|
||||||
|
return `db.collection('${pureName}')
|
||||||
|
.find(${JSON.stringify(buildGridMongoCondition($$props) || {})})
|
||||||
|
.sort(${JSON.stringify(buildMongoSort($$props) || {})})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function exportGrid() {
|
||||||
|
const initialValues: any = {};
|
||||||
|
initialValues.sourceStorageType = 'query';
|
||||||
|
initialValues.sourceConnectionId = conid;
|
||||||
|
initialValues.sourceDatabaseName = database;
|
||||||
|
initialValues.sourceSql = getExportQuery();
|
||||||
|
initialValues.sourceList = [pureName];
|
||||||
|
showModal(ImportExportModal, { initialValues });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openQuery() {
|
||||||
|
openNewTab(
|
||||||
|
{
|
||||||
|
title: 'Query #',
|
||||||
|
icon: 'img sql-file',
|
||||||
|
tabComponent: 'QueryTab',
|
||||||
|
props: {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
editor: getExportQuery(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenu(
|
||||||
|
{ command: 'collectionDataGrid.openQuery', tag: 'export' },
|
||||||
|
{ command: 'collectionDataGrid.export', tag: 'export' }
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<LoadingDataGridCore
|
<LoadingDataGridCore
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
label: `${format.name} files(s)`,
|
label: `${format.name} files(s)`,
|
||||||
directions: getFileFormatDirections(format),
|
directions: getFileFormatDirections(format),
|
||||||
})),
|
})),
|
||||||
{ value: 'query', label: 'SQL Query', directions: ['source'] },
|
{ value: 'query', label: 'Query', directions: ['source'] },
|
||||||
{ value: 'archive', label: 'Archive', directions: ['source', 'target'] },
|
{ value: 'archive', label: 'Archive', directions: ['source', 'target'] },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user