mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 21:53:58 +00:00
tab order by creation
This commit is contained in:
@@ -44,6 +44,7 @@ export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.fi
|
|||||||
export const recentDatabases = writableWithStorage([], 'recentDatabases');
|
export const recentDatabases = writableWithStorage([], 'recentDatabases');
|
||||||
export const pinnedDatabases = writableWithStorage([], 'pinnedDatabases');
|
export const pinnedDatabases = writableWithStorage([], 'pinnedDatabases');
|
||||||
export const pinnedTables = writableWithStorage([], 'pinnedTables');
|
export const pinnedTables = writableWithStorage([], 'pinnedTables');
|
||||||
|
export const tabDatabaseGroupOrder = writableWithStorage({}, 'tabDatabaseGroupOrder');
|
||||||
export const commandsSettings = writable({});
|
export const commandsSettings = writable({});
|
||||||
export const allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
|
export const allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
|
||||||
export const archiveFilesAsDataSheets = writableWithStorage([], 'archiveFilesAsDataSheets');
|
export const archiveFilesAsDataSheets = writableWithStorage([], 'archiveFilesAsDataSheets');
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import uuidv1 from 'uuid/v1';
|
import uuidv1 from 'uuid/v1';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { openedTabs } from '../stores';
|
import { getOpenedTabs, openedTabs, tabDatabaseGroupOrder } from '../stores';
|
||||||
import tabs from '../tabs';
|
import tabs from '../tabs';
|
||||||
import { setSelectedTabFunc } from './common';
|
import { setSelectedTabFunc } from './common';
|
||||||
import localforage from 'localforage';
|
import localforage from 'localforage';
|
||||||
@@ -72,15 +72,38 @@ export default async function openNewTab(newTab, initialData = undefined, option
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openedTabs.update(files => [
|
openedTabs.update(files => [
|
||||||
...(files || []).map(x => ({ ...x, selected: false })),
|
...(files || []).map(x => ({ ...x, selected: false })),
|
||||||
{
|
{
|
||||||
...newTab,
|
...newTab,
|
||||||
tabid,
|
tabid,
|
||||||
selected: true,
|
selected: true,
|
||||||
|
// @ts-ignore
|
||||||
|
tabOrder: (_.max(files.map(x => x.tabOrder || 0)) || 0) + 1,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const allOpenedTabs = getOpenedTabs();
|
||||||
|
|
||||||
|
tabDatabaseGroupOrder.update(groupOrder => {
|
||||||
|
const groupOrderFiltered = _.pickBy(groupOrder, (v, k) =>
|
||||||
|
allOpenedTabs.filter(x => x.closedTime == null).find(x => getTabDbKey(x) == k)
|
||||||
|
);
|
||||||
|
const dbKey = getTabDbKey({
|
||||||
|
...newTab,
|
||||||
|
tabid,
|
||||||
|
});
|
||||||
|
const newOrder =
|
||||||
|
groupOrderFiltered[dbKey] ||
|
||||||
|
// @ts-ignore
|
||||||
|
(_.max(Object.values(groupOrderFiltered)) || 0) + 1;
|
||||||
|
return {
|
||||||
|
...groupOrderFiltered,
|
||||||
|
[dbKey]: newOrder,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// console.log('OPENING NEW TAB', newTab);
|
// console.log('OPENING NEW TAB', newTab);
|
||||||
// const tabid = uuidv1();
|
// const tabid = uuidv1();
|
||||||
// openedTabs.update(tabs => [
|
// openedTabs.update(tabs => [
|
||||||
@@ -124,3 +147,16 @@ export async function duplicateTab(tab) {
|
|||||||
{ forceNewTab: true }
|
{ forceNewTab: true }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getTabDbKey(tab) {
|
||||||
|
if (tab.props && tab.props.conid && tab.props.database) {
|
||||||
|
return `database://${tab.props.database}-${tab.props.conid}`;
|
||||||
|
}
|
||||||
|
if (tab.props && tab.props.conid) {
|
||||||
|
return `server://${tab.props.conid}`;
|
||||||
|
}
|
||||||
|
if (tab.props && tab.props.archiveFolder) {
|
||||||
|
return `archive://${tab.props.archiveFolder}`;
|
||||||
|
}
|
||||||
|
return `no://${tab.tabid}`;
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,19 +59,6 @@
|
|||||||
return '(no DB)';
|
return '(no DB)';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTabDbKey(tab) {
|
|
||||||
if (tab.props && tab.props.conid && tab.props.database) {
|
|
||||||
return `database://${tab.props.database}-${tab.props.conid}`;
|
|
||||||
}
|
|
||||||
if (tab.props && tab.props.conid) {
|
|
||||||
return `server://${tab.props.conid}`;
|
|
||||||
}
|
|
||||||
if (tab.props && tab.props.archiveFolder) {
|
|
||||||
return `archive://${tab.props.archiveFolder}`;
|
|
||||||
}
|
|
||||||
return '_no';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDbIcon(key) {
|
function getDbIcon(key) {
|
||||||
if (key.startsWith('database://')) return 'icon database';
|
if (key.startsWith('database://')) return 'icon database';
|
||||||
if (key.startsWith('archive://')) return 'icon archive';
|
if (key.startsWith('archive://')) return 'icon archive';
|
||||||
@@ -132,14 +119,22 @@
|
|||||||
import FavoriteModal from '../modals/FavoriteModal.svelte';
|
import FavoriteModal from '../modals/FavoriteModal.svelte';
|
||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
|
|
||||||
import { currentDatabase, getActiveTab, getOpenedTabs, openedTabs, activeTabId, getActiveTabId } from '../stores';
|
import {
|
||||||
|
currentDatabase,
|
||||||
|
getActiveTab,
|
||||||
|
getOpenedTabs,
|
||||||
|
openedTabs,
|
||||||
|
activeTabId,
|
||||||
|
getActiveTabId,
|
||||||
|
tabDatabaseGroupOrder,
|
||||||
|
} from '../stores';
|
||||||
import tabs from '../tabs';
|
import tabs from '../tabs';
|
||||||
import { setSelectedTab } from '../utility/common';
|
import { setSelectedTab } from '../utility/common';
|
||||||
import contextMenu from '../utility/contextMenu';
|
import contextMenu from '../utility/contextMenu';
|
||||||
import getConnectionLabel from '../utility/getConnectionLabel';
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import { isElectronAvailable } from '../utility/getElectron';
|
import { isElectronAvailable } from '../utility/getElectron';
|
||||||
import { getConnectionInfo, useConnectionList } from '../utility/metadataLoaders';
|
import { getConnectionInfo, useConnectionList } from '../utility/metadataLoaders';
|
||||||
import { duplicateTab } from '../utility/openNewTab';
|
import { duplicateTab, getTabDbKey } from '../utility/openNewTab';
|
||||||
import { useConnectionColorFactory } from '../utility/useConnectionColor';
|
import { useConnectionColorFactory } from '../utility/useConnectionColor';
|
||||||
|
|
||||||
$: connectionList = useConnectionList();
|
$: connectionList = useConnectionList();
|
||||||
@@ -160,7 +155,7 @@
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
$: tabsByDb = _.groupBy(tabsWithDb, 'tabDbKey');
|
$: tabsByDb = _.groupBy(tabsWithDb, 'tabDbKey');
|
||||||
$: dbKeys = _.keys(tabsByDb).sort();
|
$: dbKeys = _.sortBy(_.keys(tabsByDb), [x => $tabDatabaseGroupOrder[x] || 0, x => x]);
|
||||||
|
|
||||||
$: scrollInViewTab($activeTabId);
|
$: scrollInViewTab($activeTabId);
|
||||||
|
|
||||||
@@ -265,12 +260,14 @@
|
|||||||
<FontIcon icon={getDbIcon(dbKey)} />
|
<FontIcon icon={getDbIcon(dbKey)} />
|
||||||
{tabsByDb[dbKey][0].tabDbName}
|
{tabsByDb[dbKey][0].tabDbName}
|
||||||
|
|
||||||
<span class="close-button-right tabCloseButton" on:click={e => closeWithSameDb(tabsByDb[dbKey][0].tabid)}>
|
{#if tabsByDb[dbKey].length > 1}
|
||||||
<FontIcon icon="icon close" />
|
<span class="close-button-right tabCloseButton" on:click={e => closeWithSameDb(tabsByDb[dbKey][0].tabid)}>
|
||||||
</span>
|
<FontIcon icon="icon close" />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="db-group">
|
<div class="db-group">
|
||||||
{#each _.sortBy(tabsByDb[dbKey], ['title', 'tabid']) as tab}
|
{#each _.sortBy(tabsByDb[dbKey], [x => x['tabOrder'] || 0, 'title', 'tabid']) as tab}
|
||||||
<div
|
<div
|
||||||
id={`file-tab-item-${tab.tabid}`}
|
id={`file-tab-item-${tab.tabid}`}
|
||||||
class="file-tab-item"
|
class="file-tab-item"
|
||||||
@@ -317,9 +314,9 @@
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
.db-name:hover {
|
/* .db-name:hover {
|
||||||
background-color: var(--theme-bg-3);
|
background-color: var(--theme-bg-3);
|
||||||
}
|
} */
|
||||||
.db-name.selected {
|
.db-name.selected {
|
||||||
background-color: var(--theme-bg-1);
|
background-color: var(--theme-bg-1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user