From e6d87fa40d07f434507d4113702f83bd1bab7cf9 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Tue, 14 Jul 2020 03:42:50 -0400 Subject: [PATCH] wip: server history support --- .../directives/views/historyMenu.ts | 91 ++++++++----------- .../templates/directives/history-menu.pug | 2 +- 2 files changed, 40 insertions(+), 53 deletions(-) diff --git a/app/assets/javascripts/directives/views/historyMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts index d9eba473d..77976e75d 100644 --- a/app/assets/javascripts/directives/views/historyMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -14,10 +14,10 @@ class HistoryMenuCtrl implements HistoryScope { $timeout: ng.ITimeoutService diskEnabled = false autoOptimize = false - fetchingServerHistory = false application!: WebApplication item!: SNItem - history!: ItemHistory + sessionHistory?: ItemHistory + serverHistory?: ItemHistory /* @ngInject */ constructor( @@ -28,12 +28,17 @@ class HistoryMenuCtrl implements HistoryScope { $onInit() { this.reloadHistory(); + this.fetchServerHistory(); this.diskEnabled = this.application.historyManager!.isDiskEnabled(); this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled(); } - async reloadHistory() { - this.history = await this.application.historyManager!.historyForItem(this.item); + reloadHistory() { + this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item); + } + + async fetchServerHistory() { + this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item); } openRevision(revision: ItemHistoryEntry) { @@ -56,50 +61,40 @@ class HistoryMenuCtrl implements HistoryScope { clearItemHistory() { this.application.alertService!.confirm( - "Are you sure you want to delete the local session history for this note?", - undefined, - undefined, - undefined, - () => { - this.application.historyManager!.clearHistoryForItem(this.item).then(() => { - this.$timeout(() => { - this.reloadHistory(); - }); + "Are you sure you want to delete the local session history for this note?" + ).then((confirmed) => { + if (!confirmed) { + return; + } + this.application.historyManager!.clearHistoryForItem(this.item).then(() => { + this.$timeout(() => { + this.reloadHistory(); }); - }, - undefined, - true, - ); + }); + }); } clearAllHistory() { this.application.alertService!.confirm( - "Are you sure you want to delete the local session history for all notes?", - undefined, - undefined, - undefined, - () => { - this.application.historyManager!.clearAllHistory().then(() => { - this.$timeout(() => { - this.reloadHistory(); - }); + "Are you sure you want to delete the local session history for all notes?" + ).then((confirmed) => { + if (!confirmed) { + return; + } + this.application.historyManager!.clearAllHistory().then(() => { + this.$timeout(() => { + this.reloadHistory(); }); - }, - undefined, - true, - ); + }); + }); } get historySessionEntries() { - return this.history.entries.filter((entry) => { - return entry.payload.source === PayloadSource.SessionHistory; - }); + return this.sessionHistory?.entries; } get historyServerEntries() { - return this.history.entries.filter((entry) => { - return entry.payload.source === PayloadSource.ServerHistory; - }); + return this.serverHistory?.entries } toggleDiskSaving() { @@ -112,16 +107,14 @@ class HistoryMenuCtrl implements HistoryScope { }; if (!this.application.historyManager!.isDiskEnabled()) { this.application.alertService!.confirm( - `Are you sure you want to save history to disk? This will decrease general - performance, especially as you type. You are advised to disable this feature - if you experience any lagging.`, - undefined, - undefined, - undefined, - run, - undefined, - true, - ); + "Are you sure you want to save history to disk? This will decrease general " + + "performance, especially as you type. You are advised to disable this feature " + + "if you experience any lagging." + ).then((confirmed) => { + if (confirmed) { + run(); + } + }); } else { run(); } @@ -134,12 +127,6 @@ class HistoryMenuCtrl implements HistoryScope { }); }); } - - fetchServerHistory() { - this.fetchingServerHistory = true; - this.reloadHistory(); - this.fetchingServerHistory = false; - } } export class HistoryMenu extends WebDirective { diff --git a/app/assets/templates/directives/history-menu.pug b/app/assets/templates/directives/history-menu.pug index 80df589b8..0fd6d5a78 100644 --- a/app/assets/templates/directives/history-menu.pug +++ b/app/assets/templates/directives/history-menu.pug @@ -43,7 +43,7 @@ div(ng-if='ctrl.showServerOptions') menu-row( action='ctrl.fetchServerHistory()' - label="(ctrl.fetchingServerHistory ? 'Refreshing...' : 'Refresh')") + label="'Refresh'") .sk-sublabel | Fetch history from server. menu-row(