import { Injectable, ViewChild, ViewContainerRef } from '@angular/core'; import {NotificationService} from '@progress/kendo-angular-notification'; import { DialogRef, DialogService, DialogCloseResult } from '@progress/kendo-angular-dialog'; import { Observable, Subject } from 'rxjs'; import Swal from 'sweetalert2'; @Injectable() export class HRMNotificationService { constructor(public notificationService: NotificationService, public dialogService: DialogService) { } // showSuccess(message: string, title?: string) { // this.notificationService.show({ // content: message, // cssClass: 'button-notification', // animation: { type: 'slide', duration: 400 }, // position: { horizontal: 'center', vertical: 'bottom' }, // type: { style: 'success', icon: true }, // }); // } // showSuccess(message: string, title?: string) { // //this.toastr.success(message, title); // this.showSuccessExtra(message, title); // } // showSuccessExtra(message: string, title?: string, // disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, // progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { // //this.toastr.toastrConfig.maxOpened = maxOpened; // //this.toastr.success(message, title, { // // disableTimeOut: disableTimeOut, // // timeOut: timeOut, // // tapToDismiss: tapToDismiss, // // progressBar: progressBar, // // closeButton: closeButton, // // positionClass: positionClass // //}); // Swal.fire(title, message, 'success'); // } showSuccess(message: string, title?: string) { //this.toastr.success(message, title); this.showSuccessExtra(message, title); } showError(message: string, title?: string) { //this.toastr.error(message, title); this.showErrorExtra(message, title); } showWarning(message: string, title?: string) { //this.toastr.warning(message, title); this.showWarningExtra(message, title); } showInfo(message: string, title?: string) { //this.toastr.info(message, title); this.showInfoExtra(message, title); } showConfirm(title: string, message: string): boolean { let isConfirm: boolean = true; Swal.fire({ title: title, text: message, icon: 'warning', showCancelButton: true, confirmButtonColor: '#0e2b63', cancelButtonColor: '#d33', confirmButtonText: 'Yes' }).then((result) => { if (result.isConfirmed) { } }) return isConfirm; } showSuccessConfirm(message: string): Promise { return new Promise((resolve) => { Swal.fire({ text: message, icon: 'success', confirmButtonColor: '#50af47', confirmButtonText: 'OK', }).then((result) => { const isConfirmed: boolean = result.isConfirmed; resolve(isConfirmed); }); }); } showActiveConfirm(title: string, message: string): Promise { return new Promise((resolve) => { Swal.fire({ title: title, text: message, icon: 'warning', showCancelButton: true, confirmButtonColor: '#414278', cancelButtonColor: '#d33', confirmButtonText: 'Yes', cancelButtonText: 'No' }).then((result) => { const isConfirmed: boolean = result.isConfirmed; resolve(isConfirmed); }); }); } showSuccessExtra(message: string, title?: string, disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { //this.toastr.toastrConfig.maxOpened = maxOpened; //this.toastr.success(message, title, { // disableTimeOut: disableTimeOut, // timeOut: timeOut, // tapToDismiss: tapToDismiss, // progressBar: progressBar, // closeButton: closeButton, // positionClass: positionClass //}); Swal.fire(title, message, 'success'); } showErrorExtra(message: string, title?: string, disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { //this.toastr.toastrConfig.maxOpened = maxOpened; //this.toastr.error(message, title, { // disableTimeOut: disableTimeOut, // timeOut: timeOut, // tapToDismiss: tapToDismiss, // progressBar: progressBar, // closeButton: closeButton, // positionClass: positionClass //}); Swal.fire(title, message, 'error'); } showWarningExtra(message: string, title?: string, disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { //this.toastr.toastrConfig.maxOpened = maxOpened; //this.toastr.warning(message, title, { // disableTimeOut: disableTimeOut, // timeOut: timeOut, // tapToDismiss: tapToDismiss, // progressBar: progressBar, // closeButton: closeButton, // positionClass: positionClass //}); Swal.fire(title, message, 'warning'); } showInfoExtra(message: string, title?: string, disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { //this.toastr.toastrConfig.maxOpened = maxOpened; //this.toastr.info(message, title, { // disableTimeOut: disableTimeOut, // timeOut: timeOut, // tapToDismiss: tapToDismiss, // progressBar: progressBar, // closeButton: closeButton, // positionClass: positionClass //}); Swal.fire(title, message, 'info'); } // showError(message: string, title?: string) { // this.notificationService.show({ // content: message, // cssClass: 'button-notification', // animation: { type: 'slide', duration: 400 }, // position: { horizontal: 'center', vertical: 'bottom' }, // type: { style: 'error', icon: true }, // }); // } // showWarning(message: string, title?: string) { // this.notificationService.show({ // content: message, // cssClass: 'button-notification', // animation: { type: 'slide', duration: 400 }, // position: { horizontal: 'center', vertical: 'bottom' }, // type: { style: 'error', icon: true }, // }); // } // public _subject: Subject = new Subject(); // public showConfirmation(message: string, title: string): Observable { // const dialog: DialogRef = this.dialogService.open({ // title: message, // content: title, // actions: [ // { text: 'No' }, // { text: 'Yes', primary: true } // ], // width: 450, // height: 200, // minWidth: 250 // }); // this._subject.unsubscribe(); // this._subject = new Subject(); // dialog.result.subscribe((result) => { // if (result instanceof DialogCloseResult) { // this._subject.next(true); // } else { // this._subject.next(false); // } // }); // return this._subject.asObservable(); // } // showInfo(message: string, title?: string) { // this.notificationService.show({ // content: message, // cssClass: 'button-notification', // animation: { type: 'slide', duration: 400 }, // position: { horizontal: 'center', vertical: 'bottom' }, // type: { style: 'info', icon: true }, // }); // } //showSuccessExtra(message: string, title?: string, // disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, // progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { // this.toastr.toastrConfig.maxOpened = maxOpened; // this.toastr.success(message, title, { // disableTimeOut: disableTimeOut, // timeOut: timeOut, // tapToDismiss: tapToDismiss, // progressBar: progressBar, // closeButton: closeButton, // positionClass: positionClass // }); //} //showErrorExtra(message: string, title?: string, // disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, // progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { // this.toastr.toastrConfig.maxOpened = maxOpened; // this.toastr.error(message, title, { // disableTimeOut: disableTimeOut, // timeOut: timeOut, // tapToDismiss: tapToDismiss, // progressBar: progressBar, // closeButton: closeButton, // positionClass: positionClass // }); //} //showWarningExtra(message: string, title?: string, // disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, // progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { // this.toastr.toastrConfig.maxOpened = maxOpened; // this.toastr.warning(message, title, { // disableTimeOut: disableTimeOut, // timeOut: timeOut, // tapToDismiss: tapToDismiss, // progressBar: progressBar, // closeButton: closeButton, // positionClass: positionClass // }); //} //showInfoExtra(message: string, title?: string, // disableTimeOut: boolean = false, timeOut: number = 4000, maxOpened: number = 3, tapToDismiss: boolean = true, // progressBar: boolean = true, closeButton: boolean = true, positionClass: string = 'toast-top-center') { // this.toastr.toastrConfig.maxOpened = maxOpened; // this.toastr.info(message, title, { // disableTimeOut: disableTimeOut, // timeOut: timeOut, // tapToDismiss: tapToDismiss, // progressBar: progressBar, // closeButton: closeButton, // positionClass: positionClass // }); //} }