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, OnInit, OnDestroy, OnChanges, Input, Output, EventEmitter } from '@angular/core'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 17 | import { |
| 18 | FnService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 19 | LionService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 20 | LogService, |
| 21 | DetailsPanelBaseImpl, |
| 22 | WebSocketService |
| 23 | } from 'gui2-fw-lib'; |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 24 | import { trigger, state, style, transition, animate } from '@angular/animations'; |
| 25 | |
| 26 | /** |
| 27 | * The details view when a flow is clicked from the flows view |
| 28 | * |
| 29 | * This is expected to be passed an 'id' and it makes a call |
| 30 | * to the WebSocket with a flowDetailsRequest, and gets back a |
| 31 | * flowDetailsResponse. |
| 32 | * |
| 33 | * The animated fly-in is controlled by the animation below |
| 34 | * The flowDetailsState is attached to flow-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-flowdetails', |
| 40 | templateUrl: './flowdetails.component.html', |
| 41 | styleUrls: [ |
| 42 | './flowdetails.component.css', |
| 43 | '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css' |
| 44 | ], |
| 45 | animations: [ |
| 46 | trigger('flowDetailsState', [ |
| 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 | export class FlowDetailsComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy, OnChanges { |
| 61 | |
| 62 | @Input() flowId: string; |
| 63 | @Input() appId: string; |
| 64 | |
| 65 | @Output() closeEvent = new EventEmitter<string>(); |
| 66 | |
| 67 | lionFn; // Function |
| 68 | |
| 69 | constructor( |
| 70 | protected fs: FnService, |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 71 | protected log: LogService, |
| 72 | protected wss: WebSocketService, |
| 73 | protected lion: LionService, |
| 74 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 75 | super(fs, log, wss, 'flow'); |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 76 | if (this.lion.ubercache.length === 0) { |
| 77 | this.lionFn = this.dummyLion; |
| 78 | this.lion.loadCbs.set('flowdetails', () => this.doLion()); |
| 79 | } else { |
| 80 | this.doLion(); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * There is a possibility that a previous selection |
| 86 | * is already registered for call - if so wait 100ms |
| 87 | * for it to deregister - this is because in the list of |
| 88 | * flows we might have selected one higher up the list and |
| 89 | * it is now being processed here before an older selection |
| 90 | * farther down the list has been removed |
| 91 | */ |
| 92 | ngOnInit() { |
| 93 | this.init(); |
| 94 | this.log.debug('Flow Details Component initialized:', this.flowId); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Stop listening to flowDetailsResponse on WebSocket |
| 99 | */ |
| 100 | ngOnDestroy() { |
| 101 | this.lion.loadCbs.delete('flowdetails'); |
| 102 | this.destroy(); |
| 103 | this.log.debug('Flow Details Component destroyed'); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Details Panel Data Request on row selection changes |
| 108 | * Should be called whenever flow id changes |
| 109 | * If flowId or appId is empty, no request is made |
| 110 | */ |
| 111 | ngOnChanges() { |
| 112 | if (this.flowId === '' || this.appId === '') { |
| 113 | return; |
| 114 | } else { |
| 115 | const query = { |
| 116 | 'flowId': this.flowId, |
| 117 | 'appId': this.appId |
| 118 | }; |
| 119 | this.requestDetailsPanelData(query); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Read the LION bundle for Flow and set up the lionFn |
| 125 | */ |
| 126 | doLion() { |
| 127 | this.lionFn = this.lion.bundle('core.view.Flow'); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Return immediate value of flow treatment on flow details request |
| 132 | */ |
| 133 | immed(treatmentData: any) { |
| 134 | if (treatmentData === undefined) { |
| 135 | return ''; |
| 136 | } else { |
| 137 | return treatmentData.immed; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Return clear deferred value of flow treatment on flow details request |
| 143 | */ |
| 144 | clearDef(treatmentData: any) { |
| 145 | if (treatmentData === undefined) { |
| 146 | return ''; |
| 147 | } else { |
| 148 | return treatmentData.clearDef; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | close() { |
| 153 | this.flowId = null; |
| 154 | this.appId = null; |
| 155 | this.closed = true; |
| 156 | this.closeEvent.emit(this.flowId); |
| 157 | } |
| 158 | } |