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