Saves the settings for countdown-controls

This commit is contained in:
GabrielMeyer 2019-09-24 18:55:30 +02:00
parent 23a7f26437
commit 7462918e43
3 changed files with 45 additions and 7 deletions

View File

@ -34,7 +34,7 @@ export class ProjectionDialogService {
*
* @param obj The projectable.
*/
public async openProjectDialogFor(obj: Projectable | ProjectorElementBuildDeskriptor): Promise<void> {
public async openProjectDialogFor(obj: Projectable | ProjectorElementBuildDeskriptor): Promise<object> {
let descriptor: ProjectorElementBuildDeskriptor;
if (isProjectable(obj)) {
descriptor = obj.getSlide(this.configService);
@ -55,10 +55,12 @@ export class ProjectionDialogService {
const [action, projectors, projectorElement]: ProjectionDialogReturnType = response;
if (action === 'project') {
this.projectorService.projectOnMultiple(projectors, projectorElement);
return { fullscreen: projectorElement.fullscreen, displayType: projectorElement.displayType };
} else if (action === 'addToPreview') {
projectors.forEach(projector => {
this.projectorService.addElementToPreview(projector, projectorElement);
});
return null;
}
}
}

View File

@ -4,9 +4,10 @@ import { Subscription } from 'rxjs';
import { distinctUntilChanged } from 'rxjs/operators';
import { ProjectorService } from 'app/core/core-services/projector.service';
import { StorageService } from 'app/core/core-services/storage.service';
import { ProjectorRepositoryService } from 'app/core/repositories/projector/projector-repository.service';
import { ProjectionDialogService } from 'app/core/ui-services/projection-dialog.service';
import { Projector } from 'app/shared/models/core/projector';
import { IdentifiableProjectorElement, Projector } from 'app/shared/models/core/projector';
import {
isProjectable,
isProjectorElementBuildDeskriptor,
@ -71,7 +72,8 @@ export class ProjectorButtonComponent implements OnInit, OnDestroy {
public constructor(
private projectorRepo: ProjectorRepositoryService,
private projectionDialogService: ProjectionDialogService,
private projectorService: ProjectorService
private projectorService: ProjectorService,
private storage: StorageService
) {}
/**
@ -104,7 +106,7 @@ export class ProjectorButtonComponent implements OnInit, OnDestroy {
*
* @param event the click event
*/
public onClick(event?: Event): void {
public async onClick(event?: Event): Promise<void> {
if (event) {
event.stopPropagation();
}
@ -115,8 +117,11 @@ export class ProjectorButtonComponent implements OnInit, OnDestroy {
// remove the projected object
this.projectorService.removeFrom(this.projector, this.object);
} else {
const projectorElement = this.getProjectorElement(
await this.storage.get<object>('projectorElementOptions')
);
// instantly project the object
this.projectorService.projectOn(this.projector, this.object);
this.projectorService.projectOn(this.projector, projectorElement || this.object);
}
} else {
// open the projection dialog
@ -139,4 +144,17 @@ export class ProjectorButtonComponent implements OnInit, OnDestroy {
? this.projectorService.isProjectedOn(this.object, this.projector)
: this.projectorService.isProjected(this.object);
}
/**
* @param options The previous configured options of a projector.
*/
private getProjectorElement(options: object): IdentifiableProjectorElement | null {
let element = null;
if (isProjectable(this.object)) {
element = this.object.getSlide().getBasicProjectorElement(options);
} else if (isProjectorElementBuildDeskriptor(this.object)) {
element = this.object.getBasicProjectorElement(options);
}
return Object.assign(element, options);
}
}

View File

@ -4,6 +4,7 @@ import { Title } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core';
import { StorageService } from 'app/core/core-services/storage.service';
import { CountdownRepositoryService } from 'app/core/repositories/projector/countdown-repository.service';
import { ConfigService } from 'app/core/ui-services/config.service';
import { ProjectionDialogService } from 'app/core/ui-services/projection-dialog.service';
@ -44,6 +45,11 @@ export class CountdownControlsComponent extends BaseViewComponent {
*/
public warningTime: number;
/**
* The key to storage.
*/
private storageKey = 'projectorElementOptions';
/**
* Constructor
*
@ -61,7 +67,8 @@ export class CountdownControlsComponent extends BaseViewComponent {
private repo: CountdownRepositoryService,
private configService: ConfigService,
private promptService: PromptService,
private projectionDialogService: ProjectionDialogService
private projectionDialogService: ProjectionDialogService,
private storage: StorageService
) {
super(titleService, translate, matSnackBar);
@ -110,7 +117,9 @@ export class CountdownControlsComponent extends BaseViewComponent {
* Brings the projection dialog
*/
public onBringDialog(): void {
this.projectionDialogService.openProjectDialogFor(this.countdown);
this.projectionDialogService
.openProjectDialogFor(this.countdown)
.then(options => this.storeSettings(options), null);
}
/**
@ -123,4 +132,13 @@ export class CountdownControlsComponent extends BaseViewComponent {
this.repo.delete(this.countdown).then(() => {}, this.raiseError);
}
}
/**
* Stores the options for a projector in the local-storage.
*
* @param element The configured options for projector
*/
private storeSettings(element: object): void {
this.storage.set(this.storageKey, element);
}
}