wip: server history support
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
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 { SNItem, ItemHistoryEntry } from '@node_modules/snjs/dist/@types';
|
||||
import { PureViewCtrl } from '@/views';
|
||||
import { ItemSessionHistory } from 'snjs/dist/@types/services/history/session/item_session_history';
|
||||
import { RemoteHistoryList, RemoteHistoryListEntry } from 'snjs/dist/@types/services/history/history_manager';
|
||||
|
||||
interface HistoryScope {
|
||||
application: WebApplication
|
||||
@@ -15,8 +17,8 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
||||
autoOptimize = false
|
||||
application!: WebApplication
|
||||
item!: SNItem
|
||||
sessionHistory?: ItemHistory
|
||||
serverHistory?: ItemHistory
|
||||
sessionHistory?: ItemSessionHistory
|
||||
remoteHistory?: RemoteHistoryList
|
||||
|
||||
/* @ngInject */
|
||||
constructor(
|
||||
@@ -24,7 +26,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
||||
) {
|
||||
super($timeout);
|
||||
this.state = {
|
||||
fetchingServerHistory: false
|
||||
fetchingRemoteHistory: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,23 +42,36 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
||||
this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item);
|
||||
}
|
||||
|
||||
get isFetchingServerHistory() {
|
||||
return this.state.fetchingServerHistory;
|
||||
get isfetchingRemoteHistory() {
|
||||
return this.state.fetchingRemoteHistory;
|
||||
}
|
||||
|
||||
set fetchingRemoteHistory(value: boolean) {
|
||||
this.setState({
|
||||
fetchingRemoteHistory: value
|
||||
});
|
||||
}
|
||||
|
||||
async fetchServerHistory() {
|
||||
this.setState({
|
||||
fetchingServerHistory: true
|
||||
});
|
||||
this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item)
|
||||
this.fetchingRemoteHistory = true;
|
||||
this.remoteHistory = await this.application.historyManager!.remoteHistoryForItem(this.item)
|
||||
.finally(() => {
|
||||
this.setState({
|
||||
fetchingServerHistory: false
|
||||
});
|
||||
this.fetchingRemoteHistory = false;
|
||||
});
|
||||
}
|
||||
|
||||
openRevision(revision: ItemHistoryEntry) {
|
||||
async openSessionRevision(revision: ItemHistoryEntry) {
|
||||
this.application.presentRevisionPreviewModal(
|
||||
revision.payload.uuid,
|
||||
revision.payload.content
|
||||
);
|
||||
}
|
||||
|
||||
async openRemoteRevision(revision: RemoteHistoryListEntry) {
|
||||
const itemUuid = this.item.uuid;
|
||||
this.fetchingRemoteHistory = true;
|
||||
revision = await this.application.historyManager!.fetchRemoteRevision(itemUuid, revision);
|
||||
this.fetchingRemoteHistory = false;
|
||||
this.application.presentRevisionPreviewModal(
|
||||
revision.payload.uuid,
|
||||
revision.payload.content
|
||||
@@ -104,12 +119,12 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
||||
});
|
||||
}
|
||||
|
||||
get historySessionEntries() {
|
||||
get sessionHistoryEntries() {
|
||||
return this.sessionHistory?.entries;
|
||||
}
|
||||
|
||||
get historyServerEntries() {
|
||||
return this.serverHistory?.entries
|
||||
get remoteHistoryEntries() {
|
||||
return this.remoteHistory;
|
||||
}
|
||||
|
||||
toggleDiskSaving() {
|
||||
@@ -142,6 +157,11 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
previewTitle(revision: RemoteHistoryListEntry) {
|
||||
const createdAt = revision.created_at!;
|
||||
return new Date(createdAt).toLocaleString();
|
||||
}
|
||||
}
|
||||
|
||||
export class HistoryMenu extends WebDirective {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
.sk-menu-panel.dropdown-menu
|
||||
.sk-menu-panel-header
|
||||
.sk-menu-panel-header-title Session
|
||||
.sk-menu-panel-header-subtitle {{ctrl.historySessionEntries.length || 'No'}} revisions
|
||||
.sk-menu-panel-header-subtitle {{ctrl.sessionHistoryEntries.length || 'No'}} revisions
|
||||
a.sk-a.info.sk-h5(
|
||||
ng-click='ctrl.showSessionOptions = !ctrl.showSessionOptions; $event.stopPropagation();'
|
||||
) Options
|
||||
@@ -28,30 +28,28 @@
|
||||
| Saving to disk is not recommended. Decreases performance and increases app
|
||||
| loading time and memory footprint.
|
||||
menu-row(
|
||||
ng-repeat='revision in ctrl.historySessionEntries track by $index'
|
||||
action='ctrl.openRevision(revision);'
|
||||
ng-repeat='revision in ctrl.sessionHistoryEntries track by $index'
|
||||
action='ctrl.openSessionRevision(revision);'
|
||||
label='revision.previewTitle()'
|
||||
)
|
||||
.sk-sublabel.opaque(ng-class='ctrl.classForRevision(revision)')
|
||||
| {{revision.previewSubTitle()}}
|
||||
.sk-menu-panel-header
|
||||
.sk-menu-panel-header-title Server
|
||||
.sk-menu-panel-header-subtitle {{ctrl.historyServerEntries.length || 'No'}} revisions
|
||||
.sk-menu-panel-header-title Remote
|
||||
.sk-menu-panel-header-subtitle {{ctrl.remoteHistoryEntries.length || 'No'}} revisions
|
||||
a.sk-a.info.sk-h5(
|
||||
ng-click='ctrl.showServerOptions = !ctrl.showServerOptions; $event.stopPropagation();'
|
||||
ng-click='ctrl.showRemoteOptions = !ctrl.showRemoteOptions; $event.stopPropagation();'
|
||||
) Options
|
||||
div(ng-if='ctrl.showServerOptions')
|
||||
div(ng-if='ctrl.showRemoteOptions')
|
||||
menu-row(
|
||||
action='ctrl.fetchServerHistory()'
|
||||
action='ctrl.fetchRemoteHistory()'
|
||||
label="'Refresh'"
|
||||
disabled="ctrl.isFetchingServerHistory"
|
||||
spinner-class="ctrl.isFetchingServerHistory ? 'info' : null")
|
||||
disabled="ctrl.isfetchingRemoteHistory"
|
||||
spinner-class="ctrl.isfetchingRemoteHistory ? 'info' : null")
|
||||
.sk-sublabel
|
||||
| Fetch history from server.
|
||||
menu-row(
|
||||
ng-repeat='revision in ctrl.historyServerEntries track by $index'
|
||||
action='ctrl.openRevision(revision);'
|
||||
label='revision.previewTitle()'
|
||||
ng-repeat='revision in ctrl.remoteHistoryEntries track by $index'
|
||||
action='ctrl.openRemoteRevision(revision);'
|
||||
label='ctrl.previewTitle(revision);'
|
||||
)
|
||||
.sk-sublabel.opaque(ng-class='ctrl.classForRevision(revision)')
|
||||
| {{revision.previewSubTitle()}}
|
||||
|
||||
Reference in New Issue
Block a user