blob: 24913ab619964a5431e12d57f5bfdf6ffefc40b8 [file] [log] [blame]
Boyuan Yan6b23b382019-06-04 11:59:35 -07001/*
2 * Copyright 2019-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, OnDestroy, OnInit } from '@angular/core';
17import {
18 FnService,
19 LogService,
20 PrefsService,
21 WebSocketService,
Andrea Campanella7cbeb972019-07-25 15:05:59 +020022 IconService,
Boyuan Yan6b23b382019-06-04 11:59:35 -070023 SortDir, TableBaseImpl, TableResponse
Sean Condon98b6ddb2019-12-24 08:07:40 +000024} from '../../../../../../web/gui2-fw-lib/public_api';
Boyuan Yan6b23b382019-06-04 11:59:35 -070025import { ActivatedRoute } from '@angular/router';
26import {FormGroup, FormControl} from '@angular/forms';
27
28/**
29 * Model of the response from WebSocket
30 */
31interface RoadmPortTableResponse extends TableResponse {
32 roadmPorts: RoadmPort[];
33}
34
35/**
36 * Model of the roadm ports returned from the WebSocket
37 */
38interface RoadmPort {
39 id: string;
40 reversePort: string;
41 name: string;
42 type: string;
43 enabled: string;
44 minFreq: string;
45 maxFreq: string;
46 grid: string;
Andrea Campanella02e2eb4e2019-08-29 11:46:57 -070047 currFreq: string;
Boyuan Yan6b23b382019-06-04 11:59:35 -070048 powerRange: string;
49 currentPower: string;
50 targetPower: string;
Andrea Campanellabdeeda12019-08-02 16:12:05 +020051 modulation: string;
Boyuan Yan6b23b382019-06-04 11:59:35 -070052 hasTargetPower: string;
53 serviceState: string;
54}
55
56interface FilterToggleState {
57 devId: string;
58 nzFilter: boolean;
59 showDelta: boolean;
60}
61
62const defaultPortPrefsState = {
63 nzFilter: 1,
64 showDelta: 0,
65};
66
67/**
68 * ONOS GUI -- Port View Component
69 */
70@Component({
71 selector: 'roadm-port',
72 templateUrl: './port.component.html',
Sean Condon98b6ddb2019-12-24 08:07:40 +000073 styleUrls: ['./port.component.css',
74 '../../../../../../web/gui2-fw-lib/lib/widget/table.theme.css',
75 '../../../../../../web/gui2-fw-lib/lib/widget/table.css',
76 ]
Boyuan Yan6b23b382019-06-04 11:59:35 -070077})
78export class RoadmPortComponent extends TableBaseImpl implements OnInit, OnDestroy {
79 devId: string;
80 nzFilter: boolean = true;
81 showDelta: boolean = false;
82 prefsState = {};
83 toggleState: FilterToggleState;
84
85 powerForm: FormGroup;
Andrea Campanellabdeeda12019-08-02 16:12:05 +020086 modulationForm: FormGroup;
Andrea Campanella6ac13ff2019-08-29 16:51:14 -070087 freqForm: FormGroup;
Boyuan Yan6b23b382019-06-04 11:59:35 -070088 SET_POWER_REQ = 'roadmSetTargetPowerRequest';
89 SET_POWER_RESP = 'roadmSetTargetPowerResponse';
Andrea Campanellabdeeda12019-08-02 16:12:05 +020090 SET_MODULATION = 'roadmSetModulationRequest';
Andrea Campanella6ac13ff2019-08-29 16:51:14 -070091 SET_FREQUENCY = 'roadmSetFrequencyRequest';
Boyuan Yan6b23b382019-06-04 11:59:35 -070092
93 restorePrefsConfig; // Function
94
95 deviceTip = 'Show device table';
96
97 constructor(protected fs: FnService,
98 protected log: LogService,
99 protected ar: ActivatedRoute,
100 protected wss: WebSocketService,
Andrea Campanella7cbeb972019-07-25 15:05:59 +0200101 protected prefs: PrefsService,
102 protected is: IconService,
Boyuan Yan6b23b382019-06-04 11:59:35 -0700103 ) {
104 super(fs, log, wss, 'roadmPort');
105 this.ar.queryParams.subscribe(params => {
106 this.devId = params['devId'];
107
108 });
109
110 this.payloadParams = {
111 devId: this.devId
112 };
113
114 this.responseCallback = this.portResponseCb;
115 this.restorePrefsConfig = this.restoreConfigFromPrefs;
116
117 this.sortParams = {
118 firstCol: 'id',
119 firstDir: SortDir.desc,
120 secondCol: 'type',
121 secondDir: SortDir.asc,
122 };
Andrea Campanella7cbeb972019-07-25 15:05:59 +0200123
124 this.is.loadIconDef('switch');
Boyuan Yan6b23b382019-06-04 11:59:35 -0700125 }
126
127 ngOnInit() {
128 this.init();
129 this.createForm();
130 this.wss.bindHandlers(new Map<string, (data) => void>([
131 [this.SET_POWER_RESP, (data) => this.powerConfigCb(data)]
132 ]));
133 this.log.debug('RoadmPortComponent initialized');
134 }
135
136 createForm() {
137 this.powerForm = new FormGroup({
138 newPower: new FormControl(''),
139 });
Andrea Campanellabdeeda12019-08-02 16:12:05 +0200140 this.modulationForm = new FormGroup({
141 newModulation: new FormControl(''),
142 });
Andrea Campanella6ac13ff2019-08-29 16:51:14 -0700143 this.freqForm = new FormGroup({
144 newFreq: new FormControl(''),
145 });
Andrea Campanellabdeeda12019-08-02 16:12:05 +0200146 this.log.debug('Create Forms');
Boyuan Yan6b23b382019-06-04 11:59:35 -0700147 }
148
149 ngOnDestroy() {
150 this.destroy();
151 this.log.debug('RoadmPortComponent destroyed');
152 }
153
154 portResponseCb(data: RoadmPortTableResponse) {
155 this.log.debug('Roadm Port response received for ', data.roadmPorts.length, 'port');
156 }
157
158 isNz(): boolean {
159 return this.nzFilter;
160 }
161
162 isDelta(): boolean {
163 return this.showDelta;
164 }
165
166 toggleNZState(b?: any) {
167 if (b === undefined) {
168 this.nzFilter = !this.nzFilter;
169 } else {
170 this.nzFilter = b;
171 }
172 this.payloadParams = this.filterToggleState();
173 this.updatePrefsState('nzFilter', this.nzFilter);
174 this.forceRefesh();
175 }
176
177 toggleDeltaState(b?: any) {
178 if (b === undefined) {
179 this.showDelta = !this.showDelta;
180 } else {
181 this.showDelta = b;
182 }
183
184 this.payloadParams = this.filterToggleState();
185 this.updatePrefsState('showDelta', this.showDelta);
186 this.forceRefesh();
187 }
188
189 updatePrefsState(what: any, b: any) {
190 this.prefsState[what] = b ? 1 : 0;
191 this.prefs.setPrefs('port_prefs', this.prefsState);
192 }
193
194 filterToggleState(): FilterToggleState {
195 return this.toggleState = {
196 devId: this.devId,
197 nzFilter: this.nzFilter,
198 showDelta: this.showDelta,
199 };
200 }
201
202 forceRefesh() {
203 this.requestTableData();
204 }
205
206 restoreConfigFromPrefs() {
207 this.prefsState = this.prefs.asNumbers(
208 this.prefs.getPrefs('port_prefs', defaultPortPrefsState, )
209 );
210
211 this.log.debug('Port - Prefs State:', this.prefsState);
212 this.toggleDeltaState(this.prefsState['showDelta']);
213 this.toggleNZState(this.prefsState['nzFilter']);
214 }
215
216 submitPower(devId, port) {
217 this.log.debug('Set power of port ', port, 'in device ', devId, 'as value ', this.powerForm.value['newPower'], 'dBm.');
218 this.wss.sendEvent(this.SET_POWER_REQ, {
219 'targetPower': this.powerForm.value['newPower'],
220 'devId': devId,
221 'id': port,
222 });
223 }
224
Andrea Campanellabdeeda12019-08-02 16:12:05 +0200225 submitModulation(devId, port) {
226 this.log.debug('Set Modulation of port ', port, 'in device ', devId, 'as value ', this.modulationForm.value['newModulation']);
227 this.wss.sendEvent(this.SET_MODULATION, {
228 'modulation': this.modulationForm.value['newModulation'],
229 'devId': devId,
230 'id': port,
231 });
232 }
233
Andrea Campanella6ac13ff2019-08-29 16:51:14 -0700234 submitFrequency(devId, port) {
235 this.log.debug('Set Frequency of port ', port, 'in device ', devId, 'as value ', this.freqForm.value['newFreq']);
236 this.wss.sendEvent(this.SET_FREQUENCY, {
237 'currFreq': this.freqForm.value['newFreq'],
238 'devId': devId,
239 'id': port,
240 });
241 }
242
Boyuan Yan6b23b382019-06-04 11:59:35 -0700243 powerConfigCb(data) {
244 if (!data.valid) {
245 const info = 'The power config operation is failed. The reason is: \n' + data.message;
246 alert(info);
247 } else {
248 this.log.debug('The power config operation is successful!');
249 }
250 }
Sean Condonf20b8ef2019-08-13 16:45:52 +0100251
252 convertNumber(str: string): number {
253 return Number(str);
254 }
Boyuan Yan6b23b382019-06-04 11:59:35 -0700255}