diff --git a/packages/web/public/global.css b/packages/web/public/global.css index 4fa2e42c..9e25c3d2 100644 --- a/packages/web/public/global.css +++ b/packages/web/public/global.css @@ -55,6 +55,10 @@ body { position: relative; } +.col-10 { + flex-basis: 83.3333%; + max-width: 83.3333%; +} .col-9 { flex-basis: 75%; max-width: 75%; @@ -63,10 +67,18 @@ body { flex-basis: 66.6667%; max-width: 66.6667%; } +.col-7 { + flex-basis: 58.3333%; + max-width: 58.3333%; +} .col-6 { flex-basis: 50%; max-width: 50%; } +.col-5 { + flex-basis: 41.6667%; + max-width: 41.6667%; +} .col-4 { flex-basis: 33.3333%; max-width: 33.3333%; @@ -75,6 +87,10 @@ body { flex-basis: 25%; max-width: 25%; } +.col-2 { + flex-basis: 16.6666%; + max-width: 16.6666%; +} .largeFormMarker input[type='text'] { width: 100%; diff --git a/packages/web/src/elements/ForeignKeyObjectListControl.svelte b/packages/web/src/elements/ForeignKeyObjectListControl.svelte index 4ca6a70c..59b17773 100644 --- a/packages/web/src/elements/ForeignKeyObjectListControl.svelte +++ b/packages/web/src/elements/ForeignKeyObjectListControl.svelte @@ -7,11 +7,14 @@ export let collection; export let title; + export let clickable; + import FormStyledButton from '../elements/FormStyledButton.svelte'; + import uuidv1 from 'uuid/v1'; + + import FormSelectField from '../forms/FormSelectField.svelte'; + import FormTextField from '../forms/FormTextField.svelte'; + import FormCheckboxField from '../forms/FormCheckboxField.svelte'; + + import FormProvider from '../forms/FormProvider.svelte'; + import FormSubmit from '../forms/FormSubmit.svelte'; + import ModalBase from '../modals/ModalBase.svelte'; + import { closeCurrentModal } from '../modals/modalTools'; + import ElectronFilesInput from '../impexp/ElectronFilesInput.svelte'; + import DropDownButton from '../elements/DropDownButton.svelte'; + import DataTypeEditor from './DataTypeEditor.svelte'; + import { editorAddConstraint, editorDeleteConstraint, editorModifyConstraint } from 'dbgate-tools'; + import TextField from '../forms/TextField.svelte'; + import SelectField from '../forms/SelectField.svelte'; + + export let constraintInfo; + export let setTableInfo; + export let tableInfo; + export let dbInfo; + + let constraintName = constraintInfo?.constraintName; + let columns = constraintInfo?.columns || []; + let refTableName = constraintInfo?.refTableName; + let refSchemaName = constraintInfo?.refSchemaName; + + $: refTableInfo = dbInfo?.tables?.find(x => x.pureName == refTableName && x.schemaName == refSchemaName); + + function getConstraint() { + return { + pairingId: uuidv1(), + ...constraintInfo, + columns, + pureName: tableInfo.pureName, + schemaName: tableInfo.schemaName, + constraintName, + constraintType: 'foreignKey', + refTableName, + refSchemaName, + }; + } + + + + {constraintInfo ? `Edit foreign key` : `Add foreign key`} + +
+
+
Constraint name
+
+ (constraintName = e.target['value'])} focused /> +
+
+ +
+
+ Base column - {tableInfo.pureName} +
+
+ Ref column - {refTableName} +
+
+ + {#each columns as column, index} +
+
+ {#key column.columnName} + ({ + label: col.columnName, + value: col.columnName, + }))} + on:change={e => { + if (e.detail) { + columns = columns.map((col, i) => (i == index ? { ...col, columnName: e.detail } : col)); + } + }} + /> + {/key} +
+
+ {#key column.refColumnName} + ({ + label: col.columnName, + value: col.columnName, + }))} + on:change={e => { + if (e.detail) { + columns = columns.map((col, i) => (i == index ? { ...col, refColumnName: e.detail } : col)); + } + }} + /> + {/key} +
+
+ { + const x = [...columns]; + x.splice(index, 1); + columns = x; + }} + /> +
+
+ {/each} + + { + columns = [...columns, {}]; + }} + /> +
+ + + { + closeCurrentModal(); + if (constraintInfo) { + setTableInfo(tbl => editorModifyConstraint(tbl, getConstraint())); + } else { + setTableInfo(tbl => editorAddConstraint(tbl, getConstraint())); + } + }} + /> + + + {#if constraintInfo} + { + closeCurrentModal(); + setTableInfo(tbl => editorDeleteConstraint(tbl, constraintInfo)); + }} + /> + {/if} + +
+ + diff --git a/packages/web/src/tableeditor/TableEditor.svelte b/packages/web/src/tableeditor/TableEditor.svelte index 97ab657b..6db6c291 100644 --- a/packages/web/src/tableeditor/TableEditor.svelte +++ b/packages/web/src/tableeditor/TableEditor.svelte @@ -22,7 +22,6 @@ testEnabled: () => getCurrentEditor()?.allowAddPrimaryKey(), onClick: () => getCurrentEditor().addPrimaryKey(), }); -
@@ -154,7 +154,12 @@ {row?.columns.map(x => x.columnName).join(', ')} - + showModal(ForeignKeyEditorModal, { constraintInfo: e.detail, tableInfo, setTableInfo, dbInfo })} + />
@@ -168,5 +173,4 @@ background-color: var(--theme-bg-0); overflow: auto; } - diff --git a/packages/web/src/tabs/TableStructureTab.svelte b/packages/web/src/tabs/TableStructureTab.svelte index d04ee7c2..c112f5ac 100644 --- a/packages/web/src/tabs/TableStructureTab.svelte +++ b/packages/web/src/tabs/TableStructureTab.svelte @@ -1,7 +1,6 @@ setEditorData(tbl => {