From 0eeb9b7da11b98c89d785c97040975fd76c5b959 Mon Sep 17 00:00:00 2001 From: Mo Date: Mon, 27 Dec 2021 22:56:21 -0600 Subject: [PATCH] refactor: rename note controller to note view controller --- app/assets/javascripts/app.ts | 8 ++--- .../ui_models/app_state/app_state.ts | 12 +++---- .../ui_models/app_state/notes_state.ts | 8 ++--- .../javascripts/ui_models/application.ts | 6 ++-- .../views/application/application-view.pug | 2 +- app/assets/javascripts/views/index.ts | 4 +-- .../note-group-view.pug} | 2 +- .../note_group_view/note_group_controller.ts} | 34 +++++++++---------- .../note_group_view.ts} | 12 +++---- .../note-view.pug} | 0 .../note_view.test.ts} | 6 ++-- .../editor_view.ts => note_view/note_view.ts} | 12 +++---- .../note_view/note_view_controller.ts} | 4 +-- 13 files changed, 55 insertions(+), 55 deletions(-) rename app/assets/javascripts/views/{editor_group/editor-group-view.pug => note_group_view/note-group-view.pug} (95%) rename app/assets/javascripts/{ui_models/note_controller_group.ts => views/note_group_view/note_group_controller.ts} (65%) rename app/assets/javascripts/views/{editor_group/editor_group_view.ts => note_group_view/note_group_view.ts} (72%) rename app/assets/javascripts/views/{editor/editor-view.pug => note_view/note-view.pug} (100%) rename app/assets/javascripts/views/{editor/editor_view.test.ts => note_view/note_view.test.ts} (97%) rename app/assets/javascripts/views/{editor/editor_view.ts => note_view/note_view.ts} (99%) rename app/assets/javascripts/{ui_models/note_controller.ts => views/note_view/note_view_controller.ts} (96%) diff --git a/app/assets/javascripts/app.ts b/app/assets/javascripts/app.ts index 05b5dbd3dcf..039f62df91c 100644 --- a/app/assets/javascripts/app.ts +++ b/app/assets/javascripts/app.ts @@ -30,8 +30,8 @@ import { AccountSwitcher } from './views/account_switcher/account_switcher'; import { ApplicationGroupView, ApplicationView, - EditorGroupView, - EditorView, + NoteGroupViewDirective, + NoteViewDirective, TagsView, FooterView, ChallengeModal, @@ -141,8 +141,8 @@ const startApplication: StartApplication = async function startApplication( .module('app') .directive('applicationGroupView', () => new ApplicationGroupView()) .directive('applicationView', () => new ApplicationView()) - .directive('editorGroupView', () => new EditorGroupView()) - .directive('editorView', () => new EditorView()) + .directive('noteGroupView', () => new NoteGroupViewDirective()) + .directive('noteView', () => new NoteViewDirective()) .directive('tagsView', () => new TagsView()) .directive('footerView', () => new FooterView()); diff --git a/app/assets/javascripts/ui_models/app_state/app_state.ts b/app/assets/javascripts/ui_models/app_state/app_state.ts index e413c29223a..642d9f8c08b 100644 --- a/app/assets/javascripts/ui_models/app_state/app_state.ts +++ b/app/assets/javascripts/ui_models/app_state/app_state.ts @@ -2,7 +2,7 @@ import { Bridge } from '@/services/bridge'; import { storage, StorageKey } from '@/services/localStorage'; import { WebApplication } from '@/ui_models/application'; import { AccountMenuState } from '@/ui_models/app_state/account_menu_state'; -import { NoteController } from '@/ui_models/note_controller'; +import { NoteViewController } from '@/views/note_view/note_view_controller'; import { isDesktopApplication } from '@/utils'; import { ApplicationEvent, @@ -236,7 +236,7 @@ export class AppState { : this.selectedTag.uuid : undefined; - await this.application.noteControllerGroup.createNoteController( + await this.application.noteControllerGroup.createNoteView( undefined, title, activeTagUuid @@ -251,16 +251,16 @@ export class AppState { return this.application.noteControllerGroup.noteControllers; } - closeNoteController(controller: NoteController) { - this.application.noteControllerGroup.closeController(controller); + closeNoteController(controller: NoteViewController) { + this.application.noteControllerGroup.closeNoteView(controller); } closeActiveNoteController() { - this.application.noteControllerGroup.closeActiveController(); + this.application.noteControllerGroup.closeActiveNoteView(); } closeAllNoteControllers() { - this.application.noteControllerGroup.closeAllControllers(); + this.application.noteControllerGroup.closeAllNoteViews(); } noteControllerForNote(note: SNNote) { diff --git a/app/assets/javascripts/ui_models/app_state/notes_state.ts b/app/assets/javascripts/ui_models/app_state/notes_state.ts index 05859a37660..44dda28e180 100644 --- a/app/assets/javascripts/ui_models/app_state/notes_state.ts +++ b/app/assets/javascripts/ui_models/app_state/notes_state.ts @@ -17,7 +17,7 @@ import { runInAction, } from 'mobx'; import { WebApplication } from '../application'; -import { NoteController } from '../note_controller'; +import { NoteViewController } from '@/views/note_view/note_view_controller'; import { AppState } from './app_state'; export class NotesState { @@ -68,7 +68,7 @@ export class NotesState { ); } - get activeNoteController(): NoteController | undefined { + get activeNoteController(): NoteViewController | undefined { return this.application.noteControllerGroup.noteControllers[0]; } @@ -168,10 +168,10 @@ export class NotesState { } if (this.activeNoteController) { - this.application.noteControllerGroup.closeActiveController(); + this.application.noteControllerGroup.closeActiveNoteView(); } - await this.application.noteControllerGroup.createNoteController(noteUuid); + await this.application.noteControllerGroup.createNoteView(noteUuid); this.appState.noteTags.reloadTags(); await this.onActiveEditorChanged(); diff --git a/app/assets/javascripts/ui_models/application.ts b/app/assets/javascripts/ui_models/application.ts index 5a9ac004d7f..d574a938b55 100644 --- a/app/assets/javascripts/ui_models/application.ts +++ b/app/assets/javascripts/ui_models/application.ts @@ -10,7 +10,7 @@ import { StatusManager } from '@/services/statusManager'; import { ThemeManager } from '@/services/themeManager'; import { PasswordWizardScope, PasswordWizardType } from '@/types'; import { AppState } from '@/ui_models/app_state'; -import { NoteControllerGroup } from '@/ui_models/note_controller_group'; +import { NoteGroupController } from '@/views/note_group_view/note_group_controller'; import { AppVersion } from '@/version'; import { WebDeviceInterface } from '@/web_device_interface'; import { @@ -36,7 +36,7 @@ export class WebApplication extends SNApplication { private scope?: angular.IScope; private webServices!: WebServices; private currentAuthenticationElement?: angular.IRootElementService; - public noteControllerGroup: NoteControllerGroup; + public noteControllerGroup: NoteGroupController; /* @ngInject */ constructor( @@ -66,7 +66,7 @@ export class WebApplication extends SNApplication { this.$compile = $compile; this.scope = scope; deviceInterface.setApplication(this); - this.noteControllerGroup = new NoteControllerGroup(this); + this.noteControllerGroup = new NoteGroupController(this); this.presentPermissionsDialog = this.presentPermissionsDialog.bind(this); } diff --git a/app/assets/javascripts/views/application/application-view.pug b/app/assets/javascripts/views/application/application-view.pug index e39519b6c42..01630f2b565 100644 --- a/app/assets/javascripts/views/application/application-view.pug +++ b/app/assets/javascripts/views/application/application-view.pug @@ -10,7 +10,7 @@ application='self.application' app-state='self.appState' ) - editor-group-view.flex-grow(application='self.application') + note-group-view.flex-grow(application='self.application') footer-view( ng-if='!self.state.needsUnlock && self.state.launched' diff --git a/app/assets/javascripts/views/index.ts b/app/assets/javascripts/views/index.ts index a68bf862dcb..82223ae4cea 100644 --- a/app/assets/javascripts/views/index.ts +++ b/app/assets/javascripts/views/index.ts @@ -1,8 +1,8 @@ export { PureViewCtrl } from './abstract/pure_view_ctrl'; export { ApplicationGroupView } from './application_group/application_group_view'; export { ApplicationView } from './application/application_view'; -export { EditorGroupView } from './editor_group/editor_group_view'; -export { EditorView } from './editor/editor_view'; +export { NoteGroupViewDirective } from './note_group_view/note_group_view'; +export { NoteViewDirective } from './note_view/note_view'; export { FooterView } from './footer/footer_view'; export { TagsView } from './tags/tags_view'; export { ChallengeModal } from './challenge_modal/challenge_modal'; diff --git a/app/assets/javascripts/views/editor_group/editor-group-view.pug b/app/assets/javascripts/views/note_group_view/note-group-view.pug similarity index 95% rename from app/assets/javascripts/views/editor_group/editor-group-view.pug rename to app/assets/javascripts/views/note_group_view/note-group-view.pug index de3ed6773da..4baafa105ed 100644 --- a/app/assets/javascripts/views/editor_group/editor-group-view.pug +++ b/app/assets/javascripts/views/note_group_view/note-group-view.pug @@ -8,7 +8,7 @@ ng-if='!self.state.showMultipleSelectedNotes' ng-repeat='controller in self.controllers' ) - editor-view( + note-view( application='self.application' controller='controller' ) diff --git a/app/assets/javascripts/ui_models/note_controller_group.ts b/app/assets/javascripts/views/note_group_view/note_group_controller.ts similarity index 65% rename from app/assets/javascripts/ui_models/note_controller_group.ts rename to app/assets/javascripts/views/note_group_view/note_group_controller.ts index a30c82898f2..c625fc47cfc 100644 --- a/app/assets/javascripts/ui_models/note_controller_group.ts +++ b/app/assets/javascripts/views/note_group_view/note_group_controller.ts @@ -1,11 +1,11 @@ import { removeFromArray, UuidString } from '@standardnotes/snjs'; -import { NoteController } from './note_controller'; -import { WebApplication } from './application'; +import { NoteViewController } from '@/views/note_view/note_view_controller'; +import { WebApplication } from '@/ui_models/application'; type NoteControllerGroupChangeCallback = () => void; -export class NoteControllerGroup { - public noteControllers: NoteController[] = []; +export class NoteGroupController { + public noteControllers: NoteViewController[] = []; private application: WebApplication; changeObservers: NoteControllerGroupChangeCallback[] = []; @@ -16,16 +16,16 @@ export class NoteControllerGroup { public deinit() { (this.application as unknown) = undefined; for (const controller of this.noteControllers) { - this.deleteController(controller); + this.deleteNoteView(controller); } } - async createNoteController( + async createNoteView( noteUuid?: string, noteTitle?: string, noteTag?: UuidString ) { - const controller = new NoteController( + const controller = new NoteViewController( this.application, noteUuid, noteTitle, @@ -36,30 +36,30 @@ export class NoteControllerGroup { this.notifyObservers(); } - deleteController(controller: NoteController) { + deleteNoteView(controller: NoteViewController) { controller.deinit(); removeFromArray(this.noteControllers, controller); } - closeController(controller: NoteController) { - this.deleteController(controller); + closeNoteView(controller: NoteViewController) { + this.deleteNoteView(controller); this.notifyObservers(); } - closeActiveController() { - const activeController = this.activeNoteController; + closeActiveNoteView() { + const activeController = this.activeNoteViewController; if (activeController) { - this.deleteController(activeController); + this.deleteNoteView(activeController); } } - closeAllControllers() { + closeAllNoteViews() { for (const controller of this.noteControllers) { - this.deleteController(controller); + this.deleteNoteView(controller); } } - get activeNoteController() { + get activeNoteViewController() { return this.noteControllers[0]; } @@ -68,7 +68,7 @@ export class NoteControllerGroup { */ public addChangeObserver(callback: NoteControllerGroupChangeCallback) { this.changeObservers.push(callback); - if (this.activeNoteController) { + if (this.activeNoteViewController) { callback(); } return () => { diff --git a/app/assets/javascripts/views/editor_group/editor_group_view.ts b/app/assets/javascripts/views/note_group_view/note_group_view.ts similarity index 72% rename from app/assets/javascripts/views/editor_group/editor_group_view.ts rename to app/assets/javascripts/views/note_group_view/note_group_view.ts index 4b056b12102..8d598d1aa2b 100644 --- a/app/assets/javascripts/views/editor_group/editor_group_view.ts +++ b/app/assets/javascripts/views/note_group_view/note_group_view.ts @@ -1,15 +1,15 @@ import { WebDirective } from './../../types'; -import template from './editor-group-view.pug'; -import { NoteController } from '@/ui_models/note_controller'; +import template from './note-group-view.pug'; +import { NoteViewController } from '@/views/note_view/note_view_controller'; import { PureViewCtrl } from '../abstract/pure_view_ctrl'; -class EditorGroupViewCtrl extends PureViewCtrl< +class NoteGroupView extends PureViewCtrl< unknown, { showMultipleSelectedNotes: boolean; } > { - public controllers: NoteController[] = []; + public controllers: NoteViewController[] = []; /* @ngInject */ constructor($timeout: ng.ITimeoutService) { @@ -31,11 +31,11 @@ class EditorGroupViewCtrl extends PureViewCtrl< } } -export class EditorGroupView extends WebDirective { +export class NoteGroupViewDirective extends WebDirective { constructor() { super(); this.template = template; - this.controller = EditorGroupViewCtrl; + this.controller = NoteGroupView; this.controllerAs = 'self'; this.bindToController = true; this.scope = { diff --git a/app/assets/javascripts/views/editor/editor-view.pug b/app/assets/javascripts/views/note_view/note-view.pug similarity index 100% rename from app/assets/javascripts/views/editor/editor-view.pug rename to app/assets/javascripts/views/note_view/note-view.pug diff --git a/app/assets/javascripts/views/editor/editor_view.test.ts b/app/assets/javascripts/views/note_view/note_view.test.ts similarity index 97% rename from app/assets/javascripts/views/editor/editor_view.test.ts rename to app/assets/javascripts/views/note_view/note_view.test.ts index d70a3c9d082..c930668540d 100644 --- a/app/assets/javascripts/views/editor/editor_view.test.ts +++ b/app/assets/javascripts/views/note_view/note_view.test.ts @@ -2,19 +2,19 @@ * @jest-environment jsdom */ -import { EditorViewCtrl } from '@Views/editor/editor_view'; +import { NoteView } from '@Views/note_view/note_view'; import { ApplicationEvent, ProposedSecondsToDeferUILevelSessionExpirationDuringActiveInteraction, } from '@standardnotes/snjs/'; describe('editor-view', () => { - let ctrl: EditorViewCtrl; + let ctrl: NoteView; let setShowProtectedWarningSpy: jest.SpyInstance; beforeEach(() => { const $timeout = {} as jest.Mocked; - ctrl = new EditorViewCtrl($timeout); + ctrl = new NoteView($timeout); setShowProtectedWarningSpy = jest.spyOn(ctrl, 'setShowProtectedOverlay'); diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/note_view/note_view.ts similarity index 99% rename from app/assets/javascripts/views/editor/editor_view.ts rename to app/assets/javascripts/views/note_view/note_view.ts index 247ffab7606..cd385760566 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/note_view/note_view.ts @@ -1,5 +1,5 @@ import { STRING_SAVING_WHILE_DOCUMENT_HIDDEN } from './../../strings'; -import { NoteController } from '@/ui_models/note_controller'; +import { NoteViewController } from '@/views/note_view/note_view_controller'; import { WebApplication } from '@/ui_models/application'; import { PanelPuppet, WebDirective } from '@/types'; import angular from 'angular'; @@ -23,7 +23,7 @@ import { } from '@standardnotes/snjs'; import { debounce, isDesktopApplication } from '@/utils'; import { KeyboardModifier, KeyboardKey } from '@/services/ioService'; -import template from './editor-view.pug'; +import template from './note-view.pug'; import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl'; import { EventSource } from '@/ui_models/app_state'; import { @@ -90,10 +90,10 @@ function sortAlphabetically(array: SNComponent[]): SNComponent[] { ); } -export class EditorViewCtrl extends PureViewCtrl { +export class NoteView extends PureViewCtrl { /** Passed through template */ readonly application!: WebApplication; - readonly controller!: NoteController; + readonly controller!: NoteViewController; private leftPanelPuppet?: PanelPuppet; private rightPanelPuppet?: PanelPuppet; @@ -1039,7 +1039,7 @@ export class EditorViewCtrl extends PureViewCtrl { } } -export class EditorView extends WebDirective { +export class NoteViewDirective extends WebDirective { constructor() { super(); this.restrict = 'E'; @@ -1049,7 +1049,7 @@ export class EditorView extends WebDirective { }; this.template = template; this.replace = true; - this.controller = EditorViewCtrl; + this.controller = NoteView; this.controllerAs = 'self'; this.bindToController = true; } diff --git a/app/assets/javascripts/ui_models/note_controller.ts b/app/assets/javascripts/views/note_view/note_view_controller.ts similarity index 96% rename from app/assets/javascripts/ui_models/note_controller.ts rename to app/assets/javascripts/views/note_view/note_view_controller.ts index f904cb275fe..5b6a81d14a6 100644 --- a/app/assets/javascripts/ui_models/note_controller.ts +++ b/app/assets/javascripts/views/note_view/note_view_controller.ts @@ -5,9 +5,9 @@ import { UuidString, SNTag, } from '@standardnotes/snjs'; -import { WebApplication } from './application'; +import { WebApplication } from '@/ui_models/application'; -export class NoteController { +export class NoteViewController { public note!: SNNote; private application: WebApplication; private onNoteValueChange?: (note: SNNote, source: PayloadSource) => void;