wip: server history support

This commit is contained in:
Johnny Almonte
2020-07-16 02:25:40 -04:00
parent 875d4f1fc0
commit 9d8f6a3167
2 changed files with 23 additions and 6 deletions

View File

@@ -2,16 +2,15 @@ import { WebDirective } from '../../types';
import { WebApplication } from '@/ui_models/application';
import template from '%/directives/history-menu.pug';
import { SNItem, ItemHistoryEntry, ItemHistory } from '@node_modules/snjs/dist/@types';
import { PayloadSource } from 'snjs';
import { PureViewCtrl } from '@/views';
interface HistoryScope {
application: WebApplication
item: SNItem
}
class HistoryMenuCtrl implements HistoryScope {
class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
$timeout: ng.ITimeoutService
diskEnabled = false
autoOptimize = false
application!: WebApplication
@@ -23,10 +22,14 @@ class HistoryMenuCtrl implements HistoryScope {
constructor(
$timeout: ng.ITimeoutService
) {
this.$timeout = $timeout;
super($timeout);
this.state = {
fetchingServerHistory: false
};
}
$onInit() {
super.$onInit();
this.reloadHistory();
this.fetchServerHistory();
this.diskEnabled = this.application.historyManager!.isDiskEnabled();
@@ -37,8 +40,20 @@ class HistoryMenuCtrl implements HistoryScope {
this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item);
}
get isFetchingServerHistory() {
return this.state.fetchingServerHistory;
}
async fetchServerHistory() {
this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item);
this.setState({
fetchingServerHistory: true
});
this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item)
.finally(() => {
this.setState({
fetchingServerHistory: false
});
});
}
openRevision(revision: ItemHistoryEntry) {

View File

@@ -43,7 +43,9 @@
div(ng-if='ctrl.showServerOptions')
menu-row(
action='ctrl.fetchServerHistory()'
label="'Refresh'")
label="'Refresh'"
disabled="ctrl.isFetchingServerHistory"
spinner-class="ctrl.isFetchingServerHistory ? 'info' : null")
.sk-sublabel
| Fetch history from server.
menu-row(