Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 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 | */ |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 16 | import { Component, OnInit, OnDestroy} from '@angular/core'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 17 | |
| 18 | import { |
| 19 | FnService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 20 | LogService, |
| 21 | WebSocketService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 22 | SortDir, TableBaseImpl, TableResponse |
| 23 | } from 'gui2-fw-lib'; |
| 24 | |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 25 | import { ActivatedRoute, Router } from '@angular/router'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 26 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 27 | /** |
| 28 | * Model of the response from WebSocket |
| 29 | */ |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 30 | interface DeviceTableResponse extends TableResponse { |
| 31 | devices: Device[]; |
| 32 | } |
| 33 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 34 | /** |
| 35 | * Model of the devices returned from the WebSocket |
| 36 | */ |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 37 | interface Device { |
| 38 | available: boolean; |
| 39 | chassisid: string; |
| 40 | hw: string; |
| 41 | id: string; |
| 42 | masterid: string; |
| 43 | mfr: string; |
| 44 | name: string; |
| 45 | num_ports: number; |
| 46 | protocol: string; |
| 47 | serial: string; |
| 48 | sw: string; |
| 49 | _iconid_available: string; |
| 50 | _iconid_type: string; |
| 51 | } |
| 52 | |
| 53 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 54 | /** |
| 55 | * ONOS GUI -- Device View Component |
| 56 | */ |
| 57 | @Component({ |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 58 | selector: 'onos-device', |
| 59 | templateUrl: './device.component.html', |
| 60 | styleUrls: ['./device.component.css', './device.theme.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css'] |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 61 | }) |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 62 | export class DeviceComponent extends TableBaseImpl implements OnInit, OnDestroy { |
| 63 | |
| 64 | // TODO: Update for LION |
| 65 | flowTip = 'Show flow view for selected device'; |
| 66 | portTip = 'Show port view for selected device'; |
| 67 | groupTip = 'Show group view for selected device'; |
| 68 | meterTip = 'Show meter view for selected device'; |
| 69 | pipeconfTip = 'Show pipeconf view for selected device'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 70 | |
| 71 | constructor( |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 72 | protected fs: FnService, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 73 | protected log: LogService, |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 74 | protected as: ActivatedRoute, |
| 75 | protected router: Router, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 76 | protected wss: WebSocketService, |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 77 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 78 | super(fs, log, wss, 'device'); |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 79 | this.responseCallback = this.deviceResponseCb; |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 80 | |
| 81 | this.as.queryParams.subscribe(params => { |
| 82 | this.selId = params['devId']; |
| 83 | |
| 84 | }); |
| 85 | |
| 86 | this.payloadParams = { |
| 87 | devId: this.selId |
| 88 | }; |
| 89 | |
| 90 | this.sortParams = { |
| 91 | firstCol: 'name', |
| 92 | firstDir: SortDir.asc, |
| 93 | secondCol: 'id', |
| 94 | secondDir: SortDir.desc, |
| 95 | }; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | ngOnInit() { |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 99 | this.init(); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 100 | this.log.debug('DeviceComponent initialized'); |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | ngOnDestroy() { |
| 104 | this.destroy(); |
| 105 | this.log.debug('DeviceComponent destroyed'); |
| 106 | } |
| 107 | |
| 108 | deviceResponseCb(data: DeviceTableResponse) { |
| 109 | this.log.debug('Device response received for ', data.devices.length, 'devices'); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 112 | navto(path) { |
Sean Condon | afe47c2 | 2019-12-19 14:28:06 +0000 | [diff] [blame] | 113 | this.log.debug('navigate to', path); |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 114 | if (this.selId) { |
| 115 | this.router.navigate([path], { queryParams: { devId: this.selId } }); |
| 116 | } |
| 117 | } |
| 118 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 119 | } |