fix: support refactored SNJS history
This commit is contained in:
@@ -1,71 +1,64 @@
|
|||||||
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 } from '@standardnotes/snjs';
|
import { HistoryEntry, SNItem } from '@standardnotes/snjs';
|
||||||
import { PureViewCtrl } from '@/views';
|
import { PureViewCtrl } from '@/views';
|
||||||
import { ItemSessionHistory } from '@standardnotes/snjs';
|
|
||||||
import { RevisionListEntry, SingleRevision } from '@standardnotes/snjs';
|
import { RevisionListEntry, SingleRevision } from '@standardnotes/snjs';
|
||||||
import { confirmDialog } from '@/services/alertService';
|
import { alertDialog, confirmDialog } from '@/services/alertService';
|
||||||
|
|
||||||
type HistoryState = {
|
type HistoryState = {
|
||||||
fetchingRemoteHistory: boolean
|
sessionHistory?: HistoryEntry[];
|
||||||
}
|
remoteHistory?: RevisionListEntry[];
|
||||||
|
fetchingRemoteHistory: boolean;
|
||||||
|
autoOptimize: boolean;
|
||||||
|
diskEnabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
interface HistoryScope {
|
class HistoryMenuCtrl extends PureViewCtrl<unknown, HistoryState> {
|
||||||
application: WebApplication
|
application!: WebApplication;
|
||||||
item: SNItem
|
item!: SNItem;
|
||||||
}
|
|
||||||
|
|
||||||
class HistoryMenuCtrl extends PureViewCtrl<unknown, HistoryState> implements HistoryScope {
|
/** @template */
|
||||||
|
showSessionOptions = false;
|
||||||
diskEnabled = false
|
|
||||||
autoOptimize = false
|
|
||||||
application!: WebApplication
|
|
||||||
item!: SNItem
|
|
||||||
sessionHistory?: ItemSessionHistory
|
|
||||||
remoteHistory?: RevisionListEntry[]
|
|
||||||
|
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor(
|
constructor($timeout: ng.ITimeoutService) {
|
||||||
$timeout: ng.ITimeoutService
|
|
||||||
) {
|
|
||||||
super($timeout);
|
super($timeout);
|
||||||
this.state = {
|
}
|
||||||
fetchingRemoteHistory: false
|
|
||||||
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
fetchingRemoteHistory: false,
|
||||||
|
autoOptimize: this.application.historyManager.autoOptimize,
|
||||||
|
diskEnabled: this.application.historyManager.isDiskEnabled(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reloadState() {
|
||||||
|
this.setState({
|
||||||
|
...this.getInitialState(),
|
||||||
|
fetchingRemoteHistory: this.state.fetchingRemoteHistory,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
super.$onInit();
|
super.$onInit();
|
||||||
this.reloadSessionHistory();
|
|
||||||
this.fetchRemoteHistory();
|
this.fetchRemoteHistory();
|
||||||
this.diskEnabled = this.application.historyManager!.isDiskEnabled();
|
|
||||||
this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
reloadSessionHistory() {
|
|
||||||
this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item);
|
|
||||||
}
|
|
||||||
|
|
||||||
get isfetchingRemoteHistory() {
|
|
||||||
return this.state.fetchingRemoteHistory;
|
|
||||||
}
|
|
||||||
|
|
||||||
set fetchingRemoteHistory(value: boolean) {
|
|
||||||
this.setState({
|
|
||||||
fetchingRemoteHistory: value
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchRemoteHistory() {
|
async fetchRemoteHistory() {
|
||||||
this.fetchingRemoteHistory = true;
|
this.setState({ fetchingRemoteHistory: true });
|
||||||
this.remoteHistory = await this.application.historyManager!.remoteHistoryForItem(this.item)
|
try {
|
||||||
.finally(() => {
|
const remoteHistory = await this.application.historyManager.remoteHistoryForItem(
|
||||||
this.fetchingRemoteHistory = false;
|
this.item
|
||||||
});
|
);
|
||||||
|
this.setState({ remoteHistory });
|
||||||
|
} finally {
|
||||||
|
this.setState({ fetchingRemoteHistory: false });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async openSessionRevision(revision: ItemHistoryEntry) {
|
async openSessionRevision(revision: HistoryEntry) {
|
||||||
this.application.presentRevisionPreviewModal(
|
this.application.presentRevisionPreviewModal(
|
||||||
revision.payload.uuid,
|
revision.payload.uuid,
|
||||||
revision.payload.content
|
revision.payload.content
|
||||||
@@ -73,11 +66,17 @@ class HistoryMenuCtrl extends PureViewCtrl<unknown, HistoryState> implements His
|
|||||||
}
|
}
|
||||||
|
|
||||||
async openRemoteRevision(revision: RevisionListEntry) {
|
async openRemoteRevision(revision: RevisionListEntry) {
|
||||||
this.fetchingRemoteHistory = true;
|
this.setState({ fetchingRemoteHistory: true });
|
||||||
const remoteRevision = await this.application.historyManager!.fetchRemoteRevision(this.item.uuid, revision);
|
const remoteRevision = await this.application.historyManager.fetchRemoteRevision(
|
||||||
this.fetchingRemoteHistory = false;
|
this.item.uuid,
|
||||||
|
revision
|
||||||
|
);
|
||||||
|
this.setState({ fetchingRemoteHistory: false });
|
||||||
if (!remoteRevision) {
|
if (!remoteRevision) {
|
||||||
this.application.alertService!.alert("The remote revision could not be loaded. Please try again later.");
|
alertDialog({
|
||||||
|
text:
|
||||||
|
'The remote revision could not be loaded. Please try again later.',
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.application.presentRevisionPreviewModal(
|
this.application.presentRevisionPreviewModal(
|
||||||
@@ -86,7 +85,7 @@ class HistoryMenuCtrl extends PureViewCtrl<unknown, HistoryState> implements His
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
classForSessionRevision(revision: ItemHistoryEntry) {
|
classForSessionRevision(revision: HistoryEntry) {
|
||||||
const vector = revision.operationVector();
|
const vector = revision.operationVector();
|
||||||
if (vector === 0) {
|
if (vector === 0) {
|
||||||
return 'default';
|
return 'default';
|
||||||
@@ -97,81 +96,63 @@ class HistoryMenuCtrl extends PureViewCtrl<unknown, HistoryState> implements His
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearItemSessionHistory() {
|
async clearItemSessionHistory() {
|
||||||
confirmDialog({
|
if (
|
||||||
text: "Are you sure you want to delete the local session history for this note?",
|
await confirmDialog({
|
||||||
confirmButtonStyle: "danger"
|
text:
|
||||||
}).then((confirmed) => {
|
'Are you sure you want to delete the local session history for this note?',
|
||||||
if (!confirmed) {
|
confirmButtonStyle: 'danger',
|
||||||
return;
|
})
|
||||||
}
|
) {
|
||||||
this.application.historyManager!.clearHistoryForItem(this.item).then(() => {
|
this.application.historyManager.clearHistoryForItem(this.item);
|
||||||
this.$timeout(() => {
|
this.reloadState();
|
||||||
this.reloadSessionHistory();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
clearAllSessionHistory() {
|
|
||||||
confirmDialog({
|
|
||||||
text: "Are you sure you want to delete the local session history for all notes?",
|
|
||||||
confirmButtonStyle: "danger"
|
|
||||||
}).then((confirmed) => {
|
|
||||||
if (!confirmed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.application.historyManager!.clearAllHistory().then(() => {
|
|
||||||
this.$timeout(() => {
|
|
||||||
this.reloadSessionHistory();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get sessionHistoryEntries() {
|
|
||||||
return this.sessionHistory?.entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
get remoteHistoryEntries() {
|
|
||||||
return this.remoteHistory;
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleSessionHistoryDiskSaving() {
|
|
||||||
const run = () => {
|
|
||||||
this.application.historyManager!.toggleDiskSaving().then(() => {
|
|
||||||
this.$timeout(() => {
|
|
||||||
this.diskEnabled = this.application.historyManager!.isDiskEnabled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
if (!this.application.historyManager!.isDiskEnabled()) {
|
|
||||||
confirmDialog({
|
|
||||||
text: "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 " +
|
|
||||||
"if you experience any lagging.",
|
|
||||||
confirmButtonStyle: "danger"
|
|
||||||
}).then((confirmed) => {
|
|
||||||
if (confirmed) {
|
|
||||||
run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
run();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async clearAllSessionHistory() {
|
||||||
|
if (
|
||||||
|
await confirmDialog({
|
||||||
|
text:
|
||||||
|
'Are you sure you want to delete the local session history for all notes?',
|
||||||
|
confirmButtonStyle: 'danger',
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
await this.application.historyManager.clearAllHistory();
|
||||||
|
this.reloadState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @entries */
|
||||||
|
get sessionHistoryEntries() {
|
||||||
|
return this.state.sessionHistory?.entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
async toggleSessionHistoryDiskSaving() {
|
||||||
|
if (!this.state.diskEnabled) {
|
||||||
|
if (
|
||||||
|
await confirmDialog({
|
||||||
|
text:
|
||||||
|
'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 ' +
|
||||||
|
'if you experience any lagging.',
|
||||||
|
confirmButtonStyle: 'danger',
|
||||||
|
})
|
||||||
|
) {
|
||||||
|
this.application.historyManager.toggleDiskSaving();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.application.historyManager.toggleDiskSaving();
|
||||||
|
}
|
||||||
|
this.reloadState();
|
||||||
|
}
|
||||||
|
|
||||||
toggleSessionHistoryAutoOptimize() {
|
toggleSessionHistoryAutoOptimize() {
|
||||||
this.application.historyManager!.toggleAutoOptimize().then(() => {
|
this.application.historyManager.toggleAutoOptimize();
|
||||||
this.$timeout(() => {
|
this.reloadState();
|
||||||
this.autoOptimize = this.application.historyManager!.autoOptimize;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
previewRemoteHistoryTitle(revision: SingleRevision) {
|
previewRemoteHistoryTitle(revision: SingleRevision) {
|
||||||
const createdAt = revision.created_at!;
|
return new Date(revision.created_at).toLocaleString();
|
||||||
return new Date(createdAt).toLocaleString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +166,7 @@ export class HistoryMenu extends WebDirective {
|
|||||||
this.bindToController = true;
|
this.bindToController = true;
|
||||||
this.scope = {
|
this.scope = {
|
||||||
item: '=',
|
item: '=',
|
||||||
application: '='
|
application: '=',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
)
|
)
|
||||||
menu-row(
|
menu-row(
|
||||||
action='ctrl.toggleSessionHistoryAutoOptimize()'
|
action='ctrl.toggleSessionHistoryAutoOptimize()'
|
||||||
label="(ctrl.autoOptimize ? 'Disable' : 'Enable') + ' auto cleanup'")
|
label="(ctrl.state.autoOptimize ? 'Disable' : 'Enable') + ' auto cleanup'")
|
||||||
.sk-sublabel
|
.sk-sublabel
|
||||||
| Automatically cleans up small revisions to conserve space.
|
| Automatically cleans up small revisions to conserve space.
|
||||||
menu-row(
|
menu-row(
|
||||||
action='ctrl.toggleSessionHistoryDiskSaving()'
|
action='ctrl.toggleSessionHistoryDiskSaving()'
|
||||||
label="(ctrl.diskEnabled ? 'Disable' : 'Enable') + ' saving history to disk'"
|
label="(ctrl.state.diskEnabled ? 'Disable' : 'Enable') + ' saving history to disk'"
|
||||||
)
|
)
|
||||||
.sk-sublabel
|
.sk-sublabel
|
||||||
| Saving to disk is not recommended. Decreases performance and increases app
|
| Saving to disk is not recommended. Decreases performance and increases app
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
.sk-sublabel
|
.sk-sublabel
|
||||||
| Fetch history from server.
|
| Fetch history from server.
|
||||||
menu-row(
|
menu-row(
|
||||||
ng-repeat='revision in ctrl.remoteHistoryEntries track by $index'
|
ng-repeat='revision in ctrl.remoteHistory track by $index'
|
||||||
action='ctrl.openRemoteRevision(revision);'
|
action='ctrl.openRemoteRevision(revision);'
|
||||||
label='ctrl.previewRemoteHistoryTitle(revision);'
|
label='ctrl.previewRemoteHistoryTitle(revision);'
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user