# All files / src/lib/services/action action.service.ts

51.72% Statements 15/29
37.03% Branches 10/27
37.5% Functions 3/8
43.47% Lines 10/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    561x
    1x
    1x
    1x
    1x

    1x

    1x
    1x

    1x

     import { Injectable } from '@angular/core';
    import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
    impoIrt { MatSnackBar } from '@angular/material/snack-bar';
    import { DialogTemplateComponent } from '../../components/material/dialog.component';

    import { INotificationOptions } from '../../models/notification-options.model';

    @Injectable({
    	providedIn: 'root'
    })
    export class ActionService {

    	private dialogRef: MatDialogRef<DialogTemplateComponent>;
    	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);
    			this.dialogRef.afterClosed().subscribe((result) => {
    				this.dialogRef = null;
    			});
    		}
    	}

    	closeDialog() {
    		this.dialogRef.close();
    	}
    }