fix: rename session related functions

This commit is contained in:
Johnny Almonte
2020-08-14 11:12:41 -04:00
parent ee49d80ceb
commit 07bbd0e6b2
2 changed files with 31 additions and 24 deletions

View File

@@ -5,14 +5,18 @@ 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';
import { confirmDialog } from '@/services/alertService';
import { confirmDialog } from '@/services/alertService';
type HistoryState = {
fetchingRemoteHistory: boolean
}
interface HistoryScope {
application: WebApplication
item: SNItem
}
class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
class HistoryMenuCtrl extends PureViewCtrl<{}, HistoryState> implements HistoryScope {
diskEnabled = false
autoOptimize = false
@@ -33,13 +37,13 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
$onInit() {
super.$onInit();
this.reloadHistory();
this.fetchServerHistory();
this.reloadSessionHistory();
this.fetchRemoteHistory();
this.diskEnabled = this.application.historyManager!.isDiskEnabled();
this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled();
}
reloadHistory() {
reloadSessionHistory() {
this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item);
}
@@ -53,7 +57,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
});
}
async fetchServerHistory() {
async fetchRemoteHistory() {
this.fetchingRemoteHistory = true;
this.remoteHistory = await this.application.historyManager!.remoteHistoryForItem(this.item)
.finally(() => {
@@ -69,17 +73,20 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
}
async openRemoteRevision(revision: RemoteHistoryListEntry) {
const itemUuid = this.item.uuid;
this.fetchingRemoteHistory = true;
revision = await this.application.historyManager!.fetchRemoteRevision(itemUuid, revision);
const remoteRevision = await this.application.historyManager!.fetchRemoteRevision(this.item.uuid, revision);
this.fetchingRemoteHistory = false;
if (!remoteRevision) {
this.application.alertService!.alert("The remote revision could not be loaded. Please try again later.");
return;
}
this.application.presentRevisionPreviewModal(
revision.payload.uuid,
revision.payload.content
remoteRevision!.payload.uuid,
remoteRevision!.payload.content
);
}
classForRevision(revision: ItemHistoryEntry) {
classForSessionRevision(revision: ItemHistoryEntry) {
const vector = revision.operationVector();
if (vector === 0) {
return 'default';
@@ -90,7 +97,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
}
}
clearItemHistory() {
clearItemSessionHistory() {
confirmDialog({
text: "Are you sure you want to delete the local session history for this note?",
confirmButtonStyle: "danger"
@@ -100,13 +107,13 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
}
this.application.historyManager!.clearHistoryForItem(this.item).then(() => {
this.$timeout(() => {
this.reloadHistory();
this.reloadSessionHistory();
});
});
});
}
clearAllHistory() {
clearAllSessionHistory() {
confirmDialog({
text: "Are you sure you want to delete the local session history for all notes?",
confirmButtonStyle: "danger"
@@ -116,7 +123,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
}
this.application.historyManager!.clearAllHistory().then(() => {
this.$timeout(() => {
this.reloadHistory();
this.reloadSessionHistory();
});
});
});
@@ -130,7 +137,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
return this.remoteHistory;
}
toggleDiskSaving() {
toggleSessionHistoryDiskSaving() {
const run = () => {
this.application.historyManager!.toggleDiskSaving().then(() => {
this.$timeout(() => {
@@ -154,7 +161,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
}
}
toggleAutoOptimize() {
toggleSessionHistoryAutoOptimize() {
this.application.historyManager!.toggleAutoOptimize().then(() => {
this.$timeout(() => {
this.autoOptimize = this.application.historyManager!.autoOptimize;
@@ -162,7 +169,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
});
}
previewTitle(revision: RemoteHistoryListEntry) {
previewRemoteHistoryTitle(revision: RemoteHistoryListEntry) {
const createdAt = revision.created_at!;
return new Date(createdAt).toLocaleString();
}

View File

@@ -8,20 +8,20 @@
) Options
div(ng-if='ctrl.showSessionOptions')
menu-row(
action='ctrl.clearItemHistory()'
action='ctrl.clearItemSessionHistory()'
label="'Clear note local history'"
)
menu-row(
action='ctrl.clearAllHistory()'
action='ctrl.clearAllSessionHistory()'
label="'Clear all local history'"
)
menu-row(
action='ctrl.toggleAutoOptimize()'
action='ctrl.toggleSessionHistoryAutoOptimize()'
label="(ctrl.autoOptimize ? 'Disable' : 'Enable') + ' auto cleanup'")
.sk-sublabel
| Automatically cleans up small revisions to conserve space.
menu-row(
action='ctrl.toggleDiskSaving()'
action='ctrl.toggleSessionHistoryDiskSaving()'
label="(ctrl.diskEnabled ? 'Disable' : 'Enable') + ' saving history to disk'"
)
.sk-sublabel
@@ -32,7 +32,7 @@
action='ctrl.openSessionRevision(revision);'
label='revision.previewTitle()'
)
.sk-sublabel.opaque(ng-class='ctrl.classForRevision(revision)')
.sk-sublabel.opaque(ng-class='ctrl.classForSessionRevision(revision)')
| {{revision.previewSubTitle()}}
.sk-menu-panel-header
.sk-menu-panel-header-title Remote
@@ -51,5 +51,5 @@
menu-row(
ng-repeat='revision in ctrl.remoteHistoryEntries track by $index'
action='ctrl.openRemoteRevision(revision);'
label='ctrl.previewTitle(revision);'
label='ctrl.previewRemoteHistoryTitle(revision);'
)