mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
save commands
This commit is contained in:
parent
423644e9d9
commit
49f22e1a3b
@ -347,5 +347,6 @@ export function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function changeSetContainsChanges(changeSet: ChangeSet) {
|
export function changeSetContainsChanges(changeSet: ChangeSet) {
|
||||||
|
if (!changeSet) return false;
|
||||||
return changeSet.deletes.length > 0 || changeSet.updates.length > 0 || changeSet.inserts.length > 0;
|
return changeSet.deletes.length > 0 || changeSet.updates.length > 0 || changeSet.inserts.length > 0;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
const currentDataGrid = writable(null);
|
const currentDataGrid = writable(null);
|
||||||
|
|
||||||
|
const currentDataGridChangeSet = memberStore(currentDataGrid, grid => grid?.getChangeSetStore() || nullStore);
|
||||||
|
|
||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'dataGrid.refresh',
|
id: 'dataGrid.refresh',
|
||||||
category: 'Data grid',
|
category: 'Data grid',
|
||||||
@ -8,7 +10,7 @@
|
|||||||
keyText: 'F5',
|
keyText: 'F5',
|
||||||
toolbar: true,
|
toolbar: true,
|
||||||
icon: 'icon reload',
|
icon: 'icon reload',
|
||||||
enabledStore: derived([currentDataGrid], ([grid]) => grid != null),
|
enabledStore: derived(currentDataGrid, grid => grid != null),
|
||||||
onClick: () => get(currentDataGrid).refresh(),
|
onClick: () => get(currentDataGrid).refresh(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -19,10 +21,27 @@
|
|||||||
keyText: 'Ctrl+S',
|
keyText: 'Ctrl+S',
|
||||||
toolbar: true,
|
toolbar: true,
|
||||||
icon: 'icon save',
|
icon: 'icon save',
|
||||||
enabledStore: derived([currentDataGrid], ([grid]) => grid?.getGrider()?.allowSave),
|
enabledStore: derived(currentDataGridChangeSet, (changeSet: any) => changeSetContainsChanges(changeSet?.value)),
|
||||||
onClick: () => get(currentDataGrid).save(),
|
onClick: () => get(currentDataGrid).save(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'dataGrid.revertRowChanges',
|
||||||
|
category: 'Data grid',
|
||||||
|
name: 'Revert row changes',
|
||||||
|
keyText: 'Ctrl+R',
|
||||||
|
enabledStore: derived(currentDataGridChangeSet, (changeSet: any) => changeSetContainsChanges(changeSet?.value)),
|
||||||
|
onClick: () => get(currentDataGrid).revertRowChanges(),
|
||||||
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'dataGrid.revertAllChanges',
|
||||||
|
category: 'Data grid',
|
||||||
|
name: 'Revert all changes',
|
||||||
|
enabledStore: derived(currentDataGridChangeSet, (changeSet: any) => changeSetContainsChanges(changeSet?.value)),
|
||||||
|
onClick: () => get(currentDataGrid).revertAllChanges(),
|
||||||
|
});
|
||||||
|
|
||||||
function getRowCountInfo(selectedCells, grider, realColumnUniqueNames, selectedRowData, allRowCount) {
|
function getRowCountInfo(selectedCells, grider, realColumnUniqueNames, selectedRowData, allRowCount) {
|
||||||
if (selectedCells.length > 1 && selectedCells.every(x => _.isNumber(x[0]) && _.isNumber(x[1]))) {
|
if (selectedCells.length > 1 && selectedCells.every(x => _.isNumber(x[0]) && _.isNumber(x[1]))) {
|
||||||
let sum = _.sumBy(selectedCells, cell => {
|
let sum = _.sumBy(selectedCells, cell => {
|
||||||
@ -49,7 +68,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { GridDisplay } from 'dbgate-datalib';
|
import { changeSetContainsChanges, GridDisplay } from 'dbgate-datalib';
|
||||||
import { get_current_component } from 'svelte/internal';
|
import { get_current_component } from 'svelte/internal';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { writable, get, derived } from 'svelte/store';
|
import { writable, get, derived } from 'svelte/store';
|
||||||
@ -76,6 +95,7 @@
|
|||||||
import createReducer from '../utility/createReducer';
|
import createReducer from '../utility/createReducer';
|
||||||
import keycodes from '../utility/keycodes';
|
import keycodes from '../utility/keycodes';
|
||||||
import { nullStore } from '../stores';
|
import { nullStore } from '../stores';
|
||||||
|
import memberStore from '../utility/memberStore';
|
||||||
|
|
||||||
export let loadNextData = undefined;
|
export let loadNextData = undefined;
|
||||||
export let grider = undefined;
|
export let grider = undefined;
|
||||||
@ -91,6 +111,7 @@
|
|||||||
|
|
||||||
export let isLoadedAll;
|
export let isLoadedAll;
|
||||||
export let loadedTime;
|
export let loadedTime;
|
||||||
|
export let changeSetStore;
|
||||||
|
|
||||||
const wheelRowCount = 5;
|
const wheelRowCount = 5;
|
||||||
const instance = get_current_component();
|
const instance = get_current_component();
|
||||||
@ -124,6 +145,22 @@
|
|||||||
return grider;
|
return grider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getChangeSetStore() {
|
||||||
|
return changeSetStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function revertRowChanges() {
|
||||||
|
grider.beginUpdate();
|
||||||
|
for (const index of getSelectedRowIndexes()) {
|
||||||
|
if (_.isNumber(index)) grider.revertRowChanges(index);
|
||||||
|
}
|
||||||
|
grider.endUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function revertAllChanges() {
|
||||||
|
grider.revertAllChanges();
|
||||||
|
}
|
||||||
|
|
||||||
$: autofillMarkerCell =
|
$: autofillMarkerCell =
|
||||||
selectedCells && selectedCells.length > 0 && _.uniq(selectedCells.map(x => x[0])).length == 1
|
selectedCells && selectedCells.length > 0 && _.uniq(selectedCells.map(x => x[0])).length == 1
|
||||||
? [_.max(selectedCells.map(x => x[0])), _.max(selectedCells.map(x => x[1]))]
|
? [_.max(selectedCells.map(x => x[0])), _.max(selectedCells.map(x => x[1]))]
|
||||||
|
19
packages/web/src/utility/memberStore.ts
Normal file
19
packages/web/src/utility/memberStore.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { writable } from 'svelte/store';
|
||||||
|
|
||||||
|
export default function memberStore(store, extractStore) {
|
||||||
|
let res;
|
||||||
|
let unsubscribeSub = null;
|
||||||
|
store.subscribe(value => {
|
||||||
|
const subStore = extractStore(value);
|
||||||
|
if (unsubscribeSub) unsubscribeSub();
|
||||||
|
unsubscribeSub = subStore.subscribe(subValue => {
|
||||||
|
if (res) {
|
||||||
|
console.log('subValue', subValue);
|
||||||
|
res.set(subValue);
|
||||||
|
} else {
|
||||||
|
res = writable(subValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user