add a devInfo method to toaster service
This commit is contained in:
parent
d6f7122329
commit
8b304a7279
@ -15,6 +15,11 @@ export abstract class IqserUserPreferenceService extends GenericService<UserAttr
|
||||
protected abstract readonly _devFeaturesEnabledKey: string;
|
||||
#userAttributes: UserAttributes = {};
|
||||
|
||||
get isIqserDevMode(): boolean {
|
||||
const value = sessionStorage.getItem(this._devFeaturesEnabledKey);
|
||||
return value === 'true';
|
||||
}
|
||||
|
||||
get userAttributes(): UserAttributes {
|
||||
return this.#userAttributes;
|
||||
}
|
||||
@ -74,3 +79,7 @@ export class DefaultUserPreferenceService extends IqserUserPreferenceService {
|
||||
protected readonly _defaultModelPath = 'attributes';
|
||||
protected readonly _devFeaturesEnabledKey = inject(BASE_HREF) + '.enable-dev-features';
|
||||
}
|
||||
|
||||
export function isIqserDevMode() {
|
||||
return inject(IqserUserPreferenceService).isIqserDevMode;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { ErrorMessageService } from './error-message.service';
|
||||
import { isIqserDevMode } from './iqser-user-preference.service';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
|
||||
const enum NotificationType {
|
||||
@ -26,6 +27,7 @@ export interface ToasterOptions extends IndividualConfig {
|
||||
*/
|
||||
readonly params?: Record<string, string | number>;
|
||||
readonly actions?: ToasterActions[];
|
||||
readonly useRaw?: boolean;
|
||||
}
|
||||
|
||||
export interface ErrorToasterOptions extends ToasterOptions {
|
||||
@ -35,10 +37,19 @@ export interface ErrorToasterOptions extends ToasterOptions {
|
||||
readonly error?: HttpErrorResponse;
|
||||
}
|
||||
|
||||
const defaultDevToastOptions: Partial<ToasterOptions> = {
|
||||
timeOut: 10000,
|
||||
easing: 'ease-in-out',
|
||||
easeTime: 500,
|
||||
useRaw: true,
|
||||
};
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class Toaster {
|
||||
readonly #isIqserDevMode = isIqserDevMode();
|
||||
|
||||
constructor(
|
||||
private readonly _toastr: ToastrService,
|
||||
private readonly _router: Router,
|
||||
@ -66,6 +77,14 @@ export class Toaster {
|
||||
return this._toastr.error(message, undefined, config);
|
||||
}
|
||||
|
||||
devInfo(message: string): ActiveToast<unknown> | undefined {
|
||||
if (!this.#isIqserDevMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.info(message, defaultDevToastOptions);
|
||||
}
|
||||
|
||||
info(message: string, options?: Partial<ToasterOptions>): ActiveToast<unknown> {
|
||||
return this._showToastNotification(message, NotificationType.INFO, options);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user