table data grid

This commit is contained in:
Jan Prochazka
2021-02-22 17:34:24 +01:00
parent 60c1090d6c
commit 1e540b3fe9
22 changed files with 928 additions and 5678 deletions

View File

@@ -0,0 +1,30 @@
import { openedTabs } from '../stores';
export class LoadingToken {
constructor() {
this.isCanceled = false;
}
cancel() {
this.isCanceled = true;
}
}
export function sleep(milliseconds) {
return new Promise(resolve => window.setTimeout(() => resolve(null), milliseconds));
}
export function changeTab(tabid, setOpenedTabs, changeFunc) {
setOpenedTabs(files => files.map(tab => (tab.tabid == tabid ? changeFunc(tab) : tab)));
}
export function setSelectedTabFunc(files, tabid) {
return [
...(files || []).filter(x => x.tabid != tabid).map(x => ({ ...x, selected: false })),
...(files || []).filter(x => x.tabid == tabid).map(x => ({ ...x, selected: true })),
];
}
export function setSelectedTab(tabid) {
openedTabs.update(tabs => setSelectedTabFunc(tabs, tabid));
}

View File

@@ -2,7 +2,7 @@ import uuidv1 from 'uuid/v1';
import { openedTabs } from '../stores';
export default async function openNewTab(newTab, initialData = undefined, options = undefined) {
console.log('OPENING NEW TAB', newTab);
// console.log('OPENING NEW TAB', newTab);
const tabid = uuidv1();
openedTabs.update(tabs => [
...(tabs || []).map(x => ({ ...x, selected: false })),

View File

@@ -0,0 +1,21 @@
import { createGridConfig } from 'dbgate-datalib';
import { writable } from 'svelte/store';
import { onDestroy } from 'svelte';
const loadGridConfigFunc = tabid => () => {
const existing = localStorage.getItem(`tabdata_grid_${tabid}`);
if (existing) {
return {
...createGridConfig(),
...JSON.parse(existing),
};
}
return createGridConfig();
};
export default function useGridConfig(tabid) {
const config = writable(loadGridConfigFunc(tabid));
const unsubscribe = config.subscribe(value => localStorage.setItem(`tabdata_grid_${tabid}`, JSON.stringify(value)));
onDestroy(unsubscribe)
return config;
}