mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 16:26:00 +00:00
configurable dictionary description
This commit is contained in:
@@ -113,8 +113,10 @@
|
||||
{value.toString()}
|
||||
{/if}
|
||||
|
||||
{#if allowHintField && rowData && rowData[col.hintColumnName]}
|
||||
<span class="hint">{rowData[col.hintColumnName]}</span>
|
||||
{#if allowHintField && rowData && _.some(col.hintColumnNames, hintColumnName => rowData[hintColumnName])}
|
||||
<span class="hint"
|
||||
>{col.hintColumnNames.map(hintColumnName => rowData[hintColumnName]).join(col.hintColumnDelimiter || ' ')}</span
|
||||
>
|
||||
{/if}
|
||||
|
||||
{#if col.foreignKey && rowData && rowData[col.uniqueName]}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
$: hintFieldsAllowed = visibleRealColumns
|
||||
.filter(col => {
|
||||
if (!col.hintColumnName) return false;
|
||||
if (!col.hintColumnNames) return false;
|
||||
if (rowStatus.modifiedFields && rowStatus.modifiedFields.has(col.uniqueName)) return false;
|
||||
return true;
|
||||
})
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
import SqlDataGridCore from './SqlDataGridCore.svelte';
|
||||
import SqlFormView from '../formview/SqlFormView.svelte';
|
||||
import { getBoolSettingsValue } from '../settings/settingsTools';
|
||||
import { getDictionaryDescription } from '../utility/dictionaryDescriptionTools';
|
||||
|
||||
export let conid;
|
||||
export let database;
|
||||
@@ -64,7 +65,8 @@
|
||||
setCache,
|
||||
$dbinfo,
|
||||
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) },
|
||||
$serverVersion
|
||||
$serverVersion,
|
||||
table => getDictionaryDescription(table, conid, database)
|
||||
)
|
||||
: null;
|
||||
|
||||
@@ -79,7 +81,8 @@
|
||||
setCache,
|
||||
$dbinfo,
|
||||
{ showHintColumns: getBoolSettingsValue('dataGrid.showHintColumns', true) },
|
||||
$serverVersion
|
||||
$serverVersion,
|
||||
table => getDictionaryDescription(table, conid, database)
|
||||
)
|
||||
: null;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
import FormProviderCore from '../forms/FormProviderCore.svelte';
|
||||
import {
|
||||
changeDelimitedColumnList,
|
||||
checkDescriptionExpression,
|
||||
getDictionaryDescription,
|
||||
parseDelimitedColumnList,
|
||||
saveDictionaryDescription,
|
||||
@@ -27,7 +28,7 @@
|
||||
|
||||
$: tableInfo = useTableInfo({ conid, database, schemaName, pureName });
|
||||
|
||||
$: descriptionInfo = getDictionaryDescription($tableInfo, conid, database);
|
||||
$: descriptionInfo = getDictionaryDescription($tableInfo, conid, database, true);
|
||||
|
||||
const values = writable({});
|
||||
|
||||
@@ -78,6 +79,7 @@
|
||||
<svelte:fragment slot="footer">
|
||||
<FormSubmit
|
||||
value="OK"
|
||||
disabled={!checkDescriptionExpression($values?.columns, $tableInfo)}
|
||||
on:click={() => {
|
||||
closeCurrentModal();
|
||||
saveDictionaryDescription(
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
import { DictionaryDescription } from 'dbgate-datalib';
|
||||
import { TableInfo } from 'dbgate-types';
|
||||
import _ from 'lodash';
|
||||
import { getLocalStorage, setLocalStorage, removeLocalStorage } from './storageCache';
|
||||
|
||||
interface DictionaryDescription {
|
||||
expression: string;
|
||||
columns: string[];
|
||||
delimiter: string;
|
||||
function checkDescriptionColumns(columns: string[], table: TableInfo) {
|
||||
return columns.length > 0 && columns.every(x => table.columns.find(y => y.columnName == x));
|
||||
}
|
||||
|
||||
function checkDescription(desc: DictionaryDescription, table: TableInfo) {
|
||||
return desc.columns.length > 0 && desc.columns.every(x => table.columns.find(y => y.columnName == x));
|
||||
}
|
||||
|
||||
export function getDictionaryDescription(table: TableInfo, conid: string, database: string): DictionaryDescription {
|
||||
export function getDictionaryDescription(
|
||||
table: TableInfo,
|
||||
conid: string,
|
||||
database: string,
|
||||
skipCheckSaved: boolean = false
|
||||
): DictionaryDescription {
|
||||
const keySpecific = `dictionary_spec_${table.schemaName}||${table.pureName}||${conid}||${database}`;
|
||||
const keyCommon = `dictionary_spec_${table.schemaName}||${table.pureName}`;
|
||||
|
||||
const cachedSpecific = getLocalStorage(keySpecific);
|
||||
const cachedCommon = getLocalStorage(keyCommon);
|
||||
|
||||
if (cachedSpecific && checkDescription(cachedSpecific, table)) return cachedSpecific;
|
||||
if (cachedCommon && checkDescription(cachedCommon, table)) return cachedCommon;
|
||||
if (cachedSpecific && (skipCheckSaved || checkDescriptionColumns(cachedSpecific.columns, table)))
|
||||
return cachedSpecific;
|
||||
if (cachedCommon && (skipCheckSaved || checkDescriptionColumns(cachedCommon.columns, table))) return cachedCommon;
|
||||
|
||||
const descColumn = table.columns.find(x => x?.dataType?.toLowerCase()?.includes('char'));
|
||||
if (descColumn) {
|
||||
@@ -34,10 +35,16 @@ export function getDictionaryDescription(table: TableInfo, conid: string, databa
|
||||
return null;
|
||||
}
|
||||
|
||||
export function parseDelimitedColumnList(columns) {
|
||||
export function parseDelimitedColumnList(columns): string[] {
|
||||
return _.compact((columns || '').split(',').map(x => x.trim()));
|
||||
}
|
||||
|
||||
export function checkDescriptionExpression(expression: string, table: TableInfo) {
|
||||
if (!expression) return false;
|
||||
if (!table) return false;
|
||||
return checkDescriptionColumns(parseDelimitedColumnList(expression), table);
|
||||
}
|
||||
|
||||
export function changeDelimitedColumnList(columns, columnName, isChecked) {
|
||||
const parsed = parseDelimitedColumnList(columns);
|
||||
const includes = parsed.includes(columnName);
|
||||
|
||||
Reference in New Issue
Block a user