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