blob: d81031973879dd40f03e4a5de8fe2fef63ca105a [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,
Sean Condon5ca00262018-09-06 17:55:25 +010020 LogService,
21 WebSocketService,
Sean Condon5ca00262018-09-06 17:55:25 +010022 SortDir, TableBaseImpl, TableResponse
23} from 'gui2-fw-lib';
24
Bhavesh72ead492018-07-19 16:29:18 +053025import { ActivatedRoute, Router } from '@angular/router';
Sean Condon83fc39f2018-04-19 18:56:13 +010026
Sean Condon28ecc5f2018-06-25 12:50:16 +010027/**
28 * Model of the response from WebSocket
29 */
Sean Condon2bd11b72018-06-15 08:00:48 +010030interface DeviceTableResponse extends TableResponse {
31 devices: Device[];
32}
33
Sean Condon28ecc5f2018-06-25 12:50:16 +010034/**
35 * Model of the devices returned from the WebSocket
36 */
Sean Condon2bd11b72018-06-15 08:00:48 +010037interface 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 Condon83fc39f2018-04-19 18:56:13 +010054/**
55 * ONOS GUI -- Device View Component
56 */
57@Component({
Bhavesh72ead492018-07-19 16:29:18 +053058 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 Condon83fc39f2018-04-19 18:56:13 +010061})
Sean Condon2bd11b72018-06-15 08:00:48 +010062export 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 Condon83fc39f2018-04-19 18:56:13 +010070
71 constructor(
Sean Condon2bd11b72018-06-15 08:00:48 +010072 protected fs: FnService,
Sean Condon2bd11b72018-06-15 08:00:48 +010073 protected log: LogService,
Bhavesh72ead492018-07-19 16:29:18 +053074 protected as: ActivatedRoute,
75 protected router: Router,
Sean Condon2bd11b72018-06-15 08:00:48 +010076 protected wss: WebSocketService,
Sean Condon83fc39f2018-04-19 18:56:13 +010077 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010078 super(fs, log, wss, 'device');
Sean Condon2bd11b72018-06-15 08:00:48 +010079 this.responseCallback = this.deviceResponseCb;
Bhavesh72ead492018-07-19 16:29:18 +053080
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 Condon83fc39f2018-04-19 18:56:13 +010096 }
97
98 ngOnInit() {
Sean Condon2bd11b72018-06-15 08:00:48 +010099 this.init();
Sean Condon83fc39f2018-04-19 18:56:13 +0100100 this.log.debug('DeviceComponent initialized');
Sean Condon2bd11b72018-06-15 08:00:48 +0100101 }
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 Condon83fc39f2018-04-19 18:56:13 +0100110 }
111
Bhavesh72ead492018-07-19 16:29:18 +0530112 navto(path) {
113 this.log.debug('navigate');
114 if (this.selId) {
115 this.router.navigate([path], { queryParams: { devId: this.selId } });
116 }
117 }
118
Sean Condon83fc39f2018-04-19 18:56:13 +0100119}