mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 15:03:57 +00:00
table editor - add pk command
This commit is contained in:
@@ -71,6 +71,7 @@
|
|||||||
'icon plugin': 'mdi mdi-toy-brick',
|
'icon plugin': 'mdi mdi-toy-brick',
|
||||||
'icon menu': 'mdi mdi-menu',
|
'icon menu': 'mdi mdi-menu',
|
||||||
'icon add-column': 'mdi mdi-table-column-plus-after',
|
'icon add-column': 'mdi mdi-table-column-plus-after',
|
||||||
|
'icon add-key': 'mdi mdi-key-plus',
|
||||||
|
|
||||||
'img ok': 'mdi mdi-check-circle color-icon-green',
|
'img ok': 'mdi mdi-check-circle color-icon-green',
|
||||||
'img ok-inv': 'mdi mdi-check-circle color-icon-inv-green',
|
'img ok-inv': 'mdi mdi-check-circle color-icon-inv-green',
|
||||||
@@ -114,6 +115,7 @@
|
|||||||
'img filter': 'mdi mdi-filter',
|
'img filter': 'mdi mdi-filter',
|
||||||
'img group': 'mdi mdi-group',
|
'img group': 'mdi mdi-group',
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<span class={iconNames[icon] || icon} {title} on:click />
|
<span class={iconNames[icon] || icon} {title} on:click />
|
||||||
|
|||||||
@@ -12,11 +12,23 @@
|
|||||||
onClick: () => getCurrentEditor().addColumn(),
|
onClick: () => getCurrentEditor().addColumn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'tableEditor.addPrimaryKey',
|
||||||
|
category: 'Table editor',
|
||||||
|
name: 'Add primary key',
|
||||||
|
icon: 'icon add-key',
|
||||||
|
toolbar: true,
|
||||||
|
isRelatedToTab: true,
|
||||||
|
testEnabled: () => getCurrentEditor()?.allowAddPrimaryKey(),
|
||||||
|
onClick: () => getCurrentEditor().addPrimaryKey(),
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { tick } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
|
import invalidateCommands from '../commands/invalidateCommands';
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
|
|
||||||
import ColumnLabel from '../elements/ColumnLabel.svelte';
|
import ColumnLabel from '../elements/ColumnLabel.svelte';
|
||||||
@@ -30,7 +42,7 @@
|
|||||||
|
|
||||||
import { useDbCore } from '../utility/metadataLoaders';
|
import { useDbCore } from '../utility/metadataLoaders';
|
||||||
import ColumnEditorModal from './ColumnEditorModal.svelte';
|
import ColumnEditorModal from './ColumnEditorModal.svelte';
|
||||||
import PrimaryKeyEditorModal from './PrimaryKeyEditorModal.svelte';
|
import PrimaryKeyEditorModal from './PrimaryKeyEditorModal.svelte';
|
||||||
|
|
||||||
export const activator = createActivator('TableEditor', true);
|
export const activator = createActivator('TableEditor', true);
|
||||||
|
|
||||||
@@ -52,11 +64,27 @@ import PrimaryKeyEditorModal from './PrimaryKeyEditorModal.svelte';
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function allowAddPrimaryKey() {
|
||||||
|
return writable() && !tableInfo.primaryKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addPrimaryKey() {
|
||||||
|
showModal(PrimaryKeyEditorModal, {
|
||||||
|
setTableInfo,
|
||||||
|
tableInfo,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$: columns = tableInfo?.columns;
|
$: columns = tableInfo?.columns;
|
||||||
$: primaryKey = tableInfo?.primaryKey;
|
$: primaryKey = tableInfo?.primaryKey;
|
||||||
$: foreignKeys = tableInfo?.foreignKeys;
|
$: foreignKeys = tableInfo?.foreignKeys;
|
||||||
$: dependencies = tableInfo?.dependencies;
|
$: dependencies = tableInfo?.dependencies;
|
||||||
|
|
||||||
|
$: {
|
||||||
|
tableInfo;
|
||||||
|
invalidateCommands();
|
||||||
|
}
|
||||||
|
|
||||||
$: console.log('tableInfo', tableInfo);
|
$: console.log('tableInfo', tableInfo);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -114,7 +142,6 @@ import PrimaryKeyEditorModal from './PrimaryKeyEditorModal.svelte';
|
|||||||
title="Primary key"
|
title="Primary key"
|
||||||
clickable={writable()}
|
clickable={writable()}
|
||||||
on:clickrow={e => showModal(PrimaryKeyEditorModal, { constraintInfo: e.detail, tableInfo, setTableInfo })}
|
on:clickrow={e => showModal(PrimaryKeyEditorModal, { constraintInfo: e.detail, tableInfo, setTableInfo })}
|
||||||
|
|
||||||
columns={[
|
columns={[
|
||||||
{
|
{
|
||||||
fieldName: 'columns',
|
fieldName: 'columns',
|
||||||
|
|||||||
Reference in New Issue
Block a user