Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 1 | /* |
| 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 | import { Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core'; |
| 17 | import { animate, state, style, transition, trigger } from '@angular/animations'; |
| 18 | import { DetailsPanelBaseImpl } from '../../../fw/widget/detailspanel.base'; |
| 19 | import { FnService } from '../../../fw/util/fn.service'; |
| 20 | import { LoadingService } from '../../../fw/layer/loading.service'; |
| 21 | import { LogService } from '../../../log.service'; |
| 22 | import { IconService } from '../../../fw/svg/icon.service'; |
| 23 | import { 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 | }) |
| 56 | export 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 | } |