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