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