blob: 9af7bf7535e2d5b61bddc52be86a520683c1fd71 [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
24} from 'gui2-fw-lib';
25import { 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',
73 styleUrls: ['./port.component.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
74})
75export class RoadmPortComponent extends TableBaseImpl implements OnInit, OnDestroy {
76 devId: string;
77 nzFilter: boolean = true;
78 showDelta: boolean = false;
79 prefsState = {};
80 toggleState: FilterToggleState;
81
82 powerForm: FormGroup;
Andrea Campanellabdeeda12019-08-02 16:12:05 +020083 modulationForm: FormGroup;
Andrea Campanella6ac13ff2019-08-29 16:51:14 -070084 freqForm: FormGroup;
Boyuan Yan6b23b382019-06-04 11:59:35 -070085 SET_POWER_REQ = 'roadmSetTargetPowerRequest';
86 SET_POWER_RESP = 'roadmSetTargetPowerResponse';
Andrea Campanellabdeeda12019-08-02 16:12:05 +020087 SET_MODULATION = 'roadmSetModulationRequest';
Andrea Campanella6ac13ff2019-08-29 16:51:14 -070088 SET_FREQUENCY = 'roadmSetFrequencyRequest';
Boyuan Yan6b23b382019-06-04 11:59:35 -070089
90 restorePrefsConfig; // Function
91
92 deviceTip = 'Show device table';
93
94 constructor(protected fs: FnService,
95 protected log: LogService,
96 protected ar: ActivatedRoute,
97 protected wss: WebSocketService,
Andrea Campanella7cbeb972019-07-25 15:05:59 +020098 protected prefs: PrefsService,
99 protected is: IconService,
Boyuan Yan6b23b382019-06-04 11:59:35 -0700100 ) {
101 super(fs, log, wss, 'roadmPort');
102 this.ar.queryParams.subscribe(params => {
103 this.devId = params['devId'];
104
105 });
106
107 this.payloadParams = {
108 devId: this.devId
109 };
110
111 this.responseCallback = this.portResponseCb;
112 this.restorePrefsConfig = this.restoreConfigFromPrefs;
113
114 this.sortParams = {
115 firstCol: 'id',
116 firstDir: SortDir.desc,
117 secondCol: 'type',
118 secondDir: SortDir.asc,
119 };
Andrea Campanella7cbeb972019-07-25 15:05:59 +0200120
121 this.is.loadIconDef('switch');
Boyuan Yan6b23b382019-06-04 11:59:35 -0700122 }
123
124 ngOnInit() {
125 this.init();
126 this.createForm();
127 this.wss.bindHandlers(new Map<string, (data) => void>([
128 [this.SET_POWER_RESP, (data) => this.powerConfigCb(data)]
129 ]));
130 this.log.debug('RoadmPortComponent initialized');
131 }
132
133 createForm() {
134 this.powerForm = new FormGroup({
135 newPower: new FormControl(''),
136 });
Andrea Campanellabdeeda12019-08-02 16:12:05 +0200137 this.modulationForm = new FormGroup({
138 newModulation: new FormControl(''),
139 });
Andrea Campanella6ac13ff2019-08-29 16:51:14 -0700140 this.freqForm = new FormGroup({
141 newFreq: new FormControl(''),
142 });
Andrea Campanellabdeeda12019-08-02 16:12:05 +0200143 this.log.debug('Create Forms');
Boyuan Yan6b23b382019-06-04 11:59:35 -0700144 }
145
146 ngOnDestroy() {
147 this.destroy();
148 this.log.debug('RoadmPortComponent destroyed');
149 }
150
151 portResponseCb(data: RoadmPortTableResponse) {
152 this.log.debug('Roadm Port response received for ', data.roadmPorts.length, 'port');
153 }
154
155 isNz(): boolean {
156 return this.nzFilter;
157 }
158
159 isDelta(): boolean {
160 return this.showDelta;
161 }
162
163 toggleNZState(b?: any) {
164 if (b === undefined) {
165 this.nzFilter = !this.nzFilter;
166 } else {
167 this.nzFilter = b;
168 }
169 this.payloadParams = this.filterToggleState();
170 this.updatePrefsState('nzFilter', this.nzFilter);
171 this.forceRefesh();
172 }
173
174 toggleDeltaState(b?: any) {
175 if (b === undefined) {
176 this.showDelta = !this.showDelta;
177 } else {
178 this.showDelta = b;
179 }
180
181 this.payloadParams = this.filterToggleState();
182 this.updatePrefsState('showDelta', this.showDelta);
183 this.forceRefesh();
184 }
185
186 updatePrefsState(what: any, b: any) {
187 this.prefsState[what] = b ? 1 : 0;
188 this.prefs.setPrefs('port_prefs', this.prefsState);
189 }
190
191 filterToggleState(): FilterToggleState {
192 return this.toggleState = {
193 devId: this.devId,
194 nzFilter: this.nzFilter,
195 showDelta: this.showDelta,
196 };
197 }
198
199 forceRefesh() {
200 this.requestTableData();
201 }
202
203 restoreConfigFromPrefs() {
204 this.prefsState = this.prefs.asNumbers(
205 this.prefs.getPrefs('port_prefs', defaultPortPrefsState, )
206 );
207
208 this.log.debug('Port - Prefs State:', this.prefsState);
209 this.toggleDeltaState(this.prefsState['showDelta']);
210 this.toggleNZState(this.prefsState['nzFilter']);
211 }
212
213 submitPower(devId, port) {
214 this.log.debug('Set power of port ', port, 'in device ', devId, 'as value ', this.powerForm.value['newPower'], 'dBm.');
215 this.wss.sendEvent(this.SET_POWER_REQ, {
216 'targetPower': this.powerForm.value['newPower'],
217 'devId': devId,
218 'id': port,
219 });
220 }
221
Andrea Campanellabdeeda12019-08-02 16:12:05 +0200222 submitModulation(devId, port) {
223 this.log.debug('Set Modulation of port ', port, 'in device ', devId, 'as value ', this.modulationForm.value['newModulation']);
224 this.wss.sendEvent(this.SET_MODULATION, {
225 'modulation': this.modulationForm.value['newModulation'],
226 'devId': devId,
227 'id': port,
228 });
229 }
230
Andrea Campanella6ac13ff2019-08-29 16:51:14 -0700231 submitFrequency(devId, port) {
232 this.log.debug('Set Frequency of port ', port, 'in device ', devId, 'as value ', this.freqForm.value['newFreq']);
233 this.wss.sendEvent(this.SET_FREQUENCY, {
234 'currFreq': this.freqForm.value['newFreq'],
235 'devId': devId,
236 'id': port,
237 });
238 }
239
Boyuan Yan6b23b382019-06-04 11:59:35 -0700240 powerConfigCb(data) {
241 if (!data.valid) {
242 const info = 'The power config operation is failed. The reason is: \n' + data.message;
243 alert(info);
244 } else {
245 this.log.debug('The power config operation is successful!');
246 }
247 }
Sean Condonf20b8ef2019-08-13 16:45:52 +0100248
249 convertNumber(str: string): number {
250 return Number(str);
251 }
Boyuan Yan6b23b382019-06-04 11:59:35 -0700252}