import { override } from '@microsoft/decorators' ; import { BaseApplicationCustomizer } from '@microsoft/sp-application-base' ; import { Log } from '@microsoft/sp-core-library' ; import { SPComponentLoader } from '@microsoft/sp-loader' ; import { getIconClassName } from '@uifabric/styling' ; import * as $ from 'jquery' ; import * as strings from 'SpfxToastrApplicationCustomizerStrings' ; import * as toastr from 'toastr' ; import { IToast } from '../../services/toastService/IToast' ; import { ToastService } from '../../services/toastService/ToastService' ; import styles from './SpfxToastr.module.scss' ; const LOG_SOURCE = 'SpfxToastrApplicationCustomizer' ; /**
 * If your command set uses the ClientSideComponentProperties JSON input,
 * it will be deserialized into the BaseExtension.properties object.
 * You can define an interface to describe it.
 */ export interface ISpfxToastrApplicationCustomizerProperties { } /** A Custom Action which can be run during execution of a Client Side Application */ export default class SpfxToastrApplicationCustomizer extends BaseApplicationCustomizer < ISpfxToastrApplicationCustomizerProperties > { private toastsPromise : Promise < IToast [ ] > ; @ override public onInit ( ) { Log . info ( LOG_SOURCE , `Initialized ${ strings . Title }` ) ; SPComponentLoader . loadCss ( 'https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css' ) ; this . toastsPromise = ToastService . getToasts ( this . context . spHttpClient , this . context . pageContext . web . absoluteUrl , this . context . pageContext . web . id ) ; function getClass ( ) { return "css-147" ; } $ ( document ) . ready ( ( ) => { toastr . options . positionClass = `${ styles . topRight } ${ styles . spfxToastr }` ; toastr . options . preventDuplicates = true ; toastr . options . newestOnTop = false ; toastr . options . timeOut = 0 ; toastr . options . extendedTimeOut = 0 ; toastr . options . tapToDismiss = true ; toastr . options . closeButton = true ; toastr . options . titleClass = 'ms-font-m ms-fontWeight-semibold' ; toastr . options . messageClass = 'ms-font-s' ; toastr . options . iconClasses = { info : `${ styles . info } ${ styles . fabricIcon } ${ getIconClassName ( 'Info' ) }` , warning : `${ styles . warning } ${ styles . fabricIcon } ${ getIconClassName ( 'Warning' ) }` , error : `${ styles . error } ${ styles . fabricIcon } ${ getIconClassName ( 'Error' ) }` , success : `${ styles . success } ${ styles . fabricIcon } ${ getIconClassName ( 'Completed' ) }` } ; debugger ; this . toastsPromise . then ( ( toasts ) => { for ( let t of toasts ) { let overrides = { onclick : ( ) => { ToastService . acknowledgeToast ( t . Id , this . context . pageContext . web . id ) ; } , onCloseClick : ( ) => { ToastService . acknowledgeToast ( t . Id , this . context . pageContext . web . id ) ; } } ; switch ( t . Severity ) { case 'Warning' : toastr . warning ( t . Message , t . Title , overrides ) ; break ; case 'Error' : toastr . error ( t . Message , t . Title , overrides ) ; break ; case 'Success' : toastr . success ( t . Message , t . Title , overrides ) ; break ; default : toastr . info ( t . Message , t . Title , overrides ) ; break ; } } } ) . catch ( ( error ) : void => { toastr . error ( error , strings . FailedToLoad ) ; } ) ; } ) ; return Promise . resolve < void > ( ) ; } }