blob: 3197285a7cf2dd8b674882e3d21401813e426109 [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';
17import { DetailsPanelBaseImpl } from '../../../../fw/widget/detailspanel.base';
18import { FnService } from '../../../../fw/util/fn.service';
19import { LoadingService } from '../../../../fw/layer/loading.service';
20import { LogService } from '../../../../log.service';
21import { WebSocketService } from '../../../../fw/remote/websocket.service';
22import { LionService } from '../../../../fw/util/lion.service';
23import { trigger, state, style, transition, animate } from '@angular/animations';
24
25/**
26 * The details view when a flow is clicked from the flows view
27 *
28 * This is expected to be passed an 'id' and it makes a call
29 * to the WebSocket with a flowDetailsRequest, and gets back a
30 * flowDetailsResponse.
31 *
32 * The animated fly-in is controlled by the animation below
33 * The flowDetailsState is attached to flow-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-flowdetails',
39 templateUrl: './flowdetails.component.html',
40 styleUrls: [
41 './flowdetails.component.css',
42 '../../../../fw/widget/panel.css', '../../../../fw/widget/panel-theme.css'
43 ],
44 animations: [
45 trigger('flowDetailsState', [
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 FlowDetailsComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy, OnChanges {
60
61 @Input() flowId: string;
62 @Input() appId: string;
63
64 @Output() closeEvent = new EventEmitter<string>();
65
66 lionFn; // Function
67
68 constructor(
69 protected fs: FnService,
70 protected ls: LoadingService,
71 protected log: LogService,
72 protected wss: WebSocketService,
73 protected lion: LionService,
74 ) {
75 super(fs, ls, log, wss, 'flow');
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}