blob: a5c750a668469b7d6bd4217dc8dcc6d1ac3a24f9 [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, OnInit, OnDestroy, OnChanges } from '@angular/core';
17import { trigger, state, style, animate, transition } from '@angular/animations';
Sean Condon5ca00262018-09-06 17:55:25 +010018import {
19 FnService,
20 IconService,
Sean Condon5ca00262018-09-06 17:55:25 +010021 LogService,
22 DetailsPanelBaseImpl,
23 WebSocketService
24} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053025
26/**
27 * The details view when a device row is clicked from the Device view
28 *
29 * This is expected to be passed an 'id' and it makes a call
30 * to the WebSocket with an deviceDetailsRequest, and gets back an
31 * deviceDetailsResponse.
32 *
33 * The animated fly-in is controlled by the animation below
34 * The deviceDetailsState is attached to device-details-panel
35 * and is false (flies out) when id='' and true (flies in) when
36 * id has a value
37 */
38@Component({
39 selector: 'onos-devicedetails',
40 templateUrl: './devicedetails.component.html',
41 styleUrls: ['./devicedetails.component.css',
42 '../../../fw/widget/panel.css', '../../../fw/widget/panel-theme.css'
43 ],
44 animations: [
45 trigger('deviceDetailsState', [
46 state('true', style({
47 transform: 'translateX(-100%)',
48 opacity: '100'
49 })),
50 state('false', style({
51 transform: 'translateX(0%)',
52 opacity: '0'
53 })),
54 transition('0 => 1', animate('100ms ease-in')),
55 transition('1 => 0', animate('100ms ease-out'))
56 ])
57 ]
58})
59
60
61export class DeviceDetailsComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy, OnChanges {
62 @Input() id: string;
63
64 constructor(protected fs: FnService,
Bhavesh72ead492018-07-19 16:29:18 +053065 protected log: LogService,
66 protected is: IconService,
67 protected wss: WebSocketService
68 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010069 super(fs, log, wss, 'device');
Bhavesh72ead492018-07-19 16:29:18 +053070 }
71
72 ngOnInit() {
73 this.init();
Sean Condon87b78502018-09-17 20:53:24 +010074 this.log.debug('Device Details Component initialized:', this.id);
Bhavesh72ead492018-07-19 16:29:18 +053075 }
76
77 /**
78 * Stop listening to appDetailsResponse on WebSocket
79 */
80 ngOnDestroy() {
81 this.destroy();
Sean Condon87b78502018-09-17 20:53:24 +010082 this.log.debug('Device Details Component destroyed');
Bhavesh72ead492018-07-19 16:29:18 +053083 }
84
85 /**
86 * Details Panel Data Request on row selection changes
87 * Should be called whenever id changes
88 * If id is empty, no request is made
89 */
90 ngOnChanges() {
91 if (this.id === '') {
92 return '';
93 } else {
94 const query = {
95 'id': this.id
96 };
97 this.requestDetailsPanelData(query);
98 }
99 }
100
101}