UI: Change ws command to new format and change API uri

This commit is contained in:
Vladyslav_Prykhodko 2023-12-07 15:45:58 +02:00
parent 31f95fbe62
commit 6b4c7c7ce4
3 changed files with 61 additions and 166 deletions

View File

@ -22,14 +22,12 @@ import {
AlarmDataCmd, AlarmDataCmd,
AlarmDataUnsubscribeCmd, AlarmDataUnsubscribeCmd,
AlarmDataUpdate, AlarmDataUpdate,
AttributesSubscriptionCmd,
EntityCountCmd, EntityCountCmd,
EntityCountUnsubscribeCmd, EntityCountUnsubscribeCmd,
EntityCountUpdate, EntityCountUpdate,
EntityDataCmd, EntityDataCmd,
EntityDataUnsubscribeCmd, EntityDataUnsubscribeCmd,
EntityDataUpdate, EntityDataUpdate,
GetHistoryCmd,
isAlarmCountUpdateMsg, isAlarmCountUpdateMsg,
isAlarmDataUpdateMsg, isAlarmDataUpdateMsg,
isEntityCountUpdateMsg, isEntityCountUpdateMsg,
@ -38,10 +36,8 @@ import {
NotificationsUpdate, NotificationsUpdate,
SubscriptionCmd, SubscriptionCmd,
SubscriptionUpdate, SubscriptionUpdate,
TelemetryFeature,
TelemetryPluginCmdsWrapper, TelemetryPluginCmdsWrapper,
TelemetrySubscriber, TelemetrySubscriber,
TimeseriesSubscriptionCmd,
WebsocketDataMsg WebsocketDataMsg
} from '@app/shared/models/telemetry/telemetry.models'; } from '@app/shared/models/telemetry/telemetry.models';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
@ -72,7 +68,7 @@ export class TelemetryWebsocketService extends WebsocketService<TelemetrySubscri
protected authService: AuthService, protected authService: AuthService,
protected ngZone: NgZone, protected ngZone: NgZone,
@Inject(WINDOW) protected window: Window) { @Inject(WINDOW) protected window: Window) {
super(store, authService, ngZone, 'api/ws/plugins/telemetry', new TelemetryPluginCmdsWrapper(), window); super(store, authService, ngZone, 'api/ws', new TelemetryPluginCmdsWrapper(), window);
} }
public subscribe(subscriber: TelemetrySubscriber) { public subscribe(subscriber: TelemetrySubscriber) {
@ -80,35 +76,11 @@ export class TelemetryWebsocketService extends WebsocketService<TelemetrySubscri
subscriber.subscriptionCommands.forEach( subscriber.subscriptionCommands.forEach(
(subscriptionCommand) => { (subscriptionCommand) => {
const cmdId = this.nextCmdId(); const cmdId = this.nextCmdId();
this.subscribersMap.set(cmdId, subscriber); if (!(subscriptionCommand instanceof MarkAsReadCmd) && !(subscriptionCommand instanceof MarkAllAsReadCmd)) {
subscriptionCommand.cmdId = cmdId; this.subscribersMap.set(cmdId, subscriber);
if (subscriptionCommand instanceof SubscriptionCmd) {
if (subscriptionCommand.getType() === TelemetryFeature.TIMESERIES) {
this.cmdWrapper.tsSubCmds.push(subscriptionCommand as TimeseriesSubscriptionCmd);
} else {
this.cmdWrapper.attrSubCmds.push(subscriptionCommand as AttributesSubscriptionCmd);
}
} else if (subscriptionCommand instanceof GetHistoryCmd) {
this.cmdWrapper.historyCmds.push(subscriptionCommand);
} else if (subscriptionCommand instanceof EntityDataCmd) {
this.cmdWrapper.entityDataCmds.push(subscriptionCommand);
} else if (subscriptionCommand instanceof AlarmDataCmd) {
this.cmdWrapper.alarmDataCmds.push(subscriptionCommand);
} else if (subscriptionCommand instanceof EntityCountCmd) {
this.cmdWrapper.entityCountCmds.push(subscriptionCommand);
} else if (subscriptionCommand instanceof AlarmCountCmd) {
this.cmdWrapper.alarmCountCmds.push(subscriptionCommand);
} else if (subscriptionCommand instanceof UnreadCountSubCmd) {
this.cmdWrapper.unreadNotificationsCountSubCmds.push(subscriptionCommand);
} else if (subscriptionCommand instanceof UnreadSubCmd) {
this.cmdWrapper.unreadNotificationsSubCmds.push(subscriptionCommand);
} else if (subscriptionCommand instanceof MarkAsReadCmd) {
this.cmdWrapper.markNotificationAsReadCmds.push(subscriptionCommand);
this.subscribersMap.delete(cmdId);
} else if (subscriptionCommand instanceof MarkAllAsReadCmd) {
this.cmdWrapper.markAllNotificationsAsReadCmds.push(subscriptionCommand);
this.subscribersMap.delete(cmdId);
} }
subscriptionCommand.cmdId = cmdId;
this.cmdWrapper.cmds.push(subscriptionCommand);
} }
); );
this.subscribersCount++; this.subscribersCount++;
@ -119,10 +91,8 @@ export class TelemetryWebsocketService extends WebsocketService<TelemetrySubscri
if (!this.isReconnect) { if (!this.isReconnect) {
subscriber.subscriptionCommands.forEach( subscriber.subscriptionCommands.forEach(
(subscriptionCommand) => { (subscriptionCommand) => {
if (subscriptionCommand.cmdId && subscriptionCommand instanceof EntityDataCmd) { if (subscriptionCommand.cmdId && (subscriptionCommand instanceof EntityDataCmd || subscriptionCommand instanceof UnreadSubCmd)) {
this.cmdWrapper.entityDataCmds.push(subscriptionCommand); this.cmdWrapper.cmds.push(subscriptionCommand);
} else if (subscriptionCommand.cmdId && subscriptionCommand instanceof UnreadSubCmd) {
this.cmdWrapper.unreadNotificationsSubCmds.push(subscriptionCommand);
} }
} }
); );
@ -136,31 +106,27 @@ export class TelemetryWebsocketService extends WebsocketService<TelemetrySubscri
(subscriptionCommand) => { (subscriptionCommand) => {
if (subscriptionCommand instanceof SubscriptionCmd) { if (subscriptionCommand instanceof SubscriptionCmd) {
subscriptionCommand.unsubscribe = true; subscriptionCommand.unsubscribe = true;
if (subscriptionCommand.getType() === TelemetryFeature.TIMESERIES) { this.cmdWrapper.cmds.push(subscriptionCommand);
this.cmdWrapper.tsSubCmds.push(subscriptionCommand as TimeseriesSubscriptionCmd);
} else {
this.cmdWrapper.attrSubCmds.push(subscriptionCommand as AttributesSubscriptionCmd);
}
} else if (subscriptionCommand instanceof EntityDataCmd) { } else if (subscriptionCommand instanceof EntityDataCmd) {
const entityDataUnsubscribeCmd = new EntityDataUnsubscribeCmd(); const entityDataUnsubscribeCmd = new EntityDataUnsubscribeCmd();
entityDataUnsubscribeCmd.cmdId = subscriptionCommand.cmdId; entityDataUnsubscribeCmd.cmdId = subscriptionCommand.cmdId;
this.cmdWrapper.entityDataUnsubscribeCmds.push(entityDataUnsubscribeCmd); this.cmdWrapper.cmds.push(entityDataUnsubscribeCmd);
} else if (subscriptionCommand instanceof AlarmDataCmd) { } else if (subscriptionCommand instanceof AlarmDataCmd) {
const alarmDataUnsubscribeCmd = new AlarmDataUnsubscribeCmd(); const alarmDataUnsubscribeCmd = new AlarmDataUnsubscribeCmd();
alarmDataUnsubscribeCmd.cmdId = subscriptionCommand.cmdId; alarmDataUnsubscribeCmd.cmdId = subscriptionCommand.cmdId;
this.cmdWrapper.alarmDataUnsubscribeCmds.push(alarmDataUnsubscribeCmd); this.cmdWrapper.cmds.push(alarmDataUnsubscribeCmd);
} else if (subscriptionCommand instanceof EntityCountCmd) { } else if (subscriptionCommand instanceof EntityCountCmd) {
const entityCountUnsubscribeCmd = new EntityCountUnsubscribeCmd(); const entityCountUnsubscribeCmd = new EntityCountUnsubscribeCmd();
entityCountUnsubscribeCmd.cmdId = subscriptionCommand.cmdId; entityCountUnsubscribeCmd.cmdId = subscriptionCommand.cmdId;
this.cmdWrapper.entityCountUnsubscribeCmds.push(entityCountUnsubscribeCmd); this.cmdWrapper.cmds.push(entityCountUnsubscribeCmd);
} else if (subscriptionCommand instanceof AlarmCountCmd) { } else if (subscriptionCommand instanceof AlarmCountCmd) {
const alarmCountUnsubscribeCmd = new AlarmCountUnsubscribeCmd(); const alarmCountUnsubscribeCmd = new AlarmCountUnsubscribeCmd();
alarmCountUnsubscribeCmd.cmdId = subscriptionCommand.cmdId; alarmCountUnsubscribeCmd.cmdId = subscriptionCommand.cmdId;
this.cmdWrapper.alarmCountUnsubscribeCmds.push(alarmCountUnsubscribeCmd); this.cmdWrapper.cmds.push(alarmCountUnsubscribeCmd);
} else if (subscriptionCommand instanceof UnreadCountSubCmd || subscriptionCommand instanceof UnreadSubCmd) { } else if (subscriptionCommand instanceof UnreadCountSubCmd || subscriptionCommand instanceof UnreadSubCmd) {
const notificationsUnsubCmds = new UnsubscribeCmd(); const notificationsUnsubCmds = new UnsubscribeCmd();
notificationsUnsubCmds.cmdId = subscriptionCommand.cmdId; notificationsUnsubCmds.cmdId = subscriptionCommand.cmdId;
this.cmdWrapper.notificationsUnsubCmds.push(notificationsUnsubCmds); this.cmdWrapper.cmds.push(notificationsUnsubCmds);
} }
const cmdId = subscriptionCommand.cmdId; const cmdId = subscriptionCommand.cmdId;
if (cmdId) { if (cmdId) {

View File

@ -38,15 +38,7 @@ import { entityFields } from '@shared/models/entity.models';
import { isUndefined } from '@core/utils'; import { isUndefined } from '@core/utils';
import { CmdWrapper, WsSubscriber } from '@shared/models/websocket/websocket.models'; import { CmdWrapper, WsSubscriber } from '@shared/models/websocket/websocket.models';
import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service'; import { TelemetryWebsocketService } from '@core/ws/telemetry-websocket.service';
import { import { NotificationCountUpdateMsg, NotificationsUpdateMsg } from '@shared/models/websocket/notification-ws.models';
MarkAllAsReadCmd,
MarkAsReadCmd,
NotificationCountUpdateMsg,
NotificationsUpdateMsg,
UnreadCountSubCmd,
UnreadSubCmd,
UnsubscribeCmd
} from '@shared/models/websocket/notification-ws.models';
import { Notification } from '@shared/models/notification.models'; import { Notification } from '@shared/models/notification.models';
export const NOT_SUPPORTED = 'Not supported!'; export const NOT_SUPPORTED = 'Not supported!';
@ -70,11 +62,6 @@ export enum AttributeScope {
SHARED_SCOPE = 'SHARED_SCOPE' SHARED_SCOPE = 'SHARED_SCOPE'
} }
export enum TelemetryFeature {
ATTRIBUTES = 'ATTRIBUTES',
TIMESERIES = 'TIMESERIES'
}
export enum TimeseriesDeleteStrategy { export enum TimeseriesDeleteStrategy {
DELETE_ALL_DATA = 'DELETE_ALL_DATA', DELETE_ALL_DATA = 'DELETE_ALL_DATA',
DELETE_ALL_DATA_EXCEPT_LATEST_VALUE = 'DELETE_ALL_DATA_EXCEPT_LATEST_VALUE', DELETE_ALL_DATA_EXCEPT_LATEST_VALUE = 'DELETE_ALL_DATA_EXCEPT_LATEST_VALUE',
@ -134,8 +121,30 @@ export enum DataSortOrder {
DESC = 'DESC' DESC = 'DESC'
} }
export enum WsCmdType {
ATTRIBUTES = 'ATTRIBUTES',
TIMESERIES = 'TIMESERIES',
TIMESERIES_HISTORY = 'TIMESERIES_HISTORY',
ENTITY_DATA = 'ENTITY_DATA',
ENTITY_COUNT = 'ENTITY_COUNT',
ALARM_DATA = 'ALARM_DATA',
ALARM_COUNT = 'ALARM_COUNT',
NOTIFICATIONS = 'NOTIFICATIONS',
NOTIFICATIONS_COUNT = 'NOTIFICATIONS_COUNT',
MARK_NOTIFICATIONS_AS_READ = 'MARK_NOTIFICATIONS_AS_READ',
MARK_ALL_NOTIFICATIONS_AS_READ = 'MARK_ALL_NOTIFICATIONS_AS_READ',
ALARM_DATA_UNSUBSCRIBE = 'ALARM_DATA_UNSUBSCRIBE',
ALARM_COUNT_UNSUBSCRIBE = 'ALARM_COUNT_UNSUBSCRIBE',
ENTITY_DATA_UNSUBSCRIBE = 'ENTITY_DATA_UNSUBSCRIBE',
ENTITY_COUNT_UNSUBSCRIBE = 'ENTITY_COUNT_UNSUBSCRIBE',
NOTIFICATIONS_UNSUBSCRIBE = 'NOTIFICATIONS_UNSUBSCRIBE'
}
export interface WebsocketCmd { export interface WebsocketCmd {
cmdId: number; cmdId: number;
type: WsCmdType;
} }
export interface TelemetryPluginCmd extends WebsocketCmd { export interface TelemetryPluginCmd extends WebsocketCmd {
@ -149,13 +158,11 @@ export abstract class SubscriptionCmd implements TelemetryPluginCmd {
entityId: string; entityId: string;
scope?: AttributeScope; scope?: AttributeScope;
unsubscribe: boolean; unsubscribe: boolean;
abstract getType(): TelemetryFeature; abstract type: WsCmdType;
} }
export class AttributesSubscriptionCmd extends SubscriptionCmd { export class AttributesSubscriptionCmd extends SubscriptionCmd {
getType() { type = WsCmdType.ATTRIBUTES;
return TelemetryFeature.ATTRIBUTES;
}
} }
export class TimeseriesSubscriptionCmd extends SubscriptionCmd { export class TimeseriesSubscriptionCmd extends SubscriptionCmd {
@ -164,10 +171,7 @@ export class TimeseriesSubscriptionCmd extends SubscriptionCmd {
interval: number; interval: number;
limit: number; limit: number;
agg: AggregationType; agg: AggregationType;
type = WsCmdType.TIMESERIES;
getType() {
return TelemetryFeature.TIMESERIES;
}
} }
export class GetHistoryCmd implements TelemetryPluginCmd { export class GetHistoryCmd implements TelemetryPluginCmd {
@ -180,6 +184,7 @@ export class GetHistoryCmd implements TelemetryPluginCmd {
interval: number; interval: number;
limit: number; limit: number;
agg: AggregationType; agg: AggregationType;
type = WsCmdType.TIMESERIES_HISTORY;
} }
export interface EntityHistoryCmd { export interface EntityHistoryCmd {
@ -235,6 +240,7 @@ export class EntityDataCmd implements WebsocketCmd {
tsCmd?: TimeSeriesCmd; tsCmd?: TimeSeriesCmd;
aggHistoryCmd?: AggEntityHistoryCmd; aggHistoryCmd?: AggEntityHistoryCmd;
aggTsCmd?: AggTimeSeriesCmd; aggTsCmd?: AggTimeSeriesCmd;
type = WsCmdType.ENTITY_DATA;
public isEmpty(): boolean { public isEmpty(): boolean {
return !this.query && !this.historyCmd && !this.latestCmd && !this.tsCmd && !this.aggTsCmd && !this.aggHistoryCmd; return !this.query && !this.historyCmd && !this.latestCmd && !this.tsCmd && !this.aggTsCmd && !this.aggHistoryCmd;
@ -244,11 +250,13 @@ export class EntityDataCmd implements WebsocketCmd {
export class EntityCountCmd implements WebsocketCmd { export class EntityCountCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
query?: EntityCountQuery; query?: EntityCountQuery;
type = WsCmdType.ENTITY_COUNT;
} }
export class AlarmDataCmd implements WebsocketCmd { export class AlarmDataCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
query?: AlarmDataQuery; query?: AlarmDataQuery;
type = WsCmdType.ALARM_DATA;
public isEmpty(): boolean { public isEmpty(): boolean {
return !this.query; return !this.query;
@ -258,60 +266,36 @@ export class AlarmDataCmd implements WebsocketCmd {
export class AlarmCountCmd implements WebsocketCmd { export class AlarmCountCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
query?: AlarmCountQuery; query?: AlarmCountQuery;
type = WsCmdType.ALARM_COUNT;
} }
export class EntityDataUnsubscribeCmd implements WebsocketCmd { export class EntityDataUnsubscribeCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
type = WsCmdType.ENTITY_DATA_UNSUBSCRIBE;
} }
export class EntityCountUnsubscribeCmd implements WebsocketCmd { export class EntityCountUnsubscribeCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
type = WsCmdType.ENTITY_COUNT_UNSUBSCRIBE;
} }
export class AlarmDataUnsubscribeCmd implements WebsocketCmd { export class AlarmDataUnsubscribeCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
type = WsCmdType.ALARM_DATA_UNSUBSCRIBE;
} }
export class AlarmCountUnsubscribeCmd implements WebsocketCmd { export class AlarmCountUnsubscribeCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
type = WsCmdType.ALARM_COUNT_UNSUBSCRIBE;
} }
export class TelemetryPluginCmdsWrapper implements CmdWrapper { export class TelemetryPluginCmdsWrapper implements CmdWrapper {
constructor() { constructor() {
this.attrSubCmds = []; this.cmds = [];
this.tsSubCmds = [];
this.historyCmds = [];
this.entityDataCmds = [];
this.entityDataUnsubscribeCmds = [];
this.alarmDataCmds = [];
this.alarmDataUnsubscribeCmds = [];
this.entityCountCmds = [];
this.entityCountUnsubscribeCmds = [];
this.alarmCountCmds = [];
this.alarmCountUnsubscribeCmds = [];
this.unreadNotificationsCountSubCmds = [];
this.unreadNotificationsSubCmds = [];
this.notificationsUnsubCmds = [];
this.markNotificationAsReadCmds = [];
this.markAllNotificationsAsReadCmds = [];
} }
attrSubCmds: Array<AttributesSubscriptionCmd>;
tsSubCmds: Array<TimeseriesSubscriptionCmd>; cmds: Array<WebsocketCmd>;
historyCmds: Array<GetHistoryCmd>;
entityDataCmds: Array<EntityDataCmd>;
entityDataUnsubscribeCmds: Array<EntityDataUnsubscribeCmd>;
alarmDataCmds: Array<AlarmDataCmd>;
alarmDataUnsubscribeCmds: Array<AlarmDataUnsubscribeCmd>;
entityCountCmds: Array<EntityCountCmd>;
entityCountUnsubscribeCmds: Array<EntityCountUnsubscribeCmd>;
alarmCountCmds: Array<AlarmCountCmd>;
alarmCountUnsubscribeCmds: Array<AlarmCountUnsubscribeCmd>;
unreadNotificationsCountSubCmds: Array<UnreadCountSubCmd>;
unreadNotificationsSubCmds: Array<UnreadSubCmd>;
notificationsUnsubCmds: Array<UnsubscribeCmd>;
markNotificationAsReadCmds: Array<MarkAsReadCmd>;
markAllNotificationsAsReadCmds: Array<MarkAllAsReadCmd>;
private static popCmds<T>(cmds: Array<T>, leftCount: number): Array<T> { private static popCmds<T>(cmds: Array<T>, leftCount: number): Array<T> {
const toPublish = Math.min(cmds.length, leftCount); const toPublish = Math.min(cmds.length, leftCount);
@ -323,77 +307,16 @@ export class TelemetryPluginCmdsWrapper implements CmdWrapper {
} }
public hasCommands(): boolean { public hasCommands(): boolean {
return this.tsSubCmds.length > 0 || return this.cmds.length > 0;
this.historyCmds.length > 0 ||
this.attrSubCmds.length > 0 ||
this.entityDataCmds.length > 0 ||
this.entityDataUnsubscribeCmds.length > 0 ||
this.alarmDataCmds.length > 0 ||
this.alarmDataUnsubscribeCmds.length > 0 ||
this.entityCountCmds.length > 0 ||
this.entityCountUnsubscribeCmds.length > 0 ||
this.alarmCountCmds.length > 0 ||
this.alarmCountUnsubscribeCmds.length > 0 ||
this.unreadNotificationsCountSubCmds.length > 0 ||
this.unreadNotificationsSubCmds.length > 0 ||
this.notificationsUnsubCmds.length > 0 ||
this.markNotificationAsReadCmds.length > 0 ||
this.markAllNotificationsAsReadCmds.length > 0;
} }
public clear() { public clear() {
this.attrSubCmds.length = 0; this.cmds.length = 0;
this.tsSubCmds.length = 0;
this.historyCmds.length = 0;
this.entityDataCmds.length = 0;
this.entityDataUnsubscribeCmds.length = 0;
this.alarmDataCmds.length = 0;
this.alarmDataUnsubscribeCmds.length = 0;
this.entityCountCmds.length = 0;
this.entityCountUnsubscribeCmds.length = 0;
this.alarmCountCmds.length = 0;
this.alarmCountUnsubscribeCmds.length = 0;
this.unreadNotificationsSubCmds.length = 0;
this.unreadNotificationsCountSubCmds.length = 0;
this.notificationsUnsubCmds.length = 0;
this.markNotificationAsReadCmds.length = 0;
this.markAllNotificationsAsReadCmds.length = 0;
} }
public preparePublishCommands(maxCommands: number): TelemetryPluginCmdsWrapper { public preparePublishCommands(maxCommands: number): TelemetryPluginCmdsWrapper {
const preparedWrapper = new TelemetryPluginCmdsWrapper(); const preparedWrapper = new TelemetryPluginCmdsWrapper();
let leftCount = maxCommands; preparedWrapper.cmds = TelemetryPluginCmdsWrapper.popCmds(this.cmds, maxCommands);
preparedWrapper.tsSubCmds = TelemetryPluginCmdsWrapper.popCmds(this.tsSubCmds, leftCount);
leftCount -= preparedWrapper.tsSubCmds.length;
preparedWrapper.historyCmds = TelemetryPluginCmdsWrapper.popCmds(this.historyCmds, leftCount);
leftCount -= preparedWrapper.historyCmds.length;
preparedWrapper.attrSubCmds = TelemetryPluginCmdsWrapper.popCmds(this.attrSubCmds, leftCount);
leftCount -= preparedWrapper.attrSubCmds.length;
preparedWrapper.entityDataCmds = TelemetryPluginCmdsWrapper.popCmds(this.entityDataCmds, leftCount);
leftCount -= preparedWrapper.entityDataCmds.length;
preparedWrapper.entityDataUnsubscribeCmds = TelemetryPluginCmdsWrapper.popCmds(this.entityDataUnsubscribeCmds, leftCount);
leftCount -= preparedWrapper.entityDataUnsubscribeCmds.length;
preparedWrapper.alarmDataCmds = TelemetryPluginCmdsWrapper.popCmds(this.alarmDataCmds, leftCount);
leftCount -= preparedWrapper.alarmDataCmds.length;
preparedWrapper.alarmDataUnsubscribeCmds = TelemetryPluginCmdsWrapper.popCmds(this.alarmDataUnsubscribeCmds, leftCount);
leftCount -= preparedWrapper.alarmDataUnsubscribeCmds.length;
preparedWrapper.entityCountCmds = TelemetryPluginCmdsWrapper.popCmds(this.entityCountCmds, leftCount);
leftCount -= preparedWrapper.entityCountCmds.length;
preparedWrapper.entityCountUnsubscribeCmds = TelemetryPluginCmdsWrapper.popCmds(this.entityCountUnsubscribeCmds, leftCount);
leftCount -= preparedWrapper.entityCountUnsubscribeCmds.length;
preparedWrapper.alarmCountCmds = TelemetryPluginCmdsWrapper.popCmds(this.alarmCountCmds, leftCount);
leftCount -= preparedWrapper.alarmCountCmds.length;
preparedWrapper.alarmCountUnsubscribeCmds = TelemetryPluginCmdsWrapper.popCmds(this.alarmCountUnsubscribeCmds, leftCount);
leftCount -= preparedWrapper.unreadNotificationsSubCmds.length;
preparedWrapper.unreadNotificationsSubCmds = TelemetryPluginCmdsWrapper.popCmds(this.unreadNotificationsSubCmds, leftCount);
leftCount -= preparedWrapper.unreadNotificationsCountSubCmds.length;
preparedWrapper.unreadNotificationsCountSubCmds = TelemetryPluginCmdsWrapper.popCmds(this.unreadNotificationsCountSubCmds, leftCount);
leftCount -= preparedWrapper.notificationsUnsubCmds.length;
preparedWrapper.notificationsUnsubCmds = TelemetryPluginCmdsWrapper.popCmds(this.notificationsUnsubCmds, leftCount);
leftCount -= preparedWrapper.markNotificationAsReadCmds.length;
preparedWrapper.markNotificationAsReadCmds = TelemetryPluginCmdsWrapper.popCmds(this.markNotificationAsReadCmds, leftCount);
leftCount -= preparedWrapper.markAllNotificationsAsReadCmds.length;
preparedWrapper.markAllNotificationsAsReadCmds = TelemetryPluginCmdsWrapper.popCmds(this.markAllNotificationsAsReadCmds, leftCount);
return preparedWrapper; return preparedWrapper;
} }
} }

View File

@ -20,7 +20,8 @@ import {
NotificationCountUpdate, NotificationCountUpdate,
NotificationsUpdate, NotificationsUpdate,
WebsocketCmd, WebsocketCmd,
WebsocketDataMsg WebsocketDataMsg,
WsCmdType
} from '@shared/models/telemetry/telemetry.models'; } from '@shared/models/telemetry/telemetry.models';
import { NgZone } from '@angular/core'; import { NgZone } from '@angular/core';
import { isDefinedAndNotNull } from '@core/utils'; import { isDefinedAndNotNull } from '@core/utils';
@ -127,11 +128,13 @@ export class NotificationSubscriber extends WsSubscriber {
export class UnreadCountSubCmd implements WebsocketCmd { export class UnreadCountSubCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
type = WsCmdType.NOTIFICATIONS_COUNT;
} }
export class UnreadSubCmd implements WebsocketCmd { export class UnreadSubCmd implements WebsocketCmd {
limit: number; limit: number;
cmdId: number; cmdId: number;
type = WsCmdType.NOTIFICATIONS;
constructor(limit = 10) { constructor(limit = 10) {
this.limit = limit; this.limit = limit;
@ -140,12 +143,14 @@ export class UnreadSubCmd implements WebsocketCmd {
export class UnsubscribeCmd implements WebsocketCmd { export class UnsubscribeCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
type = WsCmdType.NOTIFICATIONS_UNSUBSCRIBE;
} }
export class MarkAsReadCmd implements WebsocketCmd { export class MarkAsReadCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
notifications: string[]; notifications: string[];
type = WsCmdType.MARK_NOTIFICATIONS_AS_READ;
constructor(ids: string[]) { constructor(ids: string[]) {
this.notifications = ids; this.notifications = ids;
@ -154,6 +159,7 @@ export class MarkAsReadCmd implements WebsocketCmd {
export class MarkAllAsReadCmd implements WebsocketCmd { export class MarkAllAsReadCmd implements WebsocketCmd {
cmdId: number; cmdId: number;
type = WsCmdType.MARK_ALL_NOTIFICATIONS_AS_READ;
} }
export interface NotificationCountUpdateMsg extends CmdUpdateMsg { export interface NotificationCountUpdateMsg extends CmdUpdateMsg {