chore: rename editor model to note controller

This commit is contained in:
Mo
2021-12-27 18:46:56 -06:00
parent 54e5fc9184
commit 15aea42d4f
12 changed files with 184 additions and 182 deletions

View File

@@ -114,7 +114,7 @@
component-view.component-view(
component-viewer='self.state.editorComponentViewer',
ng-if='self.state.editorComponentViewer',
on-load='self.onEditorLoad',
on-load='self.onEditorComponentLoad',
request-reload='self.editorComponentViewerRequestsReload'
application='self.application'
app-state='self.appState'

View File

@@ -1,5 +1,5 @@
import { STRING_SAVING_WHILE_DOCUMENT_HIDDEN } from './../../strings';
import { Editor } from '@/ui_models/editor';
import { NoteController } from '@/ui_models/note_controller';
import { WebApplication } from '@/ui_models/application';
import { PanelPuppet, WebDirective } from '@/types';
import angular from 'angular';
@@ -93,7 +93,7 @@ function sortAlphabetically(array: SNComponent[]): SNComponent[] {
export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
/** Passed through template */
readonly application!: WebApplication;
readonly editor!: Editor;
readonly controller!: NoteController;
private leftPanelPuppet?: PanelPuppet;
private rightPanelPuppet?: PanelPuppet;
@@ -101,7 +101,7 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
private statusTimeout?: ng.IPromise<void>;
private lastEditorFocusEventSource?: EventSource;
public editorValues: EditorValues = { title: '', text: '' };
onEditorLoad?: () => void;
onEditorComponentLoad?: () => void;
private scrollPosition = 0;
private removeTrashKeyObserver?: () => void;
@@ -127,7 +127,7 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.resetScrollPosition = this.resetScrollPosition.bind(this);
this.editorComponentViewerRequestsReload =
this.editorComponentViewerRequestsReload.bind(this);
this.onEditorLoad = () => {
this.onEditorComponentLoad = () => {
this.application.getDesktopService().redoSearch();
};
this.debounceReloadEditorComponent = debounce(
@@ -148,7 +148,7 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.removeTabObserver = undefined;
this.leftPanelPuppet = undefined;
this.rightPanelPuppet = undefined;
this.onEditorLoad = undefined;
this.onEditorComponentLoad = undefined;
this.saveTimeout = undefined;
this.statusTimeout = undefined;
(this.onPanelResizeFinish as unknown) = undefined;
@@ -161,14 +161,14 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
}
get note() {
return this.editor.note;
return this.controller.note;
}
$onInit() {
super.$onInit();
this.registerKeyboardShortcuts();
this.editor.setOnNoteValueChange((note, source) => {
this.onNoteChanges(note, source);
this.controller.setOnNoteInnerValueChange((note, source) => {
this.onNoteInnerChange(note, source);
});
this.autorun(() => {
this.setState({
@@ -184,14 +184,14 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.reloadPreferences();
if (this.editor.isTemplateNote) {
if (this.controller.isTemplateNote) {
this.$timeout(() => {
this.focusTitle();
});
}
}
private onNoteChanges(note: SNNote, source: PayloadSource): void {
private onNoteInnerChange(note: SNNote, source: PayloadSource): void {
if (note.uuid !== this.note.uuid) {
throw Error('Editor received changes for non-current note');
}
@@ -423,8 +423,8 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.note
);
/** Editors cannot interact with template notes so the note must be inserted */
if (newEditor && this.editor.isTemplateNote) {
await this.editor.insertTemplatedNote();
if (newEditor && this.controller.isTemplateNote) {
await this.controller.insertTemplatedNote();
this.associateComponentWithCurrentNote(newEditor);
}
const currentComponentViewer = this.state.editorComponentViewer;
@@ -479,8 +479,8 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
const transactions: TransactionalMutation[] = [];
this.setMenuState('showEditorMenu', false);
if (this.appState.getActiveEditor()?.isTemplateNote) {
await this.appState.getActiveEditor().insertTemplatedNote();
if (this.appState.getActiveNoteController()?.isTemplateNote) {
await this.appState.getActiveNoteController().insertTemplatedNote();
}
if (this.note.locked) {
this.application.alertService.alert(STRING_EDIT_LOCKED_ATTEMPT);
@@ -566,7 +566,7 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
) {
const title = editorValues.title;
const text = editorValues.text;
const isTemplate = this.editor.isTemplateNote;
const isTemplate = this.controller.isTemplateNote;
if (document.hidden) {
this.application.alertService.alert(STRING_SAVING_WHILE_DOCUMENT_HIDDEN);
return;
@@ -576,7 +576,7 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
return;
}
if (isTemplate) {
await this.editor.insertTemplatedNote();
await this.controller.insertTemplatedNote();
}
if (!this.application.findItem(note.uuid)) {
this.application.alertService.alert(STRING_INVALID_NOTE);
@@ -614,7 +614,7 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.saveTimeout = this.$timeout(() => {
this.application.sync();
if (closeAfterSync) {
this.appState.closeEditor(this.editor);
this.appState.closeNoteController(this.controller);
}
}, syncDebouceMs);
}
@@ -719,7 +719,7 @@ export class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
}
async deleteNote(permanently: boolean) {
if (this.editor.isTemplateNote) {
if (this.controller.isTemplateNote) {
this.application.alertService.alert(STRING_DELETE_PLACEHOLDER_ATTEMPT);
return;
}
@@ -1044,7 +1044,7 @@ export class EditorView extends WebDirective {
super();
this.restrict = 'E';
this.scope = {
editor: '=',
controller: '=',
application: '=',
};
this.template = template;

View File

@@ -6,9 +6,9 @@
)
.flex-grow.h-full(
ng-if='!self.state.showMultipleSelectedNotes'
ng-repeat='editor in self.editors'
ng-repeat='controller in self.controllers'
)
editor-view(
application='self.application'
editor='editor'
controller='controller'
)

View File

@@ -1,29 +1,31 @@
import { WebDirective } from './../../types';
import template from './editor-group-view.pug';
import { Editor } from '@/ui_models/editor';
import { NoteController } from '@/ui_models/note_controller';
import { PureViewCtrl } from '../abstract/pure_view_ctrl';
class EditorGroupViewCtrl extends PureViewCtrl<unknown, {
showMultipleSelectedNotes: boolean
}> {
public editors: Editor[] = []
class EditorGroupViewCtrl extends PureViewCtrl<
unknown,
{
showMultipleSelectedNotes: boolean;
}
> {
public controllers: NoteController[] = [];
/* @ngInject */
constructor($timeout: ng.ITimeoutService,) {
constructor($timeout: ng.ITimeoutService) {
super($timeout);
this.state = {
showMultipleSelectedNotes: false
showMultipleSelectedNotes: false,
};
}
$onInit() {
this.application.editorGroup.addChangeObserver(() => {
this.editors = this.application.editorGroup.editors;
this.application.noteControllerGroup.addChangeObserver(() => {
this.controllers = this.application.noteControllerGroup.noteControllers;
});
this.autorun(() => {
this.setState({
showMultipleSelectedNotes: this.appState.notes.selectedNotesCount > 1
showMultipleSelectedNotes: this.appState.notes.selectedNotesCount > 1,
});
});
}
@@ -37,7 +39,7 @@ export class EditorGroupView extends WebDirective {
this.controllerAs = 'self';
this.bindToController = true;
this.scope = {
application: '='
application: '=',
};
}
}