From 54b476fc27b68a48dc3f0fa2650a6225fa9921ad Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sat, 13 Nov 2021 16:19:42 +0100 Subject: [PATCH] lookup search --- packages/web/public/global.css | 1 + packages/web/src/elements/SearchInput.svelte | 12 +++- .../src/modals/DictionaryLookupModal.svelte | 58 ++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/packages/web/public/global.css b/packages/web/public/global.css index 9e25c3d2..9f4b0ca2 100644 --- a/packages/web/public/global.css +++ b/packages/web/public/global.css @@ -98,6 +98,7 @@ body { font-size: 14px; box-sizing: border-box; border-radius: 4px; + border: 1px solid var(--theme-border); } .largeFormMarker input[type='password'] { diff --git a/packages/web/src/elements/SearchInput.svelte b/packages/web/src/elements/SearchInput.svelte index 19b93121..bf8810ba 100644 --- a/packages/web/src/elements/SearchInput.svelte +++ b/packages/web/src/elements/SearchInput.svelte @@ -1,9 +1,13 @@ { + if (isDebounced) debouncedSet(domInput.value); + else value = domInput.value; + }} on:keydown={handleKeyDown} bind:this={domInput} on:focus={e => domInput.select()} diff --git a/packages/web/src/modals/DictionaryLookupModal.svelte b/packages/web/src/modals/DictionaryLookupModal.svelte index 77f6fa63..b1dd97d8 100644 --- a/packages/web/src/modals/DictionaryLookupModal.svelte +++ b/packages/web/src/modals/DictionaryLookupModal.svelte @@ -11,6 +11,10 @@ import { getDictionaryDescription } from '../utility/dictionaryDescriptionTools'; import { onMount } from 'svelte'; import { dumpSqlSelect } from 'dbgate-sqltree'; + import LoadingInfo from '../elements/LoadingInfo.svelte'; + import SearchInput from '../elements/SearchInput.svelte'; + import FormTextField from '../forms/FormTextField.svelte'; + import _ from 'lodash'; export let onConfirm; export let conid; @@ -22,6 +26,9 @@ let rows = null; let tableInfo; let description; + let isLoading = false; + + let search = ''; let checkedKeys = []; @@ -63,10 +70,35 @@ })), ], }; - // @ts-ignore + if (search) { + const tokens = _.compact(search.split(' ').map(x => x.trim())); + if (tokens.length > 0) { + // @ts-ignore + select.where = { + conditionType: 'and', + conditions: tokens.map(token => ({ + conditionType: 'or', + conditions: description.columns.map(columnName => ({ + conditionType: 'like', + left: { + exprType: 'column', + columnName, + }, + right: { + exprType: 'value', + value: `%${token}%`, + }, + })), + })), + }; + } + } + + // @ts-ignore dumpSqlSelect(dmp, select); + isLoading = true; const response = await axiosInstance.request({ url: 'database-connections/query-data', method: 'post', @@ -78,6 +110,12 @@ }); rows = response.data.rows; + isLoading = false; + } + + $: { + search; + reload(); } onMount(() => { @@ -89,10 +127,25 @@ Lookup from {pureName} - {#if tableInfo && description && rows && tableInfo?.primaryKey?.columns?.length == 1} + +
+ +
+ + {#if isLoading} + + {/if} + + {#if !isLoading && tableInfo && description && rows && tableInfo?.primaryKey?.columns?.length == 1}
{ + const value = e.detail[tableInfo.primaryKey.columns[0].columnName]; + if (checkedKeys.includes(value)) checkedKeys = checkedKeys.filter(x => x != value); + else checkedKeys = [...checkedKeys, value]; + }} columns={[ { fieldName: 'checked', @@ -122,6 +175,7 @@ const value = row[tableInfo.primaryKey.columns[0].columnName]; if (e.target.checked) checkedKeys = [...checkedKeys, value]; else checkedKeys = checkedKeys.filter(x => x != value); + e.stopPropagation(); }} />