blob: 5e70270e79842d6bba5567f73ca15233dad74a39 [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*/
16
17import { Component, Input, OnInit, OnDestroy, OnChanges } from '@angular/core';
18import { trigger, state, style, animate, transition } from '@angular/animations';
Sean Condon5ca00262018-09-06 17:55:25 +010019import {
20 FnService,
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 host row is clicked from the Host view
28 *
29 * This is expected to be passed an 'id' and it makes a call
30 * to the WebSocket with an hostDetailsRequest, and gets back an
31 * hostDetailsResponse.
32 *
33 * The animated fly-in is controlled by the animation below
34 * The hostDetailsState is attached to host-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-hostdetails',
40 templateUrl: './hostdetails.component.html',
41 styleUrls: ['./hostdetails.component.css',
42 '../../../fw/widget/panel.css', '../../../fw/widget/panel-theme.css'
43 ],
44 animations: [
45 trigger('hostDetailsState', [
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})
59export class HostDetailsComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy, OnChanges {
60 @Input() id: string;
61
62 constructor(
63 protected fs: FnService,
Bhavesh72ead492018-07-19 16:29:18 +053064 protected log: LogService,
65 protected wss: WebSocketService
66 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010067 super(fs, log, wss, 'host');
Bhavesh72ead492018-07-19 16:29:18 +053068 }
69
70 ngOnInit() {
71 this.init();
72 this.log.debug('Hosts Details Component initialized:', this.id);
73 }
74
75 ngOnDestroy() {
76 this.destroy();
77 this.log.debug('Hosts Details Component destroyed');
78 }
79
80 /**
81 * Details Panel Data Request on row selection changes
82 * Should be called whenever id changes
83 * If id is empty, no request is made
84 */
85 ngOnChanges() {
86 if (this.id === '') {
87 return '';
88 } else {
89 const query = {
90 'id': this.id
91 };
92 this.requestDetailsPanelData(query);
93 }
94 }
95
96}