connection workflow

This commit is contained in:
Jan Prochazka
2022-05-19 13:05:59 +02:00
parent b3a2197820
commit 1d013f96fb
3 changed files with 19 additions and 5 deletions

View File

@@ -25,6 +25,7 @@
import getConnectionLabel from '../utility/getConnectionLabel'; import getConnectionLabel from '../utility/getConnectionLabel';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { openConnection } from '../appobj/ConnectionAppObject.svelte'; import { openConnection } from '../appobj/ConnectionAppObject.svelte';
import { closeMultipleTabs } from '../widgets/TabsPanel.svelte';
export let connection; export let connection;
export let tabid; export let tabid;
@@ -112,6 +113,7 @@
$values = { $values = {
...$values, ...$values,
_id: saved._id, _id: saved._id,
unsaved: false,
}; };
changeTab(tabid, tab => ({ changeTab(tabid, tab => ({
...tab, ...tab,
@@ -126,13 +128,15 @@
async function handleConnect() { async function handleConnect() {
let connection = getCurrentConnection(); let connection = getCurrentConnection();
if (!connection._id) if (!connection._id) {
connection = { connection = {
...connection, ...connection,
unsaved: true, unsaved: !connection._id,
}; };
}
const saved = await apiCall('connections/save', connection); const saved = await apiCall('connections/save', connection);
openConnection(saved); openConnection(saved);
closeMultipleTabs(x => x.tabid == tabid, true);
} }
onMount(async () => { onMount(async () => {

View File

@@ -6,7 +6,8 @@
import { showModal } from '../modals/modalTools'; import { showModal } from '../modals/modalTools';
import { openedTabs } from '../stores'; import { openedTabs } from '../stores';
import { getConfig, useFavorites } from './metadataLoaders'; import { getConfig, getConnectionList, useFavorites } from './metadataLoaders';
import openNewTab from './openNewTab';
import { showSnackbarInfo } from './snackbar'; import { showSnackbarInfo } from './snackbar';
$: favorites = useFavorites(); $: favorites = useFavorites();
@@ -48,6 +49,14 @@
} }
} }
if (!$openedTabs.find(x => x.closedTime == null) && !(await getConnectionList()).find(x => !x.unsaved)) {
openNewTab({
title: 'New Connection',
icon: 'img connection',
tabComponent: 'ConnectionTab',
});
}
const config = await getConfig(); const config = await getConfig();
const appVersion = localStorage.getItem('appVersion'); const appVersion = localStorage.getItem('appVersion');
if (appVersion && appVersion != config.version) { if (appVersion && appVersion != config.version) {

View File

@@ -8,7 +8,7 @@
import AppObjectList from '../appobj/AppObjectList.svelte'; import AppObjectList from '../appobj/AppObjectList.svelte';
import * as connectionAppObject from '../appobj/ConnectionAppObject.svelte'; import * as connectionAppObject from '../appobj/ConnectionAppObject.svelte';
import SubDatabaseList from '../appobj/SubDatabaseList.svelte'; import SubDatabaseList from '../appobj/SubDatabaseList.svelte';
import { commands, commandsCustomized, expandedConnections, openedConnections } from '../stores'; import { commands, commandsCustomized, expandedConnections, openedConnections, openedTabs } from '../stores';
import ToolbarButton from '../buttons/ToolbarButton.svelte'; import ToolbarButton from '../buttons/ToolbarButton.svelte';
import runCommand from '../commands/runCommand'; import runCommand from '../commands/runCommand';
import getConnectionLabel from '../utility/getConnectionLabel'; import getConnectionLabel from '../utility/getConnectionLabel';
@@ -17,6 +17,7 @@
import CloseSearchButton from '../buttons/CloseSearchButton.svelte'; import CloseSearchButton from '../buttons/CloseSearchButton.svelte';
import { apiCall } from '../utility/api'; import { apiCall } from '../utility/api';
import LargeButton from '../buttons/LargeButton.svelte'; import LargeButton from '../buttons/LargeButton.svelte';
import { matchingProps } from '../tabs/TableDataTab.svelte';
const connections = useConnectionList(); const connections = useConnectionList();
const serverStatus = useServerStatus(); const serverStatus = useServerStatus();
@@ -66,7 +67,7 @@
setIsExpanded={(data, value) => setIsExpanded={(data, value) =>
expandedConnections.update(old => (value ? [...old, data._id] : old.filter(x => x != data._id)))} expandedConnections.update(old => (value ? [...old, data._id] : old.filter(x => x != data._id)))}
/> />
{#if $connections && $connections.length == 0 && $commandsCustomized['new.connection']?.enabled} {#if $connections && !$connections.find(x => !x.unsaved) && $openedConnections.length == 0 && $commandsCustomized['new.connection']?.enabled && !$openedTabs.find(x => !x.closedTime && x.tabComponent == 'ConnectionTab' && !x.props?.conid)}
<LargeButton icon="icon new-connection" on:click={() => runCommand('new.connection')} fillHorizontal <LargeButton icon="icon new-connection" on:click={() => runCommand('new.connection')} fillHorizontal
>Add new connection</LargeButton >Add new connection</LargeButton
> >