blob: 4a0d36e11657fccf9f4fca8a3bcbd16d5ff33c7f [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;
47 powerRange: string;
48 currentPower: string;
49 targetPower: string;
Andrea Campanellabdeeda12019-08-02 16:12:05 +020050 modulation: string;
Boyuan Yan6b23b382019-06-04 11:59:35 -070051 hasTargetPower: string;
52 serviceState: string;
53}
54
55interface FilterToggleState {
56 devId: string;
57 nzFilter: boolean;
58 showDelta: boolean;
59}
60
61const defaultPortPrefsState = {
62 nzFilter: 1,
63 showDelta: 0,
64};
65
66/**
67 * ONOS GUI -- Port View Component
68 */
69@Component({
70 selector: 'roadm-port',
71 templateUrl: './port.component.html',
72 styleUrls: ['./port.component.css', '../../../fw/widget/table.css', '../../../fw/widget/table.theme.css']
73})
74export class RoadmPortComponent extends TableBaseImpl implements OnInit, OnDestroy {
75 devId: string;
76 nzFilter: boolean = true;
77 showDelta: boolean = false;
78 prefsState = {};
79 toggleState: FilterToggleState;
80
81 powerForm: FormGroup;
Andrea Campanellabdeeda12019-08-02 16:12:05 +020082 modulationForm: FormGroup;
Boyuan Yan6b23b382019-06-04 11:59:35 -070083 SET_POWER_REQ = 'roadmSetTargetPowerRequest';
84 SET_POWER_RESP = 'roadmSetTargetPowerResponse';
Andrea Campanellabdeeda12019-08-02 16:12:05 +020085 SET_MODULATION = 'roadmSetModulationRequest';
Boyuan Yan6b23b382019-06-04 11:59:35 -070086
87 restorePrefsConfig; // Function
88
89 deviceTip = 'Show device table';
90
91 constructor(protected fs: FnService,
92 protected log: LogService,
93 protected ar: ActivatedRoute,
94 protected wss: WebSocketService,
Andrea Campanella7cbeb972019-07-25 15:05:59 +020095 protected prefs: PrefsService,
96 protected is: IconService,
Boyuan Yan6b23b382019-06-04 11:59:35 -070097 ) {
98 super(fs, log, wss, 'roadmPort');
99 this.ar.queryParams.subscribe(params => {
100 this.devId = params['devId'];
101
102 });
103
104 this.payloadParams = {
105 devId: this.devId
106 };
107
108 this.responseCallback = this.portResponseCb;
109 this.restorePrefsConfig = this.restoreConfigFromPrefs;
110
111 this.sortParams = {
112 firstCol: 'id',
113 firstDir: SortDir.desc,
114 secondCol: 'type',
115 secondDir: SortDir.asc,
116 };
Andrea Campanella7cbeb972019-07-25 15:05:59 +0200117
118 this.is.loadIconDef('switch');
Boyuan Yan6b23b382019-06-04 11:59:35 -0700119 }
120
121 ngOnInit() {
122 this.init();
123 this.createForm();
124 this.wss.bindHandlers(new Map<string, (data) => void>([
125 [this.SET_POWER_RESP, (data) => this.powerConfigCb(data)]
126 ]));
127 this.log.debug('RoadmPortComponent initialized');
128 }
129
130 createForm() {
131 this.powerForm = new FormGroup({
132 newPower: new FormControl(''),
133 });
Andrea Campanellabdeeda12019-08-02 16:12:05 +0200134 this.modulationForm = new FormGroup({
135 newModulation: new FormControl(''),
136 });
137 this.log.debug('Create Forms');
Boyuan Yan6b23b382019-06-04 11:59:35 -0700138 }
139
140 ngOnDestroy() {
141 this.destroy();
142 this.log.debug('RoadmPortComponent destroyed');
143 }
144
145 portResponseCb(data: RoadmPortTableResponse) {
146 this.log.debug('Roadm Port response received for ', data.roadmPorts.length, 'port');
147 }
148
149 isNz(): boolean {
150 return this.nzFilter;
151 }
152
153 isDelta(): boolean {
154 return this.showDelta;
155 }
156
157 toggleNZState(b?: any) {
158 if (b === undefined) {
159 this.nzFilter = !this.nzFilter;
160 } else {
161 this.nzFilter = b;
162 }
163 this.payloadParams = this.filterToggleState();
164 this.updatePrefsState('nzFilter', this.nzFilter);
165 this.forceRefesh();
166 }
167
168 toggleDeltaState(b?: any) {
169 if (b === undefined) {
170 this.showDelta = !this.showDelta;
171 } else {
172 this.showDelta = b;
173 }
174
175 this.payloadParams = this.filterToggleState();
176 this.updatePrefsState('showDelta', this.showDelta);
177 this.forceRefesh();
178 }
179
180 updatePrefsState(what: any, b: any) {
181 this.prefsState[what] = b ? 1 : 0;
182 this.prefs.setPrefs('port_prefs', this.prefsState);
183 }
184
185 filterToggleState(): FilterToggleState {
186 return this.toggleState = {
187 devId: this.devId,
188 nzFilter: this.nzFilter,
189 showDelta: this.showDelta,
190 };
191 }
192
193 forceRefesh() {
194 this.requestTableData();
195 }
196
197 restoreConfigFromPrefs() {
198 this.prefsState = this.prefs.asNumbers(
199 this.prefs.getPrefs('port_prefs', defaultPortPrefsState, )
200 );
201
202 this.log.debug('Port - Prefs State:', this.prefsState);
203 this.toggleDeltaState(this.prefsState['showDelta']);
204 this.toggleNZState(this.prefsState['nzFilter']);
205 }
206
207 submitPower(devId, port) {
208 this.log.debug('Set power of port ', port, 'in device ', devId, 'as value ', this.powerForm.value['newPower'], 'dBm.');
209 this.wss.sendEvent(this.SET_POWER_REQ, {
210 'targetPower': this.powerForm.value['newPower'],
211 'devId': devId,
212 'id': port,
213 });
214 }
215
Andrea Campanellabdeeda12019-08-02 16:12:05 +0200216 submitModulation(devId, port) {
217 this.log.debug('Set Modulation of port ', port, 'in device ', devId, 'as value ', this.modulationForm.value['newModulation']);
218 this.wss.sendEvent(this.SET_MODULATION, {
219 'modulation': this.modulationForm.value['newModulation'],
220 'devId': devId,
221 'id': port,
222 });
223 }
224
Boyuan Yan6b23b382019-06-04 11:59:35 -0700225 powerConfigCb(data) {
226 if (!data.valid) {
227 const info = 'The power config operation is failed. The reason is: \n' + data.message;
228 alert(info);
229 } else {
230 this.log.debug('The power config operation is successful!');
231 }
232 }
Sean Condonf20b8ef2019-08-13 16:45:52 +0100233
234 convertNumber(str: string): number {
235 return Number(str);
236 }
Boyuan Yan6b23b382019-06-04 11:59:35 -0700237}