From 50f45547a4fc3fc48abec65f4c9c2a4950855f4f Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Mon, 13 Jul 2020 03:18:49 -0400 Subject: [PATCH 1/8] wip: server history support --- app/assets/javascripts/app.ts | 4 +- .../{sessionHistoryMenu.ts => historyMenu.ts} | 41 +++++++++----- .../javascripts/directives/views/index.ts | 2 +- .../javascripts/views/editor/editor-view.pug | 12 ++-- .../templates/directives/history-menu.pug | 55 +++++++++++++++++++ .../directives/session-history-menu.pug | 35 ------------ 6 files changed, 92 insertions(+), 57 deletions(-) rename app/assets/javascripts/directives/views/{sessionHistoryMenu.ts => historyMenu.ts} (77%) create mode 100644 app/assets/templates/directives/history-menu.pug delete mode 100644 app/assets/templates/directives/session-history-menu.pug diff --git a/app/assets/javascripts/app.ts b/app/assets/javascripts/app.ts index 64fb23e63..49ef4852a 100644 --- a/app/assets/javascripts/app.ts +++ b/app/assets/javascripts/app.ts @@ -44,7 +44,7 @@ import { PrivilegesAuthModal, PrivilegesManagementModal, RevisionPreviewModal, - SessionHistoryMenu, + HistoryMenu, SyncResolutionMenu } from './directives/views'; @@ -100,7 +100,7 @@ angular .directive('privilegesAuthModal', () => new PrivilegesAuthModal()) .directive('privilegesManagementModal', () => new PrivilegesManagementModal()) .directive('revisionPreviewModal', () => new RevisionPreviewModal()) - .directive('sessionHistoryMenu', () => new SessionHistoryMenu()) + .directive('historyMenu', () => new HistoryMenu()) .directive('syncResolutionMenu', () => new SyncResolutionMenu()); // Filters diff --git a/app/assets/javascripts/directives/views/sessionHistoryMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts similarity index 77% rename from app/assets/javascripts/directives/views/sessionHistoryMenu.ts rename to app/assets/javascripts/directives/views/historyMenu.ts index a4baabd35..d9eba473d 100644 --- a/app/assets/javascripts/directives/views/sessionHistoryMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -1,21 +1,22 @@ -import { WebDirective } from './../../types'; +import { WebDirective } from '../../types'; import { WebApplication } from '@/ui_models/application'; -import template from '%/directives/session-history-menu.pug'; +import template from '%/directives/history-menu.pug'; import { SNItem, ItemHistoryEntry, ItemHistory } from '@node_modules/snjs/dist/@types'; +import { PayloadSource } from 'snjs'; -interface SessionHistoryScope { +interface HistoryScope { application: WebApplication item: SNItem } -class SessionHistoryMenuCtrl implements SessionHistoryScope { +class HistoryMenuCtrl implements HistoryScope { $timeout: ng.ITimeoutService diskEnabled = false autoOptimize = false + fetchingServerHistory = false application!: WebApplication item!: SNItem - entries!: ItemHistoryEntry[] history!: ItemHistory /* @ngInject */ @@ -31,12 +32,8 @@ class SessionHistoryMenuCtrl implements SessionHistoryScope { this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled(); } - reloadHistory() { - const history = this.application.historyManager!.historyForItem(this.item); - this.entries = history.entries.slice(0).sort((a, b) => { - return a.payload.updated_at! < b.payload.updated_at! ? 1 : -1; - }); - this.history = history; + async reloadHistory() { + this.history = await this.application.historyManager!.historyForItem(this.item); } openRevision(revision: ItemHistoryEntry) { @@ -93,6 +90,18 @@ class SessionHistoryMenuCtrl implements SessionHistoryScope { ); } + get historySessionEntries() { + return this.history.entries.filter((entry) => { + return entry.payload.source === PayloadSource.SessionHistory; + }); + } + + get historyServerEntries() { + return this.history.entries.filter((entry) => { + return entry.payload.source === PayloadSource.ServerHistory; + }); + } + toggleDiskSaving() { const run = () => { this.application.historyManager!.toggleDiskSaving().then(() => { @@ -125,14 +134,20 @@ class SessionHistoryMenuCtrl implements SessionHistoryScope { }); }); } + + fetchServerHistory() { + this.fetchingServerHistory = true; + this.reloadHistory(); + this.fetchingServerHistory = false; + } } -export class SessionHistoryMenu extends WebDirective { +export class HistoryMenu extends WebDirective { constructor() { super(); this.restrict = 'E'; this.template = template; - this.controller = SessionHistoryMenuCtrl; + this.controller = HistoryMenuCtrl; this.controllerAs = 'ctrl'; this.bindToController = true; this.scope = { diff --git a/app/assets/javascripts/directives/views/index.ts b/app/assets/javascripts/directives/views/index.ts index 1f51d0023..adee8d90c 100644 --- a/app/assets/javascripts/directives/views/index.ts +++ b/app/assets/javascripts/directives/views/index.ts @@ -11,5 +11,5 @@ export { PermissionsModal } from './permissionsModal'; export { PrivilegesAuthModal } from './privilegesAuthModal'; export { PrivilegesManagementModal } from './privilegesManagementModal'; export { RevisionPreviewModal } from './revisionPreviewModal'; -export { SessionHistoryMenu } from './sessionHistoryMenu'; +export { HistoryMenu } from './historyMenu'; export { SyncResolutionMenu } from './syncResolutionMenu'; diff --git a/app/assets/javascripts/views/editor/editor-view.pug b/app/assets/javascripts/views/editor/editor-view.pug index e5ab4338b..20f06047c 100644 --- a/app/assets/javascripts/views/editor/editor-view.pug +++ b/app/assets/javascripts/views/editor/editor-view.pug @@ -183,14 +183,14 @@ application='self.application' ) .sk-app-bar-item( - click-outside=`self.setMenuState('showSessionHistory', false)`, - is-open='self.state.showSessionHistory', - ng-click="self.toggleMenu('showSessionHistory')" + click-outside=`self.setMenuState('showHistory', false)`, + is-open='self.state.showHistory', + ng-click="self.toggleMenu('showHistory')" ) - .sk-label Session History - session-history-menu( + .sk-label History + history-menu( item='self.note', - ng-if='self.state.showSessionHistory', + ng-if='self.state.showHistory', application='self.application' ) #editor-content.editor-content(ng-if='!self.note.errorDecrypting') diff --git a/app/assets/templates/directives/history-menu.pug b/app/assets/templates/directives/history-menu.pug new file mode 100644 index 000000000..80df589b8 --- /dev/null +++ b/app/assets/templates/directives/history-menu.pug @@ -0,0 +1,55 @@ +#history-menu.sn-component + .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 + a.sk-a.info.sk-h5( + ng-click='ctrl.showSessionOptions = !ctrl.showSessionOptions; $event.stopPropagation();' + ) Options + div(ng-if='ctrl.showSessionOptions') + menu-row( + action='ctrl.clearItemHistory()' + label="'Clear note local history'" + ) + menu-row( + action='ctrl.clearAllHistory()' + label="'Clear all local history'" + ) + menu-row( + action='ctrl.toggleAutoOptimize()' + label="(ctrl.autoOptimize ? 'Disable' : 'Enable') + ' auto cleanup'") + .sk-sublabel + | Automatically cleans up small revisions to conserve space. + menu-row( + action='ctrl.toggleDiskSaving()' + label="(ctrl.diskEnabled ? 'Disable' : 'Enable') + ' saving history to disk'" + ) + .sk-sublabel + | 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);' + 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 + a.sk-a.info.sk-h5( + ng-click='ctrl.showServerOptions = !ctrl.showServerOptions; $event.stopPropagation();' + ) Options + div(ng-if='ctrl.showServerOptions') + menu-row( + action='ctrl.fetchServerHistory()' + label="(ctrl.fetchingServerHistory ? 'Refreshing...' : 'Refresh')") + .sk-sublabel + | Fetch history from server. + menu-row( + ng-repeat='revision in ctrl.historyServerEntries track by $index' + action='ctrl.openRevision(revision);' + label='revision.previewTitle()' + ) + .sk-sublabel.opaque(ng-class='ctrl.classForRevision(revision)') + | {{revision.previewSubTitle()}} diff --git a/app/assets/templates/directives/session-history-menu.pug b/app/assets/templates/directives/session-history-menu.pug deleted file mode 100644 index 36788db7a..000000000 --- a/app/assets/templates/directives/session-history-menu.pug +++ /dev/null @@ -1,35 +0,0 @@ -#session-history-menu.sn-component - .sk-menu-panel.dropdown-menu - .sk-menu-panel-header - .sk-menu-panel-header-title {{ctrl.history.entries.length || 'No'}} revisions - a.sk-a.info.sk-h5( - ng-click='ctrl.showOptions = !ctrl.showOptions; $event.stopPropagation();' - ) Options - div(ng-if='ctrl.showOptions') - menu-row( - action='ctrl.clearItemHistory()' - label="'Clear note local history'" - ) - menu-row( - action='ctrl.clearAllHistory()' - label="'Clear all local history'" - ) - menu-row( - action='ctrl.toggleAutoOptimize()' - label="(ctrl.autoOptimize ? 'Disable' : 'Enable') + ' auto cleanup'") - .sk-sublabel - | Automatically cleans up small revisions to conserve space. - menu-row( - action='ctrl.toggleDiskSaving()' - label="(ctrl.diskEnabled ? 'Disable' : 'Enable') + ' saving history to disk'" - ) - .sk-sublabel - | Saving to disk is not recommended. Decreases performance and increases app - | loading time and memory footprint. - menu-row( - ng-repeat='revision in ctrl.entries' - action='ctrl.openRevision(revision);' - label='revision.previewTitle()' - ) - .sk-sublabel.opaque(ng-class='ctrl.classForRevision(revision)') - | {{revision.previewSubTitle()}} From e6d87fa40d07f434507d4113702f83bd1bab7cf9 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Tue, 14 Jul 2020 03:42:50 -0400 Subject: [PATCH 2/8] wip: server history support --- .../directives/views/historyMenu.ts | 91 ++++++++----------- .../templates/directives/history-menu.pug | 2 +- 2 files changed, 40 insertions(+), 53 deletions(-) diff --git a/app/assets/javascripts/directives/views/historyMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts index d9eba473d..77976e75d 100644 --- a/app/assets/javascripts/directives/views/historyMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -14,10 +14,10 @@ class HistoryMenuCtrl implements HistoryScope { $timeout: ng.ITimeoutService diskEnabled = false autoOptimize = false - fetchingServerHistory = false application!: WebApplication item!: SNItem - history!: ItemHistory + sessionHistory?: ItemHistory + serverHistory?: ItemHistory /* @ngInject */ constructor( @@ -28,12 +28,17 @@ class HistoryMenuCtrl implements HistoryScope { $onInit() { this.reloadHistory(); + this.fetchServerHistory(); this.diskEnabled = this.application.historyManager!.isDiskEnabled(); this.autoOptimize = this.application.historyManager!.isAutoOptimizeEnabled(); } - async reloadHistory() { - this.history = await this.application.historyManager!.historyForItem(this.item); + reloadHistory() { + this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item); + } + + async fetchServerHistory() { + this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item); } openRevision(revision: ItemHistoryEntry) { @@ -56,50 +61,40 @@ class HistoryMenuCtrl implements HistoryScope { clearItemHistory() { this.application.alertService!.confirm( - "Are you sure you want to delete the local session history for this note?", - undefined, - undefined, - undefined, - () => { - this.application.historyManager!.clearHistoryForItem(this.item).then(() => { - this.$timeout(() => { - this.reloadHistory(); - }); + "Are you sure you want to delete the local session history for this note?" + ).then((confirmed) => { + if (!confirmed) { + return; + } + this.application.historyManager!.clearHistoryForItem(this.item).then(() => { + this.$timeout(() => { + this.reloadHistory(); }); - }, - undefined, - true, - ); + }); + }); } clearAllHistory() { this.application.alertService!.confirm( - "Are you sure you want to delete the local session history for all notes?", - undefined, - undefined, - undefined, - () => { - this.application.historyManager!.clearAllHistory().then(() => { - this.$timeout(() => { - this.reloadHistory(); - }); + "Are you sure you want to delete the local session history for all notes?" + ).then((confirmed) => { + if (!confirmed) { + return; + } + this.application.historyManager!.clearAllHistory().then(() => { + this.$timeout(() => { + this.reloadHistory(); }); - }, - undefined, - true, - ); + }); + }); } get historySessionEntries() { - return this.history.entries.filter((entry) => { - return entry.payload.source === PayloadSource.SessionHistory; - }); + return this.sessionHistory?.entries; } get historyServerEntries() { - return this.history.entries.filter((entry) => { - return entry.payload.source === PayloadSource.ServerHistory; - }); + return this.serverHistory?.entries } toggleDiskSaving() { @@ -112,16 +107,14 @@ class HistoryMenuCtrl implements HistoryScope { }; if (!this.application.historyManager!.isDiskEnabled()) { this.application.alertService!.confirm( - `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.`, - undefined, - undefined, - undefined, - run, - undefined, - true, - ); + "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." + ).then((confirmed) => { + if (confirmed) { + run(); + } + }); } else { run(); } @@ -134,12 +127,6 @@ class HistoryMenuCtrl implements HistoryScope { }); }); } - - fetchServerHistory() { - this.fetchingServerHistory = true; - this.reloadHistory(); - this.fetchingServerHistory = false; - } } export class HistoryMenu extends WebDirective { diff --git a/app/assets/templates/directives/history-menu.pug b/app/assets/templates/directives/history-menu.pug index 80df589b8..0fd6d5a78 100644 --- a/app/assets/templates/directives/history-menu.pug +++ b/app/assets/templates/directives/history-menu.pug @@ -43,7 +43,7 @@ div(ng-if='ctrl.showServerOptions') menu-row( action='ctrl.fetchServerHistory()' - label="(ctrl.fetchingServerHistory ? 'Refreshing...' : 'Refresh')") + label="'Refresh'") .sk-sublabel | Fetch history from server. menu-row( From 875d4f1fc0c4b7301fd37c92f97a859ba97856c5 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Tue, 14 Jul 2020 10:59:46 -0400 Subject: [PATCH 3/8] fix: alertService.confirm --- .../directives/views/revisionPreviewModal.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/directives/views/revisionPreviewModal.ts b/app/assets/javascripts/directives/views/revisionPreviewModal.ts index 931160dcd..99f11cacf 100644 --- a/app/assets/javascripts/directives/views/revisionPreviewModal.ts +++ b/app/assets/javascripts/directives/views/revisionPreviewModal.ts @@ -110,14 +110,12 @@ class RevisionPreviewModalCtrl implements RevisionPreviewScope { if (!asCopy) { this.application.alertService!.confirm( - "Are you sure you want to replace the current note's contents with what you see in this preview?", - undefined, - undefined, - undefined, - run, - undefined, - true, - ); + "Are you sure you want to replace the current note's contents with what you see in this preview?" + ).then((confirmed) => { + if (confirmed) { + run(); + } + }); } else { run(); } From 9d8f6a316744e5b4328748a143a6e361b903bc3c Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Thu, 16 Jul 2020 02:25:40 -0400 Subject: [PATCH 4/8] wip: server history support --- .../directives/views/historyMenu.ts | 25 +++++++++++++++---- .../templates/directives/history-menu.pug | 4 ++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/directives/views/historyMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts index 77976e75d..fcbc50a67 100644 --- a/app/assets/javascripts/directives/views/historyMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -2,16 +2,15 @@ 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 { PayloadSource } from 'snjs'; +import { PureViewCtrl } from '@/views'; interface HistoryScope { application: WebApplication item: SNItem } -class HistoryMenuCtrl implements HistoryScope { +class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope { - $timeout: ng.ITimeoutService diskEnabled = false autoOptimize = false application!: WebApplication @@ -23,10 +22,14 @@ class HistoryMenuCtrl implements HistoryScope { constructor( $timeout: ng.ITimeoutService ) { - this.$timeout = $timeout; + super($timeout); + this.state = { + fetchingServerHistory: false + }; } $onInit() { + super.$onInit(); this.reloadHistory(); this.fetchServerHistory(); this.diskEnabled = this.application.historyManager!.isDiskEnabled(); @@ -37,8 +40,20 @@ class HistoryMenuCtrl implements HistoryScope { this.sessionHistory = this.application.historyManager!.sessionHistoryForItem(this.item); } + get isFetchingServerHistory() { + return this.state.fetchingServerHistory; + } + async fetchServerHistory() { - this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item); + this.setState({ + fetchingServerHistory: true + }); + this.serverHistory = await this.application.historyManager!.serverHistoryForItem(this.item) + .finally(() => { + this.setState({ + fetchingServerHistory: false + }); + }); } openRevision(revision: ItemHistoryEntry) { diff --git a/app/assets/templates/directives/history-menu.pug b/app/assets/templates/directives/history-menu.pug index 0fd6d5a78..e6be80da4 100644 --- a/app/assets/templates/directives/history-menu.pug +++ b/app/assets/templates/directives/history-menu.pug @@ -43,7 +43,9 @@ div(ng-if='ctrl.showServerOptions') menu-row( action='ctrl.fetchServerHistory()' - label="'Refresh'") + label="'Refresh'" + disabled="ctrl.isFetchingServerHistory" + spinner-class="ctrl.isFetchingServerHistory ? 'info' : null") .sk-sublabel | Fetch history from server. menu-row( From ef651298e378669933f0e5a59c7e356b26852a30 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Thu, 13 Aug 2020 12:47:14 -0400 Subject: [PATCH 5/8] wip: server history support --- .../directives/views/historyMenu.ts | 54 +++++++++++++------ .../templates/directives/history-menu.pug | 28 +++++----- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/app/assets/javascripts/directives/views/historyMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts index fcbc50a67..88936c7c0 100644 --- a/app/assets/javascripts/directives/views/historyMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -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 { diff --git a/app/assets/templates/directives/history-menu.pug b/app/assets/templates/directives/history-menu.pug index e6be80da4..dbc9334b0 100644 --- a/app/assets/templates/directives/history-menu.pug +++ b/app/assets/templates/directives/history-menu.pug @@ -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()}} From ee49d80cebe89ccdebf8a121963fff10c20a4239 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Thu, 13 Aug 2020 13:10:52 -0400 Subject: [PATCH 6/8] fix: use confirmDialog --- .../directives/views/historyMenu.ts | 24 +++++++++++-------- .../directives/views/revisionPreviewModal.ts | 8 ++++--- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/directives/views/historyMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts index 88936c7c0..a2b83f68f 100644 --- a/app/assets/javascripts/directives/views/historyMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -5,6 +5,7 @@ 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'; interface HistoryScope { application: WebApplication @@ -90,9 +91,10 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope { } clearItemHistory() { - this.application.alertService!.confirm( - "Are you sure you want to delete the local session history for this note?" - ).then((confirmed) => { + confirmDialog({ + text: "Are you sure you want to delete the local session history for this note?", + confirmButtonStyle: "danger" + }).then((confirmed) => { if (!confirmed) { return; } @@ -105,9 +107,10 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope { } clearAllHistory() { - this.application.alertService!.confirm( - "Are you sure you want to delete the local session history for all notes?" - ).then((confirmed) => { + confirmDialog({ + text: "Are you sure you want to delete the local session history for all notes?", + confirmButtonStyle: "danger" + }).then((confirmed) => { if (!confirmed) { return; } @@ -136,11 +139,12 @@ class HistoryMenuCtrl extends PureViewCtrl implements HistoryScope { }); }; if (!this.application.historyManager!.isDiskEnabled()) { - this.application.alertService!.confirm( - "Are you sure you want to save history to disk? This will decrease general " + + 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." - ).then((confirmed) => { + "if you experience any lagging.", + confirmButtonStyle: "danger" + }).then((confirmed) => { if (confirmed) { run(); } diff --git a/app/assets/javascripts/directives/views/revisionPreviewModal.ts b/app/assets/javascripts/directives/views/revisionPreviewModal.ts index 99f11cacf..d98ed71c3 100644 --- a/app/assets/javascripts/directives/views/revisionPreviewModal.ts +++ b/app/assets/javascripts/directives/views/revisionPreviewModal.ts @@ -9,6 +9,7 @@ import { } from 'snjs'; import template from '%/directives/revision-preview-modal.pug'; import { PayloadContent } from '@node_modules/snjs/dist/@types/protocol/payloads/generator'; +import { confirmDialog } from '@/services/alertService'; interface RevisionPreviewScope { uuid: string @@ -109,9 +110,10 @@ class RevisionPreviewModalCtrl implements RevisionPreviewScope { }; if (!asCopy) { - this.application.alertService!.confirm( - "Are you sure you want to replace the current note's contents with what you see in this preview?" - ).then((confirmed) => { + confirmDialog({ + text: "Are you sure you want to replace the current note's contents with what you see in this preview?", + confirmButtonStyle: "danger" + }).then((confirmed) => { if (confirmed) { run(); } From 07bbd0e6b22c4d9bf34a374bf1588c73ced0cb75 Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Fri, 14 Aug 2020 11:12:41 -0400 Subject: [PATCH 7/8] fix: rename session related functions --- .../directives/views/historyMenu.ts | 43 +++++++++++-------- .../templates/directives/history-menu.pug | 12 +++--- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/directives/views/historyMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts index a2b83f68f..21f3d277c 100644 --- a/app/assets/javascripts/directives/views/historyMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -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(); } diff --git a/app/assets/templates/directives/history-menu.pug b/app/assets/templates/directives/history-menu.pug index dbc9334b0..0a8bcacb7 100644 --- a/app/assets/templates/directives/history-menu.pug +++ b/app/assets/templates/directives/history-menu.pug @@ -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);' ) From 39f3fb930e4ce4e9c29a9960eeaaeb7c76e7886c Mon Sep 17 00:00:00 2001 From: Johnny Almonte Date: Fri, 14 Aug 2020 11:16:13 -0400 Subject: [PATCH 8/8] fix: not necessary to check for undefined --- app/assets/javascripts/directives/views/historyMenu.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/directives/views/historyMenu.ts b/app/assets/javascripts/directives/views/historyMenu.ts index 21f3d277c..c33c01efb 100644 --- a/app/assets/javascripts/directives/views/historyMenu.ts +++ b/app/assets/javascripts/directives/views/historyMenu.ts @@ -81,8 +81,8 @@ class HistoryMenuCtrl extends PureViewCtrl<{}, HistoryState> implements HistoryS return; } this.application.presentRevisionPreviewModal( - remoteRevision!.payload.uuid, - remoteRevision!.payload.content + remoteRevision.payload.uuid, + remoteRevision.payload.content ); }