File

alarms/alarms-view.service.ts

Description

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.

Index

Properties
Methods

Constructor

constructor(alarmService: AlarmService, optionsService: OptionsService)
Parameters :
Name Type Optional
alarmService AlarmService No
optionsService OptionsService No

Methods

Async clearAllActiveAlarms
clearAllActiveAlarms(selectedSeverities: SeverityType[], sourceId: string | number)

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.

Example

Example :
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.
Parameters :
Name Type Optional Description
selectedSeverities SeverityType[] No

An array of severities to be cleared. If not provided, all severities will be cleared.

sourceId string | number No
  • Identifier for the source associated with the alarms to be cleared.
Returns : Promise<literal type>

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

Example :
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.
Async getAlarmsCountBySeverity
getAlarmsCountBySeverity(severity: SeverityType, showCleared: boolean, filter?: AlarmQueryFilter)

Fetches the count of alarms filtered by severity and clearance status.

Parameters :
Name Type Optional Description
severity SeverityType No
  • The severity level to filter by (e.g., CRITICAL, MAJOR, etc.).
showCleared boolean No
  • Whether or not to include cleared alarms in the count.
filter AlarmQueryFilter Yes
  • Additional filter criteria for alarms.
Returns : Promise<number>

A promise that resolves to the number of alarms that match the filter criteria.

getRouterLink
getRouterLink(contextData?: ContextData, alarm?: IAlarm)

Returns the correct link based on the provided context data.

Parameters :
Name Type Optional Description
contextData ContextData Yes

The context the navigation was triggered from.

alarm IAlarm Yes

The alarm to navigate to.

Returns : string

A link to be used as an url navigation.

getRouterNavigationArray
getRouterNavigationArray(contextData?: ContextData, alarm?: IAlarm)

Returns the correct array navigation.

Parameters :
Name Type Optional Description
contextData ContextData Yes

The context the navigation was triggered from.

alarm IAlarm Yes

The alarm to navigate to.

Returns : string[]

A link to be used as a router.navigation.

isIntervalRefresh
isIntervalRefresh()

Retrieves the current alarms refresh type from the OptionsService and determines whether it is set to "interval".

Returns : boolean

true if the alarms refresh type is "interval," otherwise false.

retrieveAlarms
retrieveAlarms(severities: SeverityType[], showCleared, filter?: AlarmQueryFilter)

Retrieves a list of alarms filtered by specified severities and other optional query filters.

Parameters :
Name Type Optional Default value Description
severities SeverityType[] No

an array of severities to filter the alarms.

showCleared No false

flag indicating whether to show cleared alarms. Defaults to false.

filter AlarmQueryFilter Yes

additional query filters for retrieving alarms.

Returns : Promise<IResultList<IAlarm>>

A promise that resolves to a list of alarms satisfying the specified filters.

updateAlarmList
updateAlarmList()

Emits a subject to initialize the alarms reloading.

Returns : void
updateIntervalState
updateIntervalState(value: boolean)

Updates the state to enable or disable intervals.

Parameters :
Name Type Optional Description
value boolean No
  • A boolean value to indicate whether to enable intervals.
Returns : void
updateSelectedSeverities
updateSelectedSeverities(severityUpdates: SeverityFilter)

Updates the list of selected severities based on the new severity filter.

Parameters :
Name Type Optional Description
severityUpdates SeverityFilter No
  • The object representing the updates to each severity.
Returns : SeverityType[]

An array representing the updated selected severities.

Properties

Readonly ALARM_REFRESH_TYPE_KEY
Default value : 'alarmsRefreshType'
Readonly DEFAULT_INTERVAL_VALUE
Type : number
Default value : 30_000
Readonly DEFAULT_INTERVAL_VALUES
Type : []
Default value : [5_000, 10_000, 15_000, 30_000, 60_000]
isIntervalEnabled$
Type : Observable<boolean>
Readonly REALTIME_UPDATE_ALARMS_MESSAGE
Default value : gettext('The list was updated, click to refresh.')
reloadAlarmsList$
Default value : new Subject<void>()

results matching ""

    No results matching ""