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 |
| 23 | } from 'gui2-fw-lib'; |
| 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', |
| 70 | styleUrls: ['./alarmtable.component.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css'] |
| 71 | }) |
| 72 | export class AlarmTableComponent extends TableBaseImpl implements OnInit, OnDestroy { |
| 73 | devId: string; |
| 74 | selRowAlarmId: string; |
| 75 | // TODO Add in LION translations |
| 76 | acknowledgeTip: string = 'Acknowledge'; |
| 77 | clearTip: string = 'Clear'; |
| 78 | AlarmActionEnum: any = AlarmAction; |
| 79 | alarmAction: AlarmAction = AlarmAction.NONE; |
| 80 | confirmMsg: string = ''; |
| 81 | ctrlBtnState: CtrlBtnState; |
| 82 | |
| 83 | constructor( |
| 84 | private route: ActivatedRoute, |
| 85 | @Inject('Window') private w: any, |
| 86 | protected log: LogService, |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 87 | protected fs: FnService, |
| 88 | protected wss: WebSocketService, |
| 89 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame^] | 90 | super(fs, log, wss, 'alarmTable'); |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 91 | |
| 92 | this.route.queryParams.subscribe(params => { |
| 93 | this.devId = params['devId']; |
| 94 | |
| 95 | }); |
| 96 | |
| 97 | this.payloadParams = { |
| 98 | devId: this.devId |
| 99 | }; |
| 100 | |
| 101 | this.responseCallback = this.alarmResponseCb; |
| 102 | |
| 103 | this.sortParams = { |
| 104 | firstCol: 'alarmTimeRaised', |
| 105 | firstDir: SortDir.desc, |
| 106 | secondCol: 'alarmDeviceId', |
| 107 | secondDir: SortDir.asc, |
| 108 | }; |
| 109 | |
| 110 | this.ctrlBtnState = <CtrlBtnState>{ |
| 111 | acknowledged: false, |
| 112 | cleared: false |
| 113 | }; |
| 114 | this.log.debug('AlarmTableComponent constructed'); |
| 115 | } |
| 116 | |
| 117 | ngOnInit() { |
| 118 | this.init(); |
| 119 | this.log.debug('AlarmTableComponent initialized'); |
| 120 | } |
| 121 | |
| 122 | ngOnDestroy() { |
| 123 | this.destroy(); |
| 124 | this.log.debug('AlarmTableComponent destroyed'); |
| 125 | } |
| 126 | |
| 127 | alarmResponseCb(data: AlarmTableResponse) { |
| 128 | this.log.debug('Alarm response received for ', data.alarmTables.length, 'alarm'); |
| 129 | } |
| 130 | |
| 131 | rowSelection(event: any, selRow: any) { |
| 132 | this.ctrlBtnState.acknowledged = this.selId && selRow && selRow.state === ACKNOWLEDGED; |
| 133 | this.ctrlBtnState.cleared = this.selId && selRow && selRow.cleared === CLEARED; |
| 134 | this.ctrlBtnState.selection = this.selId; |
| 135 | this.selRowAlarmId = selRow.appId; |
| 136 | this.log.debug('Row ', this.selId, 'selected', this.ctrlBtnState); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Perform one of the alarm actions - acknowledge or clear |
| 141 | * Raises a dialog which calls back the dOk() below |
| 142 | */ |
| 143 | confirmAction(action: AlarmAction): void { |
| 144 | this.alarmAction = action; |
| 145 | const alarmActionLc = (<string>AlarmAction[this.alarmAction]).toLowerCase(); |
| 146 | |
| 147 | this.confirmMsg = alarmActionLc + ' ' + this.selId + '?'; |
| 148 | |
| 149 | this.log.debug('Initiating', this.alarmAction, 'of', this.selId); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Callback when the Confirm dialog is shown and a choice is made |
| 154 | */ |
| 155 | dOk(choice: boolean) { |
| 156 | const alarmActionLc = (<string>AlarmAction[this.alarmAction]).toLowerCase(); |
| 157 | if (choice) { |
| 158 | this.log.debug('Confirmed', alarmActionLc, 'on', this.selId); |
| 159 | |
| 160 | /** commented out until backend is implemented |
| 161 | this.wss.sendEvent(APPMGMTREQ, { |
| 162 | action: alarmActionLc, |
| 163 | name: this.selId, |
| 164 | sortCol: this.sortParams.firstCol, |
| 165 | sortDir: SortDir[this.sortParams.firstDir], |
| 166 | }); |
| 167 | |
| 168 | this.wss.sendEvent(DETAILSREQ, { id: this.selId }); |
| 169 | */ |
| 170 | } else { |
| 171 | this.log.debug('Cancelled', alarmActionLc, 'on', this.selId); |
| 172 | } |
| 173 | this.confirmMsg = ''; |
| 174 | } |
| 175 | |
| 176 | ackIcon(acknowledged: string): string { |
| 177 | if (acknowledged === 'true') { |
| 178 | return 'active'; |
| 179 | } else { |
| 180 | return 'appInactive'; |
| 181 | } |
| 182 | } |
| 183 | } |