import { Observable } from 'rxjs/Observable' ; import { Injectable } from '@angular/core' ; import { MatDialog , MatDialogRef } from '@angular/material' ; import { ConfirmDialog } from '../components/confirm-dialog/confirm-dialog.component' ; import { IUser } from '../../../../../../shared/models/IUser' ; import { UploadDialog } from '../components/upload-dialog/upload-dialog.component' ; import { InfoDialog } from '../components/info-dialog/info-dialog.component' ; import { FilepickerDialog } from '../components/filepicker-dialog/filepicker-dialog.component' ; import { WriteMailDialog } from '../components/write-mail-dialog/write-mail-dialog.component' ; import { ChangePasswordDialogComponent } from '../components/change-password-dialog/change-password-dialog.component' ; import { UserProfileDialog } from '../components/user-profile-dialog/user-profile-dialog.component' ; import { User } from '../../models/User' ; import { ResponsiveImageUploadDialog } from '../components/responsive-image-upload-dialog/responsive-image-upload-dialog.component' ; import { IResponsiveImageData } from '../../../../../../shared/models/IResponsiveImageData' ; import { WhitelistDialog } from '../../course/course-edit/general-tab/whitelist-dialog/whitelist-dialog.component' ; import { ICourse } from '../../../../../../shared/models/ICourse' ; @ Injectable ( ) export class DialogService { constructor ( private dialog ) { } public info ( title , message ) { let dialogRef ; dialogRef = this . dialog . open ( InfoDialog ) ; dialogRef . componentInstance . title = title ; dialogRef . componentInstance . message = message ; return dialogRef . afterClosed ( ) ; } public whitelist ( course ) { let dialogRef ; dialogRef = this . dialog . open ( WhitelistDialog ) ; dialogRef . componentInstance . whitelistUsers = [ ] ; dialogRef . componentInstance . course = course ; return dialogRef . afterClosed ( ) ; } public userProfile ( user ) { let dialogRef ; dialogRef = this . dialog . open ( UserProfileDialog ) ; dialogRef . componentInstance . user = user ; return dialogRef . afterClosed ( ) ; } public confirm ( title , message , confirmText = 'Confirm' ) { let dialogRef ; dialogRef = this . dialog . open ( ConfirmDialog ) ; dialogRef . componentInstance . title = title ; dialogRef . componentInstance . message = message ; dialogRef . componentInstance . confirmText = confirmText ; return dialogRef . afterClosed ( ) ; } private confirmOperation ( op , itemType , itemName , opFrom ? ) { let message = 'Are you sure you want to ' + op . toLowerCase ( ) + ' the ' + itemType + ' ' + itemName ; if ( opFrom ) { message += ' from this ' + opFrom ; } message += '?' ; return this . confirm ( op + ' ' + itemType , message , op ) ; } public confirmUpdate ( itemType , itemName , removeFrom ? ) { return this . confirmOperation ( 'Update ' , itemType , itemName , removeFrom ) ; } public confirmDelete ( itemType , itemName , removeFrom ? ) { return this . confirmOperation ( 'Delete ' , itemType , itemName , removeFrom ) ; } public confirmRemove ( itemType , itemName , removeFrom ? ) { return this . confirmOperation ( 'Remove' , itemType , itemName , removeFrom ) ; } public chooseFile ( message , uploadPath ) { let dialogRef ; dialogRef = this . dialog . open ( FilepickerDialog ) ; dialogRef . componentInstance . message = message ; dialogRef . componentInstance . uploadPath = uploadPath ; return dialogRef . afterClosed ( ) ; } public uploadResponsiveImage ( message , uploadPath , responsiveImageData ) { const dialogReference = this . dialog . open ( ResponsiveImageUploadDialog ) ; dialogReference . componentInstance . message = message ; dialogReference . componentInstance . uploadPath = uploadPath ; dialogReference . componentInstance . setResponsiveImageData ( responsiveImageData ) ; return dialogReference . afterClosed ( ) ; } public upload ( user ) { let dialogRef ; dialogRef = this . dialog . open ( UploadDialog ) ; dialogRef . componentInstance . user = user ; return dialogRef . afterClosed ( ) ; } public writeMail ( data ) { const dialogRef = this . dialog . open ( WriteMailDialog ) ; dialogRef . componentInstance . bcc = data . bcc ; dialogRef . componentInstance . cc = data . cc ; dialogRef . componentInstance . markdown = data . markdown ; dialogRef . componentInstance . subject = data . subject ; return dialogRef . afterClosed ( ) ; } public changePassword ( user ) { const dialogRef = this . dialog . open ( ChangePasswordDialogComponent ) ; dialogRef . componentInstance . user = user ; return dialogRef . afterClosed ( ) ; } }