2019-08-29 12:08:49 +03:00
|
|
|
///
|
2024-01-09 10:46:16 +02:00
|
|
|
/// Copyright © 2016-2024 The Thingsboard Authors
|
2019-08-29 12:08:49 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { Injectable } from '@angular/core';
|
2020-01-22 20:05:30 +02:00
|
|
|
import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
|
2020-07-06 14:42:36 +03:00
|
|
|
import { Observable } from 'rxjs';
|
2019-08-29 12:08:49 +03:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
|
import { PageData } from '@shared/models/page/page-data';
|
|
|
|
|
import { EntityId } from '@shared/models/id/entity-id';
|
|
|
|
|
import {
|
|
|
|
|
Alarm,
|
|
|
|
|
AlarmInfo,
|
2023-04-21 18:00:56 +03:00
|
|
|
AlarmQuery, AlarmQueryV2,
|
2019-08-29 12:08:49 +03:00
|
|
|
AlarmSearchStatus,
|
|
|
|
|
AlarmSeverity,
|
2020-07-06 14:42:36 +03:00
|
|
|
AlarmStatus
|
2019-08-29 12:08:49 +03:00
|
|
|
} from '@shared/models/alarm.models';
|
2023-07-31 15:50:43 +03:00
|
|
|
import { EntitySubtype } from '@shared/models/entity-type.models';
|
2023-08-18 17:19:37 +03:00
|
|
|
import { PageLink } from '@shared/models/page/page-link';
|
2019-08-29 12:08:49 +03:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class AlarmService {
|
|
|
|
|
|
|
|
|
|
constructor(
|
2023-08-18 17:19:37 +03:00
|
|
|
private http: HttpClient
|
2019-08-29 12:08:49 +03:00
|
|
|
) { }
|
|
|
|
|
|
2019-11-15 12:22:14 +02:00
|
|
|
public getAlarm(alarmId: string, config?: RequestConfig): Observable<Alarm> {
|
|
|
|
|
return this.http.get<Alarm>(`/api/alarm/${alarmId}`, defaultHttpOptionsFromConfig(config));
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 12:22:14 +02:00
|
|
|
public getAlarmInfo(alarmId: string, config?: RequestConfig): Observable<AlarmInfo> {
|
|
|
|
|
return this.http.get<AlarmInfo>(`/api/alarm/info/${alarmId}`, defaultHttpOptionsFromConfig(config));
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 12:22:14 +02:00
|
|
|
public saveAlarm(alarm: Alarm, config?: RequestConfig): Observable<Alarm> {
|
|
|
|
|
return this.http.post<Alarm>('/api/alarm', alarm, defaultHttpOptionsFromConfig(config));
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|
|
|
|
|
|
2023-08-07 16:11:14 +03:00
|
|
|
public ackAlarm(alarmId: string, config?: RequestConfig): Observable<AlarmInfo> {
|
|
|
|
|
return this.http.post<AlarmInfo>(`/api/alarm/${alarmId}/ack`, null, defaultHttpOptionsFromConfig(config));
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|
|
|
|
|
|
2023-08-07 16:11:14 +03:00
|
|
|
public clearAlarm(alarmId: string, config?: RequestConfig): Observable<AlarmInfo> {
|
|
|
|
|
return this.http.post<AlarmInfo>(`/api/alarm/${alarmId}/clear`, null, defaultHttpOptionsFromConfig(config));
|
2020-02-20 18:50:00 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-16 14:51:24 +02:00
|
|
|
public assignAlarm(alarmId: string, assigneeId: string, config?: RequestConfig): Observable<void> {
|
|
|
|
|
return this.http.post<void>(`/api/alarm/${alarmId}/assign/${assigneeId}`, null, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public unassignAlarm(alarmId: string, config?: RequestConfig): Observable<void> {
|
|
|
|
|
return this.http.delete<void>(`/api/alarm/${alarmId}/assign`, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 16:11:14 +03:00
|
|
|
public deleteAlarm(alarmId: string, config?: RequestConfig): Observable<boolean> {
|
|
|
|
|
return this.http.delete<boolean>(`/api/alarm/${alarmId}`, defaultHttpOptionsFromConfig(config));
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getAlarms(query: AlarmQuery,
|
2019-11-15 12:22:14 +02:00
|
|
|
config?: RequestConfig): Observable<PageData<AlarmInfo>> {
|
2019-08-29 12:08:49 +03:00
|
|
|
return this.http.get<PageData<AlarmInfo>>(`/api/alarm${query.toQuery()}`,
|
2019-11-15 12:22:14 +02:00
|
|
|
defaultHttpOptionsFromConfig(config));
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|
|
|
|
|
|
2023-04-21 18:00:56 +03:00
|
|
|
public getAlarmsV2(query: AlarmQueryV2,
|
|
|
|
|
config?: RequestConfig): Observable<PageData<AlarmInfo>> {
|
|
|
|
|
return this.http.get<PageData<AlarmInfo>>(`/api/v2/alarm${query.toQuery()}`,
|
|
|
|
|
defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 19:09:05 +02:00
|
|
|
public getAllAlarms(query: AlarmQuery,
|
|
|
|
|
config?: RequestConfig): Observable<PageData<AlarmInfo>> {
|
|
|
|
|
return this.http.get<PageData<AlarmInfo>>(`/api/alarms${query.toQuery()}`,
|
|
|
|
|
defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 18:00:56 +03:00
|
|
|
public getAllAlarmsV2(query: AlarmQueryV2,
|
|
|
|
|
config?: RequestConfig): Observable<PageData<AlarmInfo>> {
|
|
|
|
|
return this.http.get<PageData<AlarmInfo>>(`/api/v2/alarms${query.toQuery()}`,
|
|
|
|
|
defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-29 12:08:49 +03:00
|
|
|
public getHighestAlarmSeverity(entityId: EntityId, alarmSearchStatus: AlarmSearchStatus, alarmStatus: AlarmStatus,
|
2019-11-15 12:22:14 +02:00
|
|
|
config?: RequestConfig): Observable<AlarmSeverity> {
|
2021-05-06 20:14:34 +03:00
|
|
|
let url = `/api/alarm/highestSeverity/${entityId.entityType}/${entityId.id}`;
|
2019-08-29 12:08:49 +03:00
|
|
|
if (alarmSearchStatus) {
|
|
|
|
|
url += `?searchStatus=${alarmSearchStatus}`;
|
|
|
|
|
} else if (alarmStatus) {
|
|
|
|
|
url += `?status=${alarmStatus}`;
|
|
|
|
|
}
|
|
|
|
|
return this.http.get<AlarmSeverity>(url,
|
2019-11-15 12:22:14 +02:00
|
|
|
defaultHttpOptionsFromConfig(config));
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|
2020-01-22 20:05:30 +02:00
|
|
|
|
2023-08-18 17:19:37 +03:00
|
|
|
public getAlarmTypes(pageLink: PageLink, config?: RequestConfig): Observable<PageData<EntitySubtype>> {
|
|
|
|
|
return this.http.get<PageData<EntitySubtype>>(`/api/alarm/types${pageLink.toQuery()}`, defaultHttpOptionsFromConfig(config));
|
2023-06-26 23:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-29 12:08:49 +03:00
|
|
|
}
|