Skip to content

Commit

Permalink
Merge pull request #571 from TomoyukiAota/feature/extract-plm-interna…
Browse files Browse the repository at this point in the history
…l-renderer-service

Extract PlmInternalRendererService.
  • Loading branch information
mergify[bot] authored Nov 29, 2024
2 parents 370531c + 1f750d8 commit f1f6675
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 112 deletions.
118 changes: 6 additions & 112 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
import { AfterViewInit, Component, NgZone, OnDestroy, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Logger } from '../../src-shared/log/logger';
import {
PlmInternalRenderer,
PlmInternalRendererAboutBox,
PlmInternalRendererPhotoSelection,
PlmInternalRendererRecordAtAppLaunch,
PlmInternalRendererSettingsDialog,
PlmInternalRendererWelcomeDialog
} from '../global-variables/global-variable-for-internal-use-in-renderer';
import { AboutBoxComponent } from './about-box/about-box.component';
import { DirectoryTreeViewSelectionService } from './directory-tree-view/directory-tree-view-selection.service';
import { SettingsDialogComponent } from './settings-dialog/settings-dialog.component';
import { OpenAfterLaunchService } from './shared/service/open-after-launch.service';
import { PlmInternalRendererService } from '../global-variables/plm-internal-renderer.service';
import { PhotoSelectionHistoryService } from './shared/service/photo-selection-history.service';
import { WelcomeDialogComponent } from './welcome-dialog/welcome-dialog.component';
import { WelcomeDialogAtAppLaunchService } from './welcome-dialog/welcome-dialog-at-app-launch/welcome-dialog-at-app-launch.service';

@Component({
Expand All @@ -24,36 +10,15 @@ import { WelcomeDialogAtAppLaunchService } from './welcome-dialog/welcome-dialog
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
constructor(private dialog: MatDialog,
private directoryTreeViewSelectionService: DirectoryTreeViewSelectionService,
private ngZone: NgZone,
private openAfterLaunchService: OpenAfterLaunchService,
private photoSelectionHistoryService: PhotoSelectionHistoryService,
constructor(private photoSelectionHistoryService: PhotoSelectionHistoryService,
private plmInternalRendererService: PlmInternalRendererService,
private translate: TranslateService,
private welcomeDialogAtAppLaunchService: WelcomeDialogAtAppLaunchService) {
translate.setDefaultLang('en');
}

public ngOnInit(): void {
window.plmInternalRenderer = window.plmInternalRenderer || new PlmInternalRenderer();

window.plmInternalRenderer.recordAtAppLaunch = window.plmInternalRenderer.recordAtAppLaunch || new PlmInternalRendererRecordAtAppLaunch();
window.plmInternalRenderer.recordAtAppLaunch.handleRecordAtAppLaunchFinished = () => this.handleRecordAtAppLaunchFinished();

window.plmInternalRenderer.aboutBox = window.plmInternalRenderer.aboutBox || new PlmInternalRendererAboutBox();
window.plmInternalRenderer.aboutBox.showAboutBox = () => this.showAboutBox();

window.plmInternalRenderer.settingsDialog = window.plmInternalRenderer.settingsDialog || new PlmInternalRendererSettingsDialog();
window.plmInternalRenderer.settingsDialog.showSettingsDialog = () => this.showSettingsDialog();

window.plmInternalRenderer.welcomeDialog = window.plmInternalRenderer.welcomeDialog || new PlmInternalRendererWelcomeDialog();
window.plmInternalRenderer.welcomeDialog.showWelcomeDialog = () => this.showWelcomeDialog();

window.plmInternalRenderer.photoSelection = window.plmInternalRenderer.photoSelection || new PlmInternalRendererPhotoSelection();
window.plmInternalRenderer.photoSelection.undo = () => this.undoPhotoSelection();
window.plmInternalRenderer.photoSelection.redo = () => this.redoPhotoSelection();
window.plmInternalRenderer.photoSelection.selectOnlyThis = (photoPath) => this.selectOnlyThis(photoPath);

this.plmInternalRendererService.initialize();
this.photoSelectionHistoryService.reset(); // Disable Undo/Redo menus after the application frontend is reloaded.
}

Expand All @@ -62,77 +27,6 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
}

public ngOnDestroy(): void {
window.plmInternalRenderer.recordAtAppLaunch.handleRecordAtAppLaunchFinished = null;
window.plmInternalRenderer.aboutBox.showAboutBox = null;
window.plmInternalRenderer.settingsDialog.showSettingsDialog = null;
window.plmInternalRenderer.welcomeDialog.showWelcomeDialog = null;
window.plmInternalRenderer.photoSelection = null;
}

private handleRecordAtAppLaunchFinished() {
// noinspection JSIgnoredPromiseFromCall
this.openAfterLaunchService.openAfterLaunchIfNeeded();
}

public showAboutBox(): void {
this.ngZone.run(() => {
this.dialog.open(AboutBoxComponent, {
width: '600px',
height: '420px',
panelClass: 'custom-dialog-container',
autoFocus: false,
restoreFocus: false
});
Logger.info('Displayed About Box.');
});
}

private showSettingsDialog() {
this.ngZone.run(() => {
this.dialog.open(SettingsDialogComponent, {
width: '1000px',
height: '600px',
panelClass: 'custom-dialog-container',
autoFocus: false,
restoreFocus: false,
disableClose: true
});
Logger.info('Displayed Settings Dialog.');
});
}

public showWelcomeDialog(): void {
this.ngZone.run(() => {
this.dialog.open(WelcomeDialogComponent, {
width: '620px',
height: '495px',
panelClass: 'custom-dialog-container',
autoFocus: false,
restoreFocus: false,
disableClose: true
});
Logger.info('Displayed Welcome Dialog.');
});
}

private undoPhotoSelection() {
this.ngZone.run(() => {
this.photoSelectionHistoryService.undo();
Logger.debug(`Called AppComponent::undoPhotoSelection`);
});
}

private redoPhotoSelection() {
this.ngZone.run(() => {
this.photoSelectionHistoryService.redo();
Logger.debug(`Called AppComponent::redoPhotoSelection`);
});
}

private selectOnlyThis(photoPath: string) {
this.ngZone.run(() => {
this.directoryTreeViewSelectionService.select([photoPath]);
Logger.debug(`Called AppComponent::selectOnlyThis for ${photoPath}`);
});
this.plmInternalRendererService.destroy();
}
}
127 changes: 127 additions & 0 deletions src/global-variables/plm-internal-renderer.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { Injectable, NgZone } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Logger } from '../../src-shared/log/logger';
import { AboutBoxComponent } from '../app/about-box/about-box.component';
import { DirectoryTreeViewSelectionService } from '../app/directory-tree-view/directory-tree-view-selection.service';
import { SettingsDialogComponent } from '../app/settings-dialog/settings-dialog.component';
import { OpenAfterLaunchService } from '../app/shared/service/open-after-launch.service';
import { PhotoSelectionHistoryService } from '../app/shared/service/photo-selection-history.service';
import { WelcomeDialogComponent } from '../app/welcome-dialog/welcome-dialog.component';
import {
PlmInternalRenderer,
PlmInternalRendererAboutBox,
PlmInternalRendererPhotoSelection,
PlmInternalRendererRecordAtAppLaunch,
PlmInternalRendererSettingsDialog,
PlmInternalRendererWelcomeDialog
} from './global-variable-for-internal-use-in-renderer';

@Injectable({
providedIn: 'root'
})
export class PlmInternalRendererService {
constructor(private dialog: MatDialog,
private directoryTreeViewSelectionService: DirectoryTreeViewSelectionService,
private ngZone: NgZone,
private openAfterLaunchService: OpenAfterLaunchService,
private photoSelectionHistoryService: PhotoSelectionHistoryService) {
}

public initialize(): void {
window.plmInternalRenderer = window.plmInternalRenderer || new PlmInternalRenderer();

window.plmInternalRenderer.recordAtAppLaunch = window.plmInternalRenderer.recordAtAppLaunch || new PlmInternalRendererRecordAtAppLaunch();
window.plmInternalRenderer.recordAtAppLaunch.handleRecordAtAppLaunchFinished = () => this.handleRecordAtAppLaunchFinished();

window.plmInternalRenderer.aboutBox = window.plmInternalRenderer.aboutBox || new PlmInternalRendererAboutBox();
window.plmInternalRenderer.aboutBox.showAboutBox = () => this.showAboutBox();

window.plmInternalRenderer.settingsDialog = window.plmInternalRenderer.settingsDialog || new PlmInternalRendererSettingsDialog();
window.plmInternalRenderer.settingsDialog.showSettingsDialog = () => this.showSettingsDialog();

window.plmInternalRenderer.welcomeDialog = window.plmInternalRenderer.welcomeDialog || new PlmInternalRendererWelcomeDialog();
window.plmInternalRenderer.welcomeDialog.showWelcomeDialog = () => this.showWelcomeDialog();

window.plmInternalRenderer.photoSelection = window.plmInternalRenderer.photoSelection || new PlmInternalRendererPhotoSelection();
window.plmInternalRenderer.photoSelection.undo = () => this.undoPhotoSelection();
window.plmInternalRenderer.photoSelection.redo = () => this.redoPhotoSelection();
window.plmInternalRenderer.photoSelection.selectOnlyThis = (photoPath) => this.selectOnlyThis(photoPath);
}

public destroy(): void {
window.plmInternalRenderer.recordAtAppLaunch.handleRecordAtAppLaunchFinished = null;
window.plmInternalRenderer.aboutBox.showAboutBox = null;
window.plmInternalRenderer.settingsDialog.showSettingsDialog = null;
window.plmInternalRenderer.welcomeDialog.showWelcomeDialog = null;
window.plmInternalRenderer.photoSelection = null;
}

private handleRecordAtAppLaunchFinished() {
this.ngZone.run(() => {
// noinspection JSIgnoredPromiseFromCall
this.openAfterLaunchService.openAfterLaunchIfNeeded();
});
}

private showAboutBox(): void {
this.ngZone.run(() => {
this.dialog.open(AboutBoxComponent, {
width: '600px',
height: '420px',
panelClass: 'custom-dialog-container',
autoFocus: false,
restoreFocus: false
});
Logger.info('Displayed About Box.');
});
}

private showSettingsDialog() {
this.ngZone.run(() => {
this.dialog.open(SettingsDialogComponent, {
width: '1000px',
height: '600px',
panelClass: 'custom-dialog-container',
autoFocus: false,
restoreFocus: false,
disableClose: true
});
Logger.info('Displayed Settings Dialog.');
});
}

private showWelcomeDialog(): void {
this.ngZone.run(() => {
this.dialog.open(WelcomeDialogComponent, {
width: '620px',
height: '495px',
panelClass: 'custom-dialog-container',
autoFocus: false,
restoreFocus: false,
disableClose: true
});
Logger.info('Displayed Welcome Dialog.');
});
}

private undoPhotoSelection() {
this.ngZone.run(() => {
this.photoSelectionHistoryService.undo();
Logger.debug(`Called PlmInternalRendererService::undoPhotoSelection`);
});
}

private redoPhotoSelection() {
this.ngZone.run(() => {
this.photoSelectionHistoryService.redo();
Logger.debug(`Called PlmInternalRendererService::redoPhotoSelection`);
});
}

private selectOnlyThis(photoPath: string) {
this.ngZone.run(() => {
this.directoryTreeViewSelectionService.select([photoPath]);
Logger.debug(`Called PlmInternalRendererService::selectOnlyThis for ${photoPath}`);
});
}
}

0 comments on commit f1f6675

Please sign in to comment.