refactor: rename note controller to note view controller

This commit is contained in:
Mo
2021-12-27 22:56:21 -06:00
parent 15aea42d4f
commit 0eeb9b7da1
13 changed files with 55 additions and 55 deletions

View File

@@ -0,0 +1,14 @@
.h-full
multiple-selected-notes-panel.h-full(
application='self.application'
app-state='self.appState'
ng-if='self.state.showMultipleSelectedNotes'
)
.flex-grow.h-full(
ng-if='!self.state.showMultipleSelectedNotes'
ng-repeat='controller in self.controllers'
)
note-view(
application='self.application'
controller='controller'
)

View File

@@ -0,0 +1,84 @@
import { removeFromArray, UuidString } from '@standardnotes/snjs';
import { NoteViewController } from '@/views/note_view/note_view_controller';
import { WebApplication } from '@/ui_models/application';
type NoteControllerGroupChangeCallback = () => void;
export class NoteGroupController {
public noteControllers: NoteViewController[] = [];
private application: WebApplication;
changeObservers: NoteControllerGroupChangeCallback[] = [];
constructor(application: WebApplication) {
this.application = application;
}
public deinit() {
(this.application as unknown) = undefined;
for (const controller of this.noteControllers) {
this.deleteNoteView(controller);
}
}
async createNoteView(
noteUuid?: string,
noteTitle?: string,
noteTag?: UuidString
) {
const controller = new NoteViewController(
this.application,
noteUuid,
noteTitle,
noteTag
);
await controller.initialize();
this.noteControllers.push(controller);
this.notifyObservers();
}
deleteNoteView(controller: NoteViewController) {
controller.deinit();
removeFromArray(this.noteControllers, controller);
}
closeNoteView(controller: NoteViewController) {
this.deleteNoteView(controller);
this.notifyObservers();
}
closeActiveNoteView() {
const activeController = this.activeNoteViewController;
if (activeController) {
this.deleteNoteView(activeController);
}
}
closeAllNoteViews() {
for (const controller of this.noteControllers) {
this.deleteNoteView(controller);
}
}
get activeNoteViewController() {
return this.noteControllers[0];
}
/**
* Notifies observer when the active controller has changed.
*/
public addChangeObserver(callback: NoteControllerGroupChangeCallback) {
this.changeObservers.push(callback);
if (this.activeNoteViewController) {
callback();
}
return () => {
removeFromArray(this.changeObservers, callback);
};
}
private notifyObservers() {
for (const observer of this.changeObservers) {
observer();
}
}
}

View File

@@ -0,0 +1,45 @@
import { WebDirective } from './../../types';
import template from './note-group-view.pug';
import { NoteViewController } from '@/views/note_view/note_view_controller';
import { PureViewCtrl } from '../abstract/pure_view_ctrl';
class NoteGroupView extends PureViewCtrl<
unknown,
{
showMultipleSelectedNotes: boolean;
}
> {
public controllers: NoteViewController[] = [];
/* @ngInject */
constructor($timeout: ng.ITimeoutService) {
super($timeout);
this.state = {
showMultipleSelectedNotes: false,
};
}
$onInit() {
this.application.noteControllerGroup.addChangeObserver(() => {
this.controllers = this.application.noteControllerGroup.noteControllers;
});
this.autorun(() => {
this.setState({
showMultipleSelectedNotes: this.appState.notes.selectedNotesCount > 1,
});
});
}
}
export class NoteGroupViewDirective extends WebDirective {
constructor() {
super();
this.template = template;
this.controller = NoteGroupView;
this.controllerAs = 'self';
this.bindToController = true;
this.scope = {
application: '=',
};
}
}