mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 08:33:58 +00:00
mongo distinct field values
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
export let pureName = null;
|
export let pureName = null;
|
||||||
export let schemaName = null;
|
export let schemaName = null;
|
||||||
export let columnName = null;
|
export let columnName = null;
|
||||||
|
export let uniqueName = null;
|
||||||
|
|
||||||
let value;
|
let value;
|
||||||
let isError;
|
let isError;
|
||||||
@@ -223,7 +224,7 @@
|
|||||||
multiselect: true,
|
multiselect: true,
|
||||||
schemaName,
|
schemaName,
|
||||||
pureName,
|
pureName,
|
||||||
columnName,
|
field: columnName || uniqueName,
|
||||||
onConfirm: keys => setFilter(keys.map(x => getFilterValueExpression(x)).join(',')),
|
onConfirm: keys => setFilter(keys.map(x => getFilterValueExpression(x)).join(',')),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -271,7 +272,7 @@
|
|||||||
<InlineButton on:click={handleShowDictionary} narrow square>
|
<InlineButton on:click={handleShowDictionary} narrow square>
|
||||||
<FontIcon icon="icon dots-horizontal" />
|
<FontIcon icon="icon dots-horizontal" />
|
||||||
</InlineButton>
|
</InlineButton>
|
||||||
{:else if pureName && columnName}
|
{:else if (pureName && columnName) || (pureName && uniqueName && driver?.databaseEngineTypes?.includes('document'))}
|
||||||
<InlineButton on:click={handleShowValuesModal} narrow square>
|
<InlineButton on:click={handleShowValuesModal} narrow square>
|
||||||
<FontIcon icon="icon dots-vertical" />
|
<FontIcon icon="icon dots-vertical" />
|
||||||
</InlineButton>
|
</InlineButton>
|
||||||
|
|||||||
@@ -1535,6 +1535,7 @@
|
|||||||
onGetReference={value => (domFilterControlsRef.get()[col.uniqueName] = value)}
|
onGetReference={value => (domFilterControlsRef.get()[col.uniqueName] = value)}
|
||||||
foreignKey={col.foreignKey}
|
foreignKey={col.foreignKey}
|
||||||
columnName={col.uniquePath.length == 1 ? col.uniquePath[0] : null}
|
columnName={col.uniquePath.length == 1 ? col.uniquePath[0] : null}
|
||||||
|
uniqueName={col.uniqueName}
|
||||||
pureName={col.pureName}
|
pureName={col.pureName}
|
||||||
schemaName={col.schemaName}
|
schemaName={col.schemaName}
|
||||||
{conid}
|
{conid}
|
||||||
|
|||||||
@@ -14,13 +14,14 @@
|
|||||||
import FormTextField from '../forms/FormTextField.svelte';
|
import FormTextField from '../forms/FormTextField.svelte';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
|
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
||||||
|
|
||||||
export let onConfirm;
|
export let onConfirm;
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
export let pureName;
|
export let pureName;
|
||||||
export let schemaName;
|
export let schemaName;
|
||||||
export let columnName;
|
export let field;
|
||||||
export let driver;
|
export let driver;
|
||||||
export let multiselect = false;
|
export let multiselect = false;
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@
|
|||||||
search,
|
search,
|
||||||
schemaName,
|
schemaName,
|
||||||
pureName,
|
pureName,
|
||||||
field: columnName,
|
field,
|
||||||
});
|
});
|
||||||
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
@@ -59,7 +60,7 @@
|
|||||||
|
|
||||||
<FormProvider>
|
<FormProvider>
|
||||||
<ModalBase {...$$restProps}>
|
<ModalBase {...$$restProps}>
|
||||||
<svelte:fragment slot="header">Choose value from {columnName}</svelte:fragment>
|
<svelte:fragment slot="header">Choose value from {field}</svelte:fragment>
|
||||||
|
|
||||||
<!-- <FormTextField name="search" label='Search' placeholder="Search" bind:value={search} /> -->
|
<!-- <FormTextField name="search" label='Search' placeholder="Search" bind:value={search} /> -->
|
||||||
<div class="largeFormMarker">
|
<div class="largeFormMarker">
|
||||||
@@ -71,51 +72,55 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if !isLoading && rows}
|
{#if !isLoading && rows}
|
||||||
<div class="tableWrapper">
|
{#if rows.errorMessage}
|
||||||
<ScrollableTableControl
|
<ErrorInfo message={rows.errorMessage} />
|
||||||
{rows}
|
{:else}
|
||||||
clickable
|
<div class="tableWrapper">
|
||||||
on:clickrow={e => {
|
<ScrollableTableControl
|
||||||
const { value } = e.detail;
|
{rows}
|
||||||
if (multiselect) {
|
clickable
|
||||||
if (checkedKeys.includes(value)) checkedKeys = checkedKeys.filter(x => x != value);
|
on:clickrow={e => {
|
||||||
else checkedKeys = [...checkedKeys, value];
|
const { value } = e.detail;
|
||||||
} else {
|
if (multiselect) {
|
||||||
closeCurrentModal();
|
|
||||||
onConfirm(value);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
columns={[
|
|
||||||
multiselect && {
|
|
||||||
fieldName: 'checked',
|
|
||||||
header: '',
|
|
||||||
width: '30px',
|
|
||||||
slot: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldName: 'value',
|
|
||||||
header: 'Value',
|
|
||||||
formatter: row => (row.value == null ? '(NULL)' : row.value),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
let:row
|
|
||||||
slot="1"
|
|
||||||
checked={checkedKeys.includes(row['value'])}
|
|
||||||
on:change={e => {
|
|
||||||
const value = row['value'];
|
|
||||||
if (e.target.checked) {
|
|
||||||
if (!checkedKeys.includes(value)) checkedKeys = [...checkedKeys, value];
|
|
||||||
} else {
|
|
||||||
if (checkedKeys.includes(value)) checkedKeys = checkedKeys.filter(x => x != value);
|
if (checkedKeys.includes(value)) checkedKeys = checkedKeys.filter(x => x != value);
|
||||||
|
else checkedKeys = [...checkedKeys, value];
|
||||||
|
} else {
|
||||||
|
closeCurrentModal();
|
||||||
|
onConfirm(value);
|
||||||
}
|
}
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
}}
|
||||||
/>
|
columns={[
|
||||||
</ScrollableTableControl>
|
multiselect && {
|
||||||
</div>
|
fieldName: 'checked',
|
||||||
|
header: '',
|
||||||
|
width: '30px',
|
||||||
|
slot: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'value',
|
||||||
|
header: 'Value',
|
||||||
|
formatter: row => (row.value == null ? '(NULL)' : row.value),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
let:row
|
||||||
|
slot="1"
|
||||||
|
checked={checkedKeys.includes(row['value'])}
|
||||||
|
on:change={e => {
|
||||||
|
const value = row['value'];
|
||||||
|
if (e.target.checked) {
|
||||||
|
if (!checkedKeys.includes(value)) checkedKeys = [...checkedKeys, value];
|
||||||
|
} else {
|
||||||
|
if (checkedKeys.includes(value)) checkedKeys = checkedKeys.filter(x => x != value);
|
||||||
|
}
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ScrollableTableControl>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<svelte:fragment slot="footer">
|
<svelte:fragment slot="footer">
|
||||||
|
|||||||
@@ -277,6 +277,54 @@ const driver = {
|
|||||||
const db = pool.db(name);
|
const db = pool.db(name);
|
||||||
await db.createCollection('collection1');
|
await db.createCollection('collection1');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async loadFieldValues(pool, name, field, search) {
|
||||||
|
try {
|
||||||
|
const collection = pool.__getDatabase().collection(name.pureName);
|
||||||
|
// console.log('options.condition', JSON.stringify(options.condition, undefined, 2));
|
||||||
|
|
||||||
|
const pipelineMatch = [];
|
||||||
|
|
||||||
|
if (search) {
|
||||||
|
const tokens = _.compact(search.split(' ').map((x) => x.trim()));
|
||||||
|
if (tokens.length > 0) {
|
||||||
|
pipelineMatch.push({
|
||||||
|
$match: {
|
||||||
|
$and: tokens.map((token) => ({
|
||||||
|
[field]: {
|
||||||
|
$regex: `.*${token}.*`,
|
||||||
|
$options: 'i',
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let cursor = await collection.aggregate([
|
||||||
|
...pipelineMatch,
|
||||||
|
{
|
||||||
|
$group: { _id: '$' + field },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$sort: { _id: 1 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$limit: 100,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const rows = await cursor.toArray();
|
||||||
|
return _.uniqBy(
|
||||||
|
rows.map(transformMongoData).map(({ _id }) => {
|
||||||
|
if (_.isArray(_id) || _.isPlainObject(_id)) return { value: null };
|
||||||
|
return { value: _id };
|
||||||
|
}),
|
||||||
|
(x) => x.value
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
return { errorMessage: err.message };
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = driver;
|
module.exports = driver;
|
||||||
|
|||||||
Reference in New Issue
Block a user