UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

129 lines 4.48 kB
import { Alert } from './alert.model'; import { BehaviorSubject } from 'rxjs'; import { StateService } from '../common/state-service.abstract'; import * as i0 from "@angular/core"; export type AlertType = 'success' | 'warning' | 'danger' | 'info' | 'system'; /** * A service which allows to display alerts. */ export declare class AlertService extends StateService { /** * Returns all alerts. * @readonly */ get state(): Alert[]; /** * @ignore */ state$: BehaviorSubject<Alert[]>; private MAX_ALERTS; private ALERT_TIMEOUT; /** * Adds a new alert to the current state. * @param alert The alert object to be added. */ add(alert: Alert): void; /** * Adds a alert by text. * @param type The type of the alert. * @param txt The text to be displayed in the alert. * @param detailedData Optional detailed data for the alert. */ addByText(type: AlertType, txt: string, detailedData?: string): void; /** * Returns all alerts. * @deprecated Use alertService.alerts instead. */ list(): Alert[]; /** * Remove an alert from the current state. * @param alert The alert object to be removed. */ remove(alert: Alert): void; /** * Updates matching alert with provided values. * @param alert The alert to be updated. * @param fieldsToUpdate An object with the fields to update in the alert. */ update(alert: Alert, fieldsToUpdate: Partial<Alert>): void; /** * Removes last danger alert. * It can be used e.g. in the case of a failed request which triggered an alert, to hide it from user. * * ```js * try { * // something that might throw a danger server msg * } catch (ex) { * this.alertService.removeLastDanger(); * } * ``` */ removeLastDanger(): void; /** * Shorthand for a save successful alert. * @param savedObject The name of the object which was saved. * @return A function that can be executed to show the msg. */ saveSuccess(savedObject: string): () => void; /** * Shorthand for a create successful alert. * @param createdObject The name of the object which was created. * @return A function that can be executed to show the msg. */ createSuccess(createdObject: string): () => void; /** * Clears all alerts. */ clearAll(): void; /** * A shorthand to display a simple success message. * @param text The success text. * @param detailedData The text with additional information. */ success(text: string, detailedData?: string): void; /** * A shorthand to display a simple danger message. * @param text The danger text. * @param detailedData The text with additional information. */ danger(text: string, detailedData?: string): void; /** * A shorthand to display a simple info message. * @param text The info text. * @param detailedData The text with additional information. */ info(text: string, detailedData?: string): void; /** * A shorthand to display a simple warning message. * @param text The warning text. * @param detailedData The text with additional information. */ warning(text: string, detailedData?: string): void; /** * A shorthand to display a simple system message. * @param text The system message text. * @param detailedData The text with additional information. */ system(text: string, detailedData?: string): void; /** * Creates alert from standard api errors. * Should be used for errors generated by @c8y/client services. * @param error The error from server. * @param type The type of alert. */ addServerFailure(error: any, type?: AlertType): void; /** * Compares two alert objects. Alerts are same if text, type, detailed data and callbacks are same. * Callbacks are same if they refer to the same function. * @param alert1 First alert to compare. * @param alert2 Second alert to compare. */ areSame(alert1: Alert, alert2: Alert): boolean; private changeAlerts; private addAlert; private hideAutomaticallyIfNeeded; private removeOldestIfMax; static ɵfac: i0.ɵɵFactoryDeclaration<AlertService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<AlertService>; } //# sourceMappingURL=alert.service.d.ts.map