blob: e5b40c3d3e0e777190b71924d6ad88a4f5540aa7 [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
Bhavesh72ead492018-07-19 16:29:18 +05302 * Copyright 2018-present Open Networking Foundation
Sean Condon83fc39f2018-04-19 18:56:13 +01003 *
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 */
Bhavesh72ead492018-07-19 16:29:18 +053016import { Component, OnInit, OnDestroy} from '@angular/core';
Sean Condon5ca00262018-09-06 17:55:25 +010017
18import {
19 FnService,
20 LoadingService,
21 LogService,
22 WebSocketService,
23 LionService,
24 SortDir, TableBaseImpl, TableResponse
25} from 'gui2-fw-lib';
26
Bhavesh72ead492018-07-19 16:29:18 +053027import { ActivatedRoute, Router } from '@angular/router';
Sean Condon83fc39f2018-04-19 18:56:13 +010028
Sean Condon28ecc5f2018-06-25 12:50:16 +010029/**
30 * Model of the response from WebSocket
31 */
Sean Condon2bd11b72018-06-15 08:00:48 +010032interface DeviceTableResponse extends TableResponse {
33 devices: Device[];
34}
35
Sean Condon28ecc5f2018-06-25 12:50:16 +010036/**
37 * Model of the devices returned from the WebSocket
38 */
Sean Condon2bd11b72018-06-15 08:00:48 +010039interface 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 Condon83fc39f2018-04-19 18:56:13 +010056/**
57 * ONOS GUI -- Device View Component
58 */
59@Component({
Bhavesh72ead492018-07-19 16:29:18 +053060 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 Condon83fc39f2018-04-19 18:56:13 +010063})
Sean Condon2bd11b72018-06-15 08:00:48 +010064export 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 Condon83fc39f2018-04-19 18:56:13 +010072
73 constructor(
Sean Condon2bd11b72018-06-15 08:00:48 +010074 protected fs: FnService,
75 protected ls: LoadingService,
Sean Condon2bd11b72018-06-15 08:00:48 +010076 protected log: LogService,
Bhavesh72ead492018-07-19 16:29:18 +053077 protected as: ActivatedRoute,
78 protected router: Router,
Sean Condon2bd11b72018-06-15 08:00:48 +010079 protected wss: WebSocketService,
Sean Condon83fc39f2018-04-19 18:56:13 +010080 ) {
Sean Condon2bd11b72018-06-15 08:00:48 +010081 super(fs, ls, log, wss, 'device');
82 this.responseCallback = this.deviceResponseCb;
Bhavesh72ead492018-07-19 16:29:18 +053083
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 Condon83fc39f2018-04-19 18:56:13 +010099 }
100
101 ngOnInit() {
Sean Condon2bd11b72018-06-15 08:00:48 +0100102 this.init();
Sean Condon83fc39f2018-04-19 18:56:13 +0100103 this.log.debug('DeviceComponent initialized');
Sean Condon2bd11b72018-06-15 08:00:48 +0100104 }
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 Condon83fc39f2018-04-19 18:56:13 +0100113 }
114
Bhavesh72ead492018-07-19 16:29:18 +0530115 navto(path) {
116 this.log.debug('navigate');
117 if (this.selId) {
118 this.router.navigate([path], { queryParams: { devId: this.selId } });
119 }
120 }
121
Sean Condon83fc39f2018-04-19 18:56:13 +0100122}