2022-01-19 17:24:11 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
|
|
import { ILogger } from '../../models/logger.model';
|
2022-04-06 12:00:42 +02:00
|
|
|
import { PanelType } from '../../models/panel.model';
|
2022-01-19 17:24:11 +01:00
|
|
|
import { LoggerService } from '../logger/logger.service';
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
2022-04-05 15:40:43 +02:00
|
|
|
export class PanelService {
|
2022-04-07 10:03:50 +02:00
|
|
|
/**
|
|
|
|
* Panel Observable which pushes the panel status in every update.
|
|
|
|
*/
|
2022-04-06 12:00:42 +02:00
|
|
|
panelOpenedObs: Observable<{ opened: boolean; type?: PanelType | string }>;
|
2022-01-19 17:24:11 +01:00
|
|
|
protected log: ILogger;
|
2022-04-06 12:00:42 +02:00
|
|
|
protected isChatOpened: boolean = false;
|
|
|
|
protected isParticipantsOpened: boolean = false;
|
2022-06-02 10:57:47 +02:00
|
|
|
protected isActivitiesOpened: boolean = false;
|
2022-04-06 12:00:42 +02:00
|
|
|
private isExternalOpened: boolean = false;
|
|
|
|
private externalType: string;
|
2022-06-02 10:57:47 +02:00
|
|
|
protected _panelOpened = <BehaviorSubject<{ opened: boolean; type?: PanelType | string, expand?: string }>>new BehaviorSubject({ opened: false });
|
2022-01-19 17:24:11 +01:00
|
|
|
|
2022-04-06 12:00:42 +02:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2022-01-19 17:24:11 +01:00
|
|
|
constructor(protected loggerSrv: LoggerService) {
|
2022-04-05 15:40:43 +02:00
|
|
|
this.log = this.loggerSrv.get('PanelService');
|
2022-04-05 15:51:10 +02:00
|
|
|
this.panelOpenedObs = this._panelOpened.asObservable();
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
2022-04-07 10:03:50 +02:00
|
|
|
/**
|
2022-05-20 12:43:53 +02:00
|
|
|
* Open or close the panel type received. Calling this method with the panel opened and the same type panel, will close the panel.
|
2022-04-07 10:03:50 +02:00
|
|
|
* If the type is differente, it will switch to the properly panel.
|
|
|
|
*/
|
2022-06-02 10:57:47 +02:00
|
|
|
togglePanel(type: PanelType | string, expand?: string) {
|
2022-01-19 17:24:11 +01:00
|
|
|
this.log.d(`Toggling ${type} menu`);
|
2022-04-06 12:00:42 +02:00
|
|
|
let opened: boolean;
|
|
|
|
if (type === PanelType.CHAT) {
|
|
|
|
this.isChatOpened = !this.isChatOpened;
|
|
|
|
this.isParticipantsOpened = false;
|
|
|
|
this.isExternalOpened = false;
|
2022-06-02 10:57:47 +02:00
|
|
|
this.isActivitiesOpened = false
|
2022-04-06 12:00:42 +02:00
|
|
|
opened = this.isChatOpened;
|
|
|
|
} else if (type === PanelType.PARTICIPANTS) {
|
|
|
|
this.isParticipantsOpened = !this.isParticipantsOpened;
|
|
|
|
this.isChatOpened = false;
|
|
|
|
this.isExternalOpened = false;
|
2022-06-02 10:57:47 +02:00
|
|
|
this.isActivitiesOpened = false;
|
2022-04-06 12:00:42 +02:00
|
|
|
opened = this.isParticipantsOpened;
|
2022-06-02 10:57:47 +02:00
|
|
|
} else if (type === PanelType.ACTIVITIES) {
|
|
|
|
this.isActivitiesOpened = !this.isActivitiesOpened;
|
|
|
|
this.isChatOpened = false;
|
|
|
|
this.isExternalOpened = false;
|
|
|
|
this.isParticipantsOpened = false;
|
|
|
|
opened = this.isActivitiesOpened;
|
2022-04-06 12:00:42 +02:00
|
|
|
} else {
|
|
|
|
this.log.d('Toggling external panel');
|
|
|
|
this.isChatOpened = false;
|
|
|
|
this.isParticipantsOpened = false;
|
2022-06-02 10:57:47 +02:00
|
|
|
this.isActivitiesOpened = false;
|
2022-04-06 12:00:42 +02:00
|
|
|
// Open when is close or is opened with another type
|
|
|
|
this.isExternalOpened = !this.isExternalOpened || this.externalType !== type;
|
|
|
|
this.externalType = !this.isExternalOpened ? '' : type;
|
|
|
|
opened = this.isExternalOpened;
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
2022-04-06 12:00:42 +02:00
|
|
|
|
2022-06-02 10:57:47 +02:00
|
|
|
this._panelOpened.next({ opened, type, expand });
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
2022-04-06 12:00:42 +02:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
isPanelOpened(): boolean {
|
2022-06-02 10:57:47 +02:00
|
|
|
return this.isChatPanelOpened() || this.isParticipantsPanelOpened() || this.isActivitiesPanelOpened() || this.isExternalPanelOpened();
|
2022-04-06 12:00:42 +02:00
|
|
|
}
|
|
|
|
|
2022-04-07 10:03:50 +02:00
|
|
|
/**
|
|
|
|
* Closes the panel (if opened)
|
|
|
|
*/
|
2022-04-06 12:00:42 +02:00
|
|
|
closePanel(): void {
|
|
|
|
this.isParticipantsOpened = false;
|
|
|
|
this.isChatOpened = false;
|
|
|
|
this.isExternalOpened = false;
|
2022-06-02 10:57:47 +02:00
|
|
|
this.isActivitiesOpened = false;
|
2022-04-05 15:51:10 +02:00
|
|
|
this._panelOpened.next({ opened: false });
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
2022-04-07 10:03:50 +02:00
|
|
|
/**
|
|
|
|
* Whether the chat panel is opened or not.
|
|
|
|
*/
|
2022-04-06 12:00:42 +02:00
|
|
|
isChatPanelOpened(): boolean {
|
|
|
|
return this.isChatOpened;
|
|
|
|
}
|
|
|
|
|
2022-04-07 10:03:50 +02:00
|
|
|
/**
|
|
|
|
* Whether the participants panel is opened or not.
|
|
|
|
*/
|
2022-04-06 12:00:42 +02:00
|
|
|
isParticipantsPanelOpened(): boolean {
|
|
|
|
return this.isParticipantsOpened;
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
2022-06-02 10:57:47 +02:00
|
|
|
/**
|
|
|
|
* Whether the activities panel is opened or not.
|
|
|
|
*/
|
|
|
|
isActivitiesPanelOpened(): boolean {
|
|
|
|
return this.isActivitiesOpened;
|
|
|
|
}
|
|
|
|
|
2022-05-05 18:07:33 +02:00
|
|
|
isExternalPanelOpened(): boolean {
|
2022-04-06 12:00:42 +02:00
|
|
|
return this.isExternalOpened;
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
}
|