2022-01-19 17:24:11 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
|
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
2022-06-02 10:57:47 +02:00
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { DeleteDialogComponent } from '../../components/dialogs/delete-recording.component';
|
|
|
|
import { RecordingDialogComponent } from '../../components/dialogs/recording-dialog.component';
|
|
|
|
import { DialogTemplateComponent } from '../../components/dialogs/dialog.component';
|
2022-01-19 17:24:11 +01:00
|
|
|
import { INotificationOptions } from '../../models/notification-options.model';
|
|
|
|
|
2022-03-23 13:48:17 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2022-01-19 17:24:11 +01:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class ActionService {
|
2022-06-02 10:57:47 +02:00
|
|
|
private dialogRef: MatDialogRef<DialogTemplateComponent | RecordingDialogComponent | DeleteDialogComponent>;
|
|
|
|
private dialogSubscription: Subscription;
|
2022-01-19 17:24:11 +01:00
|
|
|
constructor(private snackBar: MatSnackBar, public dialog: MatDialog) {}
|
|
|
|
|
|
|
|
launchNotification(options: INotificationOptions, callback): void {
|
|
|
|
if (!options.config) {
|
|
|
|
options.config = {
|
|
|
|
duration: 3000,
|
|
|
|
verticalPosition: 'top',
|
|
|
|
horizontalPosition: 'end'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const notification = this.snackBar.open(options.message, options.buttonActionText, options.config);
|
|
|
|
if (callback) {
|
|
|
|
notification.onAction().subscribe(() => {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
openDialog(titleMessage: string, descriptionMessage: string, allowClose = true) {
|
|
|
|
try {
|
|
|
|
this.closeDialog();
|
|
|
|
} catch (error) {
|
|
|
|
} finally {
|
|
|
|
const config: MatDialogConfig = {
|
|
|
|
minWidth: '250px',
|
|
|
|
data: { title: titleMessage, description: descriptionMessage, showActionButtons: allowClose },
|
|
|
|
disableClose: !allowClose
|
|
|
|
};
|
|
|
|
this.dialogRef = this.dialog.open(DialogTemplateComponent, config);
|
2022-06-02 10:57:47 +02:00
|
|
|
this.dialogSubscription = this.dialogRef.afterClosed().subscribe((result) => {
|
2022-01-19 17:24:11 +01:00
|
|
|
this.dialogRef = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-02 10:57:47 +02:00
|
|
|
openDeleteRecordingDialog(succsessCallback) {
|
|
|
|
try {
|
|
|
|
this.closeDialog();
|
|
|
|
} catch (error) {
|
|
|
|
} finally {
|
|
|
|
this.dialogRef = this.dialog.open(DeleteDialogComponent);
|
|
|
|
|
|
|
|
this.dialogSubscription = this.dialogRef.afterClosed().subscribe((result) => {
|
|
|
|
if (result) {
|
|
|
|
succsessCallback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-22 12:35:31 +02:00
|
|
|
openRecordingPlayerDialog(src: string, allowClose = true) {
|
2022-06-02 10:57:47 +02:00
|
|
|
try {
|
|
|
|
this.closeDialog();
|
|
|
|
} catch (error) {
|
|
|
|
} finally {
|
|
|
|
const config: MatDialogConfig = {
|
|
|
|
minWidth: '250px',
|
2022-06-22 12:35:31 +02:00
|
|
|
data: { src, showActionButtons: allowClose },
|
2022-06-02 10:57:47 +02:00
|
|
|
disableClose: !allowClose
|
|
|
|
};
|
|
|
|
this.dialogRef = this.dialog.open(RecordingDialogComponent, config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 17:24:11 +01:00
|
|
|
closeDialog() {
|
|
|
|
this.dialogRef.close();
|
2022-06-02 10:57:47 +02:00
|
|
|
if (this.dialogSubscription) this.dialogSubscription.unsubscribe();
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
}
|