blob: 1fd62d3293ba20ae1b930b570f10ffda9f95c9a7 [file] [log] [blame]
Bhavesh72ead492018-07-19 16:29:18 +05301/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16import { Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
17import { animate, state, style, transition, trigger } from '@angular/animations';
18import { DetailsPanelBaseImpl } from '../../../fw/widget/detailspanel.base';
19import { FnService } from '../../../fw/util/fn.service';
20import { LoadingService } from '../../../fw/layer/loading.service';
21import { LogService } from '../../../log.service';
22import { IconService } from '../../../fw/svg/icon.service';
23import { WebSocketService } from '../../../fw/remote/websocket.service';
24
25/**
26 * The details view when a port row is clicked from the Port view
27 *
28 * This is expected to be passed an 'id' and it makes a call
29 * to the WebSocket with an portDetailsRequest, and gets back an
30 * portDetailsResponse.
31 *
32 * The animated fly-in is controlled by the animation below
33 * The portDetailsState is attached to port-details-panel
34 * and is false (flies out) when id='' and true (flies in) when
35 * id has a value
36 */
37@Component({
38 selector: 'onos-portdetails',
39 templateUrl: './portdetails.component.html',
40 styleUrls: ['./portdetails.component.css', '../../../fw/widget/panel.css', '../../../fw/widget/panel-theme.css'],
41 animations: [
42 trigger('portDetailsState', [
43 state('true', style({
44 transform: 'translateX(-100%)',
45 opacity: '100'
46 })),
47 state('false', style({
48 transform: 'translateX(0%)',
49 opacity: '0'
50 })),
51 transition('0 => 1', animate('100ms ease-in')),
52 transition('1 => 0', animate('100ms ease-out'))
53 ])
54 ]
55})
56export class PortDetailsComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy, OnChanges {
57 @Input() id: string;
58 @Input() devId: string;
59
60 constructor(protected fs: FnService,
61 protected ls: LoadingService,
62 protected log: LogService,
63 protected is: IconService,
64 protected wss: WebSocketService
65 ) {
66 super(fs, ls, log, wss, 'port');
67 }
68
69 ngOnInit() {
70 this.init();
71 this.log.debug('App Details Component initialized:', this.id);
72 }
73
74 /**
75 * Stop listening to appDetailsResponse on WebSocket
76 */
77 ngOnDestroy() {
78 this.destroy();
79 this.log.debug('App Details Component destroyed');
80 }
81
82 /**
83 * Details Panel Data Request on row selection changes
84 * Should be called whenever id changes
85 * If id or devId is empty, no request is made
86 */
87 ngOnChanges() {
88 if (this.id === '' || this.devId === '') {
89 return '';
90 } else {
91 const query = {
92 'id': this.id,
93 'devId': this.devId
94 };
95 this.requestDetailsPanelData(query);
96 }
97 }
98
99}