Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [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, OnDestroy, OnInit } from '@angular/core'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 17 | import { |
| 18 | FnService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 19 | LogService, |
| 20 | WebSocketService, |
| 21 | SortDir, TableBaseImpl, TableResponse |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 22 | } from '../../../../../../../../gui2-fw-lib/public_api'; |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 23 | import { ActivatedRoute } from '@angular/router'; |
| 24 | |
| 25 | /** |
| 26 | * Model of the response from WebSocket |
| 27 | */ |
| 28 | interface MeterTableResponse extends TableResponse { |
| 29 | meters: Meter[]; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Model of the meter returned from the WebSocket |
| 34 | */ |
| 35 | interface Meter { |
| 36 | id: string; |
| 37 | appId: string; |
| 38 | state: string; |
| 39 | packets: string; |
| 40 | bytes: string; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * ONOS GUI -- Meter View Component |
| 45 | */ |
| 46 | @Component({ |
| 47 | selector: 'onos-meter', |
| 48 | templateUrl: './meter.component.html', |
| 49 | styleUrls: ['./meter.component.css', './meter.theme.css', |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 50 | '../../../../../../../../gui2-fw-lib/lib/widget/table.css', '../../../../../../../../gui2-fw-lib/lib/widget/table.theme.css'] |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 51 | }) |
| 52 | export class MeterComponent extends TableBaseImpl implements OnInit, OnDestroy { |
| 53 | |
| 54 | id: string; |
| 55 | brief: boolean = true; |
| 56 | |
| 57 | // TODO: Update for LION |
| 58 | deviceTip = 'Show device table'; |
| 59 | detailTip = 'Switch to detail view'; |
| 60 | flowTip = 'Show flow view for selected device'; |
| 61 | portTip = 'Show port view for selected device'; |
| 62 | groupTip = 'Show group view for selected device'; |
| 63 | pipeconfTip = 'Show pipeconf view for selected device'; |
| 64 | |
| 65 | constructor( |
| 66 | protected fs: FnService, |
| 67 | protected log: LogService, |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 68 | protected as: ActivatedRoute, |
| 69 | protected wss: WebSocketService, |
| 70 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 71 | super(fs, log, wss, 'meter'); |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 72 | this.as.queryParams.subscribe(params => { |
| 73 | this.id = params['devId']; |
| 74 | }); |
| 75 | |
| 76 | this.payloadParams = { |
| 77 | devId: this.id |
| 78 | }; |
| 79 | |
| 80 | this.responseCallback = this.meterResponseCb; |
| 81 | this.sortParams = { |
| 82 | firstCol: 'id', |
| 83 | firstDir: SortDir.desc, |
| 84 | secondCol: 'app_id', |
| 85 | secondDir: SortDir.asc, |
| 86 | }; |
| 87 | } |
| 88 | |
| 89 | ngOnInit() { |
| 90 | this.init(); |
| 91 | this.log.debug('MeterComponent initialized'); |
| 92 | } |
| 93 | |
| 94 | ngOnDestroy() { |
| 95 | this.destroy(); |
| 96 | this.log.debug('MeterComponent destroyed'); |
| 97 | } |
| 98 | |
| 99 | meterResponseCb(data: MeterTableResponse) { |
| 100 | this.log.debug('Meter response received for ', data.meters.length, 'meter'); |
| 101 | } |
| 102 | |
| 103 | briefToggle() { |
| 104 | this.brief = !this.brief; |
| 105 | } |
| 106 | |
| 107 | } |