wip: server history support

This commit is contained in:
Johnny Almonte
2020-07-14 03:42:50 -04:00
parent 50f45547a4
commit e6d87fa40d
2 changed files with 40 additions and 53 deletions

View File

@@ -14,10 +14,10 @@ class HistoryMenuCtrl implements HistoryScope {
$timeout: ng.ITimeoutService $timeout: ng.ITimeoutService
diskEnabled = false diskEnabled = false
autoOptimize = false autoOptimize = false
fetchingServerHistory = false
application!: WebApplication application!: WebApplication
item!: SNItem item!: SNItem
history!: ItemHistory sessionHistory?: ItemHistory
serverHistory?: ItemHistory
/* @ngInject */ /* @ngInject */
constructor( constructor(
@@ -28,12 +28,17 @@ class HistoryMenuCtrl implements HistoryScope {
$onInit() { $onInit() {
this.reloadHistory(); this.reloadHistory();
this.fetchServerHistory();
this.diskEnabled = this.application.historyManager!.isDiskEnabled(); this.diskEnabled = this.application.historyManager!.isDiskEnabled();
this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled(); this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled();
} }
async reloadHistory() { reloadHistory() {
this.history = await this.application.historyManager!.historyForItem(this.item); this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item);
}
async fetchServerHistory() {
this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item);
} }
openRevision(revision: ItemHistoryEntry) { openRevision(revision: ItemHistoryEntry) {
@@ -56,50 +61,40 @@ class HistoryMenuCtrl implements HistoryScope {
clearItemHistory() { clearItemHistory() {
this.application.alertService!.confirm( this.application.alertService!.confirm(
"Are you sure you want to delete the local session history for this note?", "Are you sure you want to delete the local session history for this note?"
undefined, ).then((confirmed) => {
undefined, if (!confirmed) {
undefined, return;
() => { }
this.application.historyManager!.clearHistoryForItem(this.item).then(() => { this.application.historyManager!.clearHistoryForItem(this.item).then(() => {
this.$timeout(() => { this.$timeout(() => {
this.reloadHistory(); this.reloadHistory();
});
}); });
}, });
undefined, });
true,
);
} }
clearAllHistory() { clearAllHistory() {
this.application.alertService!.confirm( this.application.alertService!.confirm(
"Are you sure you want to delete the local session history for all notes?", "Are you sure you want to delete the local session history for all notes?"
undefined, ).then((confirmed) => {
undefined, if (!confirmed) {
undefined, return;
() => { }
this.application.historyManager!.clearAllHistory().then(() => { this.application.historyManager!.clearAllHistory().then(() => {
this.$timeout(() => { this.$timeout(() => {
this.reloadHistory(); this.reloadHistory();
});
}); });
}, });
undefined, });
true,
);
} }
get historySessionEntries() { get historySessionEntries() {
return this.history.entries.filter((entry) => { return this.sessionHistory?.entries;
return entry.payload.source === PayloadSource.SessionHistory;
});
} }
get historyServerEntries() { get historyServerEntries() {
return this.history.entries.filter((entry) => { return this.serverHistory?.entries
return entry.payload.source === PayloadSource.ServerHistory;
});
} }
toggleDiskSaving() { toggleDiskSaving() {
@@ -112,16 +107,14 @@ class HistoryMenuCtrl implements HistoryScope {
}; };
if (!this.application.historyManager!.isDiskEnabled()) { if (!this.application.historyManager!.isDiskEnabled()) {
this.application.alertService!.confirm( this.application.alertService!.confirm(
`Are you sure you want to save history to disk? This will decrease general "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 "performance, especially as you type. You are advised to disable this feature " +
if you experience any lagging.`, "if you experience any lagging."
undefined, ).then((confirmed) => {
undefined, if (confirmed) {
undefined, run();
run, }
undefined, });
true,
);
} else { } else {
run(); run();
} }
@@ -134,12 +127,6 @@ class HistoryMenuCtrl implements HistoryScope {
}); });
}); });
} }
fetchServerHistory() {
this.fetchingServerHistory = true;
this.reloadHistory();
this.fetchingServerHistory = false;
}
} }
export class HistoryMenu extends WebDirective { export class HistoryMenu extends WebDirective {

View File

@@ -43,7 +43,7 @@
div(ng-if='ctrl.showServerOptions') div(ng-if='ctrl.showServerOptions')
menu-row( menu-row(
action='ctrl.fetchServerHistory()' action='ctrl.fetchServerHistory()'
label="(ctrl.fetchingServerHistory ? 'Refreshing...' : 'Refresh')") label="'Refresh'")
.sk-sublabel .sk-sublabel
| Fetch history from server. | Fetch history from server.
menu-row( menu-row(