Browse Source

refactor(theme-shared): remove abstract toaster class

pull/2606/head
TheDiaval 7 years ago
parent
commit
f085267d12
  1. 56
      npm/ng-packs/packages/theme-shared/src/lib/abstracts/toaster.ts

56
npm/ng-packs/packages/theme-shared/src/lib/abstracts/toaster.ts

@ -1,56 +0,0 @@
import { MessageService } from 'primeng/components/common/messageservice';
import { Observable, Subject } from 'rxjs';
import { Toaster } from '../models/toaster';
import { Config } from '@abp/ng.core';
export abstract class AbstractToaster<T = Toaster.Options> {
status$: Subject<Toaster.Status>;
key = 'abpToast';
sticky = false;
constructor(protected messageService: MessageService) {}
info(message: Config.LocalizationParam, title: Config.LocalizationParam, options?: T): Observable<Toaster.Status> {
return this.show(message, title, 'info', options);
}
success(message: Config.LocalizationParam, title: Config.LocalizationParam, options?: T): Observable<Toaster.Status> {
return this.show(message, title, 'success', options);
}
warn(message: Config.LocalizationParam, title: Config.LocalizationParam, options?: T): Observable<Toaster.Status> {
return this.show(message, title, 'warn', options);
}
error(message: Config.LocalizationParam, title: Config.LocalizationParam, options?: T): Observable<Toaster.Status> {
return this.show(message, title, 'error', options);
}
protected show(
message: Config.LocalizationParam,
title: Config.LocalizationParam,
severity: Toaster.Severity,
options?: T,
): Observable<Toaster.Status> {
this.messageService.clear(this.key);
this.messageService.add({
severity,
detail: message || '',
summary: title || '',
...options,
key: this.key,
...(typeof (options || ({} as any)).sticky === 'undefined' && { sticky: this.sticky }),
});
this.status$ = new Subject<Toaster.Status>();
return this.status$;
}
clear(status?: Toaster.Status) {
this.messageService.clear(this.key);
this.status$.next(status || Toaster.Status.dismiss);
this.status$.complete();
}
}
Loading…
Cancel
Save