Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | import { Component, Input, Inject, OnInit, OnDestroy } from '@angular/core'; |
| 17 | import { ActivatedRoute } from '@angular/router'; |
| 18 | import { |
| 19 | FnService, |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 20 | LogService, |
| 21 | WebSocketService, |
| 22 | SortDir, TableBaseImpl, TableResponse |
Sean Condon | 3dd062f | 2020-04-14 09:25:00 +0100 | [diff] [blame] | 23 | } from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Model of the response from the WebSocket |
| 27 | */ |
| 28 | export interface AlarmTableResponse extends TableResponse { |
| 29 | alarmTables: Alarm[]; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Model of the alarms returned from the WebSocket |
| 34 | */ |
| 35 | export interface Alarm { |
| 36 | id: string; |
| 37 | alarmDesc: string; |
| 38 | alarmDeviceId: string; |
| 39 | alarmSource: string; |
| 40 | alarmTimeRaised: string; |
| 41 | alarmTimeUpdated: string; |
| 42 | alarmTimeCleared: string; |
| 43 | alarmSeverity: string; |
| 44 | } |
| 45 | |
| 46 | export enum AlarmAction { |
| 47 | NONE = 0, |
| 48 | ACKNOWLEDGE = 1, |
| 49 | CLEAR = 2, |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Model of the Control Button |
| 54 | */ |
| 55 | export interface CtrlBtnState { |
| 56 | acknowledged: boolean; |
| 57 | cleared: boolean; |
| 58 | selection: string; |
| 59 | } |
| 60 | |
| 61 | const ACKNOWLEDGED = 'ACKNOWLEDGED'; |
| 62 | const CLEARED = 'CLEARED'; |
| 63 | |
| 64 | /** |
| 65 | * ONOS GUI -- Alarm Table Component extends TableBaseImpl |
| 66 | */ |
| 67 | @Component({ |
| 68 | selector: 'onos-alarmtable', |
| 69 | templateUrl: './alarmtable.component.html', |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 70 | styleUrls: ['./alarmtable.component.css', |
| 71 | '../../../../../web/gui2-fw-lib/lib/widget//table.css', |
| 72 | '../../../../../web/gui2-fw-lib/lib/widget//table.theme.css' |
| 73 | ] |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 74 | }) |
| 75 | export class AlarmTableComponent extends TableBaseImpl implements OnInit, OnDestroy { |
| 76 | devId: string; |
| 77 | selRowAlarmId: string; |
| 78 | // TODO Add in LION translations |
| 79 | acknowledgeTip: string = 'Acknowledge'; |
| 80 | clearTip: string = 'Clear'; |
| 81 | AlarmActionEnum: any = AlarmAction; |
| 82 | alarmAction: AlarmAction = AlarmAction.NONE; |
| 83 | confirmMsg: string = ''; |
| 84 | ctrlBtnState: CtrlBtnState; |
| 85 | |
| 86 | constructor( |
| 87 | private route: ActivatedRoute, |
| 88 | @Inject('Window') private w: any, |
| 89 | protected log: LogService, |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 90 | protected fs: FnService, |
| 91 | protected wss: WebSocketService, |
| 92 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 93 | super(fs, log, wss, 'alarmTable'); |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 94 | |
| 95 | this.route.queryParams.subscribe(params => { |
| 96 | this.devId = params['devId']; |
| 97 | |
| 98 | }); |
| 99 | |
| 100 | this.payloadParams = { |
| 101 | devId: this.devId |
| 102 | }; |
| 103 | |
| 104 | this.responseCallback = this.alarmResponseCb; |
| 105 | |
| 106 | this.sortParams = { |
| 107 | firstCol: 'alarmTimeRaised', |
| 108 | firstDir: SortDir.desc, |
| 109 | secondCol: 'alarmDeviceId', |
| 110 | secondDir: SortDir.asc, |
| 111 | }; |
| 112 | |
| 113 | this.ctrlBtnState = <CtrlBtnState>{ |
| 114 | acknowledged: false, |
| 115 | cleared: false |
| 116 | }; |
| 117 | this.log.debug('AlarmTableComponent constructed'); |
| 118 | } |
| 119 | |
| 120 | ngOnInit() { |
| 121 | this.init(); |
| 122 | this.log.debug('AlarmTableComponent initialized'); |
| 123 | } |
| 124 | |
| 125 | ngOnDestroy() { |
| 126 | this.destroy(); |
| 127 | this.log.debug('AlarmTableComponent destroyed'); |
| 128 | } |
| 129 | |
| 130 | alarmResponseCb(data: AlarmTableResponse) { |
| 131 | this.log.debug('Alarm response received for ', data.alarmTables.length, 'alarm'); |
| 132 | } |
| 133 | |
| 134 | rowSelection(event: any, selRow: any) { |
| 135 | this.ctrlBtnState.acknowledged = this.selId && selRow && selRow.state === ACKNOWLEDGED; |
| 136 | this.ctrlBtnState.cleared = this.selId && selRow && selRow.cleared === CLEARED; |
| 137 | this.ctrlBtnState.selection = this.selId; |
| 138 | this.selRowAlarmId = selRow.appId; |
| 139 | this.log.debug('Row ', this.selId, 'selected', this.ctrlBtnState); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Perform one of the alarm actions - acknowledge or clear |
| 144 | * Raises a dialog which calls back the dOk() below |
| 145 | */ |
| 146 | confirmAction(action: AlarmAction): void { |
| 147 | this.alarmAction = action; |
| 148 | const alarmActionLc = (<string>AlarmAction[this.alarmAction]).toLowerCase(); |
| 149 | |
| 150 | this.confirmMsg = alarmActionLc + ' ' + this.selId + '?'; |
| 151 | |
| 152 | this.log.debug('Initiating', this.alarmAction, 'of', this.selId); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Callback when the Confirm dialog is shown and a choice is made |
| 157 | */ |
| 158 | dOk(choice: boolean) { |
| 159 | const alarmActionLc = (<string>AlarmAction[this.alarmAction]).toLowerCase(); |
| 160 | if (choice) { |
| 161 | this.log.debug('Confirmed', alarmActionLc, 'on', this.selId); |
| 162 | |
| 163 | /** commented out until backend is implemented |
| 164 | this.wss.sendEvent(APPMGMTREQ, { |
| 165 | action: alarmActionLc, |
| 166 | name: this.selId, |
| 167 | sortCol: this.sortParams.firstCol, |
| 168 | sortDir: SortDir[this.sortParams.firstDir], |
| 169 | }); |
| 170 | |
| 171 | this.wss.sendEvent(DETAILSREQ, { id: this.selId }); |
| 172 | */ |
| 173 | } else { |
| 174 | this.log.debug('Cancelled', alarmActionLc, 'on', this.selId); |
| 175 | } |
| 176 | this.confirmMsg = ''; |
| 177 | } |
| 178 | |
| 179 | ackIcon(acknowledged: string): string { |
| 180 | if (acknowledged === 'true') { |
| 181 | return 'active'; |
| 182 | } else { |
| 183 | return 'appInactive'; |
| 184 | } |
| 185 | } |
| 186 | } |