blob: d2e46b21cfc8f2a5b8c0d26cd1793dd1f5a69806 [file] [log] [blame]
Sean Condon87b78502018-09-17 20:53:24 +01001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { Component, Input, Inject, OnInit, OnDestroy } from '@angular/core';
17import { ActivatedRoute } from '@angular/router';
18import {
19 FnService,
20 LoadingService,
21 LogService,
22 WebSocketService,
23 SortDir, TableBaseImpl, TableResponse
24} from 'gui2-fw-lib';
25
26/**
27 * Model of the response from the WebSocket
28 */
29export interface AlarmTableResponse extends TableResponse {
30 alarmTables: Alarm[];
31}
32
33/**
34 * Model of the alarms returned from the WebSocket
35 */
36export interface Alarm {
37 id: string;
38 alarmDesc: string;
39 alarmDeviceId: string;
40 alarmSource: string;
41 alarmTimeRaised: string;
42 alarmTimeUpdated: string;
43 alarmTimeCleared: string;
44 alarmSeverity: string;
45}
46
47export enum AlarmAction {
48 NONE = 0,
49 ACKNOWLEDGE = 1,
50 CLEAR = 2,
51}
52
53/**
54 * Model of the Control Button
55 */
56export interface CtrlBtnState {
57 acknowledged: boolean;
58 cleared: boolean;
59 selection: string;
60}
61
62const ACKNOWLEDGED = 'ACKNOWLEDGED';
63const CLEARED = 'CLEARED';
64
65/**
66* ONOS GUI -- Alarm Table Component extends TableBaseImpl
67*/
68@Component({
69 selector: 'onos-alarmtable',
70 templateUrl: './alarmtable.component.html',
71 styleUrls: ['./alarmtable.component.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
72})
73export class AlarmTableComponent extends TableBaseImpl implements OnInit, OnDestroy {
74 devId: string;
75 selRowAlarmId: string;
76 // TODO Add in LION translations
77 acknowledgeTip: string = 'Acknowledge';
78 clearTip: string = 'Clear';
79 AlarmActionEnum: any = AlarmAction;
80 alarmAction: AlarmAction = AlarmAction.NONE;
81 confirmMsg: string = '';
82 ctrlBtnState: CtrlBtnState;
83
84 constructor(
85 private route: ActivatedRoute,
86 @Inject('Window') private w: any,
87 protected log: LogService,
88 protected ls: LoadingService,
89 protected fs: FnService,
90 protected wss: WebSocketService,
91 ) {
92 super(fs, ls, log, wss, 'alarmTable');
93
94 this.route.queryParams.subscribe(params => {
95 this.devId = params['devId'];
96
97 });
98
99 this.payloadParams = {
100 devId: this.devId
101 };
102
103 this.responseCallback = this.alarmResponseCb;
104
105 this.sortParams = {
106 firstCol: 'alarmTimeRaised',
107 firstDir: SortDir.desc,
108 secondCol: 'alarmDeviceId',
109 secondDir: SortDir.asc,
110 };
111
112 this.ctrlBtnState = <CtrlBtnState>{
113 acknowledged: false,
114 cleared: false
115 };
116 this.log.debug('AlarmTableComponent constructed');
117 }
118
119 ngOnInit() {
120 this.init();
121 this.log.debug('AlarmTableComponent initialized');
122 }
123
124 ngOnDestroy() {
125 this.destroy();
126 this.log.debug('AlarmTableComponent destroyed');
127 }
128
129 alarmResponseCb(data: AlarmTableResponse) {
130 this.log.debug('Alarm response received for ', data.alarmTables.length, 'alarm');
131 }
132
133 rowSelection(event: any, selRow: any) {
134 this.ctrlBtnState.acknowledged = this.selId && selRow && selRow.state === ACKNOWLEDGED;
135 this.ctrlBtnState.cleared = this.selId && selRow && selRow.cleared === CLEARED;
136 this.ctrlBtnState.selection = this.selId;
137 this.selRowAlarmId = selRow.appId;
138 this.log.debug('Row ', this.selId, 'selected', this.ctrlBtnState);
139 }
140
141 /**
142 * Perform one of the alarm actions - acknowledge or clear
143 * Raises a dialog which calls back the dOk() below
144 */
145 confirmAction(action: AlarmAction): void {
146 this.alarmAction = action;
147 const alarmActionLc = (<string>AlarmAction[this.alarmAction]).toLowerCase();
148
149 this.confirmMsg = alarmActionLc + ' ' + this.selId + '?';
150
151 this.log.debug('Initiating', this.alarmAction, 'of', this.selId);
152 }
153
154 /**
155 * Callback when the Confirm dialog is shown and a choice is made
156 */
157 dOk(choice: boolean) {
158 const alarmActionLc = (<string>AlarmAction[this.alarmAction]).toLowerCase();
159 if (choice) {
160 this.log.debug('Confirmed', alarmActionLc, 'on', this.selId);
161
162 /** commented out until backend is implemented
163 this.wss.sendEvent(APPMGMTREQ, {
164 action: alarmActionLc,
165 name: this.selId,
166 sortCol: this.sortParams.firstCol,
167 sortDir: SortDir[this.sortParams.firstDir],
168 });
169
170 this.wss.sendEvent(DETAILSREQ, { id: this.selId });
171 */
172 } else {
173 this.log.debug('Cancelled', alarmActionLc, 'on', this.selId);
174 }
175 this.confirmMsg = '';
176 }
177
178 ackIcon(acknowledged: string): string {
179 if (acknowledged === 'true') {
180 return 'active';
181 } else {
182 return 'appInactive';
183 }
184 }
185}