blob: b6f1d95d683d6142930cae6cba8c4a21ee9e7c44 [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';
17import { FnService } from '../../../fw/util/fn.service';
18import { LoadingService } from '../../../fw/layer/loading.service';
19import { LogService } from '../../../log.service';
20import { TableBaseImpl, TableResponse, SortDir } from '../../../fw/widget/table.base';
21import { WebSocketService } from '../../../fw/remote/websocket.service';
22import { ActivatedRoute, Router } from '@angular/router';
Sean Condon83fc39f2018-04-19 18:56:13 +010023
Sean Condon28ecc5f2018-06-25 12:50:16 +010024/**
25 * Model of the response from WebSocket
26 */
Sean Condon2bd11b72018-06-15 08:00:48 +010027interface DeviceTableResponse extends TableResponse {
28 devices: Device[];
29}
30
Sean Condon28ecc5f2018-06-25 12:50:16 +010031/**
32 * Model of the devices returned from the WebSocket
33 */
Sean Condon2bd11b72018-06-15 08:00:48 +010034interface Device {
35 available: boolean;
36 chassisid: string;
37 hw: string;
38 id: string;
39 masterid: string;
40 mfr: string;
41 name: string;
42 num_ports: number;
43 protocol: string;
44 serial: string;
45 sw: string;
46 _iconid_available: string;
47 _iconid_type: string;
48}
49
50
Sean Condon83fc39f2018-04-19 18:56:13 +010051/**
52 * ONOS GUI -- Device View Component
53 */
54@Component({
Bhavesh72ead492018-07-19 16:29:18 +053055 selector: 'onos-device',
56 templateUrl: './device.component.html',
57 styleUrls: ['./device.component.css', './device.theme.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
Sean Condon83fc39f2018-04-19 18:56:13 +010058})
Sean Condon2bd11b72018-06-15 08:00:48 +010059export class DeviceComponent extends TableBaseImpl implements OnInit, OnDestroy {
60
61 // TODO: Update for LION
62 flowTip = 'Show flow view for selected device';
63 portTip = 'Show port view for selected device';
64 groupTip = 'Show group view for selected device';
65 meterTip = 'Show meter view for selected device';
66 pipeconfTip = 'Show pipeconf view for selected device';
Sean Condon83fc39f2018-04-19 18:56:13 +010067
68 constructor(
Sean Condon2bd11b72018-06-15 08:00:48 +010069 protected fs: FnService,
70 protected ls: LoadingService,
Sean Condon2bd11b72018-06-15 08:00:48 +010071 protected log: LogService,
Bhavesh72ead492018-07-19 16:29:18 +053072 protected as: ActivatedRoute,
73 protected router: Router,
Sean Condon2bd11b72018-06-15 08:00:48 +010074 protected wss: WebSocketService,
Sean Condon83fc39f2018-04-19 18:56:13 +010075 ) {
Sean Condon2bd11b72018-06-15 08:00:48 +010076 super(fs, ls, log, wss, 'device');
77 this.responseCallback = this.deviceResponseCb;
Bhavesh72ead492018-07-19 16:29:18 +053078
79 this.as.queryParams.subscribe(params => {
80 this.selId = params['devId'];
81
82 });
83
84 this.payloadParams = {
85 devId: this.selId
86 };
87
88 this.sortParams = {
89 firstCol: 'name',
90 firstDir: SortDir.asc,
91 secondCol: 'id',
92 secondDir: SortDir.desc,
93 };
Sean Condon83fc39f2018-04-19 18:56:13 +010094 }
95
96 ngOnInit() {
Sean Condon2bd11b72018-06-15 08:00:48 +010097 this.init();
Sean Condon83fc39f2018-04-19 18:56:13 +010098 this.log.debug('DeviceComponent initialized');
Sean Condon2bd11b72018-06-15 08:00:48 +010099 }
100
101 ngOnDestroy() {
102 this.destroy();
103 this.log.debug('DeviceComponent destroyed');
104 }
105
106 deviceResponseCb(data: DeviceTableResponse) {
107 this.log.debug('Device response received for ', data.devices.length, 'devices');
Sean Condon83fc39f2018-04-19 18:56:13 +0100108 }
109
Bhavesh72ead492018-07-19 16:29:18 +0530110 navto(path) {
111 this.log.debug('navigate');
112 if (this.selId) {
113 this.router.navigate([path], { queryParams: { devId: this.selId } });
114 }
115 }
116
Sean Condon83fc39f2018-04-19 18:56:13 +0100117}