mirror of
https://github.com/zadam/trilium.git
synced 2025-10-27 09:39:00 +01:00
feat(views/table): add debouncing
This commit is contained in:
parent
c5020b8884
commit
9dcd79bd94
@ -5,7 +5,8 @@ import { setLabel } from "../../../services/attributes.js";
|
|||||||
import getPromotedAttributeInformation, { buildData, TableData } from "./data.js";
|
import getPromotedAttributeInformation, { buildData, TableData } from "./data.js";
|
||||||
import applyHeaderCustomization from "./header-customization.js";
|
import applyHeaderCustomization from "./header-customization.js";
|
||||||
import server from "../../../services/server.js";
|
import server from "../../../services/server.js";
|
||||||
import type { GridState } from "ag-grid-community";
|
import type { GridApi, GridState } from "ag-grid-community";
|
||||||
|
import SpacedUpdate from "../../../services/spaced_update.js";
|
||||||
|
|
||||||
const TPL = /*html*/`
|
const TPL = /*html*/`
|
||||||
<div class="table-view">
|
<div class="table-view">
|
||||||
@ -44,6 +45,8 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
private $root: JQuery<HTMLElement>;
|
private $root: JQuery<HTMLElement>;
|
||||||
private $container: JQuery<HTMLElement>;
|
private $container: JQuery<HTMLElement>;
|
||||||
private args: ViewModeArgs;
|
private args: ViewModeArgs;
|
||||||
|
private spacedUpdate: SpacedUpdate;
|
||||||
|
private api?: GridApi;
|
||||||
|
|
||||||
constructor(args: ViewModeArgs) {
|
constructor(args: ViewModeArgs) {
|
||||||
super(args, "table");
|
super(args, "table");
|
||||||
@ -51,6 +54,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
this.$root = $(TPL);
|
this.$root = $(TPL);
|
||||||
this.$container = this.$root.find(".table-view-container");
|
this.$container = this.$root.find(".table-view-container");
|
||||||
this.args = args;
|
this.args = args;
|
||||||
|
this.spacedUpdate = new SpacedUpdate(() => this.onSave(), 5_000);
|
||||||
args.$parent.append(this.$root);
|
args.$parent.append(this.$root);
|
||||||
|
|
||||||
ModuleRegistry.registerModules([ AllCommunityModule ]);
|
ModuleRegistry.registerModules([ AllCommunityModule ]);
|
||||||
@ -74,16 +78,24 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
const viewStorage = await this.viewStorage.restore();
|
const viewStorage = await this.viewStorage.restore();
|
||||||
const initialState = viewStorage?.gridState;
|
const initialState = viewStorage?.gridState;
|
||||||
|
|
||||||
createGrid(el, {
|
this.api = createGrid(el, {
|
||||||
...buildData(info, notes),
|
...buildData(info, notes),
|
||||||
...setupEditing(),
|
...setupEditing(),
|
||||||
initialState,
|
initialState,
|
||||||
async onGridReady(event) {
|
async onGridReady(event) {
|
||||||
applyHeaderCustomization(el, event.api);
|
applyHeaderCustomization(el, event.api);
|
||||||
},
|
},
|
||||||
onStateUpdated: (event) => this.viewStorage.store({
|
onStateUpdated: () => this.spacedUpdate.scheduleUpdate()
|
||||||
gridState: event.api.getState()
|
});
|
||||||
})
|
}
|
||||||
|
|
||||||
|
private onSave() {
|
||||||
|
if (!this.api) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.viewStorage.store({
|
||||||
|
gridState: this.api.getState()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user