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