2019-08-22 14:01:17 +02:00
|
|
|
import { Component, Input, OnDestroy } from '@angular/core';
|
|
|
|
|
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { distinctUntilChanged } from 'rxjs/operators';
|
2019-04-23 16:57:35 +02:00
|
|
|
|
2019-07-26 11:46:59 +02:00
|
|
|
import { ListOfSpeakersRepositoryService } from 'app/core/repositories/agenda/list-of-speakers-repository.service';
|
2019-04-23 16:57:35 +02:00
|
|
|
import { ContentObject, isContentObject } from 'app/shared/models/base/content-object';
|
|
|
|
import { ViewListOfSpeakers } from 'app/site/agenda/models/view-list-of-speakers';
|
|
|
|
import {
|
|
|
|
BaseViewModelWithListOfSpeakers,
|
|
|
|
isBaseViewModelWithListOfSpeakers
|
|
|
|
} from 'app/site/base/base-view-model-with-list-of-speakers';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A generic button to go to the list of speakers. Give the content object with
|
|
|
|
* [object]=object, which can be a ContentObject or a ViewModelWithListOfSpeakers.
|
|
|
|
* - Usage as a mini-fab (like in the agenda) with [menuItem]=false (default)
|
|
|
|
* - Usage in a dropdown (=list) with [menuItem]=true
|
|
|
|
*/
|
|
|
|
@Component({
|
|
|
|
selector: 'os-speaker-button',
|
|
|
|
templateUrl: './speaker-button.component.html'
|
|
|
|
})
|
2019-08-22 14:01:17 +02:00
|
|
|
export class SpeakerButtonComponent implements OnDestroy {
|
2019-04-23 16:57:35 +02:00
|
|
|
@Input()
|
|
|
|
public set object(obj: BaseViewModelWithListOfSpeakers | ContentObject | null) {
|
2019-08-22 14:01:17 +02:00
|
|
|
let listOfSpeakers: ViewListOfSpeakers;
|
2019-04-23 16:57:35 +02:00
|
|
|
if (isBaseViewModelWithListOfSpeakers(obj)) {
|
2019-08-22 14:01:17 +02:00
|
|
|
listOfSpeakers = obj.listOfSpeakers;
|
2019-04-23 16:57:35 +02:00
|
|
|
} else if (isContentObject(obj)) {
|
2019-08-22 14:01:17 +02:00
|
|
|
listOfSpeakers = this.listOfSpeakersRepo.findByContentObject(obj);
|
2019-04-23 16:57:35 +02:00
|
|
|
} else {
|
2019-08-22 14:01:17 +02:00
|
|
|
listOfSpeakers = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.cleanLosSub();
|
|
|
|
|
|
|
|
if (!!listOfSpeakers) {
|
|
|
|
this.losSub = this.listOfSpeakersRepo
|
|
|
|
.getViewModelObservable(listOfSpeakers.id)
|
|
|
|
.pipe(distinctUntilChanged())
|
|
|
|
.subscribe(speakerObj => {
|
|
|
|
this.listOfSpeakers = speakerObj;
|
|
|
|
});
|
2019-04-23 16:57:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public listOfSpeakers: ViewListOfSpeakers | null;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
public disabled: boolean;
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
public menuItem = false;
|
|
|
|
|
2019-06-14 11:18:54 +02:00
|
|
|
public get listOfSpeakersUrl(): string {
|
|
|
|
if (!this.disabled) {
|
|
|
|
return this.listOfSpeakers.listOfSpeakersUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 15:49:58 +02:00
|
|
|
public get icon(): string {
|
|
|
|
return this.listOfSpeakers.closed ? 'voice_over_off' : 'record_voice_over';
|
|
|
|
}
|
|
|
|
|
|
|
|
public get tooltip(): string {
|
2019-07-30 11:12:18 +02:00
|
|
|
return this.listOfSpeakers.closed ? 'The list of speakers is closed.' : 'List of speakers';
|
2019-08-01 15:49:58 +02:00
|
|
|
}
|
|
|
|
|
2019-08-22 14:01:17 +02:00
|
|
|
private losSub: Subscription;
|
|
|
|
|
2019-04-23 16:57:35 +02:00
|
|
|
/**
|
|
|
|
* The constructor
|
|
|
|
*/
|
|
|
|
public constructor(private listOfSpeakersRepo: ListOfSpeakersRepositoryService) {}
|
2019-08-22 14:01:17 +02:00
|
|
|
|
|
|
|
public ngOnDestroy(): void {
|
|
|
|
this.cleanLosSub();
|
|
|
|
}
|
|
|
|
|
|
|
|
private cleanLosSub(): void {
|
|
|
|
if (this.losSub) {
|
|
|
|
this.losSub.unsubscribe();
|
|
|
|
this.losSub = null;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 16:57:35 +02:00
|
|
|
}
|