@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
166 lines • 8.62 kB
TypeScript
import { AlarmQueryFilter, AlarmService, IAlarm, IResultList, SeverityFilter, SeverityType } from '@c8y/client';
import { ApplicationOptions, ContextData, DateTimeContext, OptionsService, ContextRouteService } from '@c8y/ngx-components';
import { Observable, Subject } from 'rxjs';
import { ReloadAlarmsListType } from './alarms.model';
import { AlarmFilterInterval } from '@c8y/ngx-components/interval-picker';
import { ActivatedRoute, ActivatedRouteSnapshot, Router } from '@angular/router';
import * as i0 from "@angular/core";
/**
* Service for managing and retrieving alarms data within the alarms view.
*
* The `AlarmsViewService` provides functionality to interact with alarms,
* including filtering, counting, and translation-related operations in an alarms view.
*
* This service relies on the `AlarmService` for fetching alarm data and the `OptionsService`
* for configuring alarms view options.
*/
export declare class AlarmsViewService {
private alarmService;
private optionsService;
private router;
private contextRouteService;
readonly ALARM_REFRESH_TYPE_KEY: keyof ApplicationOptions;
readonly DEFAULT_INTERVAL_VALUE = 30000;
readonly DEFAULT_REFRESH_OPTION_VALUE = "interval";
readonly DEFAULT_INTERVAL_VALUES: number[];
readonly REALTIME_UPDATE_ALARMS_MESSAGE: "The list was updated, click to refresh.";
isIntervalEnabled$: Observable<boolean>;
reloadAlarmsList$: Subject<"gainsightTypeFilters">;
closeDetailsView$: Subject<void>;
private _isIntervalEnabled;
constructor(alarmService: AlarmService, optionsService: OptionsService, router: Router, contextRouteService: ContextRouteService);
/**
* Emits a subject to initialize the alarms reloading.
*/
updateAlarmList(value?: ReloadAlarmsListType): void;
/**
* Retrieves a list of alarms filtered by specified severities and other optional query filters.
*
* @param severities an array of severities to filter the alarms.
* @param showCleared flag indicating whether to show cleared alarms. Defaults to false.
* @param selectedDates an array of two dates to filter alarms by creation and last update dates.
* @param filter additional query filters for retrieving alarms.
*
* @returns A promise that resolves to a list of alarms satisfying the specified filters.
*/
retrieveFilteredAlarms(severities: SeverityType[], showCleared?: boolean, selectedDates?: [Date, Date], filter?: AlarmQueryFilter): Promise<IResultList<IAlarm>>;
retrieveAlarmsByDate(dates: DateTimeContext): Promise<IResultList<IAlarm>>;
/**
* Updates the state to enable or disable intervals.
* @param value - A boolean value to indicate whether to enable intervals.
*/
updateIntervalState(value: boolean): void;
/**
* Fetches the count of alarms filtered by severity and clearance status.
*
* @param severity - The severity level to filter by (e.g., CRITICAL, MAJOR, etc.).
* @param showCleared - Whether or not to include cleared alarms in the count.
* @param filter - Additional filter criteria for alarms.
*
* @returns A promise that resolves to the number of alarms that match the filter criteria.
*
*/
getAlarmsCountBySeverity(severity: SeverityType, showCleared: boolean, filter?: AlarmQueryFilter): Promise<number>;
/**
* Retrieves the current alarms refresh type from the OptionsService
* and determines whether it is set to "interval".
*
* @returns `true` if the alarms refresh type is "interval," otherwise `false`.
*/
isIntervalRefresh(): boolean;
/**
* Updates the list of selected severities based on the new severity filter.
*
* @param severityUpdates - The object representing the updates to each severity.
*
* @returns An array representing the updated selected severities.
*/
updateSelectedSeverities(severityUpdates: SeverityFilter): SeverityType[];
/**
* Clears all active alarms of the selected severities.
*
* This method clears all active alarms for the given list of severities by making bulk update calls. If no severities are selected, it defaults to using all available severities.
* It works by sending a series of update requests for each severity and returns a Promise that resolves with an object indicating if all alarms were resolved immediately.
*
* @param selectedSeverities An array of severities to be cleared. If not provided, all severities will be cleared.
* @param sourceId - Identifier for the source associated with the alarms to be cleared.
*
* @returns A Promise that resolves with an object with a flag `resolvedImmediately`. The flag is true if all alarms for all selected severities were cleared successfully; otherwise false.
*
* **Example**
* ```typescript
* const severitiesToClear: SeverityType[] = [Severity.MAJOR, Severity.MINOR];
*
* clearAllActiveAlarms(severitiesToClear).then(({ resolvedImmediately }) => {
* if (resolvedImmediately) {
* console.log('All selected alarms were cleared successfully.');
* } else {
* console.log('Some alarms could not be cleared.');
* }
* });
* ```
*
* **Note**
* - The method uses the `alarmService.updateBulk` for each severity to clear the active alarms.
* - It may fetch the `sourceId` based on the view (if applicable) and include it as a query parameter in the update calls.
* - The method returns immediately but the returned Promise needs to have a `then` or `catch` method call to handle the result or error respectively.
* - Uses `Promise.all` to wait for all update requests to complete before resolving the final result.
*/
clearAllActiveAlarms(selectedSeverities: SeverityType[], sourceId: string | number): Promise<{
resolvedImmediately: boolean;
}>;
/**
* Returns the correct link based on the provided context data.
* @param contextData The context the navigation was triggered from.
* @param alarm The alarm to navigate to.
* @returns A link to be used as an url navigation.
*/
getRouterLink(contextData?: ContextData, alarm?: IAlarm): string;
/**
* Returns the correct array navigation.
* @param contextData The context the navigation was triggered from.
* @param alarm The alarm to navigate to.
* @returns A link to be used as a router.navigation.
*/
getRouterNavigationArray(contextData?: ContextData, alarm?: IAlarm): string[];
/**
* Closes the details view and navigates based on the current route context,
* preserving existing query parameters.
*/
closeDetailsView(activatedRoute: ActivatedRoute | ActivatedRouteSnapshot): Promise<void>;
/**
* Returns the correct from and to dates based on the selected interval
* @param intervalId the selected interval. E.g. 'none', 'hours', 'custom' ...
* @returns The calculated date context based on the selected interval.
*/
getDateTimeContextByInterval(intervalId: AlarmFilterInterval['id']): DateTimeContext;
/**
* Converts a given number of seconds into a formatted string representing hours, minutes, and seconds.
*
* @param totalSeconds - The total number of seconds to convert.
* @returns A string in the format "HH:MM:SS", where HH is hours, MM is minutes, and SS is seconds.
*/
convertSecondsToTime(totalSeconds: number): string;
/**
* Creates a value for query parameter for filtering alarms by severity based on array of selected severities.
*
* @param severities - An array of alarm severity types to include in the filter.
* If the array is empty or undefined, no severity filter will be applied.
*
* @returns A comma-separated string of selected alarm severities,
* or null if no severities are provided.
*/
private getSeverityQueryParameter;
/**
* Creates a value for query parameter for filtering alarms by statuses based on showCleared option.
*
* @param showCleared - A flag indicating whether to include cleared statuses.
* If true, all statuses, including 'CLEARED', will be included; if false, 'CLEARED' will be excluded.
*
* @returns A comma-separated string of alarm statuses.
*/
private getStatusQueryParameter;
static ɵfac: i0.ɵɵFactoryDeclaration<AlarmsViewService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<AlarmsViewService>;
}
//# sourceMappingURL=alarms-view.service.d.ts.map