2019-01-10 15:06:10 +01:00
|
|
|
import { Component, Input, ViewChild, ElementRef, OnDestroy } from '@angular/core';
|
|
|
|
import { Title } from '@angular/platform-browser';
|
2019-01-31 13:40:27 +01:00
|
|
|
|
2019-01-10 15:06:10 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-01-31 13:40:27 +01:00
|
|
|
import { Subscription, Subject } from 'rxjs';
|
2019-01-10 15:06:10 +01:00
|
|
|
|
|
|
|
import { BaseComponent } from 'app/base.component';
|
2019-01-31 13:40:27 +01:00
|
|
|
import { ConfigService } from 'app/core/ui-services/config.service';
|
|
|
|
import { ViewProjector } from 'app/site/projector/models/view-projector';
|
|
|
|
import { Size } from 'app/site/projector/size';
|
|
|
|
import { SlideData, ProjectorDataService } from 'app/site/projector/services/projector-data.service';
|
|
|
|
import { ProjectorRepositoryService } from 'app/core/repositories/projector/projector-repository.service';
|
2019-01-10 15:06:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* THE projector. Cares about scaling and the right size and resolution.
|
|
|
|
* Watches the given projector and creates slide-containers for each projectorelement.
|
|
|
|
*/
|
|
|
|
@Component({
|
|
|
|
selector: 'os-projector',
|
|
|
|
templateUrl: './projector.component.html',
|
|
|
|
styleUrls: ['./projector.component.scss']
|
|
|
|
})
|
|
|
|
export class ProjectorComponent extends BaseComponent implements OnDestroy {
|
|
|
|
/**
|
|
|
|
* The current projector id.
|
|
|
|
*/
|
|
|
|
private projectorId: number | null = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The projector. Accessors are below.
|
|
|
|
*/
|
|
|
|
private _projector: ViewProjector;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
public set projector(projector: ViewProjector) {
|
|
|
|
this._projector = projector;
|
|
|
|
// check, if ID changed:
|
|
|
|
const newId = projector ? projector.id : null;
|
|
|
|
if (this.projectorId !== newId) {
|
|
|
|
this.projectorIdChanged(this.projectorId, newId);
|
|
|
|
this.projectorId = newId;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update scaling, if projector is set.
|
|
|
|
if (projector) {
|
|
|
|
const oldSize: Size = { ...this.currentProjectorSize };
|
|
|
|
this.currentProjectorSize.height = projector.height;
|
|
|
|
this.currentProjectorSize.width = projector.width;
|
|
|
|
if (
|
|
|
|
oldSize.height !== this.currentProjectorSize.height ||
|
|
|
|
oldSize.width !== this.currentProjectorSize.width
|
|
|
|
) {
|
|
|
|
this.updateScaling();
|
|
|
|
}
|
2019-02-21 17:04:59 +01:00
|
|
|
this.projectorStyle['background-color'] = projector.background_color;
|
|
|
|
this.headerFooterStyle.color = projector.header_font_color;
|
|
|
|
this.headerFooterStyle['background-color'] = projector.header_background_color;
|
2019-01-10 15:06:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public get projector(): ViewProjector {
|
|
|
|
return this._projector;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current projector size. This is for checking,
|
|
|
|
* if the size actually has changed.
|
|
|
|
*/
|
|
|
|
private currentProjectorSize: Size = { width: 0, height: 0 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ths subscription to the projectordata.
|
|
|
|
*/
|
|
|
|
private dataSubscription: Subscription;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The container element. THis is neede to get the size of the element,
|
|
|
|
* in which the projector must fit and be scaled to.
|
|
|
|
*/
|
|
|
|
@ViewChild('container')
|
|
|
|
private containerElement: ElementRef;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dynamic style attributes for the projector.
|
|
|
|
*/
|
|
|
|
public projectorStyle: {
|
|
|
|
transform?: string;
|
|
|
|
width: string;
|
|
|
|
height: string;
|
|
|
|
'background-color': string;
|
|
|
|
} = {
|
|
|
|
width: '0px',
|
|
|
|
height: '0px',
|
|
|
|
'background-color': 'white'
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dynamic style attributes for the header and footer.
|
|
|
|
*/
|
2019-02-21 17:04:59 +01:00
|
|
|
public headerFooterStyle: { 'background-image': string; 'background-color': string; color: string } = {
|
|
|
|
'background-image': 'none',
|
2019-01-10 15:06:10 +01:00
|
|
|
'background-color': 'blue',
|
|
|
|
color: 'white'
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dynamic style attributes for the container.
|
|
|
|
*/
|
|
|
|
public containerStyle: { height?: string } = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All slides to show on this projector
|
|
|
|
*/
|
|
|
|
public slides: SlideData<object>[] = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The scroll for this projector. 0 is the default.
|
|
|
|
*/
|
|
|
|
public scroll = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The scale for this projector. 0 is the default.
|
|
|
|
*/
|
|
|
|
public scale = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The subscription to the projector.
|
|
|
|
*/
|
|
|
|
private projectorSubscription: Subscription;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A subject that fires, if the container is resized.
|
|
|
|
*/
|
|
|
|
public resizeSubject = new Subject<void>();
|
|
|
|
|
|
|
|
// Some settings for the view from the config.
|
|
|
|
public enableHeaderAndFooter = true;
|
|
|
|
public enableTitle = true;
|
|
|
|
public enableLogo = true;
|
2019-02-25 16:40:55 +01:00
|
|
|
public projectorLogo;
|
2019-01-26 20:37:49 +01:00
|
|
|
public eventName;
|
|
|
|
public eventDescription;
|
|
|
|
public eventDate;
|
|
|
|
public eventLocation;
|
2019-01-10 15:06:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen to all related config variables. Register the resizeSubject.
|
|
|
|
*
|
|
|
|
* @param titleService
|
|
|
|
* @param translate
|
|
|
|
* @param projectorDataService
|
|
|
|
* @param projectorRepository
|
|
|
|
* @param configService
|
|
|
|
*/
|
|
|
|
public constructor(
|
|
|
|
titleService: Title,
|
|
|
|
translate: TranslateService,
|
|
|
|
private projectorDataService: ProjectorDataService,
|
|
|
|
private projectorRepository: ProjectorRepositoryService,
|
|
|
|
private configService: ConfigService
|
|
|
|
) {
|
|
|
|
super(titleService, translate);
|
2019-02-18 11:26:47 +01:00
|
|
|
// projector logo / background-image
|
|
|
|
this.configService.get<boolean>('projector_enable_logo').subscribe(val => (this.enableLogo = val));
|
2019-02-25 16:40:55 +01:00
|
|
|
this.configService.get<{ path?: string }>('logo_projector_main').subscribe(val => {
|
|
|
|
if (val && val.path) {
|
|
|
|
this.projectorLogo = val.path;
|
|
|
|
}
|
|
|
|
});
|
2019-02-18 11:26:47 +01:00
|
|
|
this.configService.get<{ path?: string }>('logo_projector_header').subscribe(val => {
|
|
|
|
if (val && val.path) {
|
|
|
|
this.headerFooterStyle['background-image'] = "url('" + val.path + "')";
|
2019-02-21 17:04:59 +01:00
|
|
|
} else {
|
|
|
|
this.headerFooterStyle['background-image'] = 'none';
|
2019-02-18 11:26:47 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// event data
|
2019-01-26 20:37:49 +01:00
|
|
|
this.configService.get<string>('general_event_name').subscribe(val => (this.eventName = val));
|
|
|
|
this.configService.get<string>('general_event_description').subscribe(val => (this.eventDescription = val));
|
|
|
|
this.configService.get<string>('general_event_date').subscribe(val => (this.eventDate = val));
|
|
|
|
this.configService.get<string>('general_event_location').subscribe(val => (this.eventLocation = val));
|
2019-01-10 15:06:10 +01:00
|
|
|
|
|
|
|
// Watches for resizing of the container.
|
|
|
|
this.resizeSubject.subscribe(() => {
|
|
|
|
if (this.containerElement) {
|
|
|
|
this.updateScaling();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scales the projector to the right format.
|
|
|
|
*/
|
|
|
|
private updateScaling(): void {
|
|
|
|
if (
|
|
|
|
!this.containerElement ||
|
|
|
|
this.currentProjectorSize.width === 0 ||
|
|
|
|
this.containerElement.nativeElement.offsetWidth === 0
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const scale = this.containerElement.nativeElement.offsetWidth / this.currentProjectorSize.width;
|
|
|
|
if (isNaN(scale)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.projectorStyle.transform = 'scale(' + scale + ')';
|
|
|
|
this.projectorStyle.width = this.currentProjectorSize.width + 'px';
|
|
|
|
this.projectorStyle.height = this.currentProjectorSize.height + 'px';
|
|
|
|
this.containerStyle.height = Math.round(scale * this.currentProjectorSize.height) + 'px';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called, if the projector id changes.
|
|
|
|
*/
|
|
|
|
private projectorIdChanged(from: number, to: number): void {
|
|
|
|
// Unsubscribe form data and projector subscriptions.
|
|
|
|
if (this.dataSubscription) {
|
|
|
|
this.dataSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
if (this.projectorSubscription) {
|
|
|
|
this.projectorSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
if (to > 0) {
|
|
|
|
if (from > 0) {
|
|
|
|
this.projectorDataService.projectorClosed(from);
|
|
|
|
}
|
|
|
|
|
2019-02-01 13:56:08 +01:00
|
|
|
this.dataSubscription = this.projectorDataService.getProjectorObservable(to).subscribe(data => {
|
|
|
|
this.slides = data || [];
|
|
|
|
});
|
2019-01-10 15:06:10 +01:00
|
|
|
this.projectorSubscription = this.projectorRepository.getViewModelObservable(to).subscribe(projector => {
|
2019-01-24 16:25:50 +01:00
|
|
|
if (projector) {
|
|
|
|
this.scroll = projector.scroll || 0;
|
|
|
|
this.scale = projector.scale || 0;
|
|
|
|
}
|
2019-01-10 15:06:10 +01:00
|
|
|
});
|
|
|
|
} else if (!to && from > 0) {
|
|
|
|
// no new projector
|
|
|
|
this.projectorDataService.projectorClosed(from);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deregister the projector from the projectordataservice.
|
|
|
|
*/
|
|
|
|
public ngOnDestroy(): void {
|
|
|
|
if (this.projectorId > 0) {
|
|
|
|
this.projectorDataService.projectorClosed(this.projectorId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|