fix: rename session related functions
This commit is contained in:
@@ -5,14 +5,18 @@ 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 { ItemSessionHistory } from 'snjs/dist/@types/services/history/session/item_session_history';
|
||||||
import { RemoteHistoryList, RemoteHistoryListEntry } from 'snjs/dist/@types/services/history/history_manager';
|
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 {
|
interface HistoryScope {
|
||||||
application: WebApplication
|
application: WebApplication
|
||||||
item: SNItem
|
item: SNItem
|
||||||
}
|
}
|
||||||
|
|
||||||
class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
class HistoryMenuCtrl extends PureViewCtrl<{}, HistoryState> implements HistoryScope {
|
||||||
|
|
||||||
diskEnabled = false
|
diskEnabled = false
|
||||||
autoOptimize = false
|
autoOptimize = false
|
||||||
@@ -33,13 +37,13 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
|||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
super.$onInit();
|
super.$onInit();
|
||||||
this.reloadHistory();
|
this.reloadSessionHistory();
|
||||||
this.fetchServerHistory();
|
this.fetchRemoteHistory();
|
||||||
this.diskEnabled = this.application.historyManager!.isDiskEnabled();
|
this.diskEnabled = this.application.historyManager!.isDiskEnabled();
|
||||||
this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled();
|
this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadHistory() {
|
reloadSessionHistory() {
|
||||||
this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item);
|
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.fetchingRemoteHistory = true;
|
||||||
this.remoteHistory = await this.application.historyManager!.remoteHistoryForItem(this.item)
|
this.remoteHistory = await this.application.historyManager!.remoteHistoryForItem(this.item)
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@@ -69,17 +73,20 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async openRemoteRevision(revision: RemoteHistoryListEntry) {
|
async openRemoteRevision(revision: RemoteHistoryListEntry) {
|
||||||
const itemUuid = this.item.uuid;
|
|
||||||
this.fetchingRemoteHistory = true;
|
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;
|
this.fetchingRemoteHistory = false;
|
||||||
|
if (!remoteRevision) {
|
||||||
|
this.application.alertService!.alert("The remote revision could not be loaded. Please try again later.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.application.presentRevisionPreviewModal(
|
this.application.presentRevisionPreviewModal(
|
||||||
revision.payload.uuid,
|
remoteRevision!.payload.uuid,
|
||||||
revision.payload.content
|
remoteRevision!.payload.content
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
classForRevision(revision: ItemHistoryEntry) {
|
classForSessionRevision(revision: ItemHistoryEntry) {
|
||||||
const vector = revision.operationVector();
|
const vector = revision.operationVector();
|
||||||
if (vector === 0) {
|
if (vector === 0) {
|
||||||
return 'default';
|
return 'default';
|
||||||
@@ -90,7 +97,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearItemHistory() {
|
clearItemSessionHistory() {
|
||||||
confirmDialog({
|
confirmDialog({
|
||||||
text: "Are you sure you want to delete the local session history for this note?",
|
text: "Are you sure you want to delete the local session history for this note?",
|
||||||
confirmButtonStyle: "danger"
|
confirmButtonStyle: "danger"
|
||||||
@@ -100,13 +107,13 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
|||||||
}
|
}
|
||||||
this.application.historyManager!.clearHistoryForItem(this.item).then(() => {
|
this.application.historyManager!.clearHistoryForItem(this.item).then(() => {
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
this.reloadHistory();
|
this.reloadSessionHistory();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
clearAllHistory() {
|
clearAllSessionHistory() {
|
||||||
confirmDialog({
|
confirmDialog({
|
||||||
text: "Are you sure you want to delete the local session history for all notes?",
|
text: "Are you sure you want to delete the local session history for all notes?",
|
||||||
confirmButtonStyle: "danger"
|
confirmButtonStyle: "danger"
|
||||||
@@ -116,7 +123,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
|||||||
}
|
}
|
||||||
this.application.historyManager!.clearAllHistory().then(() => {
|
this.application.historyManager!.clearAllHistory().then(() => {
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
this.reloadHistory();
|
this.reloadSessionHistory();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -130,7 +137,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
|||||||
return this.remoteHistory;
|
return this.remoteHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleDiskSaving() {
|
toggleSessionHistoryDiskSaving() {
|
||||||
const run = () => {
|
const run = () => {
|
||||||
this.application.historyManager!.toggleDiskSaving().then(() => {
|
this.application.historyManager!.toggleDiskSaving().then(() => {
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
@@ -154,7 +161,7 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleAutoOptimize() {
|
toggleSessionHistoryAutoOptimize() {
|
||||||
this.application.historyManager!.toggleAutoOptimize().then(() => {
|
this.application.historyManager!.toggleAutoOptimize().then(() => {
|
||||||
this.$timeout(() => {
|
this.$timeout(() => {
|
||||||
this.autoOptimize = this.application.historyManager!.autoOptimize;
|
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!;
|
const createdAt = revision.created_at!;
|
||||||
return new Date(createdAt).toLocaleString();
|
return new Date(createdAt).toLocaleString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,20 +8,20 @@
|
|||||||
) Options
|
) Options
|
||||||
div(ng-if='ctrl.showSessionOptions')
|
div(ng-if='ctrl.showSessionOptions')
|
||||||
menu-row(
|
menu-row(
|
||||||
action='ctrl.clearItemHistory()'
|
action='ctrl.clearItemSessionHistory()'
|
||||||
label="'Clear note local history'"
|
label="'Clear note local history'"
|
||||||
)
|
)
|
||||||
menu-row(
|
menu-row(
|
||||||
action='ctrl.clearAllHistory()'
|
action='ctrl.clearAllSessionHistory()'
|
||||||
label="'Clear all local history'"
|
label="'Clear all local history'"
|
||||||
)
|
)
|
||||||
menu-row(
|
menu-row(
|
||||||
action='ctrl.toggleAutoOptimize()'
|
action='ctrl.toggleSessionHistoryAutoOptimize()'
|
||||||
label="(ctrl.autoOptimize ? 'Disable' : 'Enable') + ' auto cleanup'")
|
label="(ctrl.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.toggleDiskSaving()'
|
action='ctrl.toggleSessionHistoryDiskSaving()'
|
||||||
label="(ctrl.diskEnabled ? 'Disable' : 'Enable') + ' saving history to disk'"
|
label="(ctrl.diskEnabled ? 'Disable' : 'Enable') + ' saving history to disk'"
|
||||||
)
|
)
|
||||||
.sk-sublabel
|
.sk-sublabel
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
action='ctrl.openSessionRevision(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.classForSessionRevision(revision)')
|
||||||
| {{revision.previewSubTitle()}}
|
| {{revision.previewSubTitle()}}
|
||||||
.sk-menu-panel-header
|
.sk-menu-panel-header
|
||||||
.sk-menu-panel-header-title Remote
|
.sk-menu-panel-header-title Remote
|
||||||
@@ -51,5 +51,5 @@
|
|||||||
menu-row(
|
menu-row(
|
||||||
ng-repeat='revision in ctrl.remoteHistoryEntries track by $index'
|
ng-repeat='revision in ctrl.remoteHistoryEntries track by $index'
|
||||||
action='ctrl.openRemoteRevision(revision);'
|
action='ctrl.openRemoteRevision(revision);'
|
||||||
label='ctrl.previewTitle(revision);'
|
label='ctrl.previewRemoteHistoryTitle(revision);'
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user