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

View File

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